當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。