List of usage examples for com.mongodb DBObject put
Object put(String key, Object v);
From source file:com.ebay.cloud.cms.dal.persistence.flatten.impl.embed.AbstractEmbedCommand.java
License:Apache License
protected DBObject buildModifyQuery(DBObject rootQuery, NewBsonEntity entity) { int currentVersion = entity.getVersion(); if (currentVersion != IEntity.NO_VERSION) { rootQuery.put(InternalFieldEnum.VERSION.getDbName(), currentVersion); }// w w w . j a v a 2 s. c o m if (helper.isEmbedEntity(entity.getId())) { entity.removeField(InternalFieldEnum.VERSION.getName()); } return rootQuery; }
From source file:com.ebay.cloud.cms.dal.persistence.flatten.impl.embed.AbstractEmbedCommand.java
License:Apache License
protected void buildRootUpdateObject(NewBsonEntity entity, Integer newVersion, DBObject updateBody, MetaClass rootMetaClass) {/*from w ww.ja v a 2s. co m*/ BasicDBObject setObject = (BasicDBObject) updateBody.get("$set"); if (setObject == null) { setObject = new BasicDBObject(); } // populate the data to the root entity for the internal fields if (newVersion != null) { setObject.put(InternalFieldEnum.VERSION.getDbName(), newVersion); } setObject.put(InternalFieldEnum.MODIFIER.getDbName(), entity.getModifier()); setObject.put(InternalFieldEnum.LASTMODIFIED.getDbName(), new Date()); setObject.put(InternalFieldEnum.STATUS.getDbName(), StatusEnum.ACTIVE.toString()); setObject.put(InternalFieldEnum.BRANCH.getDbName(), entity.getBranchId()); setObject.put(InternalFieldEnum.TYPE.getDbName(), rootMetaClass.getName()); String rootId = helper.getRootId(entity.getId()); setObject.put(InternalFieldEnum.ID.getDbName(), rootId); setInternalField(entity, setObject, InternalFieldEnum.COMMENT); setInternalField(entity, setObject, InternalFieldEnum.USER); updateBody.put("$set", setObject); }
From source file:com.ebay.cloud.cms.dal.persistence.flatten.impl.embed.AbstractFieldEmbedCommand.java
License:Apache License
protected void buildRootModifyBody(DBObject modifyBody) { // update entity version BasicDBObject versionObject = new BasicDBObject(); versionObject.put(InternalFieldEnum.VERSION.getDbName(), 1); modifyBody.put("$inc", versionObject); buildRootUpdateObject(entity, null, modifyBody, rootMetaClass); }
From source file:com.ebay.cloud.cms.dal.persistence.flatten.impl.embed.AbstractFieldEmbedCommand.java
License:Apache License
protected void buildEmbedModifyBody(String parentPath, DBObject modifyBody) { BasicDBObject setObject = (BasicDBObject) modifyBody.get("$set"); if (setObject == null) { setObject = new BasicDBObject(); }//from ww w .j av a2 s . c o m StringBuilder modifier = new StringBuilder(); modifier.append(parentPath).append(DOT).append(InternalFieldEnum.MODIFIER.getDbName()); StringBuilder lastModified = new StringBuilder(); lastModified.append(parentPath).append(DOT).append(InternalFieldEnum.LASTMODIFIED.getDbName()); setObject.put(modifier.toString(), entity.getModifier()); setObject.put(lastModified.toString(), entity.getLastModified()); modifyBody.put("$set", setObject); }
From source file:com.ebay.cloud.cms.dal.persistence.flatten.impl.embed.AbstractFieldEmbedCommand.java
License:Apache License
protected DBObject buildSetBody(DBObject rootObject) { BasicDBObject setModifyObject = new BasicDBObject(); Object obj = (Object) rootObject.get(embedFieldName); if (obj == null) { throw new CmsDalException(DalErrCodeEnum.ENTITY_NOT_FOUND, getOperation() + ", can not find embed field with Id: " + this.entity.getId()); }/* w w w. ja va2 s . c o m*/ // update root embed field's last modified time MetaField field = rootMetaClass.getFieldByFlattenValueDbName(embedFieldName); rootObject.put(field.getFlattenPropertyValueDbName(FieldProperty.TIMESTAMP), new Date()); setModifyObject.put(embedFieldName, obj); BasicDBObject modifyBody = new BasicDBObject(); modifyBody.put("$set", setModifyObject); // increase version on root document BasicDBObject versionObject = new BasicDBObject(); versionObject.put(InternalFieldEnum.VERSION.getDbName(), 1); modifyBody.put("$inc", versionObject); buildRootUpdateObject(entity, null, modifyBody, rootMetaClass); return modifyBody; }
From source file:com.ebay.cloud.cms.dal.persistence.flatten.impl.embed.EmbedDeleteCommand.java
License:Apache License
public DBObject buildDeleteBody(MetaRelationship metaField, String parentPath, String entityId, int newVersion, MetaClass rootMetaClass) {/*from w w w. j a v a2s .c o m*/ String embedPath = metaField.getFlattenValueDbName(); String embedLengthPath = metaField.getFlattenPropertyValueDbName(FieldProperty.LENGTH); if (!StringUtils.isNullOrEmpty(parentPath)) { embedPath = parentPath + FlattenEntityIDHelper.DOT + embedPath; embedLengthPath = parentPath + FlattenEntityIDHelper.DOT + embedLengthPath; } DBObject deleteBody = new BasicDBObject(); if (metaField.getCardinality() == CardinalityEnum.Many) { // $pull this from array BasicDBObject idObject = new BasicDBObject(); idObject.put(InternalFieldEnum.ID.getDbName(), entityId); BasicDBObject pullObject = new BasicDBObject(); pullObject.put(embedPath, idObject); deleteBody.put("$pull", pullObject); DBObject decObject = new BasicDBObject(); // maintain the _length value. decObject.put(embedLengthPath, -1); deleteBody.put("$inc", decObject); // root update object. buildRootUpdateObject(entity, newVersion, deleteBody, rootMetaClass); } else { // $unset to remove this BasicDBObject unsetObject = new BasicDBObject(); unsetObject.put(embedPath, 1); deleteBody.put("$unset", unsetObject); buildRootUpdateObject(entity, newVersion, deleteBody, rootMetaClass); } return deleteBody; }
From source file:com.ebay.cloud.cms.dal.persistence.flatten.impl.embed.EmbedFieldModifyCommand.java
License:Apache License
void buildJsonBody(BasicDBObject embedObject, MetaField field) { // incremental $set BasicDBObject enityObject = (BasicDBObject) getEntity().getNode(); BasicDBObject fieldObject = (BasicDBObject) enityObject.get(field.getFlattenValueDbName()); if (fieldObject != null) { DBObject valueObj = (DBObject) embedObject.get(field.getFlattenValueDbName()); if (valueObj == null) { valueObj = new BasicDBObject(); embedObject.put(field.getFlattenValueDbName(), valueObj); }/* w ww . j av a 2s . c o m*/ BasicDBObject givenValue = fieldObject; if (givenValue != null) { for (String key : givenValue.keySet()) { valueObj.put(key, givenValue.get(key)); } // update field property embedObject.put(field.getFlattenPropertyValueDbName(FieldProperty.TIMESTAMP), getEntity().getFieldTimestamp(field.getName())); } } }
From source file:com.ebay.cloud.cms.dal.persistence.flatten.impl.IndexBuildCommand.java
License:Apache License
private DBObject buildIndexOptionObject(IndexInfo index) { DBObject optionsObject = new BasicDBObject(); for (IndexOptionEnum option : index.getIndexOptions()) { optionsObject.put(option.name(), true); }//ww w.j a va2s. c o m optionsObject.put("name", index.getIndexName()); optionsObject.put("background", "true"); return optionsObject; }
From source file:com.ebay.cloud.cms.dal.persistence.flatten.impl.IndexBuildCommand.java
License:Apache License
private DBObject buildIndexKeyObject(MetaClass metadata, IndexInfo index, boolean onMainBranch) { DBObject keyObject = new BasicDBObject(); // in sharded case. sharding key must be prefix of the unique key boolean hashed = index.getIndexOptions().contains(IndexOptionEnum.hashed); for (String key : index.getKeyList()) { String[] keySeg = key.split("\\."); StringBuilder sb = new StringBuilder(); getKeyName(metadata, keySeg, 0, sb); keyObject.put(sb.toString(), hashed ? "hashed" : 1); }/*from w w w .j a va 2 s.co m*/ //since objects in different sub branches are in the same collection, // need to add the branch id into the index. // so the objects on different sub branches will not conflict on "unique index" if (!onMainBranch) { keyObject.put(InternalFieldEnum.BRANCH.getDbName(), 1); } return keyObject; }
From source file:com.ebay.cloud.cms.dal.persistence.flatten.impl.root.AbstractFieldCommand.java
License:Apache License
protected void buildInternalUpdate(DBObject modifyBody) { // update entity version BasicDBObject inc = new BasicDBObject(); inc.put(InternalFieldEnum.VERSION.getDbName(), 1); modifyBody.put("$inc", inc); // set internal fields BasicDBObject set = new BasicDBObject(); set.put(InternalFieldEnum.LASTMODIFIED.getDbName(), getEntity().getLastModified()); set.put(InternalFieldEnum.STATUS.getDbName(), StatusEnum.ACTIVE.toString()); set.put(InternalFieldEnum.BRANCH.getDbName(), getEntity().getBranchId()); set.put(InternalFieldEnum.MODIFIER.getDbName(), getEntity().getModifier()); set.put(InternalFieldEnum.ID.getDbName(), getEntity().getId()); set.put(InternalFieldEnum.TYPE.getDbName(), getEntity().getType()); set.put(InternalFieldEnum.METAVERSION.getDbName(), getEntity().getMetaVersion()); List<?> comments = entity.getFieldValues(InternalFieldEnum.COMMENT.getName()); if (!comments.isEmpty()) { set.put(InternalFieldEnum.COMMENT.getDbName(), comments.get(0)); }// ww w .j av a 2 s.c o m List<?> users = entity.getFieldValues(InternalFieldEnum.USER.getName()); if (!users.isEmpty()) { set.put(InternalFieldEnum.USER.getDbName(), users.get(0)); } modifyBody.put("$set", set); }