本文整理汇总了Java中org.bson.BasicBSONObject类的典型用法代码示例。如果您正苦于以下问题:Java BasicBSONObject类的具体用法?Java BasicBSONObject怎么用?Java BasicBSONObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BasicBSONObject类属于org.bson包,在下文中一共展示了BasicBSONObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: store
import org.bson.BasicBSONObject; //导入依赖的package包/类
@Override
public void store(StoreRequest request, StreamObserver<StoreResponse> responseObserver) {
try {
responseObserver.onNext(indexManger.storeDocument(request));
responseObserver.onCompleted();
}
catch (Exception e) {
log.error("Failed to store: <" + request.getUniqueId() + "> in index <" + request.getIndexName() + ">: " + e.getClass().getSimpleName() + ": ", e);
Metadata m = new Metadata();
m.put(MetaKeys.ERROR_KEY, e.getMessage());
responseObserver.onError(new StatusRuntimeException(Status.UNKNOWN, m));
if (request.hasResultDocument()) {
try {
if (request.getResultDocument().hasDocument()) {
BasicBSONObject document = (BasicBSONObject) BSON.decode(request.getResultDocument().getDocument().toByteArray());
log.error(document.toString());
}
}
catch (Exception e2) {
}
}
}
}
示例2: toDBList
import org.bson.BasicBSONObject; //导入依赖的package包/类
public static BasicDBList toDBList(MultiNameValues multiNameValues)
{
String[] names = multiNameValues.getNames();
BasicDBList basicDBList = new BasicDBList();
for (int i = 0; i < multiNameValues.count(); i++)
{
Object[] values = multiNameValues.values(i);
BasicBSONObject bsonObject = new BasicBSONObject(values.length);
for (int j = 0; j < names.length; j++)
{
bsonObject.append(names[j], values[j]);
}
basicDBList.add(bsonObject);
}
return basicDBList;
}
示例3: InsertData
import org.bson.BasicBSONObject; //导入依赖的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;
}
示例4: 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;
}
示例5: 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);
}
}
示例6: generateId
import org.bson.BasicBSONObject; //导入依赖的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();
}
}
示例7: search
import org.bson.BasicBSONObject; //导入依赖的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;
}
示例8: pushAllByPk
import org.bson.BasicBSONObject; //导入依赖的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;
}
示例9: findListByPkArray
import org.bson.BasicBSONObject; //导入依赖的package包/类
/**
* 取出来的值要按照主键ID的顺序
*
* @param primaryKeyValues
* @param cls
* @return
*/
public List<T> findListByPkArray(List<String> primaryKeyValues) {
BSONObject selector = null;
BSONObject query = new BasicBSONObject();
BSONObject matcher = new BasicBSONObject();
matcher.put(MatchConst._IN, primaryKeyValues);
query.put(this.primaryKey, matcher);
try {
List<BSONObject> result = query(query, selector, null);
if (result != null && result.size() > 0) {
return this.caseBsonsToList(result, entityClass);
}
} catch (Exception e) {
e.printStackTrace();
}
return new ArrayList<>();
}
示例10: findAttributeByPk
import org.bson.BasicBSONObject; //导入依赖的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;
}
示例11: delete
import org.bson.BasicBSONObject; //导入依赖的package包/类
/**
* 删除某个对象
*
* @param object
* @return
*/
public boolean delete(T object) {
BSONObject matcher = null;
try {
matcher = BasicBSONObject.typeToBson(object);
if (matcher != null) {
beforeDelete(object);
delete(matcher);
afterDelete(object);
return true;
}
return false;
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException
| IntrospectionException e) {
e.printStackTrace();
}
return false;
}
示例12: translatePredicate
import org.bson.BasicBSONObject; //导入依赖的package包/类
/**
* Translates compatible predicates to MongoDB queries
* @param predicate
* @return
*/
private static BSONObject translatePredicate(Predicate predicate) {
if(predicate == null)
return new BasicBSONObject();
if(predicate instanceof LogicalOperationPredicate)
return translateLogicalOperationPredicate((LogicalOperationPredicate) predicate);
if(predicate instanceof NegatedPredicate)
return translateNegatedPredicate((NegatedPredicate) predicate);
if(predicate instanceof PathExistencePredicate)
return translatePathExistencePredicate((PathExistencePredicate) predicate);
if(predicate instanceof RelationalPredicate)
return translateRelationalPredicate((RelationalPredicate) predicate);
throw new EvaluationException("Unknown predicate: " + predicate.toString());
}
示例13: translateLogicalOperationPredicate
import org.bson.BasicBSONObject; //导入依赖的package包/类
private static BSONObject translateLogicalOperationPredicate(LogicalOperationPredicate predicate) {
final BasicBSONList opList = new BasicBSONList();
opList.add(translatePredicate(predicate.getLeft()));
opList.add(translatePredicate(predicate.getRight()));
final String op;
if(predicate.getOperator().equals(LogicalOperationPredicate.Operator.AND))
op = "$and";
else if(predicate.getOperator().equals(LogicalOperationPredicate.Operator.OR))
op = "$or";
else
throw new EvaluationException("Unexpected operator: " + predicate.getOperator());
return new BasicBSONObject(op, opList);
}
示例14: getUpdater
import org.bson.BasicBSONObject; //导入依赖的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 ;
}
示例15: getUpdateCond
import org.bson.BasicBSONObject; //导入依赖的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 ;
}