本文整理汇总了Java中com.mongodb.BasicDBList.clear方法的典型用法代码示例。如果您正苦于以下问题:Java BasicDBList.clear方法的具体用法?Java BasicDBList.clear怎么用?Java BasicDBList.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.BasicDBList
的用法示例。
在下文中一共展示了BasicDBList.clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: packBackgroundsInToScenarios
import com.mongodb.BasicDBList; //导入方法依赖的package包/类
/**
* go through find all the backgrounds elements and nest them in their scenarios (simplifies application logic downstream)
*/
protected void packBackgroundsInToScenarios(final DBObject feature) {
final List<DBObject> packedScenarios = new ArrayList<DBObject>();
// go through all the backgrounds /scenarios
final BasicDBList elements = (BasicDBList) feature.get("elements");
if (elements != null) {
for (int i = 0; i < elements.size(); i++) {
final DBObject element = (DBObject) elements.get(i);
if (element.get("type").equals("background")) { // if its a background
((DBObject) elements.get(i + 1)).put("background", element); // push it in to the next element.
} else {
// assume this is a scenario/other top level element and push it to the packed array.
packedScenarios.add(element);
}
}
elements.clear();
elements.addAll(packedScenarios);
}
}
示例2: deleteOldestNExpired
import com.mongodb.BasicDBList; //导入方法依赖的package包/类
private int deleteOldestNExpired(String containerId, int size) {
log.debug("deleteOldestNExpired containerId:{}, size:{}", containerId, size);
MongoCollection<Document> collection = context.getDatabaseManager()
.getCollection(collectionName);
BasicDBList and = new BasicDBList();
DeleteResult result;
if (size >= 0) {
and.clear();
and.add(new BasicDBObject(PARENTID_KEY, containerId));
and.add(new BasicDBObject(RESTYPE_KEY, RESOURCE_TYPE.CONTENT_INST.Value()));
MongoCursor<Document> cursor = collection.find(new BasicDBObject("$and", and))
.sort(new BasicDBObject(CREATETIME_KEY, 1))
.limit(size).iterator();
int deletedCount = 0;
if (cursor.hasNext()) {
Document doc = cursor.next();
// and.clear();
// and.add(new BasicDBObject(PARENTID_KEY, containerId));
// and.add(new BasicDBObject(RESTYPE_KEY, RESOURCE_TYPE.CONTENT_INST.Value()));
// and.add(new BasicDBObject(CREATETIME_KEY, new BasicDBObject("$lt", doc.get(CREATETIME_KEY))));
//
result = collection.deleteOne(new BasicDBObject(RESID_KEY, doc.get(RESID_KEY)));
deletedCount += result.getDeletedCount();
}
log.debug("Deleted oldest contentInstance:{}", deletedCount);
return deletedCount;
}
return 0;
}
示例3: deleteOldestNExpired
import com.mongodb.BasicDBList; //导入方法依赖的package包/类
private int deleteOldestNExpired(String containerId, int size) {
log.debug("deleteOldestNExpired containerId:{}, size:{}", containerId, size);
MongoCollection<Document> collection = context.getDatabaseManager()
.getCollection(collectionName);
BasicDBList and = new BasicDBList();
DeleteResult result;
/*
String now = LocalDateTime.now().toString(DateTimeFormat.forPattern("yyyyMMdd'T'HHmmss"));
and.add(new BasicDBObject(EXPIRETIME_KEY, new BasicDBObject("$lt", now)));
and.add(new BasicDBObject(PARENTID_KEY, containerId));
result = collection.deleteMany(new BasicDBObject("$and", and));
size -= result.getDeletedCount();
log.debug("Deleted expired contentInstance:{}", result.getDeletedCount());
*/
if (size >= 0) {
and.clear();
and.add(new BasicDBObject(PARENTID_KEY, containerId));
and.add(new BasicDBObject(RESTYPE_KEY, RESOURCE_TYPE.CONTENT_INST.Value()));
MongoCursor<Document> cursor = collection.find(new BasicDBObject("$and", and))
.sort(new BasicDBObject(CREATETIME_KEY, 1))
.limit(size).iterator();
int deletedCount = 0;
if (cursor.hasNext()) {
Document doc = cursor.next();
// and.clear();
// and.add(new BasicDBObject(PARENTID_KEY, containerId));
// and.add(new BasicDBObject(RESTYPE_KEY, RESOURCE_TYPE.CONTENT_INST.Value()));
// and.add(new BasicDBObject(CREATETIME_KEY, new BasicDBObject("$lt", doc.get(CREATETIME_KEY))));
//
result = collection.deleteOne(new BasicDBObject(RESID_KEY, doc.get(RESID_KEY)));
deletedCount += result.getDeletedCount();
}
log.debug("Deleted oldest contentInstance:{}", deletedCount);
return deletedCount;
}
return 0;
}