Package com.mongodb

Examples of com.mongodb.DBCollection.save()


    @Override
    public Key<Metric> save(Metric entity) {
        DBCollection collection = getCollection(entity.getAccountId());
        DBObject dbObject = entity.toDBObject();
        collection.save(dbObject);
        entity.setId((ObjectId) dbObject.get("_id"));
        return new Key<>(Metric.class, entity.getId());
    }

    @Override
View Full Code Here


    @Override
        public Key<Metric> save(Metric entity, WriteConcern wc) {
        DBCollection collection = getCollection(entity.getAccountId());
        DBObject dbObject = entity.toDBObject();
        collection.save(dbObject, wc);
        entity.setId((ObjectId) dbObject.get("_id"));
        return new Key<>(Metric.class, entity.getId());
    }

    public Metric get(ObjectId id, String accountId) {
View Full Code Here

            Save.execute(parent);
        } else {
            doc.runCallbacks(Callbacks.Callback.before_save);
            //we cannot call doc.collection().remove() directly,because of the dam inheritance of static methods in java
            DBCollection collection = (DBCollection) staticMethod(doc.getClass(), "collection");
            collection.save(new BasicDBObject(doc.attributes()));
            doc.runCallbacks(Callbacks.Callback.after_save);
        }

        return true;
    }
View Full Code Here

        DBObject object = system.findOne();
        if (object == null) {
            object = new BasicDBObject();
        }
        object.put("next-id", Long.toString(serialNumber));
        system.save(object);
        LOG.info("serial number written: " + serialNumber);
    }

    public long readSerialNumber() {
        final DBCollection system = db.getCollection("serialnumbers");
View Full Code Here

    List<DBObject> albums = new ArrayList<DBObject>();
    artist.put("albums", albums);

    DB db = new Mongo().getDB("testdb");
    DBCollection dbCollection = db.getCollection("testCollection");
    dbCollection.save(artist);
   
    DBObject query = new BasicDBObject();
    query.put("name", "John Coltrane");
    DBObject artistFromDB = dbCollection.find(query).next();
    Object albumFromDB = artistFromDB.get("album");
View Full Code Here

           
            DBCollection dbTemp =  DbManager.getCollection(job.getOutputDatabase(), outCollection);
            BasicDBObject outObj = new BasicDBObject();
            outObj.put("key", new Date());
            outObj.put("value", com.mongodb.util.JSON.parse(BaseDbPojo.getDefaultBuilder().create().toJson(rp)));
            dbTemp.save(outObj);
           
            _statusManager.setJobComplete(job, true, false, 1, 1, ApiManager.mapToApi(rp.getStats(), null));         
            job.jobidS = null;
          }
          catch (Exception e) { // Any sort of error, just make sure we set the job to complete     
View Full Code Here

    DBCollection endpointCacheCollection = getCacheCollection();
   
    BasicDBObject toCacheObj = new BasicDBObject(SimpleFederatedCache._id_, url);
    toCacheObj.put(SimpleFederatedCache.cachedJson_, toCacheJson);
    toCacheObj.put(SimpleFederatedCache.expiryDate_, new Date(new Date().getTime() + cacheTime_days*3600L*24L*1000L));
    endpointCacheCollection.save(toCacheObj);
  }//TESTED (3.1, 4.*)

  // Document level caching, although it effectively serves as a mostly redundant request cache,
  // It's actually used to allow users to save federated query documents in their buckets
 
View Full Code Here

    DBCursor dbc = endpointCacheCollection.find();
    for (DBObject cacheEntryObj: dbc) {
      BasicDBObject cacheEntry = (BasicDBObject) cacheEntryObj;
      cacheEntry.put(SimpleFederatedCache.expiryDate_, new Date(new Date().getTime() - 3600L*1000L)); // (ie expired an hour ago)
      endpointCacheCollection.save(cacheEntry);
    }
  }
  public void test_cacheClear(boolean clearApiCache, boolean clearDocCache, String key) {
    // (DO NOT COMMENT THIS OUT)
    SimpleFederatedQueryEngine.TEST_MODE_ONLY = true;   
View Full Code Here

      for (long i = 0; i < (1 + SimpleFederatedCache.QUERY_FEDERATION_CACHE_CLEANSE_SIZE); ++i) {
        SimpleFederatedCache fakeCacheElement = new SimpleFederatedCache();
        fakeCacheElement.expiryDate = new Date(new Date().getTime() - 3600L*1000L); // (ie expired an hour ago)
        fakeCacheElement._id = testName + "_" + i;
        fakeCacheElement.cachedJson = new BasicDBObject();
        endpointCacheCollection.save(fakeCacheElement.toDb());
      }
      _lastChecked = new Date(new Date().getTime() - 602L*1000L).getTime();
    }
    long count = endpointCacheCollection.count();
    if (shouldBeFull) {
View Full Code Here

        final BasicDBObject doc = (BasicDBObject) ((DocBuilderField) getBoundUnit(Item.saveDoc)).getDBObject();

        new DbJob() {
            @Override
            public Object doRun() throws IOException {
                return col.save((DBObject) doc.copy());
            }

            @Override
            public String getNS() {
                return col.getFullName();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.