本文整理匯總了Java中org.bson.BSONObject.put方法的典型用法代碼示例。如果您正苦於以下問題:Java BSONObject.put方法的具體用法?Java BSONObject.put怎麽用?Java BSONObject.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bson.BSONObject
的用法示例。
在下文中一共展示了BSONObject.put方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: InsertData
import org.bson.BSONObject; //導入方法依賴的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();
BSONObject o = new BasicBSONObject();
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 });
coll.insert(o);
return 1;
}
示例2: findAttributeByPk
import org.bson.BSONObject; //導入方法依賴的package包/類
public <V> V findAttributeByPk(String primaryKeyValue, Class<V> clazz) {
BSONObject query = new BasicBSONObject();
query.put(this.primaryKey, primaryKeyValue);
BSONObject selector;
try {
selector = BasicBSONObject.typeToBson(clazz.newInstance());
BSONObject bsonObejct = queryOne(query, selector, null);
if (bsonObejct != null) {
return bsonObejct.as(clazz);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
示例3: findListByPkArray
import org.bson.BSONObject; //導入方法依賴的package包/類
public <V> List<V> findListByPkArray(List<String> primaryKeyValues, Class<V> clazz) {
BSONObject query = new BasicBSONObject();
BSONObject matcher = new BasicBSONObject();
matcher.put(MatchConst._IN, primaryKeyValues);
query.put(this.primaryKey, matcher);
try {
BSONObject selector = BasicBSONObject.typeToBson(clazz.newInstance());
List<BSONObject> result = query(query, selector, null);
if (result != null && result.size() > 0) {
return this.caseBsonsToList(result, clazz);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例4: generateId
import org.bson.BSONObject; //導入方法依賴的package包/類
public synchronized void generateId(T obj) {
String id = null;
while (true) {
BSONObject matcher = new BasicBSONObject();
id = CommEncode.generateId();
matcher.put(this.primaryKey, id);
BSONObject bson = queryOne(matcher, null, null);
if (bson == null) {
break;
}
}
try {
Class cls = obj.getClass();
Method method = cls.getMethod(this.getGenerateIdKeySetMethodName(), String.class);
method.invoke(obj, id);
} catch (Exception e) {
e.printStackTrace();
}
}
示例5: search
import org.bson.BSONObject; //導入方法依賴的package包/類
public List<T> search(String key, String value, BSONObject order) {
BSONObject arg = new BasicBSONObject();
BSONObject regex = new BasicBSONObject();
regex.put(MatchConst._REGEX, value);
arg.put(key, regex);
List<BSONObject> record = query(arg, null, null);
List<T> result1 = new ArrayList<T>();
for (BSONObject bsonObject : record) {
try {
result1.add(bsonObject.as(entityClass));
} catch (Exception e) {
e.printStackTrace();
}
}
return result1;
}
示例6: pushAllByPk
import org.bson.BSONObject; //導入方法依賴的package包/類
/**
* 更新一個數組的字段
*
* @param primaryKeyValue
* @param field
* @param value
* @return
*/
public <T> boolean pushAllByPk(String primaryKeyValue, String field, List<T> value) {
BSONObject query = new BasicBSONObject();
query.put(this.primaryKey, primaryKeyValue);
BSONObject update = new BasicBSONObject();
update.put(field, value);
update.put(field, value);
BSONObject modifier = new BasicBSONObject();
modifier.put("$push_all", update);
try {
super.updateWithUserDefine(query, modifier);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
示例7: getUpdater
import org.bson.BSONObject; //導入方法依賴的package包/類
public BSONObject getUpdater( Object[] row, RowMetaInterface rowMeta ) throws KettleValueException {
BSONObject updater = new BasicBSONObject() ;
for(Map.Entry<String, List<SequoiaDBUpdateFieldInfo>> entry:m_updateFields.entrySet()) {
BSONObject fieldsObj = new BasicBSONObject() ;
int fieldNum = entry.getValue().size() ;
for( int i = 0 ; i < fieldNum ; i++ ) {
SequoiaDBUpdateFieldInfo fieldTmp = entry.getValue().get(i) ;
int index = rowMeta.indexOfValue( fieldTmp.getName() ) ;
ValueMetaInterface vmi = rowMeta.getValueMeta( index ) ;
try{
fieldsObj.put(fieldTmp.getPath(), fieldTmp.getBsonValue(row[index], vmi)) ;
}
catch( KettleValueException e ){
throw new KettleValueException( BaseMessages.getString( PKG,
"SequoiaDBOutput.Msg.Err.FailedToGetTheFieldVal"
+ "(" + entry.getKey() + ":" + row[index].toString() + ")" ) );
}
}
updater.put( entry.getKey(), fieldsObj ) ;
}
if ( updater.isEmpty()) {
return null ;
}
return updater ;
}
示例8: getUpdateCond
import org.bson.BSONObject; //導入方法依賴的package包/類
public BSONObject getUpdateCond( Object[] row, RowMetaInterface rowMeta ) throws KettleValueException {
BSONObject condition = new BasicBSONObject() ;
int fieldNum = m_condFields.size() ;
for( int i = 0 ; i < fieldNum ; i++ ) {
SequoiaDBUpdateFieldInfo fieldTmp = m_condFields.get(i) ;
int index = rowMeta.indexOfValue( fieldTmp.getName() ) ;
ValueMetaInterface vmi = rowMeta.getValueMeta( index ) ;
try{
condition.put(fieldTmp.getPath(), fieldTmp.getBsonValue(row[index], vmi)) ;
}
catch( KettleValueException e ){
throw new KettleValueException( BaseMessages.getString( PKG,
"SequoiaDBOutput.Msg.Err.FailedToGetTheFieldVal"
+ "(" + fieldTmp.getName() + ":" + row[index].toString() + ")" ) );
}
}
if ( condition.isEmpty() ) {
return null ;
}
return condition ;
}
示例9: testParseEnum
import org.bson.BSONObject; //導入方法依賴的package包/類
@Test
public void testParseEnum() throws IOException {
String enumName = "FakeEnum";
String enumValue1 = "FakeEnumValue1";
String enumValue2 = "FakeEnumValue2";
BSONObject enumsNode = (BSONObject) parser.newNode();
enumsNode.put("name", enumName);
enumsNode.put("values", Arrays.asList(enumValue1, enumValue2));
Enum e = parser.parseEnum(enumsNode);
Assert.assertEquals(enumName, e.getName());
Set<EnumValue> values = e.getEnumValues();
Assert.assertEquals(2, values.size());
Assert.assertTrue(values.contains(new EnumValue(enumValue1, null)));
Assert.assertTrue(values.contains(new EnumValue(enumValue2, null)));
}
示例10: testGetValue
import org.bson.BSONObject; //導入方法依賴的package包/類
@Test
public void testGetValue() {
// root.body.profile.name.first = George
BSONObject root = new BasicBSONObject();
BSONObject body = new BasicBSONObject();
BSONObject profile = new BasicBSONObject();
BSONObject name = new BasicBSONObject();
BSONObject first = new BasicBSONObject();
first.put("first", "George");
name.put("name", first);
profile.put("profile", name);
body.put("body", profile);
root.put("root", body);
assertEquals(BSONUtilities.getValue(root, "root.body.profile.name.first"), "George");
}
示例11: testGetValues
import org.bson.BSONObject; //導入方法依賴的package包/類
@Test
public void testGetValues() {
// root.body.profile.name.first = George
BSONObject root = new BasicBSONObject();
BSONObject body = new BasicBSONObject();
BasicBSONList list = new BasicBSONList();
list.add("hello");
list.add("goodbye");
list.add("have a nice day");
body.put("body", list);
root.put("root", body);
String[] values = BSONUtilities.getValues(root, "root.body");
assertNotNull(values);
assertEquals(values.length, 3);
}
示例12: findByKey
import org.bson.BSONObject; //導入方法依賴的package包/類
@Override
public BSONObject findByKey(String key, String value) {
BSONObject map = new BasicBSONObject();
String query = "SELECT * FROM "+this.table+" WHERE "+key+"=?";
try {
this.statement = connexion.prepareStatement(query);
this.statement.setString(1, value);
ResultSet result = this.statement.executeQuery();
if(result.first())
for(int i=1; i<= result.getMetaData().getColumnCount(); i++){
map.put(result.getMetaData().getColumnLabel(i), result.getString(i));
}
else return null;
} catch (SQLException e) {
e.printStackTrace();
}
return map;
}
示例13: updateUsingSetOpreator
import org.bson.BSONObject; //導入方法依賴的package包/類
/**
*
* @param matcher
* @param obj
*/
public void updateUsingSetOpreator(BSONObject matcher, Object obj) {
BSONObject modifier = new BasicBSONObject();
Sequoiadb sdb = DbConnectionPool.getConnection();
try {
modifier.put("$set", BasicBSONObject.typeToBson(obj));
getDbCollection(sdb).update(matcher, modifier, null);
} catch (Exception e) {
e.printStackTrace();
} finally {
DbConnectionPool.free(sdb);
}
}
示例14: updateCounter
import org.bson.BSONObject; //導入方法依賴的package包/類
/**
*
* @param matcher
* @param fieldName
* @param increment
*/
public void updateCounter(BSONObject matcher, String fieldName, int increment) {
Sequoiadb sdb = DbConnectionPool.getConnection();
try {
BSONObject obj = new BasicBSONObject();
BSONObject rule = new BasicBSONObject();
rule.put(fieldName, increment);
obj.put(MatchConst._INC, rule);
getDbCollection(sdb).update(matcher, obj, null);
} catch (BaseException e) {
e.printStackTrace();
} finally {
DbConnectionPool.free(sdb);
}
}
示例15: addOrRule
import org.bson.BSONObject; //導入方法依賴的package包/類
/**
* or規則 第一個參數為值
*
* @param value
* @param keys
* @return
*/
public BSONObjectBuilder addOrRule(Object value, String... keys) {
BasicBSONList bsonList = new BasicBSONList();
for (String key : keys) {
BSONObject arg = new BasicBSONObject();
arg.put(key, value);
bsonList.add(arg);
}
bson.put(MatchConst._OR, bsonList);
return this;
}