示例#1
0
  @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<String, Long>(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 0. Probably a manual database addition by the
        // server owner.
        long mtime = raw.getLong(MTIME_FIELD, 0);

        ret.put(remoteId.toString(), mtime);
      }
    } finally {
      cursor.close();
    }

    return ret;
  }
示例#2
0
  @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 null;

    // 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;
  }
示例#3
0
  @Override
  public Long save(Coll<?> coll, String id, JsonElement 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;
  }
示例#4
0
  @Override
  public Entry<JsonElement, Long> load(Coll<?> coll, String id) {
    DBCollection dbcoll = fixColl(coll);
    BasicDBObject raw = (BasicDBObject) dbcoll.findOne(new BasicDBObject(ID_FIELD, id));
    if (raw == null) return null;

    raw.removeField(ID_FIELD);
    Long mtime = 0L;
    Object mtimeObject = raw.removeField(MTIME_FIELD);
    if (mtimeObject != null) {
      mtime = ((Number) mtimeObject).longValue();
    }

    JsonElement element = GsonMongoConverter.mongo2GsonObject(raw);

    return new SimpleEntry<JsonElement, Long>(element, mtime);
  }
示例#5
0
  @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<String>(cursor.count());
      while (cursor.hasNext()) {
        Object remoteId = cursor.next().get(ID_FIELD);
        ret.add(remoteId.toString());
      }
    } finally {
      cursor.close();
    }

    return ret;
  }
示例#6
0
 @Override
 public boolean containsId(Coll<?> coll, String id) {
   DBCollection dbcoll = fixColl(coll);
   DBCursor cursor = dbcoll.find(new BasicDBObject(ID_FIELD, id));
   return cursor.count() != 0;
 }
示例#7
0
 @Override
 public void delete(Coll<?> coll, String id) {
   DBCollection dbcoll = fixColl(coll);
   dbcoll.remove(
       new BasicDBObject(ID_FIELD, id), MassiveCoreMConf.get().getMongoDbWriteConcernDelete());
 }