當前位置: 首頁>>代碼示例>>Java>>正文


Java DBObject.put方法代碼示例

本文整理匯總了Java中com.mongodb.DBObject.put方法的典型用法代碼示例。如果您正苦於以下問題:Java DBObject.put方法的具體用法?Java DBObject.put怎麽用?Java DBObject.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mongodb.DBObject的用法示例。


在下文中一共展示了DBObject.put方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getNextId

import com.mongodb.DBObject; //導入方法依賴的package包/類
public int getNextId(GridFS destDatabase) {
	DBCollection countersCollection = destDatabase.getDB().getCollection("counters");

	DBObject record = countersCollection.findOne(new BasicDBObject("_id", "package"));
	if (record == null) {
		BasicDBObject dbObject = new BasicDBObject("_id", "package");
		dbObject.append("seq", 0);
		countersCollection.insert(dbObject);
		record = dbObject;
	}
	int oldID = (int) record.get("seq");
	int newID = oldID + 1;
	record.put("seq", newID);
	countersCollection.update(new BasicDBObject("_id", "package"), record);
	
	return newID;
}
 
開發者ID:roscisz,項目名稱:KernelHive,代碼行數:18,代碼來源:DataManager.java

示例2: insert

import com.mongodb.DBObject; //導入方法依賴的package包/類
public void insert(List<CanalEntry.Column> data, String schemaName, String tableName) {
    DBObject obj = DBConvertUtil.columnToJson(data);
    logger.debug("insert :{}", obj.toString());
    //訂單庫單獨處理
    if (schemaName.equals("order")) {
        //保存原始數據
        if (tableName.startsWith("order_base_info")) {
            tableName = "order_base_info";
        } else if (tableName.startsWith("order_detail_info")) {
            tableName = "order_detail_info";
        } else {
            logger.info("unknown data :{}.{}:{}", schemaName, tableName, obj);
            return;
        }
        insertData(schemaName, tableName, obj, obj);
    } else {
        DBObject newObj = (DBObject) ObjectUtils.clone(obj);
        if (newObj.containsField("id")) {
            newObj.put("_id", newObj.get("id"));
            newObj.removeField("id");
        }
        insertData(schemaName, tableName, newObj, obj);
    }
}
 
開發者ID:zhangtr,項目名稱:canal-mongo,代碼行數:25,代碼來源:DataService.java

示例3: getCondition

import com.mongodb.DBObject; //導入方法依賴的package包/類
private Condition getCondition() throws DBException
{
    final DBObject query = type == 0 ? new BasicDBObject() : this.query;

    if (type == 0 && regexNameValues != null)
    {
        String[] names = regexNameValues.getNames();
        Object[] values = regexNameValues.getValues();
        for (int i = 0; i < names.length; i++)
        {
            query.put(names[i], new BasicDBObject("$regex", values[i]));
        }
    }

    MongoCondition mongoCondition = new MongoCondition()
    {
        public Object toFinalObject() throws Condition.ConditionException
        {
            return query;
        }
    };

    return mongoCondition;
}
 
開發者ID:gzxishan,項目名稱:OftenPorter,代碼行數:25,代碼來源:QueryAdvanced.java

示例4: doBatchUpdate

import com.mongodb.DBObject; //導入方法依賴的package包/類
private int doBatchUpdate(DBCollection dbCollection, String collName, Collection<BatchUpdateOptions> options,
		boolean ordered) {
	DBObject command = new BasicDBObject();
	command.put("update", collName);
	List<BasicDBObject> updateList = new ArrayList<BasicDBObject>();
	for (BatchUpdateOptions option : options) {
		BasicDBObject update = new BasicDBObject();
		update.put("q", option.getQuery().getQueryObject());
		update.put("u", option.getUpdate().getUpdateObject());
		update.put("upsert", option.isUpsert());
		update.put("multi", option.isMulti());
		updateList.add(update);
	}
	command.put("updates", updateList);
	command.put("ordered", ordered);
	CommandResult commandResult = dbCollection.getDB().command(command);
	return Integer.parseInt(commandResult.get("n").toString());
}
 
開發者ID:shenan4321,項目名稱:BIMplatform,代碼行數:19,代碼來源:AbstractBaseMongoDao.java

