Java Code Examples for lotus.domino.Session#getDatabase()

The following examples show how to use lotus.domino.Session#getDatabase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseJNATestClass.java    From domino-jna with Apache License 2.0 6 votes vote down vote up
public synchronized NotesDatabase getSampleDataViewsDb() throws NotesException {
	Session session = getSession();
	NotesDatabase db;
	try {
		db = new NotesDatabase(session, "", DBPATH_SAMPLEDATA_VIEWS_NSF);
		return db;
	}
	catch (NotesError e) {
		if (e.getId() != 259) { // file does not exist
			throw e;
		}
	}
	System.out.println("Looks like our sample database "+DBPATH_SAMPLEDATA_VIEWS_NSF+" to test private views does not exist. We will now (re)create it.");

	Database dbSampleDataLegacy = session.getDatabase("", DBPATH_SAMPLEDATA_NSF, true);
	Database dbSampleDataViewsLegacy = dbSampleDataLegacy.createFromTemplate("", DBPATH_SAMPLEDATA_VIEWS_NSF, true);
	
	createSampleDbDirProfile(dbSampleDataViewsLegacy);

	dbSampleDataLegacy.recycle();
	dbSampleDataViewsLegacy.recycle();
	
	db = new NotesDatabase(session, "", DBPATH_SAMPLEDATA_VIEWS_NSF);
	db.setTitle("Domino JNA testcase views");
	return db;
}
 
Example 2
Source File: NotesRunner.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
public void run2(final Session session) throws NotesException {
	Database db = session.getDatabase("", "log.nsf");
	Document doc = db.createDocument();
	Item names = doc.replaceItemValue("Names", "CN=Nathan T Freeman/O=REDPILL");
	names.setAuthors(true);
	doc.replaceItemValue("form", "test");
	doc.save(true);
	String nid = doc.getNoteID();
	doc.recycle();
	doc = db.getDocumentByID(nid);
	Vector<Double> numbers = new Vector<Double>();
	numbers.add(new Double(1));
	numbers.add(new Double(2));

	doc.replaceItemValue("Names", numbers);
	doc.save(true);
	doc.recycle();
	doc = db.getDocumentByID(nid);
	names = doc.getFirstItem("Names");
	System.out.println("Names is " + names.getType() + " with " + names.isNames() + " and " + names.isAuthors() + " and value "
			+ names.getText());
	doc.recycle();
	db.recycle();
}
 
Example 3
Source File: NotesRunner.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
public void run3(final Session session) throws NotesException {
	Database db = session.getDatabase("", "index.ntf");
	NoteCollection nc = db.createNoteCollection(false);
	nc.setSelectIcon(true);
	nc.setSelectAcl(true);
	nc.selectAllDesignElements(true);
	nc.buildCollection();
	DxlExporter export = session.createDxlExporter();
	export.setForceNoteFormat(true);
	export.setRichTextOption(DxlExporter.DXLRICHTEXTOPTION_RAW);
	String dxl = export.exportDxl(nc);
	nc.recycle();
	export.recycle();
	db.recycle();
	try {
		PrintWriter out = new PrintWriter("c:\\data\\index.dxl");
		out.println(dxl);
		out.close();
	} catch (Throwable t) {
		t.printStackTrace();
	}
}
 
Example 4
Source File: Connect17Standard.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void run() {
	org.openntf.domino.Session sess = Factory.getSession(SessionType.NATIVE);
	try {
		TreeSet<String> names = new TreeSet<String>();
		Session session = TypeUtils.toLotus(sess);
		// Point to ExtLib demo, create a view called AllContactsByState
		// Copy AllContacts but adding a categorised column for State
		Database extLib = session.getDatabase(session.getServerName(), "odademo/oda_1.nsf");
		View states = extLib.getView("AllStates");
		states.setAutoUpdate(false);
		ViewEntry entState = states.getAllEntries().getFirstEntry();
		View byState = extLib.getView("AllContactsByState");
		byState.setAutoUpdate(false);
		Vector<String> key = new Vector<String>();
		Vector<String> stateVals = entState.getColumnValues();
		key.add(stateVals.get(0));
		ViewEntryCollection ec = byState.getAllEntriesByKey(key, true);
		ViewEntry ent = ec.getFirstEntry();
		while (null != ent) {
			Vector<Object> vals = ent.getColumnValues();
			names.add((String) vals.get(7));

			ViewEntry tmpEnt = ec.getNextEntry();
			ent.recycle(vals);
			ent.recycle();
			ent = tmpEnt;
		}
		System.out.println(names.toString());
	} catch (NotesException e) {
		e.printStackTrace();
	}
}
 
