List of usage examples for com.mongodb DBObject put
Object put(String key, Object v);
From source file:com.groupon.jenkins.dynamic.build.DbBackedBuild.java
License:Open Source License
@PrePersist private void saveTimestamp(final DBObject dbObj) { dbObj.put("scheduledDate", getTime()); }
From source file:com.groupon.jenkins.dynamic.build.DbBackedBuild.java
License:Open Source License
@PrePersist private void saveNumber(final DBObject dbObj) { dbObj.put("number", getNumber()); }
From source file:com.groupon.jenkins.dynamic.build.DbBackedProject.java
License:Open Source License
@PrePersist private void saveName(final DBObject dbObj) { dbObj.put("name", getName()); }
From source file:com.groupon.jenkins.mongo.CopyOnWriteListMapper.java
License:Open Source License
@Override public void toDBObject(Object entity, MappedField mf, DBObject dbObject, Map<Object, DBObject> involvedObjects, Mapper mapper) {// w w w . j a v a 2 s .c o m final String name = mf.getNameToStore(); CopyOnWriteList copyOnWriteList = (CopyOnWriteList) mf.getFieldValue(entity); List core = new ArrayList(); mf.getSubType(); for (Object obj : copyOnWriteList) { core.add(mapper.toDBObject(obj, involvedObjects)); } dbObject.put(name, core); }
From source file:com.groupon.jenkins.mongo.JenkinsEmbeddedMapper.java
License:Open Source License
@Override public void toDBObject(Object entity, MappedField mf, DBObject dbObject, Map<Object, DBObject> involvedObjects, Mapper mapper) {//from ww w . ja v a2s. co m Object fieldValue = mf.getFieldValue(entity); if (fieldValue == null) return; // nothing to do if (mapper.getConverters().hasSimpleValueConverter(mf) || mapper.getConverters().hasSimpleValueConverter(fieldValue)) { mapper.getOptions().getValueMapper().toDBObject(entity, mf, dbObject, involvedObjects, mapper); } else if (customMappers.containsKey(fieldValue.getClass())) { customMappers.get(fieldValue.getClass()).toDBObject(entity, mf, dbObject, involvedObjects, mapper); } else if (isAwkwardMap(mf)) { awkwardMapper.toDBObject(entity, mf, dbObject, involvedObjects, mapper); } else { // Genericly handle an object for serialization if (involvedObjects.containsKey(fieldValue)) { // already once serialized DBObject cachedStub = involvedObjects.get(fieldValue); if (cachedStub == null) { // visited, but not yet serialized, usually from mapper.toDBObject(...) DBObject newStub = createStub(mapper, fieldValue, mapper.getId(fieldValue)); involvedObjects.put(fieldValue, newStub); cachedStub = newStub; } else if (isFullySerializedObject(cachedStub, mapper)) { // remove full object from the cache and replace it with an ObjectId reference // so we're not storing redundant data Object id = cachedStub.get(mapper.ID_KEY); DBObject newStub = createStub(mapper, fieldValue, id); involvedObjects.put(fieldValue, newStub); cachedStub = newStub; } dbObject.put(mf.getNameToStore(), cachedStub); // serialize as the reference } else { mapper.getOptions().getEmbeddedMapper().toDBObject(entity, mf, dbObject, involvedObjects, mapper); } } }
From source file:com.groupon.jenkins.mongo.JenkinsEmbeddedMapper.java
License:Open Source License
private DBObject createStub(Mapper mapper, Object fieldValue, Object id) { if (id == null) { id = new ObjectId(); }//from w ww. j av a 2s. com DBObject stub = new BasicDBObject(mapper.CLASS_NAME_FIELDNAME, fieldValue.getClass().getName()); stub.put(mapper.ID_KEY, id); return stub; }
From source file:com.groupon.jenkins.mongo.MapKeyValueMapper.java
License:Open Source License
@Override public void toDBObject(Object entity, MappedField mf, DBObject dbObject, Map<Object, DBObject> involvedObjects, Mapper mapper) {/* www . ja va2s.co m*/ final String name = mf.getNameToStore(); Map<?, ?> awkwardMap = (Map<?, ?>) mf.getFieldValue(entity); List out = new ArrayList(); for (final Map.Entry entry : awkwardMap.entrySet()) { DBObject mappedEntry = new BasicDBObject(); try { Field key = entry.getClass().getDeclaredField(KEY); EntryMappedField keyField = new EntryMappedField(key, entry.getClass(), mf); Field value = entry.getClass().getDeclaredField(VALUE); EntryMappedField valueField = new EntryMappedField(value, entry.getClass(), mf); mapper.getOptions().getDefaultMapper().toDBObject(entry, keyField, mappedEntry, involvedObjects, mapper); mapper.getOptions().getDefaultMapper().toDBObject(entry, valueField, mappedEntry, involvedObjects, mapper); out.add(mappedEntry); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } } dbObject.put(name, out); }
From source file:com.hangum.tadpole.importdb.core.dialog.importdb.mongodb.QueryToMongoDBImport.java
License:Open Source License
/** * ?? ./*from www. ja va 2s . c o m*/ * * @param modTableDAO * @param userDBDAO * @throws Exception */ private void insertMongoDB() throws Exception { SQLQueryUtil qu = new SQLQueryUtil(getSourceUserDB(), userQuery); while (qu.hasNext()) { qu.nextQuery(); Map<Integer, String> mapCNameToIndex = qu.getMapColumns(); List<HashMap<Integer, Object>> listTableData = qu.getTableDataList(); // row List<DBObject> listDBObject = new ArrayList<DBObject>(); for (int i = 0; i < listTableData.size(); i++) { HashMap<Integer, Object> resultMap = listTableData.get(i); DBObject insertObject = new BasicDBObject(); // column for (int j = 0; j < mapCNameToIndex.size(); j++) { // BigDecimal is not support mongodb if (resultMap.get(j) instanceof java.math.BigDecimal) { BigDecimal db = (BigDecimal) resultMap.get(j); insertObject.put(mapCNameToIndex.get(j), db.longValue()); } else { insertObject.put(mapCNameToIndex.get(j), resultMap.get(j)); } } listDBObject.add(insertObject); } // end for MongoDBQuery.insertDocument(getTargetUserDB(), colName, listDBObject); } }
From source file:com.hangum.tadpole.importdb.core.dialog.importdb.mongodb.RDBTableToMongoDBImport.java
License:Open Source License
/** * ?? .// w ww. j a v a2 s . com * * @param modTableDAO * @param userDBDAO * @throws Exception */ private void insertMongoDB(ModTableDAO modTableDAO, String strNewColName) throws Exception { String workTable = modTableDAO.getName(); if (logger.isDebugEnabled()) logger.debug("[work table]" + workTable); SQLQueryUtil qu = new SQLQueryUtil(getSourceUserDB(), "SELECT * FROM " + workTable); while (qu.hasNext()) { qu.nextQuery(); Map<Integer, String> mapCNameToIndex = qu.getMapColumns(); List<HashMap<Integer, Object>> listTableData = qu.getTableDataList(); // row List<DBObject> listDBObject = new ArrayList<DBObject>(); for (int i = 0; i < listTableData.size(); i++) { HashMap<Integer, Object> resultMap = listTableData.get(i); DBObject insertObject = new BasicDBObject(); // column for (int j = 0; j < mapCNameToIndex.size(); j++) { // BigDecimal is not support mongodb if (resultMap.get(j) instanceof java.math.BigDecimal) { BigDecimal db = (BigDecimal) resultMap.get(j); insertObject.put(mapCNameToIndex.get(j), db.longValue()); } else { insertObject.put(mapCNameToIndex.get(j), resultMap.get(j)); } } listDBObject.add(insertObject); } // end for logger.debug("[work table]" + strNewColName + " size is " + listDBObject.size()); MongoDBQuery.insertDocument(getTargetUserDB(), strNewColName, listDBObject); } }
From source file:com.hangum.tadpole.importexport.core.utils.mongodb.RDBTableToMongoDBImport.java
License:Open Source License
/** * ?? .//w w w . j a va 2s .c o m * * @param modTableDAO * @param userDBDAO * @throws Exception */ private void insertMongoDB(ModTableDAO modTableDAO, String strNewColName) throws Exception { String workTable = modTableDAO.getName(); if (logger.isDebugEnabled()) logger.debug("[work table]" + workTable); SQLQueryUtil qu = new SQLQueryUtil(getSourceUserDB(), "SELECT * FROM " + workTable); while (qu.hasNext()) { qu.nextQuery(); Map<Integer, String> mapCNameToIndex = qu.getMapColumns(); List<HashMap<Integer, Object>> listTableData = qu.getTableDataList(); // row List<DBObject> listDBObject = new ArrayList<DBObject>(); for (int i = 0; i < listTableData.size(); i++) { HashMap<Integer, Object> resultMap = listTableData.get(i); DBObject insertObject = new BasicDBObject(); // column for (int j = 0; j < mapCNameToIndex.size(); j++) { // BigDecimal is not support mongodb if (resultMap.get(j) instanceof java.math.BigDecimal) { BigDecimal db = (BigDecimal) resultMap.get(j); insertObject.put(mapCNameToIndex.get(j), "" + db.longValue()); } else if (resultMap.get(j) instanceof java.math.BigInteger) { BigInteger db = (BigInteger) resultMap.get(j); insertObject.put(mapCNameToIndex.get(j), "" + db.longValue()); } else if (resultMap.get(j) instanceof java.sql.Timestamp) { Timestamp ts = (Timestamp) resultMap.get(j); insertObject.put(mapCNameToIndex.get(j), ts.toString()); } else { insertObject.put(mapCNameToIndex.get(j), resultMap.get(j)); } } listDBObject.add(insertObject); } // end for logger.debug("[work table]" + strNewColName + " size is " + listDBObject.size()); MongoDBQuery.insertDocument(getTargetUserDB(), strNewColName, listDBObject); } }