use of com.massivecraft.massivecore.xlib.mongodb.DBCollection 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.DBCollection 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.DBCollection 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.DBCollection in project MassiveCore by MassiveCraft.
the class DriverMongo method getIds.
@Override
public Collection<String> getIds(Coll<?> coll) {
List<String> ret = null;
DBCollection dbcoll = fixColl(coll);
DBCursor cursor = dbcoll.find(dboEmpty, dboKeysId);
try {
ret = new ArrayList<>(cursor.count());
while (cursor.hasNext()) {
Object remoteId = cursor.next().get(ID_FIELD);
ret.add(remoteId.toString());
}
} finally {
cursor.close();
}
return ret;
}
use of com.massivecraft.massivecore.xlib.mongodb.DBCollection 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