Reputation: 1413
I am programming a Server Task Add-In and am trying to make a clean, recyclable code. I am looping through a set of databases, then through some documents within the database.
for (String serverAndFilename : listofServerFilenames) {
String[] parts = serverAndFilename.split("!!");
currentGECDB = session.getDatabase(parts[0], parts[1]);
if (currentGECDB.isOpen()) {
collSourceDocuments = currentGECDB.search(this
.getSearchFormula(this
.getvariablePartOfSearchFormula()));
countOfSearchDocuments = collSourceDocuments.getCount();
docToChange = collSourceDocuments
.getFirstDocument();
while (docToChange != null) {
if (changeNamesFieldsOnThisDocument(docToChange)) {
// .... other code here
}
tmpdoc = collSourceDocuments.getNextDocument();
docToChange.recycle();
docToChange = tmpdoc;
}
}
}
}
I am concerned about the memory management issues with using a heavy Notes oject as a parameter to a Java function. Whilst checking the changes my function does, I am getting the 'old' values and need to make a recycle() on my document before re-retrieving the document.
It seems to me that I am forced to only pass primitives as arguments to an external function i.e.
public booleanfunction (String ServerName, String ReplicaIDOfDatabase, String UNIDofDocument)
but that would imply many subsequent OpenDatabase calls, which are expensive.
Is there a best way to do this?
As an example, this is part of a JUnit Test I am making on the result:
public void testNewArrivalTaskExample() {
try {
testNewArrivalTask = GECTaskNewArrival.getTestTask(db, oli);
testNewArrivalTask.save();
Document testdocNewArrival_1 = getNewTestSourceCourrierDocument();
for (NamesItemsInProcedure n : NamesItemsInProcedure.values()) {
setNamesField(testdocNewArrival_1, n,
GECTaskNewArrival.NEW_ARRIVAL_ROLE_MODEL,
NamesItemsInProcedure.NOUVELLE_ARRIVEE);
}
testdocNewArrival_1.replaceItemValue("TestDocumentDescription",
"NewArrival_AllFields");
testdocNewArrival_1.save();
GECTaskNewArrival gna = new GECTaskNewArrival(testNewArrivalTask,
db, oli);
gna.process();
Item itemsuivi = testdocNewArrival_1
.getFirstItem(NamesItemsInProcedure.SUIVI_COURRIER
.getItemName());
System.out.println("Content of document without recycle + rebirth:");
printItemValuesToSysout(itemsuivi);
System.out.println(NamesItemsInProcedure.SUIVI_COURRIER
.getItemName()
+ " Should contain "
+ GECTaskNewArrival.NEW_ARRIVAL_NEWPERSON);
String noteID = testdocNewArrival_1.getNoteID();
testdocNewArrival_1.recycle();
for (NamesItemsInProcedure n : NamesItemsInProcedure.values()) {
boolean result = itemContainsThisForTestDoc(GECAlladin, noteID,
n.getItemName(),
GECTaskNewArrival.NEW_ARRIVAL_NEWPERSON);
switch (n) {
case ENCOURS_COURRIER:
assertTrue(result);
break;
case AUTEURS_COURRIER:
assertTrue(result);
break;
case SUIVI_COURRIER:
assertTrue(result);
break;
case ECHEANCEMESSAGENOM_COURRIER:
assertTrue(result);
break;
default:
// assertFalse(result);
break;
}
}
} catch (NotesException e) {
e.printStackTrace();
}
}
and this is the console result:
Content of document without recycle + rebirth:
Suivi has these values:
Donald VieuxDeLaVieille/dsic/ville-ge`
the item belongs to this document 929E`
Suivi Should contain CN=Micky NouvelleArrivee/OU=salut/OU=Truc/O=Muche`
Suivi has these values:`
Donald VieuxDeLaVieille/dsic/ville-ge`
CN=Micky NouvelleArrivee/OU=salut/OU=Truc/O=Muche`
the item belongs to this document 929E`
Suivi contains CN=Micky NouvelleArrivee/OU=salut/OU=Truc/O=Muche`
I am still stumped.
Upvotes: 0
Views: 209
Reputation: 14628
You might try changing your code from this:
tmpdoc = collSourceDocuments.getNextDocument();
to this:
tmpdoc = collSourceDocuments.getNextDocument(docToChange);
According to the doc, omitting the Document argument from the getNextDocument call should work, but my understanding is that there are different implementations internally for the DocumentCollection depending on how the collection was built, and I'm thinking that omitting the Document argument might be giving you some strange results (i.e., explaining the 'old' values you are seeing) in the case of a DocumentCollection created by Database.search().
Upvotes: 1