use of com.massivecraft.massivecore.xlib.mongodb.BasicDBObject in project MassiveCore by MassiveCraft.
the class DriverMongo method loadRaw.
public Entry<JsonObject, Long> loadRaw(BasicDBObject raw) {
if (raw == null)
return new SimpleEntry<>(null, 0L);
// Throw away the id field
raw.removeField(ID_FIELD);
// In case there is no _mtime set we assume 1337.
// NOTE: We can not use 0 since that one is reserved for errors.
// Probably a manual database addition by the server owner.
long mtime = 1337L;
Object mtimeObject = raw.removeField(MTIME_FIELD);
if (mtimeObject != null) {
mtime = ((Number) mtimeObject).longValue();
}
// Convert MongoDB --> GSON
JsonObject element = GsonMongoConverter.mongo2GsonObject(raw);
return new SimpleEntry<>(element, mtime);
}
use of com.massivecraft.massivecore.xlib.mongodb.BasicDBObject in project MassiveCore by MassiveCraft.
the class DriverMongo method getMtime.
@Override
public long getMtime(Coll<?> coll, String id) {
DBCollection dbcoll = fixColl(coll);
BasicDBObject found = (BasicDBObject) dbcoll.findOne(new BasicDBObject(ID_FIELD, id), dboKeysMtime);
if (found == null)
return 0;
// In case there is no _mtime set we assume 1337.
// NOTE: We can not use 0 since that one is reserved for errors.
// Probably a manual database addition by the server owner.
long mtime = found.getLong(MTIME_FIELD, 1337L);
return mtime;
}
use of com.massivecraft.massivecore.xlib.mongodb.BasicDBObject in project MassiveCore by MassiveCraft.
the class DriverMongo method save.
@Override
public long save(Coll<?> coll, String id, JsonObject data) {
DBCollection dbcoll = fixColl(coll);
BasicDBObject dbo = new BasicDBObject();
long mtime = System.currentTimeMillis();
dbo.put(ID_FIELD, id);
dbo.put(MTIME_FIELD, mtime);
GsonMongoConverter.gson2MongoObject(data, dbo);
dbcoll.save(dbo, MassiveCoreMConf.get().getMongoDbWriteConcernSave());
return mtime;
}
use of com.massivecraft.massivecore.xlib.mongodb.BasicDBObject in project MassiveCore by MassiveCraft.
the class DriverMongo method delete.
@Override
public void delete(Coll<?> coll, String id) {
DBCollection dbcoll = fixColl(coll);
dbcoll.remove(new BasicDBObject(ID_FIELD, id), MassiveCoreMConf.get().getMongoDbWriteConcernDelete());
}
use of com.massivecraft.massivecore.xlib.mongodb.BasicDBObject in project MassiveCore by MassiveCraft.
the class DriverMongo method getId2mtime.
@Override
public Map<String, Long> getId2mtime(Coll<?> coll) {
Map<String, Long> ret = null;
DBCollection dbcoll = fixColl(coll);
DBCursor cursor = dbcoll.find(dboEmpty, dboKeysIdandMtime);
try {
ret = new HashMap<>(cursor.count());
while (cursor.hasNext()) {
BasicDBObject raw = (BasicDBObject) cursor.next();
Object remoteId = raw.get(ID_FIELD);
// In case there is no _mtime set we assume 1337.
// NOTE: We can not use 0 since that one is reserved for errors.
// Probably a manual database addition by the server owner.
long mtime = raw.getLong(MTIME_FIELD, 1337L);
ret.put(remoteId.toString(), mtime);
}
} finally {
cursor.close();
}
return ret;
}
Aggregations