use of lotus.domino.DocumentCollection in project org.openntf.domino by OpenNTF.
the class NotesRunner method run4.
public void run4(final Session session) throws NotesException {
Database db = session.getDatabase("", "events4.nsf");
NoteCollection cacheNC = db.createNoteCollection(false);
cacheNC.setSelectDocuments(true);
cacheNC.buildCollection();
cacheNC.recycle();
DocumentCollection cacheDc = db.getAllDocuments();
Document cacheDoc = cacheDc.getFirstDocument();
cacheDoc.recycle();
cacheDc.recycle();
db.recycle();
db = session.getDatabase("", "events4.nsf");
DocumentCollection dc = db.getAllDocuments();
Document doc = dc.getFirstDocument();
Document nextDoc = null;
int dcCount = dc.getCount();
int j = 0;
String[] dcUnids = new String[dcCount];
long dcStart = System.nanoTime();
while (doc != null) {
nextDoc = dc.getNextDocument(doc);
dcUnids[j++] = doc.getUniversalID();
doc.recycle();
doc = nextDoc;
}
System.out.println("DocumentCollection strategy got UNIDs for " + dcCount + " docs in " + (System.nanoTime() - dcStart) / 1000 + "us");
dc.recycle();
db.recycle();
db = session.getDatabase("", "events4.nsf");
NoteCollection nc3 = db.createNoteCollection(false);
nc3.setSelectDocuments(true);
nc3.buildCollection();
int nc3Count = nc3.getCount();
String[] nc3Unids = new String[nc3Count];
int[] nids = nc3.getNoteIDs();
int k = 0;
long nc3Start = System.nanoTime();
for (int id : nids) {
nc3Unids[k++] = nc3.getUNID(Integer.toHexString(id));
}
System.out.println("NoteCollection strategy ints got UNIDs for " + nc3Count + " notes in " + (System.nanoTime() - nc3Start) / 1000 + "us");
nc3.recycle();
db.recycle();
db = session.getDatabase("", "events4.nsf");
NoteCollection nc = db.createNoteCollection(false);
nc.setSelectDocuments(true);
nc.buildCollection();
int ncCount = nc.getCount();
String[] ncUnids = new String[ncCount];
String nid = nc.getFirstNoteID();
long ncStart = System.nanoTime();
for (int i = 0; i < ncCount; i++) {
ncUnids[i] = nc.getUNID(nid);
nid = nc.getNextNoteID(nid);
}
System.out.println("NoteCollection strategy first/next got UNIDs for " + ncCount + " notes in " + (System.nanoTime() - ncStart) / 1000 + "us");
nc.recycle();
db.recycle();
db = session.getDatabase("", "events4.nsf");
NoteCollection nc2 = db.createNoteCollection(false);
nc2.setSelectDocuments(true);
nc2.buildCollection();
int nc2Count = nc2.getCount();
String[] nc2Unids = new String[nc2Count];
nid = nc2.getFirstNoteID();
long nc2Start = System.nanoTime();
for (int i = 0; i < nc2Count; i++) {
Document nc2doc = db.getDocumentByID(nid);
nc2Unids[i] = nc2doc.getUniversalID();
nc2doc.recycle();
nid = nc2.getNextNoteID(nid);
}
System.out.println("NoteCollection strategy doc got UNIDs for " + nc2Count + " notes in " + (System.nanoTime() - nc2Start) / 1000 + "us");
nc2.recycle();
db.recycle();
}
use of lotus.domino.DocumentCollection in project org.openntf.domino by OpenNTF.
the class LegacyCollectionPerfTest method run.
@Override
public void run() {
try {
System.out.println("Starting NotesRunner");
Session session = NotesFactory.createSession();
Long sessId = getLotusId(session);
sessionid.set(sessId);
Database db = session.getDatabase("", "events4.nsf");
System.out.println("Db id:" + getLotusId(db));
try {
lotus.domino.Document doc = null;
lotus.domino.Document nextDoc = null;
lotus.domino.DocumentCollection allDocs = db.getAllDocuments();
System.out.println("All Collection has " + allDocs.getCount() + " documents");
int[] nids = new int[allDocs.getCount()];
long walkStartTime = System.nanoTime();
doc = allDocs.getFirstDocument();
int i = 0;
while (doc != null) {
nextDoc = allDocs.getNextDocument(doc);
nids[i++] = Integer.valueOf(doc.getNoteID(), 16);
doc.recycle();
doc = nextDoc;
}
long walkEndTime = System.nanoTime();
System.out.println("DOCWALK: noteid array has " + allDocs.getCount() + " entries in " + (walkEndTime - walkStartTime) / 1000 + "us");
long ncStartTime = System.nanoTime();
NoteCollection nc = db.createNoteCollection(false);
nc.add(allDocs);
nids = nc.getNoteIDs();
long ncBuildTime = System.nanoTime();
System.out.println("NOTECOLL: noteid array has " + nids.length + " entries in " + (ncBuildTime - ncStartTime) / 1000 + "us");
// for (int j = 0; j < nids.length; j++) {
// doc = db.getDocumentByID(Integer.toString(nids[j], 16));
// }
// long ncWalkTime = System.nanoTime();
// System.out.println("NOTECOLL: noteid array walked " + nids.length + " entries in " + (ncWalkTime - ncBuildTime) / 1000
// + "us");
long mergeStartTime = System.nanoTime();
DocumentCollection mergeColl = db.search("@False", db.getLastModified(), 1);
for (int j = 0; j < nids.length; j++) {
mergeColl.merge(nids[j]);
}
long mergeBuildTime = System.nanoTime();
System.out.println("MERGECOLL: mergeColl has " + mergeColl.getCount() + " entries in " + (mergeBuildTime - mergeStartTime) / 1000 + "us");
doc = mergeColl.getFirstDocument();
while (doc != null) {
nextDoc = mergeColl.getNextDocument(doc);
int n = Integer.valueOf(doc.getNoteID(), 16);
doc.recycle();
doc = nextDoc;
}
long mergeWalkTime = System.nanoTime();
System.out.println("MERGECOLL: mergeColl walked " + mergeColl.getCount() + " entries in " + (mergeWalkTime - mergeBuildTime) / 1000 + "us");
System.out.println("MERGECOLL: mergeColl total time " + mergeColl.getCount() + " entries in " + (mergeWalkTime - ncStartTime) / 1000 + "us");
walkStartTime = System.nanoTime();
doc = allDocs.getFirstDocument();
i = 0;
while (doc != null) {
nextDoc = allDocs.getNextDocument(doc);
nids[i++] = Integer.valueOf(doc.getNoteID(), 16);
doc.recycle();
doc = nextDoc;
}
walkEndTime = System.nanoTime();
System.out.println("DOCWALK: noteid array has " + allDocs.getCount() + " entries in " + (walkEndTime - walkStartTime) / 1000 + "us");
ncStartTime = System.nanoTime();
nc = db.createNoteCollection(false);
nc.add(allDocs);
nids = nc.getNoteIDs();
ncBuildTime = System.nanoTime();
System.out.println("NOTECOLL: noteid array has " + nids.length + " entries in " + (ncBuildTime - ncStartTime) / 1000 + "us");
// for (int j = 0; j < nids.length; j++) {
// doc = db.getDocumentByID(Integer.toString(nids[j], 16));
// }
// long ncWalkTime = System.nanoTime();
// System.out.println("NOTECOLL: noteid array walked " + nids.length + " entries in " + (ncWalkTime - ncBuildTime) / 1000
// + "us");
mergeStartTime = System.nanoTime();
mergeColl = db.search("@False", db.getLastModified(), 1);
for (int j = 0; j < nids.length; j++) {
mergeColl.merge(nids[j]);
}
mergeBuildTime = System.nanoTime();
System.out.println("MERGECOLL: mergeColl has " + mergeColl.getCount() + " entries in " + (mergeBuildTime - mergeStartTime) / 1000 + "us");
doc = mergeColl.getFirstDocument();
while (doc != null) {
nextDoc = mergeColl.getNextDocument(doc);
int n = Integer.valueOf(doc.getNoteID(), 16);
doc.recycle();
doc = nextDoc;
}
mergeWalkTime = System.nanoTime();
System.out.println("MERGECOLL: mergeColl walked " + mergeColl.getCount() + " entries in " + (mergeWalkTime - mergeBuildTime) / 1000 + "us");
System.out.println("MERGECOLL: mergeColl total time " + mergeColl.getCount() + " entries in " + (mergeWalkTime - ncStartTime) / 1000 + "us");
nc.recycle();
allDocs.recycle();
mergeColl.recycle();
} catch (Throwable t) {
t.printStackTrace();
}
session.recycle();
} catch (Throwable t) {
t.printStackTrace();
}
System.out.println("FINI!");
}
use of lotus.domino.DocumentCollection in project org.openntf.xsp.jakartaee by OpenNTF.
the class DefaultDominoDocumentCollectionManager method delete.
@Override
public void delete(DocumentDeleteQuery query) {
try {
Database database = supplier.get();
List<String> unids = query.getDocuments();
if (unids != null && !unids.isEmpty()) {
for (String unid : unids) {
if (unid != null && !unid.isEmpty()) {
lotus.domino.Document doc = database.getDocumentByUNID(unid);
doc.remove(true);
}
}
} else if (query.getCondition().isPresent()) {
// Then do it via DQL
DQLTerm dql = QueryConverter.getCondition(query.getCondition().get());
DominoQuery dominoQuery = database.createDominoQuery();
DocumentCollection docs = dominoQuery.execute(dql.toString());
docs.removeAll(true);
}
} catch (NotesException e) {
throw new RuntimeException(e);
}
}
use of lotus.domino.DocumentCollection 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);
}
}
use of lotus.domino.DocumentCollection in project org.openntf.xsp.jakartaee by OpenNTF.
the class DefaultDominoDocumentCollectionManager method count.
@Override
public long count(String documentCollection) {
try {
Database database = supplier.get();
DominoQuery dominoQuery = database.createDominoQuery();
DQLTerm dql = DQL.item(EntityConverter.NAME_FIELD).isEqualTo(documentCollection);
DocumentCollection result = dominoQuery.execute(dql.toString());
return result.getCount();
} catch (NotesException e) {
throw new RuntimeException(e);
}
}
Aggregations