Search in sources :

Example 21 with Session

use of org.openntf.domino.Session in project org.openntf.domino by OpenNTF.

the class SimpleTest method run.

@Override
public void run() {
    Factory.enableCounters(true, false);
    Session s = Factory.getSession(SessionType.CURRENT);
    Database d = s.getDatabase("", "names.nsf");
    List<String> ids = new ArrayList<String>();
    Collection<Document> documents = d.getAllDocuments();
    for (Document doc : documents) {
        ids.add(doc.getNoteID());
    }
    // System.out.println("IDS.size " + ids.size());
    for (int i = 1; i < 10; i++) {
        System.out.println(i + ": " + Factory.dumpCounters(false));
        Document doc1 = null;
        Document doc2 = null;
        Document doc3 = null;
        for (String id : ids) {
            d = s.getDatabase("", "names.nsf");
            doc1 = d.getDocumentByID(id);
            doc1 = null;
            doc2 = d.getDocumentByID(id);
            doc2 = null;
            doc3 = d.getDocumentByID(id);
            doc3 = null;
            int rndIdx = (int) Math.floor(Math.random() * ids.size());
            // if (i % 20 == 0 && false) {
            // System.gc();
            // try {
            // Thread.sleep(10);
            // } catch (InterruptedException e) {
            // e.printStackTrace();
            // }
            // }
            doc2 = d.getDocumentByID(ids.get(rndIdx));
            doc2 = null;
            d = null;
        }
        if (doc1 == null && doc2 == null && doc3 == null) {
        // NOP - just ensure access to doc1..3
        }
    // System.out.println(doc1 + "" + doc2 + "" + doc3);
    }
}
Also used : Database(org.openntf.domino.Database) ArrayList(java.util.ArrayList) Document(org.openntf.domino.Document) Session(org.openntf.domino.Session)

Example 22 with Session

use of org.openntf.domino.Session in project org.openntf.domino by OpenNTF.

the class TestDatabasePropertyWrapper method getNewSessionDesign.

public DatabaseDesign getNewSessionDesign() {
    try {
        lotus.domino.Session newSess = NotesFactory.createSession();
        Session sess = Factory.getWrapperFactory().fromLotus(AllTests.lotusSession, Session.SCHEMA, null);
        Database db = sess.getDatabase("", AllTests.EMPTY_DB);
        return db.getDesign();
    } catch (Exception e) {
        return null;
    }
}
Also used : Database(org.openntf.domino.Database) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) Session(org.openntf.domino.Session)

Example 23 with Session

use of org.openntf.domino.Session in project org.openntf.domino by OpenNTF.

the class DeferredDocumentTest method testIdentity.

// public static void main(final String[] args) {
// Factory.startup();
// 
// DominoExecutor executor = new DominoExecutor(50);
// XotsDaemon.start(executor);
// 
// for (int i = 0; i < THREAD_COUNT; i++) {
// XotsDaemon.queue(new DeferredDocumentTest());
// }
// 
// Factory.shutdown();
// }
/**
 * Test if deferred will not recycle each other.
 */
