Beispiel #1
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;
   if (!found.containsField(MTIME_FIELD))
     return null; // This should not happen! But better to ignore than crash?
   return found.getLong(MTIME_FIELD);
 }
Beispiel #2
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;

    Long mtime = ((Number) raw.removeField(MTIME_FIELD)).longValue();
    raw.removeField(ID_FIELD);

    JsonElement element = GsonMongoConverter.mongo2GsonObject(raw);

    return new SimpleEntry<JsonElement, Long>(element, mtime);
  }
Beispiel #3
0
  @Override
  public Long save(Coll<?> coll, String id, JsonElement data) {
    DBCollection dbcoll = fixColl(coll);

    BasicDBObject dbo = GsonMongoConverter.gson2MongoObject(data);
    Long mtime = System.currentTimeMillis();
    dbo.put(MTIME_FIELD, mtime);
    dbo.put(ID_FIELD, id);

    dbcoll.save(dbo);

    return mtime;
  }
Beispiel #4
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);
        if (!raw.containsField(MTIME_FIELD))
          continue; // This should not happen! But better to ignore than crash?
        Long mtime = raw.getLong(MTIME_FIELD);
        ret.put(remoteId.toString(), mtime);
      }
    } finally {
      cursor.close();
    }

    return ret;
  }