List of usage examples for com.mongodb BasicDBObjectBuilder start
public static BasicDBObjectBuilder start(final String key, final Object val)
From source file:org.alfresco.events.serialize.PropertySerializer.java
License:Open Source License
private DBObject serializeChildAssocRef(ChildAssociationRef assocRef) { NodeRef parentRef = assocRef.getParentRef(); NodeRef childRef = assocRef.getChildRef(); QName typeQName = assocRef.getTypeQName(); QName childQName = assocRef.getQName(); DBObject dbObject = BasicDBObjectBuilder.start("parentRef", serializeNodeRef(parentRef)) .add("childRef", serializeNodeRef(childRef)).add("typeQName", typeQName.toPrefixString()) .add("childQName", childQName.toPrefixString()).get(); return dbObject; }
From source file:org.alfresco.events.serialize.PropertySerializer.java
License:Open Source License
private DBObject serializeAssocRef(AssociationRef assocRef) { NodeRef sourceRef = assocRef.getSourceRef(); NodeRef targetRef = assocRef.getTargetRef(); QName typeQName = assocRef.getTypeQName(); DBObject dbObject = BasicDBObjectBuilder.start("sourceRef", serializeNodeRef(sourceRef)) .add("targetRef", serializeNodeRef(targetRef)).add("typeQName", typeQName.toPrefixString()).get(); return dbObject; }
From source file:org.alfresco.events.serialize.PropertySerializer.java
License:Open Source License
private DBObject serializeNodeRef(NodeRef nodeRef) { StoreRef storeRef = nodeRef.getStoreRef(); DBObject dbObject = BasicDBObjectBuilder.start("storeRef", BasicDBObjectBuilder .start("protocol", storeRef.getProtocol()).add("id", storeRef.getIdentifier()).get()) .add("id", nodeRef.getId()).get(); return dbObject; }
From source file:org.alfresco.module.daos.mongo.MongoNodeDAOImpl.java
License:Apache License
/** * Ensure that the necessary indexes are in place for the Mongo collections */// w ww.j a v a 2 s. c o m protected void initCollections(DB db) { aspects = db.getCollection(COLLECTION_ASPECTS); // @since 2.0 DBObject ASPECTS_NODE_QNAME = BasicDBObjectBuilder.start(FIELD_NODE_ID, 1).add(FIELD_QNAME, 1).get(); aspects.ensureIndex(ASPECTS_NODE_QNAME, "ASPECTS_NODE_QNAME", true); // @since 2.0 DBObject ASPECTS_NODE_TXN_QNAME = BasicDBObjectBuilder.start(FIELD_NODE_ID, 1).add(FIELD_TXN_ID, 1) .add(FIELD_QNAME, 1).get(); aspects.ensureIndex(ASPECTS_NODE_TXN_QNAME, "ASPECTS_NODE_TXN_QNAME", false); properties = db.getCollection(COLLECTION_PROPERTIES); }
From source file:org.alfresco.repo.domain.node.mongo.MongoNodeDAO.java
License:Open Source License
public void init() { if (db == null) { throw new RuntimeException("Mongo DB must not be null"); }//from ww w . ja v a 2 s. c om this.nodes = getCollection(db, nodesCollectionName, WriteConcern.ACKNOWLEDGED); { DBObject primary = BasicDBObjectBuilder.start("n", 1).add("v", 1).get(); DBObject options = BasicDBObjectBuilder.start("unique", true).get(); nodes.createIndex(primary, options); } { DBObject idx1 = BasicDBObjectBuilder.start("n", 1).add("vl", 1).add("c", 1).add("v", 1).get(); nodes.createIndex(idx1); } { DBObject idx1 = BasicDBObjectBuilder.start("n", 1).add("c", 1).add("v", 1).get(); nodes.createIndex(idx1); } }
From source file:org.alfresco.repo.domain.node.mongo.MongoNodeDAO.java
License:Open Source License
@Override public NodeEntity newNode(long parentNodeId, long parentNodeVersion, long childNodeId) { String txnId = TransactionSupport.getTxnId(); String childVersionLabel = "1.0"; long childNodeVersion = 1; DBObject insert = BasicDBObjectBuilder.start("t", txnId).add("pn", parentNodeId) .add("pv", parentNodeVersion).add("n", childNodeId).add("v", childNodeVersion) .add("vl", childVersionLabel).get(); try {/*from ww w. ja v a2 s. c o m*/ nodes.insert(insert); } catch (MongoException.DuplicateKey e) { throw new RuntimeException("Already exists"); } NodeEntity entity = new NodeEntity(); entity.setParentNodeId(parentNodeId); entity.setParentNodeVersion(parentNodeVersion); entity.setNodeId(childNodeId); entity.setNodeVersion(childNodeVersion); entity.setTxnId(txnId); entity.setVersionLabel(childVersionLabel); return entity; }
From source file:org.alfresco.repo.domain.node.mongo.MongoNodeDAO.java
License:Open Source License
private NodeEntity getLatest(long nodeId) { NodeEntity nodeEntity = null;/* ww w . j a v a 2 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 updateNode(long childNodeId, String childVersionLabel) { String txnId = TransactionSupport.getTxnId(); NodeEntity nodeEntity = getLatest(childNodeId); long childNodeVersion = nodeEntity.getNodeVersion() + 1; long parentNodeId = nodeEntity.getParentNodeId(); long parentNodeVersion = nodeEntity.getParentNodeVersion(); DBObject insert = BasicDBObjectBuilder.start("t", txnId).add("pn", parentNodeId) .add("pv", parentNodeVersion).add("n", childNodeId).add("v", childNodeVersion) .add("vl", childVersionLabel).get(); try {//from www. jav a 2s . c om nodes.insert(insert); } catch (MongoException.DuplicateKey e) { throw new ConcurrentModificationException(); } NodeEntity entity = new NodeEntity(); entity.setParentNodeId(parentNodeId); entity.setParentNodeVersion(parentNodeVersion); entity.setNodeId(childNodeId); entity.setNodeVersion(childNodeVersion); entity.setTxnId(txnId); entity.setVersionLabel(childVersionLabel); return entity; }
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;/*from ww w .ja va 2 s. com*/ 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 onRollback(String txnId) { DBObject query = BasicDBObjectBuilder.start("t", txnId).get(); nodes.remove(query); }