示例5: cryptFields

import com.mongodb.DBObject; //導入方法依賴的package包/類
void cryptFields(DBObject dbObject, Node node, Function<Object, Object> crypt) {
    if (node.type == Node.Type.MAP) {
        Node mapChildren = node.children.get(0);
        for (Map.Entry<String, Object> entry : ((BasicDBObject) dbObject).entrySet()) {
            cryptFields((DBObject) entry.getValue(), mapChildren, crypt);
        }
        return;
    }

    for (Node childNode : node.children) {
        Object value = dbObject.get(childNode.fieldName);
        if (value == null) continue;

        if (!childNode.children.isEmpty()) {
            if (value instanceof BasicDBList) {
                for (Object o : (BasicDBList) value)
                    cryptFields((DBObject) o, childNode, crypt);
            } else {
                cryptFields((BasicDBObject) value, childNode, crypt);
            }
            return;
        }

        dbObject.put(childNode.fieldName, crypt.apply(value));
    }
}
 
開發者ID:bolcom,項目名稱:spring-data-mongodb-encrypt,代碼行數:27,代碼來源:EncryptionEventListener.java

示例6: insert

import com.mongodb.DBObject; //導入方法依賴的package包/類
public Object insert(DBCollection collection, WriteConcern writeConcern) {
	DBObject document = new BasicDBObject();
	// 匹配_id
	for (int i = 0, n = columns.size(); i < n; i++) {
		// document.put(columns.get(i), values.get(i).getValue());

		String tempColumn = columns.get(i);
		if (3 == tempColumn.length() && tempColumn.equals("_id")) {
			document.put(tempColumn, new ObjectId(values.get(i).getValue().toString()));
		} else {
			document.put(tempColumn, values.get(i).getValue());
		}
	}
	log(document);
	// TODO: WriteConcern.ACKNOWLEDGED需要可以配置
	// WriteResult result = collection.insert(document, WriteConcern.ACKNOWLEDGED);
	// collection.insert(document, MongoComponent.getInstance().getDefaultWriteConcern());
	collection.insert(document, writeConcern);
	Object oid = document.get("_id");
	if (null != oid) {
		return oid.toString();
	}
	return null;
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:25,代碼來源:InsertVo.java

示例7: logError

import com.mongodb.DBObject; //導入方法依賴的package包/類
/**
 * 記錄拚接表錯誤記錄
 *
 * @param schemaName
 * @param tableName
 * @param event      1:INSERT;2:UPDATE;3:DELETE
 * @param step       0:預處理數據錯誤;1:保存原始數據錯誤;2:保存組合數據錯誤,
 * @param obj
 * @param e
 */
private void logError(String schemaName, String tableName, int event, int step, DBObject obj, Exception e) {
    logger.error("error data:name[{},{}] , eventType : {} , data : [{}]", schemaName, tableName, event, obj);
    DBObject errObj = new BasicDBObject();
    errObj.put("schemaName", schemaName);
    errObj.put("tableName", tableName);
    errObj.put("event", event);
    errObj.put("data", obj);
    errObj.put("step", step);
    errObj.put("time", new Date());
    errObj.put("error", e.toString());
    completeMongoTemplate.getCollection(NameConst.C_ERROR_RECORD).insert(errObj);
}
 
開發者ID:zhangtr,項目名稱:canal-mongo,代碼行數:23,代碼來源:DataService.java

示例8: setQuery

import com.mongodb.DBObject; //導入方法依賴的package包/類
@Override
public void setQuery(DBObject query, BasicDBList orList) {
	if (null == orList) {
		query.put(this.name, new BasicDBObject("$lte", value.getValue()));
	} else {
		orList.add(new BasicDBObject(this.name, new BasicDBObject("$lte", value.getValue())));
	}
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:9,代碼來源:LessThanEqualCondition.java

示例9: modifyGlbFile

import com.mongodb.DBObject; //導入方法依賴的package包/類
public void modifyGlbFile(int rid, double lon, double lat) {
	Query query = new Query();
	query.addCriteria(Criteria.where("metadata.rid").is(rid).andOperator(Criteria.where("metadata." + STORE_BIM_TYPE).is(STORE_GLB_FILE)));
	GridFSDBFile file = gridFsTemplate.findOne(query);
	DBObject metaData = file.getMetaData();
	metaData.put("lon", lon);
	metaData.put("lat", lat);
	file.save();
}
 
開發者ID:shenan4321,項目名稱:BIMplatform,代碼行數:10,代碼來源:MongoGridFs.java

示例10: saveGlbOffline

import com.mongodb.DBObject; //導入方法依賴的package包/類
public GridFSFile saveGlbOffline(InputStream inputStream, String fileName, Long id, double lon, double lat) {
	DBObject metaData = new BasicDBObject("offline", true);
	metaData.put("id", id);
	metaData.put(STORE_BIM_TYPE, STORE_GLB_FILE);
	metaData.put("lon", lon);
	metaData.put("lat", lat);
	return gridFsTemplate.store(inputStream, fileName, metaData);
}
 
開發者ID:shenan4321,項目名稱:BIMplatform,代碼行數:9,代碼來源:MongoGridFs.java

示例11: put

import com.mongodb.DBObject; //導入方法依賴的package包/類
@Override
public void put(String key, V value) {
  try {
    DBObject putObj = new BasicDBObject(2);
    putObj.put(ID, key);
    putObj.put(pKey, bytes(value));
    collection.insert(putObj);
  } catch (Exception e) {
    logger.error(e.getMessage(), e);
    throw new DrillRuntimeException(e.getMessage(), e);
  }
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:13,代碼來源:MongoPStore.java

示例12: testGridFs

import com.mongodb.DBObject; //導入方法依賴的package包/類
@Test
public void testGridFs() throws IOException {
    // 創建測試文件
    FileUtils.createTestFile();

    // 文件元信息
    DBObject metaData = new BasicDBObject();
    metaData.put("extra1", "anything 1");
    metaData.put("extra2", "anything 2");

    // 獲得文件流並保存
    InputStream inputStream = new FileInputStream(testFileName);
    gridFsOperations.store(inputStream, testFileName, metaData);
    inputStream.close();

    // 查詢保存的文件
    List<GridFSDBFile> result = gridFsOperations.find(query(whereFilename().is(testFileName)));
    Assert.assertEquals(result.size(), 1);

    // 刪除保存的文件
    gridFsOperations.delete(query(whereFilename().is(testFileName)));

    // 查詢刪除的文件
    result = gridFsOperations.find(query(whereFilename().is(testFileName)));
    Assert.assertEquals(result.size(), 0);

    // 刪除測試文件
    FileUtils.removeTestFile();
}
 
開發者ID:0x603,項目名稱:SixBox,代碼行數:30,代碼來源:TestMongoDB.java

示例13: put

import com.mongodb.DBObject; //導入方法依賴的package包/類
@Override
public void put(String email, String password) {
    DBObject object = new BasicDBObject();
    object.put(FIELD_EMAIL, email);
    object.put(FIELD_PASSWORD, password);
    collection.insert(object);
}
 
開發者ID:yeriomin,項目名稱:token-dispenser,代碼行數:8,代碼來源:PasswordsDbMongo.java

示例14: convert

import com.mongodb.DBObject; //導入方法依賴的package包/類
@Override
protected DBObject convert(MongoSession source) {

	try {
		DBObject dbSession = (DBObject) JSON.parse(this.objectMapper.writeValueAsString(source));
		dbSession.put(PRINCIPAL_FIELD_NAME, extractPrincipal(source));
		return dbSession;
	} catch (JsonProcessingException e) {
		throw new IllegalStateException("Cannot convert MongoExpiringSession", e);
	}
}
 
開發者ID:spring-projects,項目名稱:spring-session-data-mongodb,代碼行數:12,代碼來源:JacksonMongoSessionConverter.java

示例15: getFields

import com.mongodb.DBObject; //導入方法依賴的package包/類
private DBObject getFields() {
	if (null != this.allColumn) {
		return null;
	}
	DBObject fields = new BasicDBObject();
	// fields.put("_id", 0);
	for (int i = 0, n = columns.size(); i < n; i++) {
		// fields.put(columns.get(i), true);
		fields.put(columns.get(i), 1);// 1代表需要指定顯示的列
	}
	return fields;
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:13,代碼來源:SelectVo.java


注:本文中的com.mongodb.DBObject.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。