@Test
public void testIdentity() throws NotesException {
    Session session = Factory.getSession(SessionType.CURRENT);
    assertNotNull(session);
    Database db = session.getDatabase("", "log.nsf");
    assertNotNull(db);
    NoteCollection nc = db.createNoteCollection(false);
    nc.selectAllDataNotes(true);
    nc.buildCollection();
    int[] nids = nc.getNoteIDs();
    int nid1 = nids[0];
    int nid2 = nids[1];
    Document doc1 = db.getDocumentByID(nid1, true);
    Document doc2 = db.getDocumentByID(nid1, true);
    Document doc3 = db.getDocumentByID(nid2, true);
    Document doc4 = db.getDocumentByID(nid2, true);
    doc2.replaceItemValue("testfield", "testvalue");
    doc4.replaceItemValue("testfield", "testvalue2");
    assertEquals(doc1, doc2);
    assertFalse(doc1 == doc2);
    assertEquals(doc3, doc4);
    assertFalse(doc3 == doc4);
    assertEquals("testvalue", doc1.getItemValueString("testfield"));
    assertEquals("testvalue", doc2.getItemValueString("testfield"));
    assertEquals("testvalue2", doc3.getItemValueString("testfield"));
    assertEquals("testvalue2", doc4.getItemValueString("testfield"));
    // doc2 = null;
    for (int i = 0; i < 1000; i++) {
        doc1 = null;
        doc3 = null;
        System.gc();
        doc1 = db.getDocumentByID(Integer.toHexString(nid1));
        doc3 = db.getDocumentByID(Integer.toHexString(nid2));
        if (i % 100 == 0)
            System.out.println("Test complete: " + i / 10 + "%");
        // doc2.recycle();
        // assertEquals("testvalue", doc2.getItemValueString("testfield"));
        doc4 = db.getDocumentByID(nid2, true);
        assertEquals("testvalue", doc1.getItemValueString("testfield"));
        assertEquals("testvalue", doc2.getItemValueString("testfield"));
        assertEquals("testvalue2", doc3.getItemValueString("testfield"));
        assertEquals("testvalue2", doc4.getItemValueString("testfield"));
    }
}
Also used : NoteCollection(org.openntf.domino.NoteCollection) Database(org.openntf.domino.Database) Document(org.openntf.domino.Document) Session(org.openntf.domino.Session) Test(org.junit.Test)

Example 24 with Session

use of org.openntf.domino.Session in project org.openntf.domino by OpenNTF.

the class DeferredDocumentTest method testDeferredDocuments.

@Test
public void testDeferredDocuments() throws InterruptedException, ExecutionException {
    Session session = Factory.getSession(SessionType.CURRENT);
    assertNotNull(session);
    List<Future<?>> tasks = new ArrayList<Future<?>>();
    for (int i = 0; i < THREAD_COUNT; i++) {
        tasks.add(Xots.submit(new DeferredDocumentTest()));
    }
    for (Future<?> f : tasks) {
        // to catch the exceptions!
        f.get();
    }
    System.out.println("DONE");
}
Also used : ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Session(org.openntf.domino.Session) Test(org.junit.Test)

Example 25 with Session

use of org.openntf.domino.Session in project org.openntf.domino by OpenNTF.

the class DominoIndexDbTest method run.

@Override
public void run() {
    Session session = Factory.getSession(SessionType.CURRENT);
    session.setConvertMIME(false);
    session.setFixEnable(Fixes.APPEND_ITEM_VALUE, true);
    session.setFixEnable(Fixes.FORCE_JAVA_DATES, true);
    session.setFixEnable(Fixes.CREATE_DB, true);
    DbDirectory dir = session.getDbDirectory("");
    Database indexDb = dir.createDatabase("index.nsf", true);
    // Database indexDb = session.getDatabase("", "index.nsf", true);
    // indexDb.open();
    IndexDatabase index = new org.openntf.domino.big.impl.IndexDatabase(indexDb);
    index.setCaseSensitive(true);
    index.scanServer(session, "");
    System.out.println("Complete");
}
Also used : DbDirectory(org.openntf.domino.DbDirectory) IndexDatabase(org.openntf.domino.big.IndexDatabase) Database(org.openntf.domino.Database) IndexDatabase(org.openntf.domino.big.IndexDatabase) Session(org.openntf.domino.Session)

Aggregations

Session (org.openntf.domino.Session)101 Database (org.openntf.domino.Database)73 Document (org.openntf.domino.Document)28 Test (org.junit.Test)25 View (org.openntf.domino.View)20 DbDirectory (org.openntf.domino.DbDirectory)11 ArrayList (java.util.ArrayList)10 DocumentCollection (org.openntf.domino.DocumentCollection)7 Vector (java.util.Vector)5 ViewEntry (org.openntf.domino.ViewEntry)5 IOException (java.io.IOException)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 NotesException (lotus.domino.NotesException)4 Item (org.openntf.domino.Item)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Agent (org.openntf.domino.Agent)3 NoteCollection (org.openntf.domino.NoteCollection)3