当前位置: 首页>>代码示例>>Java>>正文


Java DBObject类代码示例

本文整理汇总了Java中com.mongodb.DBObject的典型用法代码示例。如果您正苦于以下问题:Java DBObject类的具体用法?Java DBObject怎么用?Java DBObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DBObject类属于com.mongodb包,在下文中一共展示了DBObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: selectOne

import com.mongodb.DBObject; //导入依赖的package包/类
public DBObject selectOne(DBCollection collection) {
	DBObject fields = getFields();
	DBObject query = getQuery();
	DBObject orderByObject = getOrderByObject();

	// 日志
	log(fields, query, orderByObject);

	if (null == fields && null == orderByObject) {
		return collection.findOne(query);
	} else if (null != fields && null == orderByObject) {
		return collection.findOne(query, fields);
	} else {
		return collection.findOne(query, fields, orderByObject);
	}
}
 
开发者ID:xsonorg,项目名称:tangyuan2,代码行数:17,代码来源:SelectVo.java

示例2: getAllIds

import com.mongodb.DBObject; //导入依赖的package包/类
public List<String> getAllIds(final Map<String, Object> conditions) {
    DBObject query = new BasicDBObject(conditions);
    DBCursor cursor = coll.find(query);

    List<String> ids = new ArrayList<String>(cursor.count());
    for (DBObject o : cursor) {
        ids.add(o.get("_id").toString());
    }

    return ids;
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:12,代码来源:MongoDbConnection.java

示例3: update

import com.mongodb.DBObject; //导入依赖的package包/类
public void update(List<CanalEntry.Column> data, String schemaName, String tableName) {
    DBObject obj = DBConvertUtil.columnToJson(data);
    logger.debug("update:{}", 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);
        }
        updateData(schemaName, tableName, new BasicDBObject("orderId", obj.get("orderId")), obj);
    } else {
        if (obj.containsField("id")) {
            updateData(schemaName, tableName, new BasicDBObject("_id", obj.get("id")), obj);
        } else {
            logger.info("unknown data structure");
        }
    }
}
 
开发者ID:zhangtr,项目名称:canal-mongo,代码行数:22,代码来源:DataService.java

示例4: insertData

import com.mongodb.DBObject; //导入依赖的package包/类
public void insertData(String schemaName, String tableName, DBObject naive, DBObject complete) {
    int i = 0;
    DBObject logObj = (DBObject) ObjectUtils.clone(complete);
    //保存原始数据
    try {
        String path = "/" + schemaName + "/" + tableName + "/" + CanalEntry.EventType.INSERT.getNumber();
        i++;
        naiveMongoTemplate.getCollection(tableName).insert(naive);
        i++;
        SpringUtil.doEvent(path, complete);
        i++;
    } catch (MongoClientException | MongoSocketException clientException) {
        //客户端连接异常抛出,阻塞同步,防止mongodb宕机
        throw clientException;
    } catch (Exception e) {
        logError(schemaName, tableName, 1, i, logObj, e);
    }
}
 
开发者ID:zhangtr,项目名称:canal-mongo,代码行数:19,代码来源:DataService.java

示例5: deleteData

import com.mongodb.DBObject; //导入依赖的package包/类
public void deleteData(String schemaName, String tableName, DBObject obj) {
    int i = 0;
    String path = "/" + schemaName + "/" + tableName + "/" + CanalEntry.EventType.DELETE.getNumber();
    DBObject newObj = (DBObject) ObjectUtils.clone(obj);
    DBObject logObj = (DBObject) ObjectUtils.clone(obj);
    //保存原始数据
    try {
        i++;
        if (obj.containsField("id")) {
            naiveMongoTemplate.getCollection(tableName).remove(new BasicDBObject("_id", obj.get("id")));
        }
        i++;
        SpringUtil.doEvent(path, newObj);
    } catch (MongoClientException | MongoSocketException clientException) {
        //客户端连接异常抛出,阻塞同步,防止mongodb宕机
        throw clientException;
    } catch (Exception e) {
        logError(schemaName, tableName, 3, i, logObj, e);
    }
}
 
