Java Code Examples for lotus.domino.Document#recycle()

The following examples show how to use lotus.domino.Document#recycle() . 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: RestDocumentNavigatorFactory.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteDocument(String id) throws ServiceException {
    checkNoDocument();
    try {
        // Should use both UNID and ID....
        Document ddoc = database.getDocumentByUNID(id);
        if(ddoc!=null) {
            try { 
                ddoc.remove(true);
                
                if( Loggers.SERVICES_LOGGER.isTraceDebugEnabled() ){
                    Loggers.SERVICES_LOGGER.traceDebugp(this, "deleteDocument", // $NON-NLS-1$
                            "Document #{0} deleted",id); // $NON-NLS-1$
                }
            } finally {
                ddoc.recycle();
            }
        } else {
            throw new ServiceException(null,"The document with id {0} cannot be found",id);  // $NLX-RestDocumentNavigatorFactory.Errorwhilecreatingaloadingdocumen.1-1$
        }
    } catch(NotesException ex) {
        throw new ServiceException(ex,"An error occurred while deleting document with id {0}",id);  // $NLX-RestDocumentNavigatorFactory.Errorwhilecreatingadeletingdocume-1$
    }
}
 
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: BaseJNATestClass.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
private void createSampleDbDirProfile(Database db) throws NotesException {
	Document docProfile = db.getProfileDocument("DirectoryProfile", null);
	docProfile.replaceItemValue("Form", "DirectoryProfile");
	docProfile.replaceItemValue("Domain", db.getParent().evaluate("@Domain", docProfile));
	docProfile.replaceItemValue("GroupSortDefault", "1");
	docProfile.replaceItemValue("AutoPopulateMembersInterval", "30");
	docProfile.replaceItemValue("SecureInetPasswords", "1");
	docProfile.replaceItemValue("AltLanguageInfoAllowed", "1");
	docProfile.computeWithForm(false, false);
	docProfile.save(true, false);
	docProfile.recycle();
}
 
Example 4
Source File: DataInitializer.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
void createUser(Database db, String id, String firstName, String lastName, String city, String state, String email) throws NotesException {
	Document doc = db.createDocument();
	try {
		doc.replaceItemValue("Form","Contact");		
		doc.replaceItemValue("Id",id);		
		doc.replaceItemValue("FirstName",firstName);		
		doc.replaceItemValue("LastName",lastName);		
		doc.replaceItemValue("City",city);		
		doc.replaceItemValue("State",state);		
		doc.replaceItemValue("email",email);		
		doc.save();
	} finally {
		doc.recycle();
	}
}
 
Example 5
Source File: DataInitializer.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
void createState(Database db, String key, String name) throws NotesException {
	Document doc = db.createDocument();
	try {
		doc.replaceItemValue("Form","State");		
		doc.replaceItemValue("Key",key);		
		doc.replaceItemValue("Name",name);		
		doc.save();
	} finally {
		doc.recycle();
	}
}
 
Example 6
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 7
Source File: DataInitializer.java    From XPagesExtensionLibrary with Apache License 2.0 4 votes vote down vote up
void createDiscussionDocument(Database db, Document parent, ArrayList<String> users, int[] pos, int nDoc) throws NotesException, IOException {
	DateTime date = db.getParent().createDateTime(new Date());
	String[] loremIpsum = SampleDataUtil.readLoremIpsum(); 
	for(int j=0; j<nDoc; j++) {
		pos[pos.length-1] = j+1; 
			
		Document doc = db.createDocument();
		try {
			doc.replaceItemValue("Form","Discussion");		
			StringBuilder b = new StringBuilder();
			for(int i=0; i<pos.length; i++) {
				if(i>0) {
					b.append("/");
				}
				b.append(pos[i]);
			}
			int idx = (int)(Math.random()*(loremIpsum.length-1));
			String body = loremIpsum[idx];
			int dot = body.indexOf('.');
			if(dot<0) {dot=body.length()-1;}
			int coma = body.indexOf(',');
			if(coma<0) {coma=body.length()-1;}
			String title = body.substring(0,Math.min(dot,coma));

			// Get a random author
			int x = Math.min((int)(Math.random()*((double)users.size())),users.size());
			String author = users.get(x);
			
			doc.replaceItemValue("Title",title);
			doc.replaceItemValue("Body",body);
			doc.replaceItemValue("Author",author);
			doc.replaceItemValue("Date",date);
			if(parent!=null) {
				doc.makeResponse(parent);
			}
			doc.computeWithForm(false, false);
			doc.save();
	
			if(pos.length<disc_maxDepth) {
				double r = Math.random();
				if(r<=(1.0/(double)pos.length)) {
					int[] newPos = new int[pos.length+1];
					System.arraycopy(pos, 0, newPos, 0, pos.length);
					int n = (int)(Math.random()*5);
					createDiscussionDocument(db, doc, users, newPos, n);
				}
			}
			// Move the date to the day before if requested
			boolean mvd = Math.random()<=0.40;
			if(mvd) {
				// Previous day...
				date.adjustDay(-1);
			}
		} finally {
			doc.recycle();
		}
	}
}
 
