Escaping dot and dollar signs in the mongo <--> gson converter, adding success message to copy command and preparing to rename gson --> flatfile.
This commit is contained in:
parent
4d6c73f1d6
commit
5e326ed672
@ -24,7 +24,9 @@ public class ConfServer extends SimpleConfig
|
||||
public static String serverid = UUID.randomUUID().toString();
|
||||
|
||||
public static Map<String, String> alias2uri = MUtil.map(
|
||||
"default", "gson://./mstore"
|
||||
"default", "flatfile",
|
||||
"flatfile", "flatfile://mstore",
|
||||
"mongodb", "mongodb://localhost:27017/mstore"
|
||||
);
|
||||
|
||||
public static String dburi = "default";
|
||||
|
@ -57,6 +57,7 @@ public class CmdMCoreMStoreCopydb extends MCoreCommand
|
||||
int countCollTotal = collnames.size();
|
||||
|
||||
// Do it!
|
||||
long before = System.currentTimeMillis();
|
||||
msg("<i>Now copying database with <h>%d <i>collections.", countCollTotal);
|
||||
for (String collname : fromDb.getCollnames())
|
||||
{
|
||||
@ -72,6 +73,9 @@ public class CmdMCoreMStoreCopydb extends MCoreCommand
|
||||
toDriver.save(toColl, id, data.getKey());
|
||||
}
|
||||
}
|
||||
long after = System.currentTimeMillis();
|
||||
long duration = after - before;
|
||||
msg("<g>The copy is now complete. <i>It took <h>%dms<i>.", duration);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package com.massivecraft.mcore.store;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.massivecraft.mcore.xlib.bson.types.ObjectId;
|
||||
import com.massivecraft.mcore.xlib.gson.JsonArray;
|
||||
import com.massivecraft.mcore.xlib.gson.JsonElement;
|
||||
@ -14,17 +16,34 @@ import com.massivecraft.mcore.xlib.mongodb.DBObject;
|
||||
|
||||
public final class MongoGsonConverter
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static final String DOT_NORMAL = ".";
|
||||
public static final String DOT_MONGO = "<dot>";
|
||||
|
||||
public static final String DOLLAR_NORMAL = "$";
|
||||
public static final String DOLLAR_MONGO = "<dollar>";
|
||||
|
||||
// -------------------------------------------- //
|
||||
// GSON 2 MONGO
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static String gson2MongoKey(String key)
|
||||
{
|
||||
key = StringUtils.replace(key, DOT_NORMAL, DOT_MONGO);
|
||||
key = StringUtils.replace(key, DOLLAR_NORMAL, DOLLAR_MONGO);
|
||||
return key;
|
||||
}
|
||||
|
||||
public static BasicDBObject gson2MongoObject(JsonElement inElement)
|
||||
{
|
||||
JsonObject in = inElement.getAsJsonObject();
|
||||
BasicDBObject out = new BasicDBObject();
|
||||
for (Entry<String, JsonElement> entry : in.entrySet())
|
||||
{
|
||||
String key = entry.getKey();
|
||||
String key = gson2MongoKey(entry.getKey());
|
||||
JsonElement val = entry.getValue();
|
||||
if (val.isJsonArray())
|
||||
{
|
||||
@ -79,6 +98,13 @@ public final class MongoGsonConverter
|
||||
// MONGO 2 GSON
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static String mongo2GsonKey(String key)
|
||||
{
|
||||
key = StringUtils.replace(key, DOT_MONGO, DOT_NORMAL);
|
||||
key = StringUtils.replace(key, DOLLAR_MONGO, DOLLAR_NORMAL);
|
||||
return key;
|
||||
}
|
||||
|
||||
public static JsonObject mongo2GsonObject(DBObject inObject)
|
||||
{
|
||||
if (!(inObject instanceof BasicDBObject)) throw new IllegalArgumentException("Expected BasicDBObject as argument type!");
|
||||
@ -87,7 +113,7 @@ public final class MongoGsonConverter
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
for (Entry<String, Object> entry : in.entrySet())
|
||||
{
|
||||
String key = entry.getKey();
|
||||
String key = mongo2GsonKey(entry.getKey());
|
||||
Object val = entry.getValue();
|
||||
if (val instanceof BasicDBList)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user