开发者ID:zhangtr,项目名称:canal-mongo,代码行数:21,代码来源:DataService.java

示例6: removeDBObject

import com.mongodb.DBObject; //导入依赖的package包/类
/**
 * 从列表中删除已存在的数据
 *
 * @param list
 * @param obj
 * @return
 */
public static List<DBObject> removeDBObject(List<DBObject> list, DBObject obj) {
    if (list == null || list.size() < 1) {
        return null;
    }
    int existFlag = -1;
    for (int i = 0; i < list.size(); i++) {
        if (list.get(i).get("id").equals(obj.get("id"))) {
            existFlag = i;
        }
    }
    if (existFlag >= 0) {
        list.remove(existFlag);
    }
    return list;
}
 
开发者ID:zhangtr,项目名称:canal-mongo,代码行数:23,代码来源:DBObjectUtil.java

示例7: upsertDBObject

import com.mongodb.DBObject; //导入依赖的package包/类
/**
 * 从列表中替换已存在的数据
 *
 * @param list
 * @param obj
 * @return
 */
public static List<DBObject> upsertDBObject(List<DBObject> list, DBObject obj) {
    if (list == null) {
        //列表不存在,添加
        list = new ArrayList<>();
        list.add(obj);
    } else {
        //列表存在,找id相同数据,有数据替换,没有数据添加
        int existFlag = -1;
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).get("id").equals(obj.get("id"))) {
                existFlag = i;
            }
        }
        if (existFlag >= 0) {
            list.remove(existFlag);
        }
        list.add(obj);
    }
    return list;
}
 
开发者ID:zhangtr,项目名称:canal-mongo,代码行数:28,代码来源:DBObjectUtil.java

示例8: toDbObject

import com.mongodb.DBObject; //导入依赖的package包/类
public static DBObject toDbObject(NameValues nameValues)
{
    final BasicDBObject basicDBObject = new BasicDBObject();
    nameValues.forEach(new NameValues.Foreach()
    {

        @Override
        public boolean forEach(String name, Object value)
        {
            basicDBObject.append(name, value);
            return true;
        }
    });

    return basicDBObject;
}
 
开发者ID:gzxishan,项目名称:OftenPorter,代码行数:17,代码来源:Util.java

示例9: 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

示例10: 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

示例11: convert

import com.mongodb.DBObject; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public VirtualObject convert(DBObject source) {
	Integer rid = (Integer) source.get("rid");
	Integer classId = (Integer) source.get("eClassId");
	Long oid = (Long) source.get("oid");
	Object featuresObject = source.get("features");
	
	EClass eclass = platformService.getEClassForCid(classId.shortValue());
	
	VirtualObject result = new VirtualObject(rid, classId.shortValue(), oid, eclass);
	
	if (featuresObject instanceof BasicDBObject) {
		Map map = (Map) featuresObject;
		processFeatures(map, result);
	}
	return result;
}
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:19,代码来源:VirtualObjectReadConverter.java

示例12: checkNonEncryptedMap

