@Override public MongoDatabase getDb() { // native MongoDB objects that offer methods with ClientSession must not be proxied. return delegate.getDb(); }
@Override public List<MongoEndpointNotification> findNotificationsByKeyHash(final byte[] keyHash) { LOG.debug("Find unicast notifications by endpoint key hash [{}] ", keyHash); DBObject dbObject = query(where(EP_ENDPOINT_KEY_HASH).is(keyHash)).getQueryObject(); DBCursor cursor = mongoTemplate.getDb().getCollection(getCollectionName()).find(dbObject); List<MongoEndpointNotification> endpointNotifications = new ArrayList<>(); while (cursor.hasNext()) { endpointNotifications.add(mongoTemplate.getConverter() .read(MongoEndpointNotification.class, cursor.next())); } return endpointNotifications; }
@Override public MongoEndpointProfile findByKeyHash(byte[] endpointKeyHash) { LOG.debug("Find endpoint profile by endpoint key hash [{}] ", endpointKeyHash); DBObject dbObject = query(where(EP_ENDPOINT_KEY_HASH) .is(endpointKeyHash)) .getQueryObject(); DBObject result = mongoTemplate.getDb() .getCollection(getCollectionName()) .findOne(dbObject); return mongoTemplate.getConverter().read(getDocumentClass(), result); }
@Override public MongoEndpointConfiguration findByHash(final byte[] hash) { LOG.debug("Find endpoint configuration by hash [{}] ", hash); DBObject dbObject = query(where(ID).is(hash)).getQueryObject(); DBObject result = mongoTemplate.getDb() .getCollection(getCollectionName()) .findOne(dbObject); return mongoTemplate.getConverter().read(getDocumentClass(), result); }
@Override public MongoEndpointProfile findByAccessToken(String endpointAccessToken) { LOG.debug("Find endpoint profile by access token [{}] ", endpointAccessToken); DBObject dbObject = query(where(EP_ACCESS_TOKEN).is(endpointAccessToken)) .getQueryObject(); DBObject result = mongoTemplate.getDb() .getCollection(getCollectionName()) .findOne(dbObject); return mongoTemplate.getConverter().read(getDocumentClass(), result); }
@Override public MongoTopicListEntry findByHash(byte[] hash) { LOG.debug("Find topic list entry by hash [{}] ", hash); DBObject dbObject = query(where(ID).is(hash)).getQueryObject(); DBObject result = mongoTemplate.getDb() .getCollection(getCollectionName()) .findOne(dbObject); return mongoTemplate.getConverter().read(getDocumentClass(), result); }
private Long findVersionByKey(byte[] endpointKeyHash) { LOG.debug("Find endpoint profile version by key hash [{}] ", endpointKeyHash); Long version = null; Query query = query(where(EP_ENDPOINT_KEY_HASH).is(endpointKeyHash)); query.fields().include(OPT_LOCK); DBObject result = mongoTemplate.getDb() .getCollection(getCollectionName()) .findOne(query.getQueryObject()); if (result != null) { version = (Long) result.get(OPT_LOCK); } return version; }
? template.getMongoDbFactory().getDb(options.getDatabaseName()) : template.getDb();
protected Message<T, R> createMessage(T source, Class<R> targetType, RequestOptions options) { SimpleMessage<T, T> message = new SimpleMessage<>(source, source, MessageProperties.builder() .databaseName(template.getDb().getName()).collectionName(options.getCollectionName()).build()); return new LazyMappingDelegatingMessage<>(message, targetType, template.getConverter()); }
@Override public MongoDatabase getDb() { // native MongoDB objects that offer methods with ClientSession must not be proxied. return delegate.getDb(); }
? template.getMongoDbFactory().getDb(options.getDatabaseName()) : template.getDb();
protected Message<T, R> createMessage(T source, Class<R> targetType, RequestOptions options) { SimpleMessage<T, T> message = new SimpleMessage<>(source, source, MessageProperties.builder() .databaseName(template.getDb().getName()).collectionName(options.getCollectionName()).build()); return new LazyMappingDelegatingMessage<>(message, targetType, template.getConverter()); }
/** * Returns the MongoDB statistics for the database in use by this {@link MongoTemplate}. * * @param template * * @return * * @throws NullPointerException if template instance provided is <code>null</code>. */ public static MongoDBStats getDatabaseStatistics(MongoTemplate template) { return getDatabaseStatistics(template.getDb()); }
/** * Returns the MongoDB statistics for the database in use by this * {@link MongoTemplate}. * * @param template * the {@link MongoTemplate} to use * * @return the {@link MongoDBStats} * * @throws NullPointerException * if template instance provided is <code>null</code>. */ public static MongoDBStats getDatabaseStatistics(MongoTemplate template) { return getDatabaseStatistics(template.getDb()); }
@PostConstruct private void postConstruct() { gridFS = new GridFS(mongoTemplate.getDb()); }
@PostConstruct private void postConstruct() { gridFS = new GridFS(mongoTemplate.getDb()); }
/** * Initialize method that gets the instance of MongoDB that needs * to be closed. * */ @PostConstruct public void init() { DB mongoDB = this.mongoTemplate.getDb(); this.mongo = mongoDB.getMongo(); // add a JVM shutdown hook Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { if(mongo != null) { mongo.close(); mongo = null; } } }); }
/** * Initialize method that gets the instance of MongoDB that needs * to be closed. * */ @PostConstruct public void init() { DB mongoDB = this.mongoTemplate.getDb(); this.mongo = mongoDB.getMongo(); // add a JVM shutdown hook Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { if(mongo != null) { mongo.close(); mongo = null; } } }); }
/** * Construct a new HdfsMongoDbJob using the provided directory and file names. * * @param dir the directory where the source file is located on hdfs * @param fileName The file from which data will be pulled. * @param collectionName the collection where the data will be written. * @param names a comma delimited list of column names that are contained in the source file. * @param mongoDbFactory The db factory for mongo */ public HdfsMongoDbJob(String dir, String fileName, String collectionName, String names, String idField, MongoDbFactory mongoDbFactory) { Assert.hasText(dir, "Dir must not be null or empty"); Assert.hasText(fileName, "FileName must not be null or empty"); Assert.hasText(collectionName, "CollectionName must not be null or empty"); Assert.hasText(names, "Names must not be null nor empty"); Assert.hasText(idField, "IdField must not be null nor empty"); this.dir = dir; this.fileName = fileName; this.collectionName = collectionName; this.names = names; this.idField = idField; mongoTemplate = new MongoTemplate(mongoDbFactory); host = mongoTemplate.getDb().getMongo().getAddress().getHost(); port = mongoTemplate.getDb().getMongo().getAddress().getPort(); }