Package com.massivecraft.mcore.xlib.mongodb

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


        }

        @Override
        public void serialize(Object obj, StringBuilder buf) {
            BSONTimestamp t = (BSONTimestamp) obj;
            BasicDBObject temp = new BasicDBObject();
            temp.put("t", Integer.valueOf(t.getTime()));
            temp.put("i", Integer.valueOf(t.getInc()));
            BasicDBObject timestampObj = new BasicDBObject();
            timestampObj.put("$timestamp", temp);
            serializer.serialize(timestampObj, buf);
        }
View Full Code Here


        @Override
        public void serialize(Object obj,  StringBuilder buf) {
            Date d = (Date) obj;
            serializer.serialize(
                    new BasicDBObject("$date", d.getTime()), buf);
        }
View Full Code Here

        BinarySerializerBase(ObjectSerializer serializer) {
            super(serializer);
        }

        protected void serialize(byte[] bytes, byte type, StringBuilder buf) {
            DBObject temp = new BasicDBObject();
            temp.put("$binary",
                    (new Base64Codec()).encode(bytes));
            temp.put("$type", type);
            serializer.serialize(temp, buf);
        }
View Full Code Here

  }
 
  public static BasicDBObject gson2MongoObject(JsonElement inElement)
  {
    JsonObject in = inElement.getAsJsonObject();
    BasicDBObject out = new BasicDBObject();
    for (Entry<String, JsonElement> entry : in.entrySet())
    {
      String key = gson2MongoKey(entry.getKey());
      JsonElement val = entry.getValue();
      if (val.isJsonArray())
      {
        out.put(key, gson2MongoArray(val));
      }
      else if (val.isJsonObject())
      {
        out.put(key, gson2MongoObject(val));
      }
      else
      {
        out.put(key, gson2MongoPrimitive(val));
      }
    }
    return out;
  }
View Full Code Here

  }
 
  public static JsonObject mongo2GsonObject(DBObject inObject)
  {
    if (!(inObject instanceof BasicDBObject)) throw new IllegalArgumentException("Expected BasicDBObject as argument type!");
    BasicDBObject in = (BasicDBObject)inObject;
   
    JsonObject jsonObject = new JsonObject();
    for (Entry<String, Object> entry : in.entrySet())
    {
      String key = mongo2GsonKey(entry.getKey());
      Object val = entry.getValue();
      if (val instanceof BasicDBList)
      {
View Full Code Here

 
  @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

    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
    {
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);
   
    JsonElement element = GsonMongoConverter.mongo2GsonObject(raw);
   
    return new SimpleEntry<JsonElement, Long>(element, mtime);
  }
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.BasicDBObject

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.