List of usage examples for com.mongodb QueryBuilder start
public static QueryBuilder start(final String key)
From source file:org.alfresco.contentstore.dao.mongo.MongoContentDAO.java
License:Open Source License
@Override public boolean nodeExists(String nodeId, long nodeVersion, boolean isPrimary) { QueryBuilder queryBuilder = QueryBuilder.start("e").is(serverIdentity.getId()).and("n").is(nodeId).and("v") .is(nodeVersion).and("pri").is(isPrimary); DBObject query = queryBuilder.get(); DBObject dbObject = contentData.findOne(query); return dbObject != null; }
From source file:org.alfresco.repo.domain.node.mongo.MongoNodeDAO.java
License:Open Source License
private NodeEntity getLatest(long nodeId) { NodeEntity nodeEntity = null;//from ww w .j a va2 s .c o m DBObject query = QueryBuilder.start("n").is(nodeId).and("c").is(true).get(); DBObject order = BasicDBObjectBuilder.start("v", -1).get(); DBCursor cursor = nodes.find(query).sort(order).limit(1); try { if (cursor.hasNext()) { DBObject dbObject = cursor.next(); nodeEntity = toNodeEntity(dbObject); } } finally { cursor.close(); } return nodeEntity; }
From source file:org.alfresco.repo.domain.node.mongo.MongoNodeDAO.java
License:Open Source License
@Override public NodeEntity getByVersionLabel(long nodeId, String versionLabel) { NodeEntity nodeEntity = null;//w ww . j a v a2 s .c o m DBObject query = QueryBuilder.start("n").is(nodeId).and("vl").is(versionLabel).and("c").is(true).get(); DBObject orderBy = BasicDBObjectBuilder.start("v", -1).get(); DBCursor cursor = nodes.find(query).sort(orderBy).limit(1); try { int size = cursor.size(); if (size > 1) { throw new RuntimeException(); } else if (size == 1) { DBObject dbObject = cursor.next(); nodeEntity = toNodeEntity(dbObject); } } finally { cursor.close(); } return nodeEntity; }
From source file:org.alfresco.repo.domain.node.mongo.MongoNodeDAO.java
License:Open Source License
@Override public void onCommit(String txnId) { DBObject query = QueryBuilder.start("t").is(txnId).get(); DBObject update = BasicDBObjectBuilder.start("$set", BasicDBObjectBuilder.start("c", true).get()).get(); nodes.update(query, update, false, true); }
From source file:org.alfresco.semantics.MongoSemantics.java
License:Open Source License
public void addRelation(String fromId, String toId, String category) { QueryBuilder queryBuilder = QueryBuilder.start("f").is(fromId).and("t").is(toId); DBObject query = queryBuilder.get(); BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("f", fromId).add("t", toId).add("c", category) .add("w", 1.0); DBObject insert = builder.get();/*from ww w . j a v a 2s . com*/ WriteResult result = relations.update(query, insert, true, false); checkResult(result, 1); }
From source file:org.alfresco.semantics.MongoSemantics.java
License:Open Source License
public void deleteRelation(String fromId, String toId) { QueryBuilder queryBuilder = QueryBuilder.start("f").is(fromId).and("t").is(toId); DBObject query = queryBuilder.get(); WriteResult result = relations.remove(query); checkResult(result, 1);/*from w ww. j a v a2 s . c om*/ }
From source file:org.alfresco.semantics.MongoSemantics.java
License:Open Source License
public void increaseWeight(String fromId, String toId, double weight) { QueryBuilder queryBuilder = QueryBuilder.start("f").is(fromId).and("t").is(toId); DBObject query = queryBuilder.get(); BasicDBObjectBuilder updateBuilder = BasicDBObjectBuilder.start("$inc", BasicDBObjectBuilder.start("w", weight).get()); DBObject update = updateBuilder.get(); WriteResult result = relations.update(query, update, false, false); checkResult(result, 1);//from ww w .ja v a2 s . c o m }
From source file:org.alfresco.semantics.MongoSemantics.java
License:Open Source License
public List<Relation> relationsFrom(String fromId, Set<String> categories, int skip, int maxItems) { List<Relation> ret = new LinkedList<>(); QueryBuilder queryBuilder = QueryBuilder.start("f").is(fromId); if (categories != null && categories.size() > 0) { queryBuilder.and("c").in(categories); }/* ww w. ja va 2 s . c om*/ DBObject query = queryBuilder.get(); BasicDBObjectBuilder orderByBuilder = BasicDBObjectBuilder.start("t", 1).add("w", 1); DBObject orderBy = orderByBuilder.get(); DBCursor cursor = relations.find(query).sort(orderBy).skip(skip).limit(maxItems); try { for (DBObject dbObject : cursor) { String toId = (String) dbObject.get("t"); double weight = (Double) dbObject.get("w"); Relation r = new Relation(fromId, toId, weight); ret.add(r); } } finally { if (cursor != null) { cursor.close(); } } return ret; }
From source file:org.alfresco.semantics.MongoSemantics.java
License:Open Source License
public List<Relation> relationsTo(String toId, Set<String> categories, int skip, int maxItems) { List<Relation> ret = new LinkedList<>(); QueryBuilder queryBuilder = QueryBuilder.start("t").is(toId); if (categories != null && categories.size() > 0) { queryBuilder.and("c").in(categories); }/*from www . ja v a 2 s .com*/ DBObject query = queryBuilder.get(); BasicDBObjectBuilder orderByBuilder = BasicDBObjectBuilder.start("f", 1).add("w", 1); DBObject orderBy = orderByBuilder.get(); DBCursor cursor = relations.find(query).sort(orderBy).skip(skip).limit(maxItems); try { for (DBObject dbObject : cursor) { String fromId = (String) dbObject.get("f"); double weight = (Double) dbObject.get("w"); Relation r = new Relation(fromId, toId, weight); ret.add(r); } } finally { if (cursor != null) { cursor.close(); } } return ret; }
From source file:org.apache.gora.mongodb.filters.DefaultFactory.java
License:Apache License
protected DBObject transformFieldFilter(final SingleFieldValueFilter<K, T> fieldFilter, final MongoStore<K, T> store) { MongoMapping mapping = store.getMapping(); String dbFieldName = mapping.getDocumentField(fieldFilter.getFieldName()); FilterOp filterOp = fieldFilter.getFilterOp(); List<Object> operands = fieldFilter.getOperands(); QueryBuilder builder = QueryBuilder.start(dbFieldName); builder = appendToBuilder(builder, filterOp, operands); if (!fieldFilter.isFilterIfMissing()) { // If false, the find query will pass if the column is not found. DBObject notExist = QueryBuilder.start(dbFieldName).exists(false).get(); builder = QueryBuilder.start().or(notExist, builder.get()); }/*from w ww .j av a 2s . c om*/ return builder.get(); }