List of usage examples for com.mongodb BasicDBObjectBuilder start
public static BasicDBObjectBuilder start(final String key, final Object val)
From source file:org.mongodb.demos.tailable.RealTimeAppServer.java
License:Apache License
private DBCollection createAndGetCappedCollection(String name) throws InterruptedException { DBCollection coll = db.getCollection(name); coll.drop();//from w w w . j a v a2 s. c om DBObject options = new BasicDBObject("capped", true); options.put("size", 1000); coll = db.createCollection(name, options); coll.insert(BasicDBObjectBuilder.start("status", "initialized").get()); System.out.println("== capped collection created ==="); return coll; }
From source file:org.obiba.magma.datasource.mongodb.MongoDBValueSet.java
License:Open Source License
@NotNull private BSONObject getDBObject() { if (object == null) { DBObject template = BasicDBObjectBuilder.start("_id", entity.getIdentifier()).get(); object = valueTable.getValueSetCollection().findOne(template); if (object == null) { throw new NoSuchValueSetException(valueTable, entity); }/*from w w w . j a v a 2 s . com*/ } return object; }
From source file:org.obiba.magma.datasource.mongodb.MongoDBValueTable.java
License:Open Source License
DBObject findVariable(String variableName) {
return getVariablesCollection().findOne(BasicDBObjectBuilder.start("name", variableName).get());
}
From source file:org.obiba.magma.datasource.mongodb.MongoDBVariableEntityProvider.java
License:Open Source License
private Set<VariableEntity> loadEntities() { ImmutableSet.Builder<VariableEntity> builder = ImmutableSet.builder(); try (DBCursor cursor = table.getValueSetCollection().find(new BasicDBObject(), BasicDBObjectBuilder.start("_id", 1).get())) { while (cursor.hasNext()) { DBObject next = cursor.next(); builder.add(new VariableEntityBean(getEntityType(), next.get("_id").toString())); }//from w w w . j ava 2s . c o m } return builder.build(); }
From source file:org.opencb.opencga.catalog.db.mongodb.CatalogMongoDBAdaptor.java
License:Apache License
private boolean studyAliasExists(int projectId, String studyAlias) { // Check if study.alias already exists. DBObject countQuery = BasicDBObjectBuilder.start(_PROJECT_ID, projectId).append("alias", studyAlias).get(); QueryResult<Long> queryResult = studyCollection.count(countQuery); return queryResult.getResult().get(0) != 0; }
From source file:org.opencb.opencga.catalog.db.mongodb.CatalogMongoDBAdaptor.java
License:Apache License
@Override public int getStudyId(int projectId, String studyAlias) throws CatalogDBException { DBObject query = BasicDBObjectBuilder.start(_PROJECT_ID, projectId).append("alias", studyAlias).get(); BasicDBObject projection = new BasicDBObject("id", "true"); QueryResult<DBObject> queryResult = studyCollection.find(query, projection, null); List<Study> studies = parseStudies(queryResult); return studies == null || studies.isEmpty() ? -1 : studies.get(0).getId(); }
From source file:org.opencb.opencga.catalog.db.mongodb.CatalogMongoDBAdaptor.java
License:Apache License
@Override public int getFileId(int studyId, String path) throws CatalogDBException { DBObject query = BasicDBObjectBuilder.start(_STUDY_ID, studyId).append("path", path).get(); BasicDBObject projection = new BasicDBObject("id", true); QueryResult<DBObject> queryResult = fileCollection.find(query, projection, null); File file = parseFile(queryResult); return file != null ? file.getId() : -1; }
From source file:org.opencb.opencga.catalog.db.mongodb.CatalogMongoDBAdaptor.java
License:Apache License
/** * @param filePath assuming 'pathRelativeToStudy + name' *//*from w w w . j a v a2 s . c o m*/ @Override public QueryResult renameFile(int fileId, String filePath) throws CatalogDBException { long startTime = startQuery(); Path path = Paths.get(filePath); String fileName = path.getFileName().toString(); File file = getFile(fileId, null).getResult().get(0); int studyId = getStudyIdByFileId(fileId); int collisionFileId = getFileId(studyId, filePath); if (collisionFileId >= 0) { throw new CatalogDBException("Can not rename: " + filePath + " already exists"); } if (file.getType().equals(File.Type.FOLDER)) { // recursive over the files inside folder QueryResult<File> allFilesInFolder = getAllFilesInFolder(fileId, null); String oldPath = file.getPath(); filePath += filePath.endsWith("/") ? "" : "/"; for (File subFile : allFilesInFolder.getResult()) { String replacedPath = subFile.getPath().replaceFirst(oldPath, filePath); renameFile(subFile.getId(), replacedPath); // first part of the path in the subfiles 3 } } BasicDBObject query = new BasicDBObject(_ID, fileId); BasicDBObject set = new BasicDBObject("$set", BasicDBObjectBuilder.start("name", fileName).append("path", filePath).get()); QueryResult<WriteResult> update = fileCollection.update(query, set, null); if (update.getResult().isEmpty() || update.getResult().get(0).getN() == 0) { throw CatalogDBException.idNotFound("File", fileId); } return endQuery("rename file", startTime); }
From source file:org.opencb.opencga.catalog.db.mongodb.CatalogMongoDBAdaptor.java
License:Apache License
private long getDiskUsageByStudy(int studyId) { List<DBObject> operations = Arrays .<DBObject>asList(new BasicDBObject("$match", new BasicDBObject(_STUDY_ID, studyId //new BasicDBObject("$in",studyIds) )), new BasicDBObject("$group", BasicDBObjectBuilder.start("_id", "$" + _STUDY_ID) .append("diskUsage", new BasicDBObject("$sum", "$diskUsage")).get())); QueryResult<DBObject> aggregate = fileCollection.aggregate(operations, null); if (aggregate.getNumResults() == 1) { Object diskUsage = aggregate.getResult().get(0).get("diskUsage"); if (diskUsage instanceof Integer) { return ((Integer) diskUsage).longValue(); } else if (diskUsage instanceof Long) { return ((Long) diskUsage); } else {//from w ww . j av a2 s. c o m return Long.parseLong(diskUsage.toString()); } } else { return 0; } }
From source file:org.opencb.opencga.catalog.db.mongodb.CatalogMongoDBAdaptor.java
License:Apache License
/** * query: db.file.find({id:2}, {acl:{$elemMatch:{userId:"jcoll"}}, studyId:1}) *///from w ww . j a va 2s . com @Override public QueryResult<Acl> getFileAcl(int fileId, String userId) throws CatalogDBException { long startTime = startQuery(); DBObject projection = BasicDBObjectBuilder .start("acl", new BasicDBObject("$elemMatch", new BasicDBObject("userId", userId))) .append("_id", false).get(); QueryResult queryResult = fileCollection.find(new BasicDBObject(_ID, fileId), projection, null); if (queryResult.getNumResults() == 0) { throw new CatalogDBException("getFileAcl: There is no file with fileId = " + fileId); } List<Acl> acl = parseFile(queryResult).getAcl(); return endQuery("get file acl", startTime, acl); }