本文整理汇总了Java中org.bson.BasicBSONObject.put方法的典型用法代码示例。如果您正苦于以下问题:Java BasicBSONObject.put方法的具体用法?Java BasicBSONObject.put怎么用?Java BasicBSONObject.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bson.BasicBSONObject
的用法示例。
在下文中一共展示了BasicBSONObject.put方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: UpData
import org.bson.BasicBSONObject; //导入方法依赖的package包/类
private int UpData(SQLUpdateStatement state) {
SQLTableSource table=state.getTableSource();
DBCollection coll =this._db.getCollection(table.toString());
SQLExpr expr=state.getWhere();
BSONObject query = parserWhere(expr);
BasicBSONObject set = new BasicBSONObject();
for(SQLUpdateSetItem col : state.getItems()){
set.put(getFieldName2(col.getColumn()), getExpValue(col.getValue()));
}
BSONObject mod = new BasicBSONObject("$set", set);
//coll.updateMulti(query, mod);
coll.update(query, mod, null);
//System.out.println("changs count:"+coll.getStats().size());
return 1;
}
示例2: parserDBObject
import org.bson.BasicBSONObject; //导入方法依赖的package包/类
private void parserDBObject(BasicBSONObject ob,String akey, String aop,Object aval){
boolean isok=false;
if (!(ob.keySet().isEmpty())) {
for (String field : ob.keySet()) {
if (akey.equals(field)){
Object val = ob.get(field);
if (val instanceof BasicBSONObject) {
((BasicBSONObject) val).put(aop, aval);
ob.put(field, (BasicBSONObject) val);
isok=true;
break;
} else if (val instanceof BasicBSONList) {
// newobj.put(field, ((BasicDBList)val).copy());
}
}
}
}
if (isok==false) {
BasicBSONObject xo = new BasicBSONObject();
xo.put(aop, aval);
ob.put(akey,xo);
}
}
示例3: reduce
import org.bson.BasicBSONObject; //导入方法依赖的package包/类
public void reduce(Text entityId, Iterator<Text> fragments,
OutputCollector<NullWritable, MongoUpdateWritable> framedEntities, Reporter arg3) throws IOException {
while (fragments.hasNext()) {
String triple = fragments.next().toString();
Map<String, Object> jsonData = (Map<String, Object>) JsonUtils.fromString(triple);
Map<String, Object> framedEntity;
try {
framedEntity = JsonLdProcessor.frame(jsonData, entityFrame.getFrame(), options);
List<Object> entities = (List<Object>)framedEntity.get("@graph");
BasicBSONObject bsonQuery = new BasicBSONObject("_id", entityId.toString());
BasicBSONObject bsonObject = new BasicBSONObject();
bsonObject.putAll((Map<String, Object>)entities.get(0));
BasicBSONObject bsonUpdate = new BasicBSONObject();
bsonUpdate.put("$set", bsonObject);
framedEntities.collect(null, new MongoUpdateWritable(bsonQuery, bsonUpdate, true, false));
} catch (JsonLdError e) {
e.printStackTrace();
}
}
}
示例4: doLegacySmallDocWrite
import org.bson.BasicBSONObject; //导入方法依赖的package包/类
/**
* Writes small documents to a {@link BasicBSONEncoder}.
*
* @return The time to write each document in microseconds.
* @see #testSmallDocumentWritePerformance()
*/
protected double doLegacySmallDocWrite() {
final BasicBSONEncoder encoder = new BasicBSONEncoder();
final long startTime = System.nanoTime();
for (int i = 0; i < ITERATIONS; ++i) {
final BasicBSONObject obj = new BasicBSONObject("_id",
Integer.valueOf(myRandom.nextInt()));
obj.put("v", SMALL_VALUE);
encoder.encode(obj);
}
final long endTime = System.nanoTime();
final double delta = ((double) (endTime - startTime))
/ TimeUnit.MICROSECONDS.toNanos(1);
return (delta / ITERATIONS);
}
示例5: opSQLExpr
import org.bson.BasicBSONObject; //导入方法依赖的package包/类
@SuppressWarnings("unused")
private void opSQLExpr(SQLBinaryOpExpr expr,BasicBSONObject o) {
SQLExpr exprL=expr.getLeft();
if (!(exprL instanceof SQLBinaryOpExpr))
{
if (expr.getOperator().getName().equals("=")) {
o.put(exprL.toString(), getExpValue(expr.getRight()));
}
else {
//BasicBSONObject xo = new BasicBSONObject();
String op="";
if (expr.getOperator().getName().equals("<")) {
op="$lt";
}
if (expr.getOperator().getName().equals("<=")) {
op = "$lte";
}
if (expr.getOperator().getName().equals(">")) {
op = "$gt";
}
if (expr.getOperator().getName().equals(">=")) {
op = "$gte";
}
if (expr.getOperator().getName().equals("!=")) {
op = "$ne";
}
if (expr.getOperator().getName().equals("<>")) {
op = "$ne";
}
//xo.put(op, getExpValue(expr.getRight()));
// o.put(exprL.toString(),xo);
parserDBObject(o,exprL.toString(),op, getExpValue(expr.getRight()));
}
}
}
示例6: orWhere
import org.bson.BasicBSONObject; //导入方法依赖的package包/类
private void orWhere(SQLExpr exprL,SQLExpr exprR ,BasicBSONObject ob){
BasicBSONObject xo = new BasicBSONObject();
BasicBSONObject yo = new BasicBSONObject();
parserWhere(exprL,xo);
parserWhere(exprR,yo);
ob.put("$or",new Object[]{xo,yo});
}
示例7: toBSONObject
import org.bson.BasicBSONObject; //导入方法依赖的package包/类
/**
*
* @param obj an array of pairs of property name and value/Map<String, Object> or an entity with getter/setter methods.
* @return
*/
public static BasicBSONObject toBSONObject(final Object obj) {
final BasicBSONObject result = new BasicBSONObject();
if (obj instanceof Map) {
result.putAll((Map<String, Object>) obj);
} else if (N.isEntity(obj.getClass())) {
Maps.deepEntity2Map(result, obj);
} else if (obj instanceof Object[]) {
final Object[] a = (Object[]) obj;
if (0 != (a.length % 2)) {
throw new IllegalArgumentException(
"The parameters must be the pairs of property name and value, or Map, or an entity class with getter/setter methods.");
}
for (int i = 0; i < a.length; i++) {
result.put((String) a[i], a[++i]);
}
} else {
throw new IllegalArgumentException("The parameters must be a Map, or an entity class with getter/setter methods");
}
resetObjectId(obj, result);
return result;
}
示例8: call
import org.bson.BasicBSONObject; //导入方法依赖的package包/类
public Tuple2<Object, BSONObject> call(
Tuple2<String, Map<String, Map<String, String>>> companyTuple)
throws Exception {
BasicBSONObject report = new BasicBSONObject();
// Create a BSON of form { companyName : financeDetails }
report.put(companyTuple._1(), companyTuple._2());
return new Tuple2<Object, BSONObject>(null, report);
}
示例9: toBSON
import org.bson.BasicBSONObject; //导入方法依赖的package包/类
/**
* return a BSON representation of the bean using filters
* @param filters : whitelist of fields to get into the representation
* @return BSON object
*/
public BSONObject toBSON(String[] filters){
BasicBSONObject BSONData = new BasicBSONObject();
for(String f : this.export){
if(filters!=null){
if(inArray(f, filters)){
BSONData.put(f, this.getParam(f));
}
}
else {
BSONData.put(f, this.getParam(f));
}
}
return BSONData;
}
示例10: parserWhere
import org.bson.BasicBSONObject; //导入方法依赖的package包/类
private void parserWhere(SQLExpr aexpr,BasicBSONObject o){
if(aexpr instanceof SQLBinaryOpExpr){
SQLBinaryOpExpr expr=(SQLBinaryOpExpr)aexpr;
SQLExpr exprL=expr.getLeft();
if (!(exprL instanceof SQLBinaryOpExpr))
{
//opSQLExpr((SQLBinaryOpExpr)aexpr,o);
if (expr.getOperator().getName().equals("=")) {
o.put(exprL.toString(), getExpValue(expr.getRight()));
}
else {
String op="";
if (expr.getOperator().getName().equals("<")) {
op = "$lt";
}
if (expr.getOperator().getName().equals("<=")) {
op = "$lte";
}
if (expr.getOperator().getName().equals(">")) {
op = "$gt";
}
if (expr.getOperator().getName().equals(">=")) {
op = "$gte";
}
if (expr.getOperator().getName().equals("!=")) {
op = "$ne";
}
if (expr.getOperator().getName().equals("<>")) {
op = "$ne";
}
parserDBObject(o,exprL.toString(),op, getExpValue(expr.getRight()));
}
}
else {
if (expr.getOperator().getName().equals("AND")) {
parserWhere(exprL,o);
parserWhere(expr.getRight(),o);
}
else if (expr.getOperator().getName().equals("OR")) {
orWhere(exprL,expr.getRight(),o);
}
else {
throw new RuntimeException("Can't identify the operation of of where");
}
}
}
}