List of usage examples for com.mongodb DBCollection getFullName
public String getFullName()
From source file:de.otto.mongodb.profiler.op.OpProfileDataFetcher.java
License:Apache License
private DBCursor getCursor() { synchronized (cursorMutex) { // Close stale cursor if (cursor != null && cursor.getCursorId() == 0L) { cursor.close();//from w w w . j ava 2 s . com cursor = null; } // Create new cursor if (cursor == null && db.collectionExists(COLLECTION)) { if (lastTs == null) { lastTs = DateTime.now(DateTimeZone.UTC); } final DBCollection collection = db.getCollection(COLLECTION); final DBObject query = QueryBuilder.start() .and(QueryBuilder.start("ns").notEquals(collection.getFullName()).get(), QueryBuilder.start("ts").greaterThan(lastTs.toDate()).get()) .get(); final DBObject sortBy = new BasicDBObject("$natural", 1); final DBCursor cursor = collection.find(query).sort(sortBy).batchSize(100) .addOption(Bytes.QUERYOPTION_TAILABLE).addOption(Bytes.QUERYOPTION_AWAITDATA); this.cursor = cursor; } } return cursor; }
From source file:juan.salida.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed columnamf[0] = "Nombre"; columnamf[1] = "ruta"; columnamf[2] = "fecha"; columnamf[3] = "marca"; columnamt[0] = "Nombre"; columnamt[1] = "ruta"; columnamt[2] = "marca"; columnamt[3] = "tamao"; columnamr[0] = "Nombre"; columnamr[1] = "ruta"; columnamr[2] = "marca"; columnamr[3] = "ancho"; columnamr[4] = "alto"; columnatf[0] = "Nombre"; columnatf[1] = "ruta"; columnatf[2] = "tamao"; columnatf[3] = "fecha"; DBCollection col = cursor.getCollection(); String collection = col.getFullName(); if (collection.equals("mydb.modelo-fecha")) { tableModel.addColumn(columnamf[0]); tableModel.addColumn(columnamf[1]); tableModel.addColumn(columnamf[2]); tableModel.addColumn(columnamf[3]); while (cursor.hasNext()) { documento = cursor.next();/*from w w w. ja va2 s.c om*/ tableModel.addRow(new Object[] { documento.get("nombre"), documento.get("ruta"), documento.get("fecha"), documento.get("marca") }); } } else if (collection.equals("mydb.modelo-tamano")) { tableModel.addColumn(columnamt[0]); tableModel.addColumn(columnamt[1]); tableModel.addColumn(columnamt[2]); tableModel.addColumn(columnamt[3]); while (cursor.hasNext()) { documento = cursor.next(); tableModel.addRow(new Object[] { documento.get("nombre"), documento.get("ruta"), documento.get("marca"), documento.get("tamano") }); } } else if (collection.equals("mydb.modelo-resolucion")) { tableModel.addColumn(columnamr[0]); tableModel.addColumn(columnamr[1]); tableModel.addColumn(columnamr[2]); tableModel.addColumn(columnamr[3]); tableModel.addColumn(columnamr[4]); while (cursor.hasNext()) { documento = cursor.next(); tableModel.addRow(new Object[] { documento.get("nombre"), documento.get("ruta"), documento.get("marca"), documento.get("width"), documento.get("height") }); } } else { tableModel.addColumn(columnatf[0]); tableModel.addColumn(columnatf[1]); tableModel.addColumn(columnatf[2]); tableModel.addColumn(columnatf[3]); while (cursor.hasNext()) { documento = cursor.next(); tableModel.addRow(new Object[] { documento.get("nombre"), documento.get("ruta"), documento.get("tamano"), documento.get("fecha") }); } } jButton1.setVisible(false); }
From source file:org.bigmouth.nvwa.log4mongo.MongoDbAppender.java
License:Apache License
/** * @param dbCollection// w ww . ja v a 2s . c o m * @param fieldName ?? * @param indexName ?? * @param order 1 ???-1 ?? * @param expire ??30 */ public static void createIndex(DBCollection dbCollection, String fieldName, String indexName, int order, boolean expire, long expireSeconds) { DBObject option = new BasicDBObject(); option.put("name", indexName); option.put("ns", dbCollection.getFullName()); if (expire) option.put("expireAfterSeconds", expireSeconds); option.put("backgroud", true); dbCollection.ensureIndex(new BasicDBObject(fieldName, order), option); }
From source file:org.broad.igv.plugin.mongocollab.MongoFeatureSource.java
License:Open Source License
public static FeatureTrack loadFeatureTrack(MongoCollabPlugin.Locator locator, List<Track> newTracks) { DBCollection collection = MongoCollabPlugin.getCollection(locator); //TODO Make this more flexible collection.setObjectClass(DBFeature.class); MongoFeatureSource source = new MongoFeatureSource(collection, locator.buildLocusIndex); FeatureTrack track = new MongoFeatureTrack(collection.getFullName(), collection.getName(), source); SearchCommand.registerNamedFeatureSearcher(source); newTracks.add(track);//from www. j a v a 2 s . c o m track.setMargin(0); return track; }
From source file:org.iternine.jeppetto.dao.mongodb.QueryLoggingCommand.java
License:Apache License
@Override public DBCursor cursor(DBCollection dbCollection) { logger.debug("Executing {} for {} cursor", delegate, dbCollection.getFullName()); DBCursor dbCursor = delegate.cursor(dbCollection); if (logger.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); DBObject plan = dbCursor.explain(); sb.append("MongoDB query plan ").append(plan).append('\n'); sb.append("\tcursor = \"").append(plan.get("cursor")).append("\"\n"); sb.append("\tnscanned = \"").append(plan.get("nscanned")).append("\"\n"); sb.append("\tn = \"").append(plan.get("n")).append("\"\n"); sb.append("\tmillis = \"").append(plan.get("millis")).append("\"\n"); logger.debug(sb.toString());/*from w ww .j a v a2 s . co m*/ } return dbCursor; }
From source file:org.mongoste.core.impl.mongodb.MongoUtil.java
License:Open Source License
public static void createIndexes(DBCollection collection, Object... indexes) { log.info("Indexing {} collection", collection.getFullName()); long t = System.currentTimeMillis(); for (Object index : indexes) { if (index instanceof String) { collection.ensureIndex((String) index); }/*from www . j av a2 s . co m*/ if (index instanceof DBObject) { collection.ensureIndex((DBObject) index); } } log.info("Done indexing {} collection in {}ms", collection.getFullName(), System.currentTimeMillis() - t); }
From source file:org.springframework.data.mongodb.core.MongoTemplate.java
License:Apache License
public void dropCollection(String collectionName) { execute(collectionName, new CollectionCallback<Void>() { public Void doInCollection(DBCollection collection) throws MongoException, DataAccessException { collection.drop();/* w w w.j av a 2 s.co m*/ if (LOGGER.isDebugEnabled()) { LOGGER.debug("Dropped collection [{}]", collection.getFullName()); } return null; } }); }
From source file:org.springframework.data.mongodb.core.MongoTemplate.java
License:Apache License
/** * Create the specified collection using the provided options * //from w w w . j a v a 2s . c o m * @param collectionName * @param collectionOptions * @return the collection that was created */ protected DBCollection doCreateCollection(final String collectionName, final DBObject collectionOptions) { return execute(new DbCallback<DBCollection>() { public DBCollection doInDB(DB db) throws MongoException, DataAccessException { DBCollection coll = db.createCollection(collectionName, collectionOptions); // TODO: Emit a collection created event if (LOGGER.isDebugEnabled()) { LOGGER.debug("Created collection [{}]", coll.getFullName()); } return coll; } }); }