use of lotus.domino.QueryResultsProcessor in project org.openntf.xsp.jakartaee by OpenNTF.
the class DefaultDominoDocumentCollectionManager method select.
@Override
public Stream<DocumentEntity> select(DocumentQuery query) {
try {
QueryConverterResult queryResult = QueryConverter.select(query);
long skip = queryResult.getSkip();
long limit = queryResult.getLimit();
List<Sort> sorts = query.getSorts();
Stream<DocumentEntity> result;
if (sorts != null && !sorts.isEmpty()) {
Database database = supplier.get();
Session sessionAsSigner = sessionSupplier.get();
Database qrpDatabase = getQrpDatabase(sessionAsSigner, database);
String userName = database.getParent().getEffectiveUserName();
// $NON-NLS-1$
String viewName = getClass().getName() + "-" + (String.valueOf(sorts) + skip + limit + userName).hashCode();
View view = qrpDatabase.getView(viewName);
try {
if (view != null) {
// Check to see if we need to "expire" it based on the data mod time of the DB
DateTime created = view.getCreated();
try {
long dataMod = NotesSession.getLastDataModificationDateByName(database.getServer(), database.getFilePath());
if (dataMod > (created.toJavaDate().getTime() / 1000)) {
view.remove();
view.recycle();
view = null;
}
} catch (NotesAPIException e) {
throw new RuntimeException(e);
} finally {
recycle(created);
}
}
if (view != null) {
result = EntityConverter.convert(database, view);
} else {
DominoQuery dominoQuery = database.createDominoQuery();
QueryResultsProcessor qrp = qrpDatabase.createQueryResultsProcessor();
try {
qrp.addDominoQuery(dominoQuery, queryResult.getStatement().toString(), null);
for (Sort sort : sorts) {
int dir = sort.getType() == SortType.DESC ? QueryResultsProcessor.SORT_DESCENDING : QueryResultsProcessor.SORT_ASCENDING;
qrp.addColumn(sort.getName(), null, null, dir, false, false);
}
if (skip == 0 && limit > 0 && limit <= Integer.MAX_VALUE) {
qrp.setMaxEntries((int) limit);
}
view = qrp.executeToView(viewName, 24);
try {
result = EntityConverter.convert(database, view);
} finally {
recycle(view);
}
} finally {
recycle(qrp, dominoQuery, qrpDatabase);
}
}
} finally {
recycle(view);
}
} else {
Database database = supplier.get();
DominoQuery dominoQuery = database.createDominoQuery();
DocumentCollection docs = dominoQuery.execute(queryResult.getStatement().toString());
try {
result = EntityConverter.convert(docs);
} finally {
recycle(docs, dominoQuery);
}
}
if (skip > 0) {
result = result.skip(skip);
}
if (limit > 0) {
result = result.limit(limit);
}
return result;
} catch (NotesException e) {
throw new RuntimeException(e);
}
}
Aggregations