Search in sources :

Example 26 with Database

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

the class DesignClassTest method testDesignFactory.

// @Test
public void testDesignFactory() throws IOException {
    Session sess = Factory.getSession(SessionType.CURRENT);
    DbDirectory dir = sess.getDbDirectory("");
    for (Database db : dir) {
        try {
            db.open();
        } catch (OpenNTFNotesException e) {
            e.printStackTrace();
        }
        if (db.isOpen()) {
            System.out.println("DB under test" + db);
            testDb(db);
        }
    }
// Database db = sess.getDatabase("D:/Daten/notesdaten_9/localdb/proglib4work2.nsf");
// Database db = sess.getDatabase("D:/Daten/notesdaten_9/localdb/empty.ns9");
}
Also used : DbDirectory(org.openntf.domino.DbDirectory) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) Database(org.openntf.domino.Database) Session(org.openntf.domino.Session)

Example 27 with Database

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

the class DesignClassTest method testDesignClass.

// @Test
public void testDesignClass() throws IOException {
    Session sess = Factory.getSession(SessionType.CURRENT);
    // Database db = sess.getDatabase("D:/Daten/notesdaten_9/localdb/empty.ns9");
    // Database db = sess.getDatabase("D:/Daten/notesdaten_9/empty2.nsf");
    // Database db = sess.getDatabase("D:/Daten/notesdaten_9/localdb/proglib4work2.nsf");
    Database db = sess.getDatabase("srv-01-ndev2!!entwicklung/alex/proglib4work22.nsf");
    testDb(db);
    DatabaseDesign design = db.getDesign();
    // -X = no AgentData
    DesignCollection<DesignBase> elems = design.getDesignElements(// 
    "!@Contains($Flags;{X}) & !($TITLE={WEB-INF/classes/plugin/Activator.class}:{$BEProfileR7}) " + "");
    // + "& @IsAvailable($ACLDigest) ");
    // + "& @contains($TITLE;{gadproxy}) ");
    System.out.println("Count: " + elems.getCount());
    Path root = Paths.get("D:/daten/temp/ods3");
    OnDiskProject odp = new OnDiskProject(root);
    // PrintWriter pw = new PrintWriter(oFile);
    for (DesignBase elem : elems) {
        // + elem.getDocument().getItemValueString("$FLAGS"));
        try {
            odp.export(elem);
        // //elem.getDxlString(null)
        // String odp = elem.getOnDiskPath();
        // if (StringUtil.isEmpty(odp)) {
        // odp = elem.getNoteID() + ".note";
        // }
        // File odsFile = new File(root, odp);
        // System.out.println(elem.getClass().getName() + "\t\t\t" + odsFile);
        // odsFile.getParentFile().mkdirs(); // ensure the path exists
        // elem.writeOnDiskFile(odsFile);
        // if (elem instanceof HasMetadata) {
        // File meta = new File(odsFile.getAbsolutePath() + ".metadata");
        // ((HasMetadata) elem).writeOnDiskMeta(meta);
        // }
        } catch (Exception ne) {
            ne.printStackTrace();
        }
    // String path = "./" + elem.getOnDiskPath();
    // String ext = elem.getOnDiskExtension();
    // if (path != null && ext != null && !path.endsWith(ext))
    // path = path + ext;
    // pw.println(path + "\t'" + elem.getClass().getSimpleName() + "\t" + elem.getNoteID() + "\t" + elem.getName() + "\t"
    // + elem.getDocument().getItemValueString("$FLAGS"));
    // if (elem instanceof HasMetadata) {
    // pw.println(path + ".metadata");
    // }
    // if (elem instanceof CustomControl) {
    // pw.println(path + "-config");
    // }
    }
}
Also used : Path(java.nio.file.Path) DatabaseDesign(org.openntf.domino.design.DatabaseDesign) DesignBase(org.openntf.domino.design.DesignBase) Database(org.openntf.domino.Database) OnDiskProject(org.openntf.domino.design.impl.OnDiskProject) IOException(java.io.IOException) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) Session(org.openntf.domino.Session)

Example 28 with Database

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

the class NoteListTest method run1.