Example 8
Source File: DataInitializer.java    From XPagesExtensionLibrary with Apache License 2.0 4 votes vote down vote up
void createAllType(Database db, int index) throws NotesException {
	Session session = db.getParent();
	String sIndex = Integer.toString(index);
	Document doc = db.createDocument();
	try {
		doc.replaceItemValue("Form","AllTypes");	
		
		doc.replaceItemValue("fldIcon",index);		
		doc.replaceItemValue("fldText","text_"+sIndex);		
		doc.replaceItemValue("fldNumber",index*100);
		doc.replaceItemValue("fldDate",createDate(session, 2010, 1, index));
		doc.replaceItemValue("fldTime",createTime(session, 5, 1, index));
		doc.replaceItemValue("fldDateTime",createDateTime(session, 2011, 2, index, 8, 9, index));
		doc.replaceItemValue("fldDateTimeRange",createDateTimeRange(session, 2012, 3, index, 8, 9, index));
		doc.replaceItemValue("fldDialogList","dlg_"+sIndex);	
		
		Vector<Object> mx = new Vector<Object>();
		mx.add("text_"+sIndex+"_1");
		mx.add("text_"+sIndex+"_2");
		mx.add("text_"+sIndex+"_3");
		doc.replaceItemValue("fldText2",mx);		
		
		Vector<Object> mn = new Vector<Object>();
		mn.add(index*100+1);
		mn.add(index*100+2);
		mn.add(index*100+3);
		doc.replaceItemValue("fldNumber2",mn);		

		Vector<Object> md = new Vector<Object>();
		md.add(createDate(session, 2010, 1, index));
		md.add(createDate(session, 2010, 2, index));
		md.add(createDate(session, 2010, 3, index));
		doc.replaceItemValue("fldDate2",md);		

		Vector<Object> mt = new Vector<Object>();
		mt.add(createTime(session, 6, 1, index));
		mt.add(createTime(session, 6, 2, index));
		mt.add(createTime(session, 6, 3, index));
		doc.replaceItemValue("fldTime2",mt);		

		Vector<Object> mdt = new Vector<Object>();
		mdt.add(createDateTime(session, 2011, 1, index, 6, 1, index));
		mdt.add(createDateTime(session, 2011, 2, index, 6, 2, index));
		mdt.add(createDateTime(session, 2011, 3, index, 6, 3, index));
		doc.replaceItemValue("fldDateTime2",mdt);		

		if(false) { // DateTime range do not work with multiple values?
			Vector<Object> mrg = new Vector<Object>();
			mrg.add(createDateTimeRange(session, 2012, 2, index, 4, 1, index));
			mrg.add(createDateTimeRange(session, 2012, 3, index, 5, 1, index));
			mrg.add(createDateTimeRange(session, 2012, 4, index, 6, 1, index));
			doc.replaceItemValue("fldDateTimeRange2",mrg);
		}
		
		Vector<Object> mdg = new Vector<Object>();
		mdg.add("dlgx_"+sIndex+"_1");
		mdg.add("dlgx_"+sIndex+"_1");
		mdg.add("dlgx_"+sIndex+"_1");
		doc.replaceItemValue("fldDialogList2",mdg);		

		doc.save();
	} finally {
		doc.recycle();
	}
}
 
Example 9
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 10
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();

}
 
Example 11
Source File: DelegateProvider.java    From XPagesExtensionLibrary with Apache License 2.0 3 votes vote down vote up
/**
 * Gets an up-to-date copy of the profile document.
 * 
 * @param database
 * @return
 * @throws NotesException
 */
private Document profileGet(Database database) throws NotesException {
    
    // Open the calendar profile.  This returns a cached copy (may not be up to date).
    
    Document profile = database.getProfileDocument("CalendarProfile", null); // $NON-NLS-1$
    String unid = profile.getUniversalID();
    profile.recycle();
    
    // Open the same document by UNID.  This ensures we get the latest copy.
    
    profile = database.getDocumentByUNID(unid);
    
    return profile;
}