import com.mongodb.DBObject; //导入依赖的package包/类
@Test
public void checkNonEncryptedMap() {
    MyBean bean = new MyBean();
    Map<String, MySubBean> map = new HashMap();
    map.put("one", new MySubBean("sky is blue", "                 earth is round"));
    map.put("two", new MySubBean("grass is green", "earth is flat"));
    bean.nonSensitiveMap = map;
    mongoTemplate.save(bean);

    MyBean fromDb = mongoTemplate.findOne(query(where("_id").is(bean.id)), MyBean.class);

    assertThat(fromDb.nonSensitiveMap.get("one").secretString, is(bean.nonSensitiveMap.get("one").secretString));
    assertThat(fromDb.nonSensitiveMap.get("one").nonSensitiveData, is(bean.nonSensitiveMap.get("one").nonSensitiveData));
    assertThat(fromDb.nonSensitiveMap.get("two").secretString, is(bean.nonSensitiveMap.get("two").secretString));
    assertThat(fromDb.nonSensitiveMap.get("two").nonSensitiveData, is(bean.nonSensitiveMap.get("two").nonSensitiveData));

    DBObject fromMongo = mongoTemplate.getCollection(MyBean.MONGO_MYBEAN).find(new BasicDBObject("_id", new ObjectId(bean.id))).next();
    DBObject mapMongo = (DBObject) fromMongo.get(MyBean.MONGO_NONSENSITIVEMAP);
    DBObject oneMongo = (DBObject) mapMongo.get("one");
    DBObject twoMongo = (DBObject) mapMongo.get("two");

    assertThat(oneMongo.get(MySubBean.MONGO_NONSENSITIVEDATA), is(map.get("one").nonSensitiveData));
    assertThat(twoMongo.get(MySubBean.MONGO_NONSENSITIVEDATA), is(map.get("two").nonSensitiveData));
    assertCryptLength(oneMongo.get(MySubBean.MONGO_SECRETSTRING), map.get("one").secretString.length() + 12);
    assertCryptLength(twoMongo.get(MySubBean.MONGO_SECRETSTRING), map.get("two").secretString.length() + 12);
}
 
开发者ID:bolcom,项目名称:spring-data-mongodb-encrypt,代码行数:27,代码来源:EncryptSystemTest.java

示例13: setQuery

import com.mongodb.DBObject; //导入依赖的package包/类
@Override
public void setQuery(DBObject query, BasicDBList orList) {
	// if (null == orList) {
	// query.put(this.name, value.getValue());
	// } else {
	// orList.add(new BasicDBObject(this.name, value.getValue()));
	// }

	if (this.name.equals("_id")) {
		if (null == orList) {
			query.put(this.name, new ObjectId(value.getValue().toString()));
		} else {
			orList.add(new BasicDBObject(this.name, new ObjectId(value.getValue().toString())));
		}
	} else {
		if (null == orList) {
			query.put(this.name, value.getValue());
		} else {
			orList.add(new BasicDBObject(this.name, value.getValue()));
		}
	}
}
 
开发者ID:xsonorg,项目名称:tangyuan2,代码行数:23,代码来源:EqualCondition.java

示例14: InsertData

import com.mongodb.DBObject; //导入依赖的package包/类
private int InsertData(SQLInsertStatement state) {
	if (state.getValues().getValues().size() ==0 ){
		throw new RuntimeException("number of  columns error");
	}		
	if (state.getValues().getValues().size() != state.getColumns().size()){
		throw new RuntimeException("number of values and columns have to match");
	}
	SQLTableSource table=state.getTableSource();
	BasicDBObject o = new BasicDBObject();
	int i=0;
	for(SQLExpr col : state.getColumns()) {
		o.put(getFieldName2(col), getExpValue(state.getValues().getValues().get(i)));
		i++;
	}		
	DBCollection coll =this._db.getCollection(table.toString());
	coll.insert(new DBObject[] { o });
	return 1;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:19,代码来源:MongoSQLParser.java

示例15: UpData

import com.mongodb.DBObject; //导入依赖的package包/类
private int UpData(SQLUpdateStatement state) {
	SQLTableSource table=state.getTableSource();
	DBCollection coll =this._db.getCollection(table.toString());
	
	SQLExpr expr=state.getWhere();
	DBObject query = parserWhere(expr);
	
	BasicDBObject set = new BasicDBObject();
	for(SQLUpdateSetItem col : state.getItems()){
		set.put(getFieldName2(col.getColumn()), getExpValue(col.getValue()));	
	}
	DBObject mod = new BasicDBObject("$set", set);
	coll.updateMulti(query, mod);
	//System.out.println("changs count:"+coll.getStats().size());
	return 1;		
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:17,代码来源:MongoSQLParser.java


注:本文中的com.mongodb.DBObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。