public void run1() {
    long testStartTime = System.nanoTime();
    Session session = this.getSession();
    Database log = session.getDatabase("", "log.nsf");
    Document storeTest = log.createDocument();
    storeTest.replaceItemValue("form", "BinaryTest");
    Database db = session.getDatabase("", "imdb/movies.nsf");
    try {
        marktime = System.nanoTime();
        NoteSet noteset = new NoteSet();
        timelog("Beginning first noteset...");
        NoteCollection notecoll2 = db.createNoteCollection(false);
        notecoll2.setSelectDocuments(true);
        notecoll2.setSelectionFormula("@Begins(Title; \"B\")");
        notecoll2.buildCollection();
        // DocumentCollection coll = db.search("@Begins(Title; \"B\")");
        timelog("Starting note coordinates of " + notecoll2.getCount() + " documents");
        // for (Document doc : notecoll) {
        for (String nid : notecoll2) {
            NoteCoordinate nc = new NoteCoordinate(notecoll2, nid);
            noteset.add(nc);
        }
        timelog("Done note coordinates of " + noteset.size() + " documents. Doing again...");
        int i = 0;
        for (String nid : notecoll2) {
            if (i++ < 10000) {
                NoteCoordinate nc = new NoteCoordinate(notecoll2, nid);
                noteset.add(nc);
            } else {
                break;
            }
        }
        timelog("Complete note coordinates of " + noteset.size() + " documents.");
        NoteList notelist = new NoteList();
        timelog("Beginning first notelist...");
        NoteCollection notecoll = db.createNoteCollection(false);
        notecoll.setSelectDocuments(true);
        notecoll.setSelectionFormula("@Begins(Title; \"B\")");
        notecoll.buildCollection();
        // DocumentCollection coll = db.search("@Begins(Title; \"B\")");
        timelog("Starting note coordinates of " + notecoll.getCount() + " documents");
        // for (Document doc : notecoll) {
        for (String nid : notecoll) {
            NoteCoordinate nc = new NoteCoordinate(notecoll, nid);
            notelist.add(nc);
        }
        timelog("Done note coordinates of " + notelist.size() + " documents. Doing again...");
        i = 0;
        for (String nid : notecoll) {
            if (i++ < 10000) {
                NoteCoordinate nc = new NoteCoordinate(notecoll, nid);
                notelist.add(nc);
            } else {
                break;
            }
        }
        timelog("Complete note coordinates of " + notelist.size() + " documents.");
        // Database eventDb = session.getDatabase("", "events4.nsf");
        // NoteCollection eventNotecoll = eventDb.createNoteCollection(false);
        // eventNotecoll.setSelectDocuments(true);
        // eventNotecoll.buildCollection();
        // timelog("Continuing note coordinates of " + eventNotecoll.getCount() + " documents");
        // for (String nid : eventNotecoll) {
        // NoteCoordinate nc = new NoteCoordinate(eventNotecoll, nid);
        // notelist.add(nc);
        // }
        // Database xspextDb = session.getDatabase("", "openntf/xpagesext.nsf");
        // NoteCollection xspextNotecoll = xspextDb.createNoteCollection(false);
        // xspextNotecoll.setSelectDocuments(true);
        // xspextNotecoll.buildCollection();
        // timelog("Continuing note coordinates of " + xspextNotecoll.getCount() + " documents");
        // for (String nid : xspextNotecoll) {
        // NoteCoordinate nc = new NoteCoordinate(xspextNotecoll, nid);
        // notelist.add(nc);
        // }
        byte[] bytes = notelist.toByteArray();
        int byteSize = bytes.length;
        timelog("Resulting bytearray is " + bytes.length + " so we expect " + (bytes.length / (2500 * 24)) + " items");
        // File file = File.createTempFile("foo", "bar");
        // FileOutputStream fos = new FileOutputStream(file);
        // fos.write(bytes);
        // fos.close();
        storeTest.writeBinary("imdbNoteList", bytes, 2500 * 24);
        storeTest.save();
        String storeId = storeTest.getUniversalID();
        storeTest.recycle();
        storeTest = null;
        // coll.recycle();
        // coll = null;
        notecoll.recycle();
        notecoll = null;
        // eventNotecoll.recycle();
        // eventNotecoll = null;
        // eventDb.recycle();
        // eventDb = null;
        // xspextNotecoll.recycle();
        // xspextNotecoll = null;
        // xspextDb.recycle();
        // xspextDb = null;
        notelist = null;
        // timelog("Binary data serialized out. Reloading...");
        db.recycle();
        db = null;
        System.gc();
        storeTest = log.getDocumentByUNID(storeId);
        // FileInputStream fis = new FileInputStream(file);
        // DbCache cache = new DbCache();
        // NoteCoordinate.setDbCache(cache);
        // NoteList notelist2 = new NoteList(cache, NoteList.getComparator("Title"));
        // byte[] loaded = storeTest.readBinary("imdbNoteList");
        // byte[] loaded = new byte[byteSize];
        // fis.read(loaded);
        // notelist2.loadByteArray(loaded);
        // timelog("Done reloading " + notelist2.size() + " sorted notes. Iterating...");
        // int notecount = 0;
        // try {
        // for (NoteCoordinate nc : notelist2) {
        // Document doc = nc.getDocument();
        // notecount++;
        // //					System.out.println("doc " + doc.getNoteID() + " " + doc.getItemValue("$UpdatedBy", String.class));
        // }
        // } catch (Exception e) {
        // e.printStackTrace();
        // }
        // timelog("iterated over " + notecount + " notes out of " + notelist2.size());
        long endTime = System.nanoTime();
    } catch (Throwable t) {
        t.printStackTrace();
    }
    long testEndTime = System.nanoTime();
    System.out.println("Completed " + getClass().getSimpleName() + " run in " + ((testEndTime - testStartTime) / 1000000) + " ms");
}
Also used : NoteCoordinate(org.openntf.domino.big.impl.NoteCoordinate) NoteSet(org.openntf.domino.big.impl.NoteSet) NoteCollection(org.openntf.domino.NoteCollection) NoteList(org.openntf.domino.big.impl.NoteList) Database(org.openntf.domino.Database) Document(org.openntf.domino.Document) Session(org.openntf.domino.Session)

