List of usage examples for com.mongodb DBObject keySet
Set<String> keySet();
From source file:com.ebay.cloud.cms.dal.search.impl.SearchServiceImpl.java
License:Apache License
private void addToList(DBObject groupMatch, List<DBObject> aggregationObjects) { if (groupMatch != null && groupMatch.keySet().size() > 0) { aggregationObjects.add(groupMatch); }//from ww w . j a v a2 s.c o m }
From source file:com.ebay.cloud.cms.metadata.mongo.MongoRepositoryServiceImpl.java
License:Apache License
@Override public void updateRepository(Repository repo) { CheckConditions.checkNotNull(repo, "repository can not be null"); CheckConditions.checkNotNull(repo.getRepositoryName(), "repository name can not be null"); String repositoryName = repo.getRepositoryName(); try {/*from www . j a va 2 s .c o m*/ metadataLock.lock(); DBObject qryDbo = new BasicDBObject(); qryDbo.put(Repository.REPOSITORY_FIELD_NAME, repositoryName); // only support admin change now DBObject updateDbo = new BasicDBObject(); DBObject setDbo = new BasicDBObject(); if (repo.getRepositoryAdmin() != null) { setDbo.put(Repository.REPOSITORY_FIELD_ADMIN_NAME, repo.getRepositoryAdmin()); setDbo.put(Repository.REPOSITORY_FIELD_TYPE_NAME, repo.getAccessType().name()); } if (repo.getOptions() != null) { setDbo.put(Repository.REPOSITORY_FIELD_OPTIONS_NAME, repositoryOptionConverter.toBson(repo.getOptions())); } if (!setDbo.keySet().isEmpty()) { updateDbo.put("$set", setDbo); WriteResult result = repoCollection.update(qryDbo, updateDbo); if (result.getN() != 1) { throw new RepositoryNotExistsException(repositoryName); } } refreshRepositoryCache(); } catch (InterruptedException e) { logger.info("lock interrupted for createRepository " + repositoryName); throw new MetaDataException(MetaErrCodeEnum.LOCK_INTERRUPTED, "lock interrupted for createRepository " + repositoryName, e); } finally { metadataLock.unlock(); } }
From source file:com.edgytech.umongo.CollectionPanel.java
License:Apache License
public void findAndModify(final ButtonBase button) { final DBCollection col = getCollectionNode().getCollection(); final DBObject query = ((DocBuilderField) getBoundUnit(Item.famQuery)).getDBObject(); final DBObject fields = ((DocBuilderField) getBoundUnit(Item.famFields)).getDBObject(); final DBObject sort = ((DocBuilderField) getBoundUnit(Item.famSort)).getDBObject(); final BasicDBObject update = (BasicDBObject) ((DocBuilderField) getBoundUnit(Item.famUpdate)).getDBObject(); final boolean remove = getBooleanFieldValue(Item.famRemove); final boolean returnNew = getBooleanFieldValue(Item.famReturnNew); final boolean upsert = getBooleanFieldValue(Item.famUpsert); BasicDBObject cmd = new BasicDBObject("findandmodify", col.getName()); if (query != null && !query.keySet().isEmpty()) { cmd.append("query", query); }// w w w . j a va2 s . c o m if (fields != null && !fields.keySet().isEmpty()) { cmd.append("fields", fields); } if (sort != null && !sort.keySet().isEmpty()) { cmd.append("sort", sort); } if (remove) { cmd.append("remove", remove); } else { if (update != null && !update.keySet().isEmpty()) { // if 1st key doesn't start with $, then object will be inserted as is, need to check it String key = update.keySet().iterator().next(); if (key.charAt(0) != '$') { MongoUtils.checkObject(update, false, false); } cmd.append("update", (DBObject) update.copy()); } if (returnNew) { cmd.append("new", returnNew); } if (upsert) { cmd.append("upsert", upsert); } } new DbJobCmd(col.getDB(), cmd, null, button).addJob(); }
From source file:com.edgytech.umongo.CollectionPanel.java
License:Apache License
private Object handleSpecialFields(DBObject doc) { for (String field : doc.keySet()) { if (field.equals("__rand")) { String type = (String) doc.get(field); if (type.equals("int")) { int min = (Integer) doc.get("min"); int max = (Integer) doc.get("max"); return min + (int) (Math.random() * ((max - min) + 1)); } else if (type.equals("str")) { int len = (Integer) doc.get("len"); StringBuilder sb = new StringBuilder(len); byte min = 0x61; byte max = 0x7a; for (int i = 0; i < len; ++i) { char c = (char) (min + (byte) (Math.random() * ((max - min) + 1))); sb.append(c);// www. j a va 2 s . c o m } return sb.toString(); } } Object val = doc.get(field); if (val instanceof BasicDBObject) { BasicDBObject subdoc = (BasicDBObject) val; Object res = handleSpecialFields(subdoc); if (res != null) { doc.put(field, res); } } else if (val instanceof BasicDBList) { BasicDBList sublist = (BasicDBList) val; handleSpecialFields(sublist); } } return null; }
From source file:com.edgytech.umongo.DbJobCmd.java
License:Apache License
public DbJobCmd(DB db, DBObject cmd, BasePanel panel, BaseTreeNode node, ButtonBase button) { this.id = null; this.label = cmd.keySet().iterator().next(); this.db = db; this.cmd = cmd; this.panel = panel; this.button = button; this.node = node; }
From source file:com.edgytech.umongo.DbJobCmd.java
License:Apache License
public DbJobCmd(DB db, DBObject cmd, BasePanel panel, ButtonBase button) { this.id = null; this.label = cmd.keySet().iterator().next(); this.db = db; this.cmd = cmd; this.panel = panel; this.button = button; }
From source file:com.edgytech.umongo.DocFieldObject.java
License:Apache License
@Override protected void structureComponentCustom(BoxPanel old) { Div fields = (Div) getBoundUnit(Item.fields); fields.removeAllChildren();/*from www . ja v a 2s. com*/ DBObject doc = (DBObject) value; if (doc == null || doc.keySet().isEmpty()) { fields.addChild(new Text(null, null, "Empty")); } else { for (String key : doc.keySet()) { Object val = doc.get(key); if (val instanceof BasicDBObject) { fields.addChild(new DocFieldObject(key, key, val, this)); } else if (val instanceof BasicDBList) { fields.addChild(new DocFieldArray(key, key, val, this)); } else { fields.addChild(new DocFieldText(key, key, val, this)); } } } fields.structureComponent(); super.structureComponentCustom(old); }
From source file:com.edgytech.umongo.DocFieldObject.java
License:Apache License
void moveUp(String key) { DBObject doc = (DBObject) value; value = createDBObject();/* ww w . j a v a 2 s.c o m*/ Iterator<String> it = doc.keySet().iterator(); String prev = it.next(); while (it.hasNext()) { String cur = it.next(); if (cur.equals(key)) { addField(cur, doc.get(cur)); cur = prev; } else { addField(prev, doc.get(prev)); } prev = cur; } addField(prev, doc.get(prev)); structureComponent(); }
From source file:com.edgytech.umongo.DocFieldObject.java
License:Apache License
void moveDown(String key) { DBObject doc = (DBObject) value; value = createDBObject();/* w ww . j av a2 s .co m*/ Iterator<String> it = doc.keySet().iterator(); while (it.hasNext()) { String cur = it.next(); if (cur.equals(key) && it.hasNext()) { String next = it.next(); addField(next, doc.get(next)); } addField(cur, doc.get(cur)); } structureComponent(); }
From source file:com.edgytech.umongo.DocumentDeserializer.java
License:Apache License
private void fillInTemplate(DBObject obj, List<String> values) { for (String field : obj.keySet()) { Object val = obj.get(field); if (val instanceof BasicDBObject) { fillInTemplate((BasicDBObject) val, values); } else if (val instanceof BasicDBList) { fillInTemplate((BasicDBList) val, values); } else if (val instanceof String) { String str = (String) val; if (str.startsWith("$")) { str = str.substring(1);//from w w w. j av a2s .c o m int slash = str.indexOf("/"); String ref = str; String type = null; if (slash > 0) { ref = str.substring(0, slash); type = str.substring(slash + 1); } // find field index int index = 0; while (index < filter.length && !filter[index].equals(ref)) { ++index; } if (index >= filter.length) { continue; } String value = values.get(index); try { if (type == null || "JSON".equals(type)) { // this is typically used for quoted Strings obj.put(field, JSON.parse(value)); } else if ("String".equals(type)) { obj.put(field, value); } else if ("Date".equals(type)) { Long time = Long.valueOf(value); obj.put(field, new Date(time)); } else if ("Boolean".equals(type)) { obj.put(field, Boolean.valueOf(value)); } else if ("Integer".equals(type)) { obj.put(field, Integer.valueOf(value)); } else if ("Long".equals(type)) { obj.put(field, Long.valueOf(value)); } else if ("Double".equals(type)) { obj.put(field, Double.valueOf(value)); } } catch (Exception ex) { Logger.getLogger(DocumentDeserializer.class.getName()).log(Level.WARNING, null, ex); } } else { // this is a static value obj.put(field, val); } } else { // this is a static value obj.put(field, val); } } }