本文整理匯總了Java中com.mongodb.DBCursor.size方法的典型用法代碼示例。如果您正苦於以下問題:Java DBCursor.size方法的具體用法?Java DBCursor.size怎麽用?Java DBCursor.size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mongodb.DBCursor
的用法示例。
在下文中一共展示了DBCursor.size方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getChatMessages
import com.mongodb.DBCursor; //導入方法依賴的package包/類
/**
* @param channelId The Unique ID of the channel.
* @param limit The Integer limit of ChatMessages to load.
* @return Returns a List of ChatMessages for the ChatChannel.
*/
private List<ChatMessage> getChatMessages(UUID channelId, int limit) {
List<ChatMessage> listChatMessages = new LinkedList<>();
// Grab all the messages with the channel_id set to the one provided.
DBObject query = new BasicDBObject("channel_id", channelId);
DBCursor cursor = collectionMessages.find(query);
// Sort the list by timestamp so that the last messages appear first.
cursor.sort(new BasicDBObject("timestamp", -1));
cursor.limit(limit);
if(cursor.size() > 0) {
List<DBObject> listObjects = cursor.toArray();
Collections.reverse(listObjects);
for(DBObject object : listObjects) {
// Create the MongoDocument.
MongoChatMessage mongoChatMessage = new MongoChatMessage(collectionMessages, object);
// Create the container for the document.
ChatMessage chatMessage = new ChatMessage(mongoChatMessage);
// Add this to the list to return.
listChatMessages.add(chatMessage);
}
}
// Close the cursor to release resources.
cursor.close();
// Return the result list of messages for the channel.
return listChatMessages;
}
示例2: verifyUser
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public static String verifyUser(String name, String passwd) {
DBCollection collection = MongoDB.getDB().getCollection("users");
BasicDBObject searchQuery = new BasicDBObject();
searchQuery.put("name", name);
DBCursor cursor = collection.find(searchQuery);
int size = cursor.size();
if (size == 0) {
return "000002";// 用戶不存在
} else {
String uname = null, upasswd = null;
while (cursor.hasNext()) {
DBObject dbo = cursor.next();
uname = dbo.get("name").toString();
upasswd = dbo.get("passwd").toString();
}
if (name.equals(uname) && passwd.equals(upasswd)) {
return "000000";// 用戶存在驗證正確
} else {
return "000001";// 用戶名或密碼不正確
}
}
}
示例3: getBasketItems
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public List<BasketItem> getBasketItems(User user) {
this.selectCollection(DB_BASKET);
String username = user.getOrganization().getName()+":"+user.getMail();
DBCursor cursor = table.find(new BasicDBObject("username", username), new BasicDBObject(ARRAY_BASKET,1).append("_id",false));
List<BasketItem> basketItems = new ArrayList<BasketItem>();
if (cursor.size() > 0) {
while (cursor.hasNext()) {
List<Map<String,String>> result = new JSONDeserializer<List<Map<String,String>>>().deserialize(cursor.next().get(ARRAY_BASKET).toString());
for (int i = 0; i < result.size(); i++) {
BasketItem basketItem = new BasketItem();
basketItem.setPid(result.get(i).get("pid"));
basketItem.setType(result.get(i).get("type"));
basketItem.setName(result.get(i).get("name"));
basketItems.add(basketItem);
}
}
}
cursor.close();
return basketItems;
}
示例4: listBasketContent
import com.mongodb.DBCursor; //導入方法依賴的package包/類
/**
* @param user name of the user (cn from ldap)
*
* @return Content of the basket in json format
*/
public String listBasketContent(User user) {
this.selectCollection(DB_BASKET);
String username = user.getOrganization().getName()+":"+user.getMail();
String jsonresult = "";
// Exclude database row id from results with .append("_id",false)
DBCursor cursor = table.find(new BasicDBObject("username", username), new BasicDBObject(ARRAY_BASKET,1).append("_id",false));
if (cursor.size() > 0) {
while (cursor.hasNext()) {
jsonresult = "["+cursor.next().toString();
}
}
if (cursor.size() > 0) {
jsonresult += "]";
}
cursor.close();
return jsonresult;
}
示例5: getDisposalListItems
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public List<DisposalListItem> getDisposalListItems(String organization){
this.selectCollection(DB_DISPOSAL);
List<DisposalListItem> disposalListItems = new ArrayList<DisposalListItem>();
DBCursor cursor = table.find(new BasicDBObject("organization", organization), new BasicDBObject("_id", 0));
if (cursor.size() > 0) {
while (cursor.hasNext()) {
List<Map<String,String>> results = new JSONDeserializer<List<Map<String,String>>>().deserialize(cursor.next().get(ARRAY_DISPOSAL).toString());
for (int i = 0; i < results.size(); i++) {
Map<String, String> item = results.get(i);
DisposalListItem disposalItem = new DisposalListItem();
disposalItem.setPid(item.get("pid"));
disposalItem.setObjectName(item.get("objname"));
disposalItem.setObjectType(item.get("objtype"));
disposalItem.setDeleter(item.get("username"));
disposalItem.setDisposalDateString(item.get("date"));
disposalItem.setDisposalDateTimestamp(Long.parseLong(item.get("timestamp")));
disposalListItems.add(disposalItem);
}
}
}
cursor.close();
return disposalListItems;
}
示例6: getLatestEdited
import com.mongodb.DBCursor; //導入方法依賴的package包/類
/** Gets latest objects user has edited
* @param user Username
* @return Object info in JSON
*/
public String getLatestEdited(User user) {
String jsonresult = "";
String username = user.getOrganization().getName()+":"+user.getMail();
this.selectCollection(DB_LATESTEDITS);
// Exclude database row id from results with .append("_id",false)
DBCursor cursor = table.find(new BasicDBObject("username", username), new BasicDBObject(ARRAY_LATESTEDITS,1).append("_id",false)).sort(new BasicDBObject("editDate", 1));
if (cursor.size() > 0) {
while (cursor.hasNext()) {
jsonresult = "["+cursor.next().toString();
}
}
if (cursor.size() > 0) {
jsonresult += "]";
}
cursor.close();
return jsonresult;
}
示例7: findListForQuery
import com.mongodb.DBCursor; //導入方法依賴的package包/類
/**
* This method creates connection to the Mongo database,
* executes find method for given query and closes this connection.
* @param coll
* @param query
* @return list of results
*/
private List<BasicDBObject> findListForQuery(DBCollection coll, BasicDBObject query) {
List<BasicDBObject> res = new ArrayList<BasicDBObject>();
DBCursor cur = coll.find(query);
if (cur != null && cur.size() == 0) {
log.debug("object not found in database. query result size is 0.");
}
try {
while (cur.hasNext()) {
res.add((BasicDBObject) cur.next());
}
} finally {
cur.close();
}
return res;
}
示例8: findSingleForQuery
import com.mongodb.DBCursor; //導入方法依賴的package包/類
/**
* This method creates connection to the Mongo database,
* executes find method for given query and closes this connection.
* @param coll
* @param query
* @return single result
*/
private BasicDBObject findSingleForQuery(DBCollection coll, BasicDBObject query) {
BasicDBObject res = null;
DBCursor cur = coll.find(query);
if (cur != null && cur.size() == 0) {
log.info("object not found in database. query result size is 0.");
}
try {
if (cur.hasNext()) {
res = (BasicDBObject) cur.next();
}
} finally {
cur.close();
}
return res;
}
示例9: getYagoTypeLabel
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public String getYagoTypeLabel(String uri){
DBCursor cursor = db.getCollection("entities_yago").find(new BasicDBObject().append("uri", uri));
if(cursor.size() > 0){
DBObject tmp = cursor.next();
BasicDBList labels = (BasicDBList)tmp.get("labels");
if(labels != null){
DBObject tmp2 = (DBObject)labels.get(0);
return tmp2.get("label").toString();
}
}
return null;
}
示例10: loadSubjectNamespaces
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public void loadSubjectNamespaces() {
// query all subjects ns for the distribution
BasicDBObject subjectQuery = new BasicDBObject(DistributionSubjectNSDB.DISTRIBUTION_ID, distributionID);
DBCollection collection = DBSuperClass2.getCollection(DistributionSubjectNSDB.COLLECTION_NAME);
DBCursor cursor = collection.find(subjectQuery);
// HashSet<String> subjectsNS = new HashSet<String>();
String resource;
filterSubjectsNS = BloomFilterFactory.newBloomFilter();
if (cursor.size() < 10000) {
filterSubjectsNS.create(10000, 0.0000001);
} else {
filterSubjectsNS.create(cursor.size(), 0.0000001);
}
while (cursor.hasNext()) {
resource = cursor.next().get(DistributionSubjectNSDB.NS).toString();
// subjectsNS.add(resource);
filterSubjectsNS.add(resource);
}
}
示例11: loadObjectNamespaces
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public void loadObjectNamespaces() {
// doing the same for objects ns
BasicDBObject objectQuery = new BasicDBObject(DistributionObjectNSDB.DISTRIBUTION_ID, distributionID);
DBCollection collection = DBSuperClass2.getCollection(DistributionObjectNSDB.COLLECTION_NAME);
DBCursor cursor = collection.find(objectQuery);
String resource;
filterObjectsNS = BloomFilterFactory.newBloomFilter();
if (cursor.size() < 10000)
filterObjectsNS.create(10000, 0.0000001);
else
filterObjectsNS.create(cursor.size(), 0.0000001);
while (cursor.hasNext()) {
resource = cursor.next().get(DistributionObjectNSDB.NS).toString();
// objectsNS.add(resource);
filterObjectsNS.add(resource);
}
}
示例12: getNumberOfAccounts
import com.mongodb.DBCursor; //導入方法依賴的package包/類
/**
* @param steamID The Steam ID being used to search for accounts.
* @return The number of accounts registered under the given Steam ID.
*/
public int getNumberOfAccounts(long steamID) {
if (steamID == -1L) {
throw new IllegalArgumentException("SledgehammerDatabase: Steam ID is invalid: " + steamID);
}
DBCursor cursor = collectionPlayers.find(new BasicDBObject("steamID", "" + steamID));
int size = cursor.size();
cursor.close();
return size;
}
示例13: insertToBasket
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public String insertToBasket(User user, String pid) {
this.selectCollection(DB_BASKET);
String success = "";
String username = user.getOrganization().getName()+":"+user.getMail();
String objName = Osa.searchManager.getItemByPid(pid, user, user.getLocale()).replace("[", "").replace("]", "");
String objType = Osa.searchManager.getObjectType(pid, user);
Vector<HashMap<String, String>> pidVector = new Vector<HashMap<String, String>>();
HashMap<String, String> pidDatamap = new HashMap<String, String>();
BasicDBObject query = new BasicDBObject();
DBCursor cursor = table.find(new BasicDBObject("username", username), new BasicDBObject(ARRAY_BASKET,1).append("_id",false));
// If basket already has items
if (cursor.size() != 0) {
success = this.updateBasket(user, pid, objName);
} else {
// If basket is empty, create new
pidDatamap.put("pid", pid);
pidDatamap.put("name", objName);
pidDatamap.put("type", objType);
pidVector.add(pidDatamap);
query.put("username", username);
query.put(ARRAY_BASKET, pidVector);
this.table.insert(query);
success = "success";
}
cursor.close();
return success;
}
示例14: fillinCache
import com.mongodb.DBCursor; //導入方法依賴的package包/類
private void fillinCache(List<DBObject> finalRes, DBCursor cursor) {
if (cursor.size() == 0) {
cachedRows = new ArrayList<DBObject>().listIterator();
} else {
while (cursor.hasNext()) {
DBObject mdbrow = cursor.next();
finalRes.add(mdbrow);
}
cachedRows = finalRes.listIterator();
}
}
示例15: fillinCache
import com.mongodb.DBCursor; //導入方法依賴的package包/類
private void fillinCache(List<DBObject> finalRes, DBCursor cursor) {
if (cursor.size() == 0) {
cachedRows = new ArrayList<DBObject>().listIterator();
} else {
while (cursor.hasNext()) {
DBObject mdbrow = cursor.next();
finalRes.add(mdbrow);
}
cachedRows = finalRes.listIterator();
}
}