org.springframework.data.mongodb.core.MongoTemplate.getDb()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(188)

本文整理了Java中org.springframework.data.mongodb.core.MongoTemplate.getDb()方法的一些代码示例,展示了MongoTemplate.getDb()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MongoTemplate.getDb()方法的具体详情如下:
包路径:org.springframework.data.mongodb.core.MongoTemplate
类名称:MongoTemplate
方法名:getDb

MongoTemplate.getDb介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-data-mongodb

@Override
public MongoDatabase getDb() {
  // native MongoDB objects that offer methods with ClientSession must not be proxied.
  return delegate.getDb();
}

代码示例来源:origin: kaaproject/kaa

@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;
}

代码示例来源:origin: kaaproject/kaa

@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);
}

代码示例来源:origin: kaaproject/kaa

@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);
}

代码示例来源:origin: kaaproject/kaa

@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);
}

代码示例来源:origin: kaaproject/kaa

@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);
}

代码示例来源:origin: kaaproject/kaa

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;
}

代码示例来源:origin: spring-projects/spring-data-mongodb

? template.getMongoDbFactory().getDb(options.getDatabaseName()) : template.getDb();

代码示例来源:origin: spring-projects/spring-data-mongodb

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());
}

代码示例来源:origin: org.springframework.data/spring-data-mongodb

@Override
public MongoDatabase getDb() {
  // native MongoDB objects that offer methods with ClientSession must not be proxied.
  return delegate.getDb();
}

代码示例来源:origin: org.springframework.data/spring-data-mongodb

? template.getMongoDbFactory().getDb(options.getDatabaseName()) : template.getDb();

代码示例来源:origin: org.springframework.data/spring-data-mongodb

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());
}

代码示例来源:origin: com.sangupta/jerry

/**
 * 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());
}

代码示例来源:origin: com.sangupta/jerry-services

/**
 * 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());
}

代码示例来源:origin: org.kurento/kurento-repository-internal

@PostConstruct
private void postConstruct() {
 gridFS = new GridFS(mongoTemplate.getDb());
}

代码示例来源:origin: Kurento/kurento-java

@PostConstruct
private void postConstruct() {
 gridFS = new GridFS(mongoTemplate.getDb());
}

代码示例来源:origin: com.sangupta/jerry-services

/**
 * 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;
      }
    }
    
  });
}

代码示例来源:origin: com.sangupta/jerry

/**
 * 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;
      }
    }
    
  });
}

代码示例来源:origin: org.springframework.xd/spring-xd-test-fixtures

/**
 * 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();
}

相关文章