Copydb command access check, remote mtime defaults to 0, mote mtime field to the top.
This commit is contained in:
parent
16fc6b94e5
commit
fa69405239
@ -78,6 +78,14 @@ public class CmdMCoreMStoreCopydb extends MCommand
|
|||||||
|
|
||||||
Collection<String> ids = fromDriver.getIds(fromColl);
|
Collection<String> ids = fromDriver.getIds(fromColl);
|
||||||
msg("<i>Now copying collection <h>%d/%d %s <i>with <h>%d <i>documents.", countCollCurrent, countCollTotal, collname, ids.size());
|
msg("<i>Now copying collection <h>%d/%d %s <i>with <h>%d <i>documents.", countCollCurrent, countCollTotal, collname, ids.size());
|
||||||
|
|
||||||
|
// Do a load check to verify we have access to this folder.
|
||||||
|
if (ids.size() > 0 && fromDriver.load(fromColl, ids.iterator().next()) == null)
|
||||||
|
{
|
||||||
|
msg("<b>Skipping <h>%s <b>since could not load data.", collname);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (String id : ids)
|
for (String id : ids)
|
||||||
{
|
{
|
||||||
Entry<JsonElement, Long> data = fromDriver.load(fromColl, id);
|
Entry<JsonElement, Long> data = fromDriver.load(fromColl, id);
|
||||||
|
@ -70,10 +70,14 @@ public class DriverMongo extends DriverAbstract
|
|||||||
public Long getMtime(Coll<?> coll, String id)
|
public Long getMtime(Coll<?> coll, String id)
|
||||||
{
|
{
|
||||||
DBCollection dbcoll = fixColl(coll);
|
DBCollection dbcoll = fixColl(coll);
|
||||||
|
|
||||||
BasicDBObject found = (BasicDBObject)dbcoll.findOne(new BasicDBObject(ID_FIELD, id), dboKeysMtime);
|
BasicDBObject found = (BasicDBObject)dbcoll.findOne(new BasicDBObject(ID_FIELD, id), dboKeysMtime);
|
||||||
if (found == null) return null;
|
if (found == null) return null;
|
||||||
if ( ! found.containsField(MTIME_FIELD)) return null; // This should not happen! But better to ignore than crash?
|
|
||||||
return found.getLong(MTIME_FIELD);
|
// In case there is no _mtime set we assume 0. Probably a manual database addition by the server owner.
|
||||||
|
long mtime = found.getLong(MTIME_FIELD, 0);
|
||||||
|
|
||||||
|
return mtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -116,8 +120,10 @@ public class DriverMongo extends DriverAbstract
|
|||||||
{
|
{
|
||||||
BasicDBObject raw = (BasicDBObject)cursor.next();
|
BasicDBObject raw = (BasicDBObject)cursor.next();
|
||||||
Object remoteId = raw.get(ID_FIELD);
|
Object remoteId = raw.get(ID_FIELD);
|
||||||
if ( ! raw.containsField(MTIME_FIELD)) continue; // This should not happen! But better to ignore than crash?
|
|
||||||
Long mtime = raw.getLong(MTIME_FIELD);
|
// In case there is no _mtime set we assume 0. Probably a manual database addition by the server owner.
|
||||||
|
long mtime = raw.getLong(MTIME_FIELD, 0);
|
||||||
|
|
||||||
ret.put(remoteId.toString(), mtime);
|
ret.put(remoteId.toString(), mtime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,8 +142,12 @@ public class DriverMongo extends DriverAbstract
|
|||||||
BasicDBObject raw = (BasicDBObject)dbcoll.findOne(new BasicDBObject(ID_FIELD, id));
|
BasicDBObject raw = (BasicDBObject)dbcoll.findOne(new BasicDBObject(ID_FIELD, id));
|
||||||
if (raw == null) return null;
|
if (raw == null) return null;
|
||||||
|
|
||||||
Long mtime = ((Number)raw.removeField(MTIME_FIELD)).longValue();
|
Long mtime = 0L;
|
||||||
raw.removeField(ID_FIELD);
|
Object mtimeObject = raw.removeField(MTIME_FIELD);
|
||||||
|
if (mtimeObject != null)
|
||||||
|
{
|
||||||
|
mtime = ((Number)mtimeObject).longValue();
|
||||||
|
}
|
||||||
|
|
||||||
JsonElement element = GsonMongoConverter.mongo2GsonObject(raw);
|
JsonElement element = GsonMongoConverter.mongo2GsonObject(raw);
|
||||||
|
|
||||||
@ -149,10 +159,13 @@ public class DriverMongo extends DriverAbstract
|
|||||||
{
|
{
|
||||||
DBCollection dbcoll = fixColl(coll);
|
DBCollection dbcoll = fixColl(coll);
|
||||||
|
|
||||||
BasicDBObject dbo = GsonMongoConverter.gson2MongoObject(data);
|
BasicDBObject dbo = new BasicDBObject();
|
||||||
|
|
||||||
Long mtime = System.currentTimeMillis();
|
Long mtime = System.currentTimeMillis();
|
||||||
dbo.put(MTIME_FIELD, mtime);
|
|
||||||
dbo.put(ID_FIELD, id);
|
dbo.put(ID_FIELD, id);
|
||||||
|
dbo.put(MTIME_FIELD, mtime);
|
||||||
|
|
||||||
|
GsonMongoConverter.gson2MongoObject(data, dbo);
|
||||||
|
|
||||||
dbcoll.save(dbo);
|
dbcoll.save(dbo);
|
||||||
|
|
||||||
|
@ -38,10 +38,9 @@ public final class GsonMongoConverter
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BasicDBObject gson2MongoObject(JsonElement inElement)
|
public static BasicDBObject gson2MongoObject(JsonElement inElement, BasicDBObject out)
|
||||||
{
|
{
|
||||||
JsonObject in = inElement.getAsJsonObject();
|
JsonObject in = inElement.getAsJsonObject();
|
||||||
BasicDBObject out = new BasicDBObject();
|
|
||||||
for (Entry<String, JsonElement> entry : in.entrySet())
|
for (Entry<String, JsonElement> entry : in.entrySet())
|
||||||
{
|
{
|
||||||
String key = gson2MongoKey(entry.getKey());
|
String key = gson2MongoKey(entry.getKey());
|
||||||
@ -62,6 +61,11 @@ public final class GsonMongoConverter
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BasicDBObject gson2MongoObject(JsonElement inElement)
|
||||||
|
{
|
||||||
|
return gson2MongoObject(inElement, new BasicDBObject());
|
||||||
|
}
|
||||||
|
|
||||||
public static BasicDBList gson2MongoArray(JsonElement inElement)
|
public static BasicDBList gson2MongoArray(JsonElement inElement)
|
||||||
{
|
{
|
||||||
JsonArray in = inElement.getAsJsonArray();
|
JsonArray in = inElement.getAsJsonArray();
|
||||||
|
Loading…
Reference in New Issue
Block a user