List of usage examples for com.mongodb BasicDBObjectBuilder start
public static BasicDBObjectBuilder start()
From source file:org.alfresco.cacheserver.dao.mongo.MongoWebSocketDAO.java
License:Open Source License
protected DBCollection getCappedCollection(DB db, String collectionName, Integer maxCollectionSize, Integer maxDocuments, WriteConcern writeConcern) { if (!db.collectionExists(collectionName)) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); builder.add("capped", true); if (maxCollectionSize != null) { builder.add("size", maxCollectionSize); }//from w w w .j a v a 2 s . co m if (maxDocuments != null) { builder.add("max", maxDocuments); } DBObject options = builder.get(); db.createCollection(collectionName, options); } DBCollection collection = db.getCollection(collectionName); collection.setWriteConcern(writeConcern); return collection; }
From source file:org.alfresco.events.serialize.NodeAddedEventSerializer.java
License:Open Source License
@Override protected DBObject serializeNodeEvent(NodeEvent nodeEvent) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); buildDBObjectFromNodeEvent(builder, nodeEvent); return builder.get(); }
From source file:org.alfresco.events.serialize.NodeCheckedOutEventSerializer.java
License:Open Source License
@Override protected DBObject serializeNodeEvent(NodeEvent nodeEvent) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); buildDBObjectFromNodeEvent(builder, nodeEvent); if (nodeEvent instanceof NodeCheckedOutEvent) { NodeCheckedOutEvent nodeCheckedOutEvent = (NodeCheckedOutEvent) nodeEvent; builder.add(FIELD_CHECKED_OUT_NODE_ID, nodeCheckedOutEvent.getCheckedOutNodeId()); }//from ww w .j a v a 2 s . co m return builder.get(); }
From source file:org.alfresco.events.serialize.NodeContentPutEventSerializer.java
License:Open Source License
@Override protected DBObject serializeNodeEvent(NodeEvent nodeEvent) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); buildDBObjectFromNodeEvent(builder, nodeEvent); if (nodeEvent instanceof NodeContentPutEvent) { NodeContentPutEvent nodeCPEvent = (NodeContentPutEvent) nodeEvent; builder.add(FIELD_SIZE, nodeCPEvent.getSize()).add(FIELD_ENCODING, nodeCPEvent.getEncoding()) .add(FIELD_MIME_TYPE, nodeCPEvent.getMimeType()); }// www . j ava2 s . c o m return builder.get(); }
From source file:org.alfresco.events.serialize.NodeMovedEventSerializer.java
License:Open Source License
@Override protected DBObject serializeNodeEvent(NodeEvent nodeEvent) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); buildDBObjectFromNodeEvent(builder, nodeEvent); if (nodeEvent instanceof NodeMovedEvent) { NodeMovedEvent nodeMovedEvent = (NodeMovedEvent) nodeEvent; List<String> toPaths = nodeMovedEvent.getToPaths(); String toPathStr = toPaths.get(0); Path toPath = new Path(toPathStr); String newName = nodeMovedEvent.getNewName(); builder.add(FIELD_TO_PARENT_NODE_IDS, nodeMovedEvent.getToParentNodeIds()) .add(FIELD_PRIMARY_TO_PATH, (toPath != null ? toPath.getArrayPath() : null)) .add(FIELD_NODE_NEW_NAME, newName); }//from www . j av a 2s .c o m return builder.get(); }
From source file:org.alfresco.events.serialize.NodeRenamedEventSerializer.java
License:Open Source License
@Override protected DBObject serializeNodeEvent(NodeEvent nodeEvent) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); buildDBObjectFromNodeEvent(builder, nodeEvent); if (nodeEvent instanceof NodeRenamedEvent) { NodeRenamedEvent nodeRenamedEvent = (NodeRenamedEvent) nodeEvent; List<String> toPaths = nodeRenamedEvent.getToPaths(); String toPathStr = toPaths.get(0); Path toPath = new Path(toPathStr); String newName = nodeRenamedEvent.getNewName(); builder.add(FIELD_PRIMARY_TO_PATH, (toPath != null ? toPath.getArrayPath() : null)) .add(FIELD_NODE_NEW_NAME, newName); }//w w w . j av a2 s . c o m return builder.get(); }
From source file:org.alfresco.events.serialize.NodeUpdatedEventSerializer.java
License:Open Source License
@Override protected DBObject serializeNodeEvent(NodeEvent nodeEvent) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); buildDBObjectFromNodeEvent(builder, nodeEvent); if (nodeEvent instanceof NodeUpdatedEvent) { NodeUpdatedEvent nodeUpdatedEvent = (NodeUpdatedEvent) nodeEvent; Set<String> aspectsAdded = nodeUpdatedEvent.getAspectsAdded(); if (aspectsAdded != null) { builder.add("aspectsAdded", aspectsAdded); }/*from w ww . java 2 s .c o m*/ Set<String> aspectsRemoved = nodeUpdatedEvent.getAspectsRemoved(); if (aspectsRemoved != null) { builder.add("aspectsRemoved", aspectsRemoved); } Map<String, Property> propsAdded = nodeUpdatedEvent.getPropertiesAdded(); if (propsAdded != null) { List<DBObject> propertiesAdded = new ArrayList<DBObject>(propsAdded.size()); for (Map.Entry<String, Property> entry : propsAdded.entrySet()) { Property prop = entry.getValue(); DBObject propDbObject = propertySerializer.serialize(prop); propertiesAdded.add(propDbObject); } builder.add("propertiesAdded", propertiesAdded); } Map<String, Property> propsChanged = nodeUpdatedEvent.getPropertiesChanged(); if (propsChanged != null) { List<DBObject> propertiesChanged = new ArrayList<DBObject>(propsChanged.size()); for (Map.Entry<String, Property> entry : propsChanged.entrySet()) { Property prop = entry.getValue(); DBObject propDbObject = propertySerializer.serialize(prop); propertiesChanged.add(propDbObject); } builder.add("propertiesChanged", propertiesChanged); } Set<String> propsRemoved = nodeUpdatedEvent.getPropertiesRemoved(); if (propsRemoved != null) { builder.add("propertiesRemoved", propsRemoved); } } return builder.get(); }
From source file:org.alfresco.events.serialize.PropertySerializer.java
License:Open Source License
public DBObject serialize(Property property) { String name = property.getName(); DataType type = property.getDataType(); Object value = property.getValue(); // Use the value as is for the data types: // DataType.Text, DataType.Int, DataType.Long, DataType.Float, DataType.Double, DataType.Boolean if (value != null) { if (type == null || type == DataType.Any) { value = value.toString();//from w w w . j ava 2 s . c o m } else if (type == DataType.Encrypted) { value = "*****"; } else if (type == DataType.Content) { // don't do anything with content properties (they're handled by contentput events) value = null; // ContentData contentData = (ContentData)value; // String contentUrl = contentData.getContentUrl(); // String encoding = contentData.getEncoding(); // String mimeType = contentData.getMimetype(); // contentData. } else if (type == DataType.Mltext) { MLText mlText = (MLText) value; BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); for (Locale locale : mlText.getLocales()) { String languageTag = locale.toLanguageTag(); String mlValue = mlText.getValue(locale); builder.add(languageTag, mlValue); } value = builder.get(); } else if (type == DataType.Date || type == DataType.Datetime) { Date date = (Date) value; value = ISO8601DateFormat.format(date); } else if (type == DataType.Qname) { QName qname = (QName) value; value = qname.toPrefixString(); } else if (type == DataType.Noderef) { NodeRef nodeRef = (NodeRef) value; value = serializeNodeRef(nodeRef); } else if (type == DataType.Childassocref) { ChildAssociationRef assocRef = (ChildAssociationRef) value; value = serializeChildAssocRef(assocRef); } else if (type == DataType.Assocref) { AssociationRef assocRef = (AssociationRef) value; value = serializeAssocRef(assocRef); } else if (type == DataType.Path) { Path path = (Path) value; value = serializePath(path); } else if (type == DataType.Category) { NodeRef nodeRef = (NodeRef) value; value = serializeNodeRef(nodeRef); } else if (type == DataType.Locale) { Locale locale = (Locale) value; value = locale.toLanguageTag(); } else if (type == DataType.Version) { VersionNumber versionNumber = (VersionNumber) value; value = versionNumber.getParts(); } else if (type == DataType.Period) { Period period = (Period) value; String periodType = period.getPeriodType(); String expression = period.getExpression(); value = BasicDBObjectBuilder.start("periodType", periodType).add("expression", expression).get(); } else { // try converting to a string value = value.toString(); } } DBObject ret = BasicDBObjectBuilder.start("name", name).add("type", (type != null ? type.toString() : null)) .add("value", value).get(); return ret; }
From source file:org.alfresco.module.daos.mongo.MongoNodeDAOImpl.java
License:Apache License
@Override protected void insertNodeAspect(Long nodeId, Long qnameId) { // Get the current transaction ID. Long txnId = getCurrentTransactionId(true); // Resolve the QName QName qname = qnameDAO.getQName(qnameId).getSecond(); String qnameStr = qname.toString(); DBObject insertObj = BasicDBObjectBuilder.start().add(FIELD_NODE_ID, nodeId).add(FIELD_TXN_ID, txnId) .add(FIELD_QNAME, qnameStr).get(); WriteResult result = aspects.insert(insertObj); if (result.getError() != null) { throw new ConcurrencyFailureException("Failed to insert aspect: " + result + "\n" + " Node ID: " + nodeId + "\n" + " QName: " + qnameStr + "\n" + " Txn ID: " + txnId); }// www . j a v a 2 s. c o m if (duplicateToSql) { // Duplicate super.insertNodeAspect(nodeId, qnameId); } }
From source file:org.alfresco.serializers.HierarchicalNodeMetadataSerializer.java
License:Open Source License
protected DBObject buildDeleteProperties(NodeVersionKey nodeVersionKey, Set<String> qnames) { if (qnames == null || qnames.isEmpty()) { throw new IllegalArgumentException(); } else {//from ww w . ja v a2 s . c om BasicDBObjectBuilder updateBuilder = BasicDBObjectBuilder.start(); BasicDBObjectBuilder propertiesBuilder = BasicDBObjectBuilder.start(); for (String propertyName : qnames) { QName propertyQName = serializerRegistry.deserialize(QName.class, propertyName); PropertyDefinition propDef = dictionaryService.getProperty(propertyQName); ClassDefinition classDef = propDef.getContainerClass(); QName aspectQName = classDef.getName(); String className = serializerRegistry.serialize(aspectQName).toString(); propertiesBuilder.add(className + "." + propertyName, ""); } updateBuilder.add("$unset", propertiesBuilder.get()); return updateBuilder.get(); } }