Example 29 with Database

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

the class NoteListTest method run2.

public void run2() {
    long testStartTime = System.nanoTime();
    Session session = this.getSession();
    try {
        Database db = session.getDatabase("", "imdb/movies.nsf");
        // db.setDelayUpdates(true);
        marktime = System.nanoTime();
        timelog("Beginning view build...");
        View byLength = db.getView("byLength");
        View btitles = db.createView("BTitles", "@Begins(Title; \"B\")", byLength);
        // View btitles = db.createView("BTitles", "@Begins(Title; \"B\")");
        ViewColumn length = btitles.createColumn(1, "Title", "Title");
        length.setSorted(true);
        timelog("View defined.");
        btitles.refresh();
        timelog("Completed view build.");
        ViewEntryCollection vec = btitles.getAllEntries();
        int count = vec.getCount();
        timelog("Found " + count + " documents in the view");
        btitles.remove();
        timelog("Removed view.");
        btitles.recycle();
        db.recycle();
    } catch (Throwable t) {
        t.printStackTrace();
    } finally {
        long testEndTime = System.nanoTime();
        System.out.println("Completed " + getClass().getSimpleName() + " run in " + ((testEndTime - testStartTime) / 1000000) + " ms");
    }
}
Also used : ViewColumn(org.openntf.domino.ViewColumn) Database(org.openntf.domino.Database) ViewEntryCollection(org.openntf.domino.ViewEntryCollection) View(org.openntf.domino.View) Session(org.openntf.domino.Session)

Example 30 with Database

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

the class RichTextItemReplaceAttachmentText method run.

@Override
public void run() {
    Session session = Factory.getSession(SessionType.NATIVE);
    Database db = session.getDatabase("", "sarmy/USSBulletins.nsf");
    Document doc = db.getDocumentByUNID("5F96214CFE92013D86258027007687FA");
    RichTextItem rtItem = (RichTextItem) doc.getFirstItem("BulletinText");
    rtItem.replaceAttachment("Feature Requests 2008.ods", "c:/data/Feature Requests 2008.ods");
    rtItem.compact();
    doc.save(true, true);
}
Also used : RichTextItem(org.openntf.domino.RichTextItem) Database(org.openntf.domino.Database) Document(org.openntf.domino.Document) Session(org.openntf.domino.Session)

Aggregations

Database (org.openntf.domino.Database)131 Session (org.openntf.domino.Session)73 Document (org.openntf.domino.Document)49 Test (org.junit.Test)19 View (org.openntf.domino.View)19 DbDirectory (org.openntf.domino.DbDirectory)17 NotesException (lotus.domino.NotesException)12 ArrayList (java.util.ArrayList)11 NoteCollection (org.openntf.domino.NoteCollection)11 OpenNTFNotesException (org.openntf.domino.exceptions.OpenNTFNotesException)10 DocumentCollection (org.openntf.domino.DocumentCollection)8 NoteCoordinate (org.openntf.domino.big.NoteCoordinate)8 Date (java.util.Date)6 UserAccessException (org.openntf.domino.exceptions.UserAccessException)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 ViewEntry (org.openntf.domino.ViewEntry)5 FastTable (javolution.util.FastTable)4 Item (org.openntf.domino.Item)4 RichTextItem (org.openntf.domino.RichTextItem)4