本文整理汇总了Java中com.mongodb.BasicDBObject.keySet方法的典型用法代码示例。如果您正苦于以下问题:Java BasicDBObject.keySet方法的具体用法?Java BasicDBObject.keySet怎么用?Java BasicDBObject.keySet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.BasicDBObject
的用法示例。
在下文中一共展示了BasicDBObject.keySet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parserDBObject
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
private void parserDBObject(BasicDBObject 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 BasicDBObject) {
((BasicDBObject) val).put(aop, aval);
ob.put(field, (BasicDBObject) val);
isok=true;
break;
} else if (val instanceof BasicDBList) {
// newobj.put(field, ((BasicDBList)val).copy());
}
}
}
}
if (isok==false) {
BasicDBObject xo = new BasicDBObject();
xo.put(aop, aval);
ob.put(akey,xo);
}
}
示例2: findAction
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private List<Map> findAction(Map queryObj, MongoCollection<Document> collection) {
Map queryparmes = queryObj; // input
BasicDBObject query = new BasicDBObject();// output
Map findparmes = (Map) queryparmes.get(DataStoreProtocol.WHERE);
String fileds = String.valueOf(queryparmes.get(DataStoreProtocol.FIELDS));
String sortJson = String.valueOf(queryparmes.get(DataStoreProtocol.SORT));
String pageindex = String.valueOf(queryparmes.get(DataStoreProtocol.PAGEINDEX));
String pagesize = String.valueOf(queryparmes.get(DataStoreProtocol.PAGESIZE));
QueryStrategy qry = new QueryStrategy();
Map express = new LinkedHashMap();
express.put(DataStoreProtocol.FIND, findparmes);
qry.concretProcessor(DataStoreProtocol.FIND, express, query);
Document sorts = new Document();
Document filterBson = new Document();
filterBson.append("_id", 0);
if (!StringHelper.isEmpty(fileds)) {
String[] filters = fileds.split(";");
for (String filter : filters) {
filterBson.append(filter, 1);
}
}
if (!StringHelper.isEmpty(sortJson)) {
Map<String, String> sortMap = JSONHelper.toObject(sortJson, Map.class);
String sortParmes = sortMap.get(DataStoreProtocol.VALUES);
String sortOrder = sortMap.get(DataStoreProtocol.SORTORDER);
String[] parames = sortParmes.split(",");
for (String parame : parames) {
sorts.append(parame, Integer.parseInt(sortOrder));
}
}
int pageIndex = 0; // 初始 index
int pageSize = 0; // 初始pageSize
if (!StringHelper.isEmpty(pageindex)) {
pageIndex = Integer.parseInt(pageindex);
}
if (!StringHelper.isEmpty(pagesize)) {
pageSize = Integer.parseInt(pagesize);
}
if (log.isDebugEnable()) {
StringBuilder sb = new StringBuilder();
for (Object qobj : query.keySet()) {
sb.append("\r\nshell in package:" + qobj.toString() + ":" + query.get(qobj));
}
sb.append("\r\nfilterBson:" + filterBson);
sb.append("\r\npageIndex:" + pageIndex);
sb.append("\r\npageSize:" + pageSize);
sb.append("\r\nsorts:" + sorts);
log.debug(this, sb.toString());
}
log.info(this, "MongoDBDataStore findAction toJson : " + query.toJson());
MongoCursor<Document> cursor = null;
if (pageIndex > 0 && pageSize > 0) {
cursor = collection.find(query).projection(filterBson).sort(sorts).skip((pageIndex - 1) * pageSize)
.limit(pageSize).iterator();
}
else {
cursor = collection.find(query).projection(filterBson).sort(sorts).iterator();
}
return queryResultFormat(cursor, false);
}