Revision 46821
Added by Alessia Bardi about 7 years ago
MongoResultSetListener.java | ||
---|---|---|
26 | 26 |
private int total = 0; |
27 | 27 |
private int count = 0; |
28 | 28 |
|
29 |
public MongoResultSetListener(final MongoCollection<DBObject> collection, final Pattern filter, final Function<DBObject, String> serializer) |
|
29 |
public MongoResultSetListener(final MongoCollection<DBObject> collection, final Pattern filter, final Function<DBObject, String> serializer, final boolean noCursorTimeout)
|
|
30 | 30 |
throws MDStoreServiceException { |
31 |
log.debug("Creating resultset");
|
|
31 |
log.debug("Creating resultset - noCursorTimeout: "+noCursorTimeout);
|
|
32 | 32 |
this.collection = collection; |
33 | 33 |
this.filter = filter; |
34 | 34 |
this.serializer = serializer; |
35 |
createCursor(); |
|
35 |
createCursor(noCursorTimeout);
|
|
36 | 36 |
if (currentCursor == null) |
37 | 37 |
throw new MDStoreServiceException("Error on creating resultset the iterator is null"); |
38 | 38 |
|
39 | 39 |
} |
40 | 40 |
|
41 |
private void createCursor() throws MDStoreServiceException { |
|
41 |
private void createCursor(final boolean noCursorTimeout) throws MDStoreServiceException {
|
|
42 | 42 |
try { |
43 | 43 |
if (filter != null) { |
44 | 44 |
Bson query = Filters.regex("body", filter); |
45 | 45 |
total = (int) collection.count(query); |
46 |
currentCursor = collection.find(query).sort(sortByIdAsc).iterator(); |
|
46 |
currentCursor = collection.find(query).noCursorTimeout(noCursorTimeout).sort(sortByIdAsc).iterator();
|
|
47 | 47 |
} else { |
48 | 48 |
total = (int) collection.count(); |
49 |
currentCursor = collection.find().sort(sortByIdAsc).iterator(); |
|
49 |
currentCursor = collection.find().noCursorTimeout(noCursorTimeout).sort(sortByIdAsc).iterator();
|
|
50 | 50 |
} |
51 | 51 |
} catch (Throwable e) { |
52 | 52 |
throw new MDStoreServiceException("Error on initialize the cursor"); |
Also available in: Unified diff
New method to disable cursor timeout when reading from mdstore