com.mongodb.gridfs.GridFS.getDB()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(2.8k)|赞(0)|评价(0)|浏览(149)

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

GridFS.getDB介绍

[英]Gets the database used.
[中]获取使用的数据库。

代码示例

代码示例来源:origin: org.mongodb/mongo-java-driver

  1. /**
  2. * Verifies that the MD5 matches between the database and the local file. This should be called after transferring a file.
  3. *
  4. * @throws MongoException if there's a failure
  5. * @deprecated there is no replacement for this method
  6. */
  7. @Deprecated
  8. public void validate() {
  9. if (fs == null) {
  10. throw new MongoException("no fs");
  11. }
  12. if (md5 == null) {
  13. throw new MongoException("no md5 stored");
  14. }
  15. DBObject cmd = new BasicDBObject("filemd5", id);
  16. cmd.put("root", fs.getBucketName());
  17. DBObject res = fs.getDB().command(cmd);
  18. if (res != null && res.containsField("md5")) {
  19. String m = res.get("md5").toString();
  20. if (m.equals(md5)) {
  21. return;
  22. }
  23. throw new MongoException("md5 differ. mine [" + md5 + "] theirs [" + m + "]");
  24. }
  25. // no md5 from the server
  26. throw new MongoException("no md5 returned from server: " + res);
  27. }

代码示例来源:origin: org.mongodb/mongodb-driver

  1. /**
  2. * Verifies that the MD5 matches between the database and the local file. This should be called after transferring a file.
  3. *
  4. * @throws MongoException if there's a failure
  5. * @deprecated there is no replacement for this method
  6. */
  7. @Deprecated
  8. public void validate() {
  9. if (fs == null) {
  10. throw new MongoException("no fs");
  11. }
  12. if (md5 == null) {
  13. throw new MongoException("no md5 stored");
  14. }
  15. DBObject cmd = new BasicDBObject("filemd5", id);
  16. cmd.put("root", fs.getBucketName());
  17. DBObject res = fs.getDB().command(cmd);
  18. if (res != null && res.containsField("md5")) {
  19. String m = res.get("md5").toString();
  20. if (m.equals(md5)) {
  21. return;
  22. }
  23. throw new MongoException("md5 differ. mine [" + md5 + "] theirs [" + m + "]");
  24. }
  25. // no md5 from the server
  26. throw new MongoException("no md5 returned from server: " + res);
  27. }

代码示例来源:origin: suninformation/ymate-platform-v2

  1. public MongoGridFSSession(IMongoDataSourceAdapter dataSourceAdapter, String bucketName) throws Exception {
  2. this.__id = UUIDUtils.UUID();
  3. this.__dataSourceHolder = dataSourceAdapter;
  4. this.__bucketName = StringUtils.defaultIfBlank(bucketName, GridFS.DEFAULT_BUCKET);
  5. //
  6. __gridFS = new GridFS(new DB(dataSourceAdapter.getMongoClient(), dataSourceAdapter.getDataSourceCfgMeta().getDatabaseName()), __bucketName);
  7. __dbCollection = __gridFS.getDB().getCollection(__bucketName.concat(".files"));
  8. }

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

  1. public void execute() throws Exception {
  2. startServer();
  3. RepositoryItem repositoryItem = getRepository().createRepositoryItem();
  4. Repository repo = getRepository();
  5. if (repo instanceof MongoRepository) {
  6. MongoRepository mrepo = (MongoRepository) repo;
  7. mrepo.getGridFS().getDB().dropDatabase();
  8. }
  9. prepareToUploadVideo(repositoryItem);
  10. prepareToDownloadVideo(repositoryItem);
  11. stopServer();
  12. }

相关文章