List of usage examples for com.mongodb DBObject putAll
void putAll(BSONObject o);
From source file:org.springframework.data.document.mongodb.query.Criteria.java
License:Apache License
protected DBObject getSingleCriteriaObject() { DBObject dbo = new BasicDBObject(); boolean not = false; for (String k : this.criteria.keySet()) { if (not) { DBObject notDbo = new BasicDBObject(); notDbo.put(k, this.criteria.get(k)); dbo.put("$not", notDbo); not = false;//from w w w . j a va 2s . c om } else { if ("$not".equals(k)) { not = true; } else { dbo.put(k, this.criteria.get(k)); } } } DBObject queryCriteria = new BasicDBObject(); if (isValue != NOT_SET) { queryCriteria.put(this.key, this.isValue); queryCriteria.putAll(dbo); } else { queryCriteria.put(this.key, dbo); } return queryCriteria; }
From source file:org.springframework.data.document.mongodb.query.Query.java
License:Apache License
public DBObject getQueryObject() { DBObject dbo = new BasicDBObject(); for (String k : criteria.keySet()) { CriteriaDefinition c = criteria.get(k); DBObject cl = c.getCriteriaObject(); dbo.putAll(cl); }//ww w . j a va2 s . c o m return dbo; }
From source file:org.springframework.data.mongodb.builder.CriteriaSpec.java
License:Apache License
public DBObject getCriteriaObject(String key) { DBObject dbo = new BasicDBObject(); boolean not = false; for (String k : criteria.keySet()) { if (not) { DBObject notDbo = new BasicDBObject(); notDbo.put(k, criteria.get(k)); dbo.put("$not", notDbo); not = false;// w w w . j av a 2 s . c o m } else { if ("$not".equals(k)) { not = true; } else { dbo.put(k, criteria.get(k)); } } } DBObject queryCriteria = new BasicDBObject(); if (isValue != null) { queryCriteria.put(key, isValue); queryCriteria.putAll(dbo); } else { queryCriteria.put(key, dbo); } return queryCriteria; }
From source file:org.springframework.data.mongodb.builder.QuerySpec.java
License:Apache License
@Override public DBObject getQueryObject() { DBObject dbo = new BasicDBObject(); for (String k : criteria.keySet()) { Criteria c = criteria.get(k);/*w ww .java 2s .com*/ DBObject cl = c.getCriteriaObject(k); dbo.putAll(cl); } return dbo; }
From source file:org.springframework.data.mongodb.core.aggregation.BucketAutoOperation.java
License:Apache License
@Override public DBObject toDBObject(AggregationOperationContext context) { DBObject options = new BasicDBObject(); options.put("buckets", buckets); options.putAll(super.toDBObject(context)); if (granularity != null) { options.put("granularity", granularity); }//w w w. ja v a2 s . co m return new BasicDBObject("$bucketAuto", options); }
From source file:org.springframework.data.mongodb.core.aggregation.BucketOperation.java
License:Apache License
@Override public DBObject toDBObject(AggregationOperationContext context) { DBObject options = new BasicDBObject(); options.put("boundaries", context.getMappedObject(new BasicDBObject("$set", boundaries)).get("$set")); if (defaultBucket != null) { options.put("default", context.getMappedObject(new BasicDBObject("$set", defaultBucket)).get("$set")); }/* w w w . jav a2s . c o m*/ options.putAll(super.toDBObject(context)); return new BasicDBObject("$bucket", options); }
From source file:org.springframework.data.mongodb.core.convert.MappingMongoConverter.java
License:Apache License
/** * Internal write conversion method which should be used for nested invocations. * //from www . j a v a2 s .co m * @param obj * @param dbo */ @SuppressWarnings("unchecked") protected void writeInternal(final Object obj, final DBObject dbo, final TypeInformation<?> typeHint) { if (null == obj) { return; } Class<?> entityType = obj.getClass(); Class<?> customTarget = conversions.getCustomWriteTarget(entityType, DBObject.class); if (customTarget != null) { DBObject result = conversionService.convert(obj, DBObject.class); dbo.putAll(result); return; } if (Map.class.isAssignableFrom(entityType)) { writeMapInternal((Map<Object, Object>) obj, dbo, ClassTypeInformation.MAP); return; } if (Collection.class.isAssignableFrom(entityType)) { writeCollectionInternal((Collection<?>) obj, ClassTypeInformation.LIST, (BasicDBList) dbo); return; } MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityType); writeInternal(obj, dbo, entity); addCustomTypeKeyIfNecessary(typeHint, obj, dbo); }
From source file:org.springframework.data.mongodb.core.convert.QueryMapper.java
License:Apache License
/** * Replaces the property keys used in the given {@link DBObject} with the appropriate keys by using the * {@link PersistentEntity} metadata.//from ww w . j a v a 2 s. com * * @param query must not be {@literal null}. * @param entity can be {@literal null}. * @return */ @SuppressWarnings("deprecation") public DBObject getMappedObject(DBObject query, MongoPersistentEntity<?> entity) { if (isNestedKeyword(query)) { return getMappedKeyword(new Keyword(query), entity); } DBObject result = new BasicDBObject(); for (String key : query.keySet()) { // TODO: remove one once QueryMapper can work with Query instances directly if (Query.isRestrictedTypeKey(key)) { @SuppressWarnings("unchecked") Set<Class<?>> restrictedTypes = (Set<Class<?>>) query.get(key); this.converter.getTypeMapper().writeTypeRestrictions(result, restrictedTypes); continue; } if (isKeyword(key)) { result.putAll(getMappedKeyword(new Keyword(query, key), entity)); continue; } try { Field field = createPropertyField(entity, key, mappingContext); Entry<String, Object> entry = getMappedObjectForField(field, query.get(key)); result.put(entry.getKey(), entry.getValue()); } catch (InvalidPersistentPropertyPath invalidPathException) { // in case the object has not already been mapped if (!(query.get(key) instanceof DBObject)) { throw invalidPathException; } result.put(key, query.get(key)); } } return result; }
From source file:org.springframework.data.mongodb.core.convert.QueryMapper.java
License:Apache License
private void mapMetaAttributes(DBObject source, MongoPersistentEntity<?> entity, MetaMapping metaMapping) { if (entity == null || source == null) { return;/*from w ww . j a v a2s.c om*/ } if (entity.hasTextScoreProperty() && !MetaMapping.IGNORE.equals(metaMapping)) { MongoPersistentProperty textScoreProperty = entity.getTextScoreProperty(); if (MetaMapping.FORCE.equals(metaMapping) || (MetaMapping.WHEN_PRESENT.equals(metaMapping) && source.containsField(textScoreProperty.getFieldName()))) { source.putAll(getMappedTextScoreField(textScoreProperty)); } } }
From source file:org.springframework.data.mongodb.core.convert.UpdateMapper.java
License:Apache License
private Entry<String, Object> getMappedUpdateModifier(Field field, Object rawValue) { Object value = null;//from w ww . j a v a2s. com if (rawValue instanceof Modifier) { value = getMappedValue(field, (Modifier) rawValue); } else if (rawValue instanceof Modifiers) { DBObject modificationOperations = new BasicDBObject(); for (Modifier modifier : ((Modifiers) rawValue).getModifiers()) { modificationOperations.putAll(getMappedValue(field, modifier).toMap()); } value = modificationOperations; } else { throw new IllegalArgumentException( String.format("Unable to map value of type '%s'!", rawValue.getClass())); } return createMapEntry(field, value); }