Search in sources :

Example 1 with DocumentSorter

use of org.openntf.domino.helpers.DocumentSorter in project org.openntf.domino by OpenNTF.

the class SortedCollectionTest method run.

@Override
public void run() {
    Session session = Factory.getSession(SessionType.CURRENT);
    Database db = session.getDatabase("", "CollTest.nsf");
    DocumentCollection coll = db.getAllDocuments();
    // System.out.println("UNSORTED");
    for (Document doc : coll) {
    // System.out.println(doc.getItemValueString("MainSortValue") + " " + doc.getLastModifiedDate().getTime());
    }
    List<String> criteria = new ArrayList<String>();
    criteria.add("MainSortValue");
    criteria.add("@modifieddate");
    try {
        DocumentSorter sorter = new DocumentSorter(coll, criteria);
        // System.out.println("SORTING...");
        long startTime = System.nanoTime();
        DocumentCollection sortedColl = sorter.sort();
        long endTime = System.nanoTime();
        System.out.println("Completed resort in " + ((endTime - startTime) / 1000000) + "ms");
        // System.out.println("SORTED");
        for (Document doc : sortedColl) {
            System.out.println(doc.getItemValueString("MainSortValue") + " " + doc.getLastModifiedDate().getTime() + " " + Integer.valueOf(doc.getNoteID(), 16));
        }
        DocumentSorter.DocumentData[] dataset = sorter._debugGetDataset();
        for (DocumentSorter.DocumentData data : dataset) {
            StringBuilder sb = new StringBuilder();
            for (Serializable s : data._debugGetValues()) {
                sb.append(s);
                sb.append(',');
            }
            System.out.println(sb.toString());
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) DocumentCollection(org.openntf.domino.DocumentCollection) Document(org.openntf.domino.Document) Database(org.openntf.domino.Database) DocumentSorter(org.openntf.domino.helpers.DocumentSorter) Session(org.openntf.domino.Session)

Example 2 with DocumentSorter

use of org.openntf.domino.helpers.DocumentSorter in project org.openntf.domino by OpenNTF.

the class LargishSortedCollectionTest method run.

@Override
public void run() {
    long testStartTime = System.nanoTime();
    Session session = Factory.getSession(SessionType.CURRENT);
    // Database db = session.getDatabase("", "events4.nsf");
    Database db = session.getDatabase("", "events4.nsf");
    // System.out.println("Starting build of byMod view");
    // long vStartTime = System.nanoTime();
    // View newView = db.createView("ModTest", "SELECT @All");
    // ViewColumn modCol = newView.createColumn(1, "Modified", "@Modified");
    // modCol.setSorted(true);
    // newView.refresh();
    // long vEndTime = System.nanoTime();
    // System.out.println("Completed building byModView in " + ((vEndTime - vStartTime) / 1000000) + "ms");
    // IndexDatabase index = new IndexDatabase(session.getDatabase("", "redpill/index.nsf"));
    // Document indexDoc = index.getDbDocument(db.getReplicaID());
    // System.out.println("UNSORTED");
    List<String> criteria = new ArrayList<String>();
    // criteria.add("@doclength");
    criteria.add("@modifieddate");
    try {
        DocumentSorter sorter = null;
        // if (indexDoc.hasItem("DocumentSorter")) {
        // sorter = indexDoc.getItemValue("DocumentSorter", DocumentSorter.class);
        // sorter.setDatabase(db);
        // System.out.println("Starting resort of " + sorter.getCount() + " documents");
        // } else {
        DocumentCollection coll = db.getAllDocuments();
        sorter = new DocumentSorter(coll, criteria);
        System.out.println("Starting resort of " + coll.getCount() + " documents");
        // }
        // System.out.println("SORTING...");
        long startTime = System.nanoTime();
        DocumentCollection sortedColl = sorter.sort();
        long endTime = System.nanoTime();
        System.out.println("Completed resort of " + sortedColl.getCount() + " in " + ((endTime - startTime) / 1000000) + " ms");
    // int count = 0;
    // for (Document doc : sortedColl) {
    // //				System.out.println(doc.getLastModifiedDate().getTime() + " " + doc.getNoteID());
    // if (++count > 500) {
    // break;
    // }
    // }
    // indexDoc.replaceItemValue("DocumentList", sortedColl);
    // indexDoc.replaceItemValue("DocumentSorter", sorter);
    // indexDoc.save();
    // System.out.println("Saved sorter and result list to document of length " + (indexDoc.getSize() / 1024) + "KB");
    // System.out.println("SORTED");
    // for (Document doc : sortedColl) {
    // System.out.println(doc.getItemValueString("MainSortValue") + " " + doc.getLastModifiedDate().getTime());
    // }
    } catch (Throwable t) {
        t.printStackTrace();
    }
    long testEndTime = System.nanoTime();
    System.out.println("Completed " + getClass().getSimpleName() + " run in " + ((testEndTime - testStartTime) / 1000000000) + " s");
// View modView = db.getView("AllByLengthMod");
// long startTime = System.nanoTime();
// if (modView != null) {
// modView.refresh();
// }
// long endTime = System.nanoTime();
// System.out.println("Completed view build in " + ((endTime - startTime) / 1000000) + "ms");
}
Also used : Database(org.openntf.domino.Database) ArrayList(java.util.ArrayList) DocumentSorter(org.openntf.domino.helpers.DocumentSorter) DocumentCollection(org.openntf.domino.DocumentCollection) Session(org.openntf.domino.Session)

Example 3 with DocumentSorter

use of org.openntf.domino.helpers.DocumentSorter in project org.openntf.domino by OpenNTF.

the class IndexDatabase method scanDatabase.

// @SuppressWarnings("unused")
// private int sortedDocCount_ = 0;
/* (non-Javadoc)
	 * @see org.openntf.domino.big.impl.IIndexDatabase#scanDatabase(org.openntf.domino.Database, org.openntf.domino.helpers.DocumentScanner)
	 */
@Override
public DocumentScanner scanDatabase(final Database db, final DocumentScanner scanner) {
    // System.out.println("Scanning database " + db.getApiPath());
    curDocCount_ = 0;
    scanner.setCaseSensitive(getCaseSensitive());
    scanner.setStateManager(this, db.getReplicaID());
    Date last = scanner.getLastScanDate();
    if (last == null) {
        last = new Date(0);
    }
    int count = db.getModifiedNoteCount(last);
    if (count > 0) {
        DocumentCollection rawColl = db.getModifiedDocuments(last);
        DocumentSorter sorter = new DocumentSorter(rawColl, MOD_SORT_LIST);
        System.out.println("Scanning database " + db.getApiPath() + " with last date of " + last.getTime() + " and found " + rawColl.getCount() + " updates to scan");
        scanner.processSorter(sorter);
    }
    return scanner;
}
Also used : DocumentSorter(org.openntf.domino.helpers.DocumentSorter) DocumentCollection(org.openntf.domino.DocumentCollection) Date(java.util.Date)

Aggregations

DocumentCollection (org.openntf.domino.DocumentCollection)3 DocumentSorter (org.openntf.domino.helpers.DocumentSorter)3 ArrayList (java.util.ArrayList)2 Database (org.openntf.domino.Database)2 Session (org.openntf.domino.Session)2 Serializable (java.io.Serializable)1 Date (java.util.Date)1 Document (org.openntf.domino.Document)1