BufferProvider getBufferPool() { return getMongo().getBufferProvider(); }
private boolean isCursorFinalizerEnabled() { return collection.getDB().getMongo().getMongoClientOptions().isCursorFinalizerEnabled(); }
/** * Constructs new {@code DBCollection} instance. This operation not reflected on the server. * @param name the name of the collection * @param database the database to which this collections belongs to */ DBCollection(final String name, final DB database, final OperationExecutor executor) { checkCollectionNameValidity(name); this.name = name; this.database = database; this.executor = executor; this.optionHolder = new Bytes.OptionHolder(database.getOptionHolder()); this.objectFactory = new DBCollectionObjectFactory(); this.objectCodec = new CompoundDBObjectCodec(getDefaultDBObjectCodec()); this.retryWrites = database.getMongo().getMongoClientOptions().getRetryWrites(); }
private void initializeCursor(final FindOperation<DBObject> operation) { cursor = new MongoBatchCursorAdapter<DBObject>(executor.execute(operation, getReadPreferenceForCursor(), getReadConcern())); if (isCursorFinalizerEnabled() && cursor.getServerCursor() != null) { optionalFinalizer = new OptionalFinalizer(collection.getDB().getMongo(), collection.getNamespace()); } }
@Override public void destroy() { indexManager.close(); if (schemaManager != null) { schemaManager.dropSchema(); } if (mongoDB != null) { logger.info("Closing connection to mongodb."); mongoDB.getMongo().close(); logger.info("Closed connection to mongodb."); } else { logger.warn("Can't close connection to MONGODB, it was already disconnected"); } externalProperties = null; schemaManager = null; }
@Autowired @Bean(name="mongoDbFactory1") private MongoDbFactory factory; @Bean(name="mongoTemplate1") MongoTemplate getMongoTemplate(String dbName) { DB db = factory.getDb(dbName); Mongo mongo = db.getMongo(); return new MongoTemplate(mongo); }
public void close() { if (db != null) { db.getMongo().close(); } }
@Autowired @Bean(name="mongoDbFactory2") private MongoDbFactory factory; @Bean(name="mongoTemplate2") MongoTemplate getMongoTemplate(String dbName) { DB db = factory.getDb(dbName); Mongo mongo = db.getMongo(); return new MongoTemplate(mongo); }
@Override public void close(final TaskAttemptContext context) { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { LOG.error("Could not close output stream", e); } } MongoConfigUtil.close(collection.getDB().getMongo()); }
@Override public void dispose() { if (LOG.isDebugEnabled()) { LOG.debug("MongoDB time: " + timeSum); } nodes.getDB().getMongo().close(); }
@Override public List<ServerAddress> servers() { return rrdCollection.getDB().getMongo().getServerAddressList(); } @Override
DB db = new Mongo("127.0.0.1").getDB("test");//Better use MongoClient since Mongo class is deprecated System.out.println(db.getMongo().getVersion());//prints 2.9.3 driverversion CommandResult commandResult = db.command("buildInfo"); System.out.println(commandResult.getString("version"));//prints 2.4.2 Note tried at home since my mongo version is 2.4.2
/** * Close the AQ native session and the database connection. */ public void close() throws ResourceException { try { this.db.getMongo().close(); } catch (Exception exception) { ResourceException resourceException = new ResourceException(exception.toString()); resourceException.initCause(exception); throw resourceException; } }
private void insertShardKeyPattern(DB mongoDb, String collectionName, DBObject collection) { String databaseName = mongoDb.getName(); String collectionWithDatabase = databaseName + DATABASE_COLLECTION_SEPARATOR + collectionName; DBObject shardKeys = shardKeys(collection); MongoDbCommands.shardCollection(mongoDb.getMongo(), collectionWithDatabase, shardKeys); }
@Override public void close() { if (cursor != null) { cursor.close(); MongoConfigUtil.close(cursor.getCollection().getDB().getMongo()); } }
public void close() { if (cursor != null) { cursor.close(); MongoConfigUtil.close(cursor.getCollection().getDB().getMongo()); } }
public static Operation putDatabaseDetails (Operation op, DB db) { op.put("dbName", db.getName()); Mongo mongo=db.getMongo(); ServerAddress address=mongo.getAddress(); op.put("host", address.getHost()); op.put("port", address.getPort()); return op; } }
protected void init() { MongoClientURI inputURI = MongoConfigUtil.getInputURI(conf); this.inputCollection = MongoConfigUtil.getCollection(inputURI); DB db = this.inputCollection.getDB(); this.mongo = db.getMongo(); MongoClientURI authURI = MongoConfigUtil.getAuthURI(conf); if (authURI != null) { if (authURI.getUsername() != null && authURI.getPassword() != null) { authDB = mongo.getDB(authURI.getDatabase()); } } }
private void initializeCursor(final FindOperation<DBObject> operation) { cursor = new MongoBatchCursorAdapter<DBObject>(executor.execute(operation, getReadPreferenceForCursor(), getReadConcern())); if (isCursorFinalizerEnabled() && cursor.getServerCursor() != null) { optionalFinalizer = new OptionalFinalizer(collection.getDB().getMongo(), collection.getNamespace()); } }