本文整理匯總了Java中com.mongodb.DBCursor.next方法的典型用法代碼示例。如果您正苦於以下問題:Java DBCursor.next方法的具體用法?Java DBCursor.next怎麽用?Java DBCursor.next使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mongodb.DBCursor
的用法示例。
在下文中一共展示了DBCursor.next方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: afterCreate
import com.mongodb.DBCursor; //導入方法依賴的package包/類
/** Read the occasions that are stored in the database and schedule them to run. */
@PostConstruct
public void afterCreate() {
String method = "afterCreate";
logger.entering(clazz, method);
orchestrator.setOccasionResource(this);
DBCollection occasions = getCollection();
DBCursor cursor = occasions.find();
while (cursor.hasNext()) {
DBObject dbOccasion = cursor.next();
Occasion occasion = new Occasion(dbOccasion);
try {
// TODO: There was a comment here about how we should mark the event as
// popped in the database, which will have different meaning for
// one-time or interval occasions. Need to re-visit this.
orchestrator.scheduleOccasion(occasion);
} catch (Throwable t) {
logger.log(Level.WARNING, "Could not schedule occasion at startup", t);
}
}
logger.exiting(clazz, method);
}
示例2: findByFirstnameUsingMetaAttributes
import com.mongodb.DBCursor; //導入方法依賴的package包/類
/**
* This test demonstrates usage of {@code $comment} {@link Meta} usage. One can also enable profiling using
* {@code --profile=2} when starting {@literal mongod}.
* <p>
* <strong>NOTE</strong>: Requires MongoDB v. 2.6.4+
*/
@Test
public void findByFirstnameUsingMetaAttributes() {
// execute derived finder method just to get the comment in the profile log
repository.findByFirstname(dave.getFirstname());
// execute another finder without meta attributes that should not be picked up
repository.findByLastname(dave.getLastname(), new Sort("firstname"));
DBCursor cursor = operations.getCollection(ApplicationConfiguration.SYSTEM_PROFILE_DB)
.find(new BasicDBObject("query.$comment", AdvancedRepository.META_COMMENT));
while (cursor.hasNext()) {
DBObject dbo = cursor.next();
DBObject query = (DBObject) dbo.get("query");
assertThat(query.containsField("$comment"), is(true));
}
}
示例3: getCacheEntry
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public CacheEntry getCacheEntry(String key, CacheEntry defaultValue) {
DBCursor cur = null;
DBCollection coll = getCollection();
BasicDBObject query = new BasicDBObject("key", key.toLowerCase());
// be sure to flush
flushInvalid(coll,query);
cur = coll.find(query);
if (cur.count() > 0) {
hits++;
MongoDBCacheDocument doc = new MongoDBCacheDocument((BasicDBObject) cur.next());
doc.addHit();
//update the statistic and persist
save(doc,0);
return new MongoDBCacheEntry(doc);
}
misses++;
return defaultValue;
}
示例4: loadMongoFactions
import com.mongodb.DBCursor; //導入方法依賴的package包/類
/**
* (Private Method)
* <p>
* Loads MongoFaction Objects from the database.
*/
private void loadMongoFactions() {
println("Loading Faction(s)...");
// Create HashMap.
mapMongoFactions = new HashMap<>();
// Initiate collection query.
DBCursor cursor = collectionFactions.find();
// Go through each entry.
while (cursor.hasNext()) {
// Create an object for each entry.
MongoFaction mongoFaction = new MongoFaction(collectionFactions, cursor.next());
// Add to the map with the UUID of the Faction.
mapMongoFactions.put(mongoFaction.getUniqueId(), mongoFaction);
}
// Close the query.
cursor.close();
// Report statistics.
int size = mapMongoFactions.size();
println("Loaded " + (size == 0 ? "no" : size + "") + " Faction" + (size == 1 ? "" : "s") + ".");
}
示例5: remove
import com.mongodb.DBCursor; //導入方法依賴的package包/類
@Override
public int remove(CacheKeyFilter filter) {
DBCursor cur = qAll_Keys();
int counter = 0;
while (cur.hasNext()) {
DBObject obj = cur.next();
String key = (String) obj.get("key");
if (filter.accept(key)) {
doDelete((BasicDBObject) obj);
counter++;
}
}
return counter;
}
示例6: getMongoPlayer
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public MongoPlayer getMongoPlayer(String username) {
if (username == null || username.isEmpty()) {
throw new IllegalArgumentException("SledgehammerDatabase: Username given is null or empty!");
}
MongoPlayer player;
player = mapPlayersByUsername.get(username);
if (player == null) {
DBCursor cursor = collectionPlayers.find(new BasicDBObject("username", username));
if (cursor.hasNext()) {
player = new MongoPlayer(collectionPlayers, cursor.next());
registerPlayer(player);
}
cursor.close();
}
return player;
}
示例7: values
import com.mongodb.DBCursor; //導入方法依賴的package包/類
@Override
public List<Object> values(CacheKeyFilter filter) {
DBCursor cur = qAll_Keys_Values();
List<Object> result = new ArrayList<Object>();
while (cur.hasNext()) {
BasicDBObject obj = (BasicDBObject) cur.next();
MongoDBCacheDocument doc = new MongoDBCacheDocument(obj);
if (filter.accept(doc.getKey())) {
try {
result.add(MongoDBCacheDocument.getValue(obj));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
return result;
}
示例8: getPlayerID
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public UUID getPlayerID(String username) {
if (username == null || username.isEmpty()) {
throw new IllegalArgumentException("SledgehammerDatabase: Username is null or empty!");
}
MongoPlayer player = getMongoPlayer(username);
if (player != null) {
return player.getUniqueId();
}
UUID returned = null;
DBCursor cursor = collectionPlayers.find(new BasicDBObject("username", username));
if (cursor.hasNext()) {
DBObject object = cursor.next();
returned = UUID.fromString(object.get("uuid").toString());
}
cursor.close();
return returned;
}
示例9: loadMongoFactionMembers
import com.mongodb.DBCursor; //導入方法依賴的package包/類
/**
* (Private Method)
* <p>
* Loads MongoFactionMember Objects from the database.
*/
private void loadMongoFactionMembers() {
println("Loading Faction Member(s)...");
// Create HashMap.
mapMongoFactionMembers = new HashMap<>();
// Initiate collection query.
DBCursor cursor = collectionFactionMembers.find();
// Go through each entry.
while (cursor.hasNext()) {
// Create an object for each entry.
MongoFactionMember mongoFactionMember = new MongoFactionMember(collectionFactionMembers, cursor.next());
// Add to the map with the UUID of the FactionMember.
mapMongoFactionMembers.put(mongoFactionMember.getPlayerId(), mongoFactionMember);
}
// Close the query.
cursor.close();
// Report statistics.
int size = mapMongoFactionMembers.size();
println("Loaded " + (size == 0 ? "no" : size + "") + " Faction Member" + (size == 1 ? "" : "s") + ".");
}
示例10: getEstimatedSizeBytes
import com.mongodb.DBCursor; //導入方法依賴的package包/類
@Override
public long getEstimatedSizeBytes(PipelineOptions options) throws Exception {
Mongo mongo = spec.connectionConfiguration().setupMongo();
try {
GridFS gridfs = spec.connectionConfiguration().setupGridFS(mongo);
DBCursor cursor = createCursor(gridfs);
long size = 0;
while (cursor.hasNext()) {
GridFSDBFile file = (GridFSDBFile) cursor.next();
size += file.getLength();
}
return size;
} finally {
mongo.close();
}
}
示例11: serializeShipments
import com.mongodb.DBCursor; //導入方法依賴的package包/類
private void serializeShipments(JsonGenerator jgen) throws IOException,
JsonProcessingException {
jgen.writeArrayFieldStart("Shipments");
DBCursor c = getDB().getCollection("shipments").find();
while (c.hasNext()) {
DBObject obj = c.next();
jgen.writeStartObject();
jgen.writeStringField("origin", obj.get("origin").toString());
jgen.writeStringField("destination", obj.get("destination")
.toString());
jgen.writeNumberField("totalVolume",
((Number) obj.get("totalVolume")).intValue());
jgen.writeEndObject();
}
jgen.writeEndArray();
}
示例12: loadUser
import com.mongodb.DBCursor; //導入方法依賴的package包/類
@Override
public User loadUser(String username, String passwd)
{
DBCollection usersTable = dataBase.getCollection("users");
BasicDBObject query = new BasicDBObject();
query.put("name", username);
query.put("password", passwd);
DBCursor cursorQ = usersTable.find(query);
if(cursorQ.hasNext()){
cursorQ.next();
return new User((String)cursorQ.curr().get("name"),
(String)cursorQ.curr().get("password"),
(Boolean)cursorQ.curr().get("admin"),
(Integer)cursorQ.curr().get("rightQuestions"),
(Integer)cursorQ.curr().get("failedQuestions"));
}
return null;
}
示例13: getApprovals
import com.mongodb.DBCursor; //導入方法依賴的package包/類
@Override
public List<Approval> getApprovals(String userName, String clientId) {
BasicDBObject query = new BasicDBObject(userIdFieldName, userName).append(clientIdFieldName, clientId);
DBCursor cursor = null;
try {
List<Approval> approvals = new ArrayList<Approval>();
cursor = getApprovalsCollection().find(query);
while (cursor.hasNext()) {
DBObject dbo = cursor.next();
approvals.add(new Approval((String) dbo.get(userIdFieldName), (String) dbo.get(clientIdFieldName),
(String) dbo.get(scopeFieldName), (Date) dbo.get(expiresAtFieldName),
Approval.ApprovalStatus.valueOf((String) dbo.get(statusFieldName)),
(Date) dbo.get(lastModifiedAtFieldName)));
}
return approvals;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
示例14: getTimeRange
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public static Pair<Date, Date> getTimeRange(String hostname, String dbName, String collection) {
Date first = null, last = null;
DBCollection coll = getCollection(hostname, dbName, collection);
DBCursor c = coll.find();
while(c.hasNext()) {
DBObject obj = c.next();
String rawJSON = obj.toString();
try {
Status status = DataObjectFactory.createStatus(rawJSON);
Date d = status.getCreatedAt();
if(first == null || first.after(d))
first = d;
if(last == null || last.before(d))
last = d;
} catch (TwitterException e) { }
}
System.out.println("First tweet at: " + first);
System.out.println("Last tweet at: " + last);
return Pair.of(first, last);
}
示例15: as
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public <T> Iterable<T> as(final Class<T> clazz) {
DBCursor cursor = new DBCursor(collection, query.toDBObject(), getFieldsAsDBObject(), readPreference);
addOptionsOn(cursor);
List<T> out = new ArrayList<>();
InstantiatedReferencesQueryingCache cache = new InstantiatedReferencesQueryingCache(queryFactory, unmarshaller, collection);
while (cursor.hasNext()) {
DBObject next = cursor.next();
T current;
if (ObjBase.class.isAssignableFrom(clazz)) {
current = (T) cache.makeValue(new ObjectId(next.get("_id")), next, (Class<? extends ObjBase>) clazz);
} else {
current = unmarshaller.unmarshall(Bson.createDocument(next), clazz, cache);
}
out.add((T) current);
}
return out;
}