List of usage examples for com.mongodb BasicDBObjectBuilder start
public static BasicDBObjectBuilder start()
From source file:Model.DAO_Etudiant.java
public DAO_Etudiant(Connection conn) throws UnknownHostException { super(conn);/*from ww w .ja v a 2s .c om*/ if (db.collectionExists("etudiant")) { collection = db.getCollection("etudiant"); } else { DBObject options = BasicDBObjectBuilder.start().add("capped", false).add("size", 2000000000l).get(); collection = db.createCollection("etudiant", options); } }
From source file:Model.DAO_Etudiant.java
public boolean archive(String uneClasse) { // Vider la base archive a chaque fois. if (db.collectionExists("etudiant_save")) { collection = db.getCollection("etudiant_save"); collection.drop();//from w w w . java2 s . c o m } else { DBObject options = BasicDBObjectBuilder.start().add("capped", false).add("size", 2000000000l).get(); collection = db.createCollection("etudiant_save", options); } collection = db.getCollection("etudiant"); DBCursor cursor = collection.find(); try { while (cursor.hasNext()) { collection = db.getCollection("etudiant_save"); collection.insert(cursor.next()); } collection = db.getCollection("etudiant"); BasicDBObject query = new BasicDBObject(); query.append("classe", uneClasse); collection.remove(query); } finally { cursor.close(); } return true; }
From source file:Model.DAO_Matiere.java
public DAO_Matiere(Connection conn) throws UnknownHostException { super(conn);//from ww w . ja v a2 s . co m if (db.collectionExists("matiere2")) { collection = db.getCollection("matiere2"); } else { DBObject options = BasicDBObjectBuilder.start().add("capped", false).add("size", 2000000000l).get(); collection = db.createCollection("matiere2", options); } }
From source file:Model.DAO_Template.java
public DAO_Template(Connection conn) throws UnknownHostException { // Enable MongoDB logging in general System.setProperty("DEBUG.MONGO", "true"); // Enable DB operation tracing System.setProperty("DB.TRACE", "true"); // try {/*from w ww . j a va 2 s . com*/ this.mongoClient = new MongoClient("172.16.1.20", 27017); //this.mongoClient = new MongoClient("192.168.2.254", 27017); db = mongoClient.getDB("test"); if (db.collectionExists("collection")) { collection = db.getCollection("collection"); } else { DBObject options = BasicDBObjectBuilder.start().add("capped", false).add("size", 2000000000l).get(); collection = db.createCollection("collection", options); } // } catch (Exception ex) { // Logger.getLogger(DAO_Template.class.getName()).log(Level.SEVERE, null, ex); //} }
From source file:mongocrud.AddWindow.java
private static DBObject create(Student s) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); builder.append("name", s.getName()); builder.append("age", s.getAge()); builder.append("_id", s.getId()); return builder.get(); }
From source file:net.tbnr.commerce.items.CommerceItemManager.java
License:Open Source License
@Override public void givePlayerItem(TBNRPlayer player, Class<? extends CommerceItem> clazz) { BasicDBList purchaseList = getPurchaseList(player); purchaseList.add(BasicDBObjectBuilder.start().add("key", getMetaFor(clazz).key()) .add("date_time", new Date()).get()); DBObject playerDocument = player.getTPlayer().getPlayerDocument(); playerDocument.put(dbListKey, purchaseList); player.getTPlayer().save();//from ww w. j a va 2 s .c o m reloadPlayer(player, clazz); }
From source file:org.alfresco.bm.api.AbstractRestResource.java
License:Open Source License
/** * Does a deep copy of an object to allow for subsequent modification *///from w ww.jav a 2s. co m public static DBObject copyDBObject(DBObject dbObject) { DBObject orig = dbObject; BasicDBObjectBuilder dbObjectBuilder = BasicDBObjectBuilder.start(); for (String field : orig.keySet()) { Object value = orig.get(field); dbObjectBuilder.add(field, value); } return dbObjectBuilder.get(); }
From source file:org.alfresco.bm.api.v1.ResultsRestAPI.java
License:Open Source License
/** * Retrieve an approximate number of results, allowing for a smoothing factor * (<a href=http://en.wikipedia.org/wiki/Moving_average#Simple_moving_average>Simple Moving Average</a>) - * the number of data results to including in the moving average. * /*from w ww . ja v a 2s. c o m*/ * @param fromTime the approximate time to start from * @param timeUnit the units of the 'reportPeriod' (default SECONDS). See {@link TimeUnit}. * @param reportPeriod how often a result should be output. This is expressed as a multiple of the 'timeUnit'. * @param smoothing the number of results to include in the Simple Moving Average calculations * @param chartOnly <tt>true</tt> to filter out results that are not of interest in performance charts * * @return JSON representing the event start time (x-axis) and the smoothed average execution time * along with data such as the events per second, failures per second, etc. */ @GET @Path("/ts") @Produces(MediaType.APPLICATION_JSON) public String getTimeSeriesResults(@DefaultValue("0") @QueryParam("fromTime") long fromTime, @DefaultValue("SECONDS") @QueryParam("timeUnit") String timeUnit, @DefaultValue("1") @QueryParam("reportPeriod") long reportPeriod, @DefaultValue("1") @QueryParam("smoothing") int smoothing, @DefaultValue("true") @QueryParam("chartOnly") boolean chartOnly) { if (logger.isDebugEnabled()) { logger.debug("Inbound: " + "[test:" + test + ",fromTime:" + fromTime + ",timeUnit:" + timeUnit + ",reportPeriod:" + reportPeriod + ",smoothing:" + smoothing + ",chartOnly:" + chartOnly + "]"); } if (reportPeriod < 1) { throwAndLogException(Status.BAD_REQUEST, "'reportPeriod' must be 1 or more."); } if (smoothing < 1) { throwAndLogException(Status.BAD_REQUEST, "'smoothing' must be 1 or more."); } TimeUnit timeUnitEnum = null; try { timeUnitEnum = TimeUnit.valueOf(timeUnit.toUpperCase()); } catch (Exception e) { // Invalid time unit throwAndLogException(Status.BAD_REQUEST, e); } final ResultService resultService = getResultService(); // Calculate the window size long reportPeriodMs = timeUnitEnum.toMillis(reportPeriod); long windowSize = reportPeriodMs * smoothing; // This is just too convenient an API final BasicDBList events = new BasicDBList(); ResultHandler handler = new ResultHandler() { @Override public boolean processResult(long fromTime, long toTime, Map<String, DescriptiveStatistics> statsByEventName, Map<String, Integer> failuresByEventName) throws Throwable { for (Map.Entry<String, DescriptiveStatistics> entry : statsByEventName.entrySet()) { String eventName = entry.getKey(); DescriptiveStatistics stats = entry.getValue(); Integer failures = failuresByEventName.get(eventName); if (failures == null) { logger.error("Found null failure count: " + entry); // Do nothing with it and stop return false; } // Per second double numPerSec = (double) stats.getN() / ((double) (toTime - fromTime) / 1000.0); double failuresPerSec = (double) failures / ((double) (toTime - fromTime) / 1000.0); // Push into an object DBObject eventObj = BasicDBObjectBuilder.start().add("time", toTime).add("name", eventName) .add("mean", stats.getMean()).add("min", stats.getMin()).add("max", stats.getMax()) .add("stdDev", stats.getStandardDeviation()).add("num", stats.getN()) .add("numPerSec", numPerSec).add("fail", failures).add("failPerSec", failuresPerSec) .get(); // Add the object to the list of events events.add(eventObj); } // Go for the next result return true; } }; try { // Get all the results resultService.getResults(handler, fromTime, windowSize, reportPeriodMs, chartOnly); // Muster into JSON String json = events.toString(); // Done if (logger.isDebugEnabled()) { int jsonLen = json.length(); if (jsonLen < 500) { logger.debug("Outbound: " + json); } else { logger.debug("Outbound: " + json.substring(0, 250) + " ... " + json.substring(jsonLen - 250, jsonLen)); } } return json; } catch (WebApplicationException e) { throw e; } catch (Exception e) { throwAndLogException(Status.INTERNAL_SERVER_ERROR, e); return null; } }
From source file:org.alfresco.bm.cm.FileFolderService.java
License:Open Source License
/** * Ensure that the MongoDB collection has the required indexes associated with * this user bean./* ww w . j a va 2s. c o m*/ */ private void checkIndexes() { collection.setWriteConcern(WriteConcern.SAFE); DBObject uidxCtxPath = BasicDBObjectBuilder.start().add(FIELD_CONTEXT, 1).add(FIELD_PATH, 1).get(); DBObject optCtxPath = BasicDBObjectBuilder.start().add("name", "uidxCtxPath").add("unique", Boolean.TRUE) .get(); collection.createIndex(uidxCtxPath, optCtxPath); DBObject uidxCtxParentName = BasicDBObjectBuilder.start().add(FIELD_CONTEXT, 1).add(FIELD_PARENT_PATH, 1) .add(FIELD_NAME, 1).get(); DBObject optCtxParentName = BasicDBObjectBuilder.start().add("name", "uidxCtxParentName") .add("unique", Boolean.FALSE).get(); collection.createIndex(uidxCtxParentName, optCtxParentName); DBObject idxCtxLevel = BasicDBObjectBuilder.start().add(FIELD_CONTEXT, 1).add(FIELD_LEVEL, 1).get(); DBObject optCtxLevel = BasicDBObjectBuilder.start().add("name", "idxCtxLevel").add("unique", Boolean.FALSE) .get(); collection.createIndex(idxCtxLevel, optCtxLevel); DBObject idxCtxFileCount = BasicDBObjectBuilder.start().add(FIELD_CONTEXT, 1).add(FIELD_FILE_COUNT, 1) .add(FIELD_LEVEL, 1).get(); DBObject optCtxFileCount = BasicDBObjectBuilder.start().add("name", "idxCtxFileCount") .add("unique", Boolean.FALSE).get(); collection.createIndex(idxCtxFileCount, optCtxFileCount); DBObject idxCtxFolderCount = BasicDBObjectBuilder.start().add(FIELD_CONTEXT, 1).add(FIELD_FOLDER_COUNT, 1) .add(FIELD_LEVEL, 1).get(); DBObject optCtxFolderCount = BasicDBObjectBuilder.start().add("name", "idxCtxFolderCount") .add("unique", Boolean.FALSE).get(); collection.createIndex(idxCtxFolderCount, optCtxFolderCount); }
From source file:org.alfresco.bm.cm.FileFolderService.java
License:Open Source License
/** * Create a new folder entry with the given data *//*from w ww. jav a 2s . co m*/ public void createNewFolder(FolderData data) { BasicDBObjectBuilder insertObjBuilder = BasicDBObjectBuilder.start().add(FIELD_ID, data.getId()) .add(FIELD_CONTEXT, data.getContext()).add(FIELD_PATH, data.getPath()) .add(FIELD_LEVEL, data.getLevel()).add(FIELD_PARENT_PATH, data.getParentPath()) .add(FIELD_NAME, data.getName()).add(FIELD_FOLDER_COUNT, data.getFolderCount()) .add(FIELD_FILE_COUNT, data.getFileCount()); DBObject insertObj = insertObjBuilder.get(); try { collection.insert(insertObj); } catch (DuplicateKeyException e) { // We just rethrow as per the API throw e; } }