List of usage examples for com.mongodb DBObject keySet
Set<String> keySet();
From source file:net.ymate.platform.persistence.mongodb.support.DefaultMongoSession.java
License:Apache License
public <T> WriteResult update(T entity, String[] fieldFilter) throws OperatorException { DBObject _value = MongoEntitySupport.randerToDBObject(entity); DBObject _cond = new BasicDBObject(MongoDB.OPT.ID, _value.removeField(MongoDB.OPT.ID)); DBObject _set = null;//from w w w . ja va 2 s. c o m if (fieldFilter != null && fieldFilter.length > 0) { DBObject _filterValue = new BasicDBObject(); for (String _field : fieldFilter) { if (_field.equals(MongoDB.OPT.ID)) { continue; } _filterValue.put(_field, _value.get(_field)); } _set = new BasicDBObject(MongoDB.OPT.SET, _filterValue.keySet().isEmpty() ? _value : _filterValue); } else { _set = new BasicDBObject(MongoDB.OPT.SET, _value); } // if (__sessionEvent != null) { __sessionEvent.onUpdateBefore(SessionEventObject.createUpdateEvent(entity, fieldFilter)); } // WriteResult _result = __clientHolder.getDB() .getCollection(MongoEntitySupport.getEntityName(entity.getClass())) .update(_cond, _set, false, false, __clientHolder.getWriteConcern()); // if (__sessionEvent != null) { __sessionEvent.onUpdateAfter( SessionEventObject.createUpdateEvent(entity, fieldFilter).addExtraParam(_result)); } // return _result; }
From source file:nl.kpmg.af.service.data.core.repository.MeasurementReadConverter.java
License:Apache License
@Override public Measurement convert(DBObject source) { Measurement measurement = new Measurement(); Set<String> keySet = source.keySet(); for (String key : keySet) { switch (key) { case "_id": measurement.setId((ObjectId) source.get(key)); break; case "version": measurement.setVersion((Integer) source.get(key)); break; case "measurementTimestamp": measurement.setMeasurementTimestamp((Date) source.get(key)); break; default://from ww w. j a v a 2s.co m measurement.put(key, source.get(key)); } } return measurement; }
From source file:nl.kpmg.lcm.server.data.dao.mongo.MongoMetaDataReadConverter.java
License:Apache License
@Override public MetaData convert(DBObject source) { MetaData metaData = new MetaData(); Set<String> keySet = source.keySet(); for (String key : keySet) { switch (key) { case "_id": metaData.setId(source.get(key).toString()); break; case "name": metaData.setName(source.get(key).toString()); break; case "inactive": metaData.setInactive(source.get(key).toString()); break; default://from w w w . j av a 2 s .c om metaData.anySetter(key, source.get(key)); } } return metaData; }
From source file:org.alfresco.bm.api.AbstractRestResource.java
License:Open Source License
/** * Does a deep copy of an object to allow for subsequent modification *///from ww w . j ava 2 s . c o m public static DBObject copyDBObject(DBObject dbObject) { DBObject orig = dbObject; BasicDBObjectBuilder dbObjectBuilder = BasicDBObjectBuilder.start(); for (String field : orig.keySet()) { Object value = orig.get(field); dbObjectBuilder.add(field, value); } return dbObjectBuilder.get(); }
From source file:org.alfresco.bm.test.mongo.MongoTestDAO.java
License:Open Source License
/** * Utility method to copy a DBObject//from www.j a va 2 s . c o m */ private static DBObject copyDBObject(DBObject input) { // Copy the property to a new instance BasicDBObjectBuilder newPropObjBuilder = BasicDBObjectBuilder.start(); for (String fieldName : input.keySet()) { Object fieldValue = input.get(fieldName); newPropObjBuilder.add(fieldName, fieldValue); } return newPropObjBuilder.get(); }
From source file:org.alfresco.events.serialize.PropertySerializer.java
License:Open Source License
@SuppressWarnings("unchecked") public Property deserialize(DBObject propDBObject) { String name = (String) propDBObject.get("name"); DataType dataType = DataType.valueOf((String) propDBObject.get("type")); Object dbValue = propDBObject.get("value"); Serializable value = null;/* w w w .ja va2 s . co m*/ if (dataType == DataType.Any) { // TODO value = null; } else if (dataType == DataType.Encrypted) { value = null; } else if (dataType == DataType.Content) { // don't do anything with content properties (they're handled by contentput events) value = null; } else if (dataType == DataType.Mltext) { DBObject dbObject = (DBObject) dbValue; MLText mlText = new MLText(); for (String languageTag : dbObject.keySet()) { Locale locale = Locale.forLanguageTag(languageTag); String mlValue = (String) dbObject.get(languageTag); mlText.addValue(locale, mlValue); } value = mlText; } else if (dataType == DataType.Date || dataType == DataType.Datetime) { String dateStr = (String) dbValue; value = ISO8601DateFormat.parse(dateStr); } else if (dataType == DataType.Qname) { String qnameStr = (String) dbValue; QName qname = QName.createQName(qnameStr); value = qname; } else if (dataType == DataType.Noderef) { DBObject dbObject = (DBObject) dbValue; NodeRef nodeRef = deserializeNodeRef(dbObject); value = nodeRef; } else if (dataType == DataType.Childassocref) { DBObject dbObject = (DBObject) dbValue; value = deserializeChildAssocRef(dbObject); } else if (dataType == DataType.Assocref) { DBObject dbObject = (DBObject) dbValue; value = deserializeAssocRef(dbObject); } else if (dataType == DataType.Path) { value = deserializePath((List<DBObject>) dbValue); } else if (dataType == DataType.Category) { DBObject dbObject = (DBObject) dbValue; value = deserializeNodeRef(dbObject); } else if (dataType == DataType.Locale) { String languageTag = (String) dbValue; value = Locale.forLanguageTag(languageTag); } else if (dataType == DataType.Version) { VersionNumber versionNumber = new VersionNumber((String) dbValue); value = versionNumber; } else if (dataType == DataType.Period) { DBObject dbObject = (DBObject) dbValue; String periodType = (String) dbObject.get("periodType"); String expression = (String) dbObject.get("expression"); String periodStr = periodType + "|" + expression; Period period = new Period(periodStr); value = period; } else { // TODO } Property property = new Property(name, value, dataType); return property; }
From source file:org.alfresco.serializers.HierarchicalNodeMetadataSerializer.java
License:Open Source License
protected void deserializeNodeProperties(Map<NodeVersionKey, Map<String, Serializable>> map, DBObject dbObject, Set<String> qnames) { Long nodeId = (Long) dbObject.get(NODE_ID); Long nodeVersion = (Long) dbObject.get(NODE_VERSION); if (nodeId == null || nodeVersion == null) { throw new RuntimeException("Expect results with a Node and Version: " + dbObject); }/*from w w w . j a v a2s . co m*/ NodeVersionKey nodeKey = new NodeVersionKey(nodeId, nodeVersion); Map<String, Serializable> props = new HashMap<>(17); DBObject classesDBObject = (DBObject) dbObject.get(CLASSES); if (classesDBObject != null) { for (String className : classesDBObject.keySet()) { DBObject propertiesDBObject = (DBObject) classesDBObject.get(className); if (propertiesDBObject != null) { for (String key : propertiesDBObject.keySet()) { int idx = key.indexOf(":"); if (idx == -1) { throw new AlfrescoRuntimeException(""); } String prefix = key.substring(0, idx); String localName = key.substring(idx + 1); try { QName propertyQName = QName.createQName(prefix, localName, namespaceService); Object propValue = propertiesDBObject.get(key); // Serializable propValue = (Serializable)dbObject.get("value"); // // GridFSDBFile out = myFS.findOne(""); // Object val = SerializationUtils.deserialize(out.getInputStream()); if (qnames == null || qnames.size() == 0 || qnames.contains(propertyQName)) { PropertyDefinition propDef = dictionaryService.getProperty(propertyQName); Object value = getPropertyValue(propDef, propValue); String propertyName = (String) serializerRegistry.serialize(propertyQName); props.put(propertyName, (Serializable) value); } } catch (NamespaceException e) { logger.warn("Unknown prefix " + prefix + ", skipping node properties for class " + className); } } } } } map.put(nodeKey, props); }
From source file:org.alfresco.serializers.HierarchicalNodeMetadataSerializer.java
License:Open Source License
protected Set<QName> deserializeNodeAspects(DBObject dbObject) { Set<QName> aspects = new HashSet<>(); DBObject classes = (DBObject) dbObject.get(CLASSES); if (classes != null) { for (String className : classes.keySet()) { if (className.equals("residual")) { // no containing class continue; }// w w w . j a v a2 s.c o m int idx = className.indexOf(":"); if (idx == -1) { throw new AlfrescoRuntimeException(""); } String prefix = className.substring(0, idx); String localName = className.substring(idx + 1); try { QName classQName = QName.createQName(prefix, localName, namespaceService); AspectDefinition aspectDef = dictionaryService.getAspect(classQName); if (aspectDef != null) { aspects.add(classQName); } } catch (NamespaceException e) { logger.warn("Unknown prefix " + prefix + ", skipping node aspect " + className); } } } return aspects; }
From source file:org.alfresco.serializers.JSON.java
License:Open Source License
public static JSON from(DBObject dbObject) { JSON json = new JSON(); for (String key : dbObject.keySet()) { Object value = dbObject.get(key); json.put(key, value);// w w w . j a v a 2s.c o m } return json; }
From source file:org.apache.felix.useradmin.mongodb.MongoSerializerHelper.java
License:Apache License
/** * Deserializes the given {@link DBObject} into the given {@link Dictionary}. * //from ww w .ja v a 2 s . com * @param dictionary the dictionary to fill, cannot be <code>null</code>; * @param object the {@link DBObject} to deserialize, can be <code>null</code>. */ private void deserializeDictionary(Dictionary dictionary, DBObject object) { // FELIX-4399: MongoDB does return null for empty properties... if (object != null) { for (String key : object.keySet()) { dictionary.put(KeyCodec.decode(key), object.get(key)); } } }