Package com.massivecraft.mcore.xlib.mongodb

Examples of com.massivecraft.mcore.xlib.mongodb.DBCollection


  }
 
  @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;
  }
View Full Code Here


  }
 
  @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);
  }
View Full Code Here

  @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())
      {
View Full Code Here

  @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())
      {
View Full Code Here

  }

  @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);
   
View Full Code Here

  }

  @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;
  }
View Full Code Here

TOP

Related Classes of com.massivecraft.mcore.xlib.mongodb.DBCollection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.