Example 5
Source File: Create200KLotus.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
	try {
		Document doc = null;
		System.out.println("START Creation of Documents:" + new Date().toString());
		Session s = Factory.getSession(SessionType.CURRENT);
		Set<Document> docset = new HashSet<Document>();
		Database db = s.getDatabase("", "OneMillionLotus.nsf", true);
		if (!db.isOpen()) {
			Database db2 = s.getDatabase("", "billing.ntf", true);
			db = db2.createCopy("", "OneMillionLotus.nsf");
			if (!db.isOpen())
				db.open();
		}

		for (int i = 1; i < 200000; i++) {
			doc = db.createDocument();
			doc.replaceItemValue("form", "doc");
			doc.replaceItemValue("Subject", String.valueOf(System.nanoTime()));
			doc.save();
			doc.recycle();
			if (i % 5000 == 0) {
				System.out.println("Created " + i + " documents so far. Still going...");
			}
		}
		System.out.println("ENDING Creation of Documents: " + new Date().toString());
	} catch (lotus.domino.NotesException e) {
		System.out.println(e.toString());
	}
}
 
Example 6
Source File: UserHelper.java    From XPagesExtensionLibrary with Apache License 2.0 4 votes vote down vote up
private boolean localFileExists(Session session, String filepath) throws NotesException {
    boolean exists = false;
    DbDirectory dbdir = null;
    Database localDb = null;
    
    try {
        try {
            // Optimistically attempt to open the database
            localDb = session.getDatabase(null, filepath, false);
            if ( localDb != null ) {
                exists = true;
            }
        }
        catch (NotesException e) {
            if ( e.id == NotesError.NOTES_ERR_DBNOACCESS ) {
                // An access error proves the database exists
                exists = true;
            }
            else {
                // Ignore other errors and fall into the exhaustive search below.
            }
        }
        
        if ( !exists) {
            
            // Exhaustive search of database directory
            
            dbdir = session.getDbDirectory(null);
            Database database = dbdir.getFirstDatabase(DbDirectory.DATABASE);
            while ( database != null ) {
                
                String path = database.getFilePath();
                if ( filepath.equals(path) ) {
                    // TODO: Make sure this is database is really a replica of the user's mail file.
                    // Usually replicas have the same name, but it's not guaranteed.
        
                    exists = true;
                    break;
                }
                
                Database next = dbdir.getNextDatabase();
                BackendUtil.safeRecycle(database);
                database = next;
            }
        }
    }
    finally {
        BackendUtil.safeRecycle(localDb);
        BackendUtil.safeRecycle(dbdir);
    }
    
    return exists;
}
 
