Search in sources :

Example 1 with DBCollection

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;
}
Also used : DBCollection(com.massivecraft.massivecore.xlib.mongodb.DBCollection) BasicDBObject(com.massivecraft.massivecore.xlib.mongodb.BasicDBObject)

Example 2 with DBCollection

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;
}
Also used : DBCollection(com.massivecraft.massivecore.xlib.mongodb.DBCollection) BasicDBObject(com.massivecraft.massivecore.xlib.mongodb.BasicDBObject)

Example 3 with DBCollection

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());
}
Also used : DBCollection(com.massivecraft.massivecore.xlib.mongodb.DBCollection) BasicDBObject(com.massivecraft.massivecore.xlib.mongodb.BasicDBObject)

Example 4 with DBCollection

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;
}
Also used : DBCollection(com.massivecraft.massivecore.xlib.mongodb.DBCollection) DBCursor(com.massivecraft.massivecore.xlib.mongodb.DBCursor) JsonObject(com.massivecraft.massivecore.xlib.gson.JsonObject) BasicDBObject(com.massivecraft.massivecore.xlib.mongodb.BasicDBObject)

Example 5 with DBCollection

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;
}
Also used : DBCollection(com.massivecraft.massivecore.xlib.mongodb.DBCollection) BasicDBObject(com.massivecraft.massivecore.xlib.mongodb.BasicDBObject) DBCursor(com.massivecraft.massivecore.xlib.mongodb.DBCursor) JsonObject(com.massivecraft.massivecore.xlib.gson.JsonObject) BasicDBObject(com.massivecraft.massivecore.xlib.mongodb.BasicDBObject)

Aggregations

BasicDBObject (com.massivecraft.massivecore.xlib.mongodb.BasicDBObject)8 DBCollection (com.massivecraft.massivecore.xlib.mongodb.DBCollection)8 DBCursor (com.massivecraft.massivecore.xlib.mongodb.DBCursor)4 JsonObject (com.massivecraft.massivecore.xlib.gson.JsonObject)3 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 Entry (java.util.Map.Entry)1