Example 7
Source File: SiteProvider.java    From XPagesExtensionLibrary with Apache License 2.0 4 votes vote down vote up
public List<String> getSites(Session session, String directory) throws ModelException {
    List<String> sites = new ArrayList<String>();
    Database database = null;
    
    try {
        if ( directory == null ) {
            throw new ModelException("Directory name not specified.", ModelException.ERR_INVALID_INPUT); // $NLX-SiteProvider.Directorynamenotspecified-1$
        }
        
        // Parse the server and file name
        
        String server = null;
        String filename = null;
        String tokens[] = directory.split("!!");
        if ( tokens == null || tokens.length < 1 ) {
            throw new ModelException("Unexpected format for directory identifier.", ModelException.ERR_NOT_FOUND); // $NLX-SiteProvider.Unexpectedformatfordirectoryident-1$
        }
        else if ( tokens.length > 1 ) {
            server = tokens[0];
            filename = tokens[1];
        }
        else {
            filename = tokens[0];
        }
        
        // Open the directory database
        
        database = session.getDatabase(server, filename, false);
        if ( database == null ) {
            throw new ModelException(MessageFormat.format("Cannot open database {0} on {1}.", filename, server), ModelException.ERR_NOT_FOUND); // $NLX-SiteProvider.Cannotopendatabase0on1-1$
        }
        
        // Open the rooms view
        
        View view = database.getView("($Rooms)"); // $NON-NLS-1$
        if ( view == null ) {
            throw new ModelException(MessageFormat.format("Cannot open ($Rooms) view in {0} on {1}.", filename, server)); // $NLX-SiteProvider.CannotopenRoomsviewin0on1-1$
        }
        
        view.setAutoUpdate(false);
        if ( !view.isCategorized() ) {
            throw new ModelException("Unexpected view format. Rooms view is not categorized."); // $NLX-SiteProvider.UnexpectedviewformatRoomsviewisno-1$
        }
        
        // Find all the sites in the ($Rooms) view
        // TODO: Investigate whether this can be optimized (perhaps with 
        // cache controls).
        
        ViewNavigator nav = view.createViewNav();
        nav.setMaxLevel(0);
        ViewEntry next = null;
        ViewEntry entry = nav.getFirst();
        while ( entry != null ) {

            // Extract the site from the first column
            
            Vector values = entry.getColumnValues();
            if ( values != null && values.size() > 0 ) {
                if ( values.get(0) instanceof String ) {
                    sites.add((String)values.get(0));
                }
            }
            
            // Get the next entry
            
            next = nav.getNextCategory();
            entry.recycle();
            entry = next;
        }

    } 
    catch (NotesException e) {
        throw new ModelException("An error occurred opening the directory database.", e); // $NLX-SiteProvider.Erroropeningdirectorydatabase-1$
    }
    finally {
        BackendUtil.safeRecycle(database);
    }

    return sites;
}
 
Example 8
Source File: NotesRunner.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public void run1(final Session session) throws NotesException {
	Long sessId = getLotusId(session);
	sessionid.set(sessId);
	Database db = session.getDatabase("", "names.nsf");
	System.out.println("Db id:" + getLotusId(db));
	Name name = null;
	int i = 0;
	try {
		for (i = 0; i <= 100000; i++) {
			name = session.createName(UUID.randomUUID().toString());
			getLotusId(name);
			DateTime dt = session.createDateTime(new Date());
			getLotusId(dt);
			DateTime end = session.createDateTime(new Date());
			getLotusId(end);
			DateRange dr = session.createDateRange(dt, end);
			getLotusId(dr);
			Document doc = db.createDocument();
			getLotusId(doc);
			Item i1 = doc.replaceItemValue("Foo", dr);
			getLotusId(i1);
			Item i2 = doc.replaceItemValue("Bar", dr.getText());
			getLotusId(i2);
			Item i3 = doc.replaceItemValue("Blah", dr.getStartDateTime().getLocalTime());
			getLotusId(i3);
			lotus.domino.ColorObject color = session.createColorObject();
			getLotusId(color);
			color.setRGB(128, 128, 128);
			Item i4 = doc.replaceItemValue("color", color.getNotesColor());
			getLotusId(i4);
			i1.recycle();
			i2.recycle();
			i3.recycle();
			i4.recycle();
			DateTime create = doc.getCreated();
			getLotusId(create);
			@SuppressWarnings("unused")
			String lc = create.getLocalTime();
			//					if (i % 10000 == 0) {
			//						System.out.println(Thread.currentThread().getName() + " Name " + i + " is " + name.getCommon() + " "
			//								+ "Local time is " + lc + "  " + dr.getText());
			//					}
			dr.recycle();
			doc.recycle();
			dt.recycle();
			end.recycle();
			create.recycle();
			color.recycle();
			name.recycle();
		}
	} catch (Throwable t) {
		t.printStackTrace();
		System.out.println("Exception at loop point " + i);
	}
}
 
Example 9
Source File: NotesRunner.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
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();

}