use of org.openntf.domino.DocumentCollection in project org.openntf.domino by OpenNTF.
the class Connect17Documents method run.
@Override
public void run() {
Session sess = Factory.getSession(SessionType.NATIVE);
Database extLib = sess.getDatabase("odademo/oda_1.nsf");
View contacts = extLib.getView("AllContacts");
View threads = extLib.getView("AllThreadsByAuthor");
Document doc = contacts.getFirstDocument();
// Clears changes this function already made
resetDoc(doc);
Document newDoc = extLib.createDocument();
doc.copyAllItems(newDoc, true);
String prevDocAsJson = doc.toJson(true);
doc.appendItemValue("State", "AZ");
doc.replaceItemValue("DateTimeField", new Date());
doc.replaceItemValue("DateOnlyField", new java.sql.Date(System.currentTimeMillis()));
System.out.println(doc.getFirstItem("DateOnlyField").getValues());
doc.replaceItemValue("TimeOnlyField", new java.sql.Time(System.currentTimeMillis()));
System.out.println(doc.getFirstItem("TimeOnlyField").getValues());
doc.replaceItemValue("EmptyDate", "");
Date blankDate = doc.getItemValue("EmptyDate", Date.class);
System.out.println(blankDate);
ArrayList<String> list = new ArrayList<String>();
list.add("Value 1");
list.add("Value 2");
doc.replaceItemValue("MVField", list);
doc.replaceItemValue("DocAsJson", prevDocAsJson);
HashMap<String, String> mapField = new HashMap<String, String>();
DocumentCollection dc = threads.getAllDocumentsByKey(doc.getItemValueString("FullName"));
for (Document tmp : dc) {
mapField.put(tmp.getUniversalID(), tmp.getItemValueString("Title"));
}
doc.put("MapField", mapField);
BigDecimal decimal = new BigDecimal("2.5");
doc.replaceItemValue("BigDecimalField", decimal);
doc.replaceItemValue("EnumField", Fixes.FORCE_HEX_LOWER_CASE);
doc.save();
HashMap tmp = doc.getItemValue("MapField", HashMap.class);
System.out.println(tmp.size());
System.out.println(doc.getMetaversalID());
System.out.println(doc.getItemValueString("EnumField"));
java.sql.Date sqlDt = doc.getItemValue("DateTimeField", java.sql.Date.class);
System.out.println(sqlDt);
java.sql.Time sqlTime = doc.getItemValue("DateTimeField", java.sql.Time.class);
System.out.println(sqlTime);
System.out.println(doc.getItemValues("BigDecimalField", BigDecimal.class));
System.out.println(doc.getFirstItem("MVField").getTypeEx());
ArrayList<String> blank = new ArrayList<String>();
doc.replaceItemValue("MVField", blank);
System.out.println(doc.hasItem("MVField"));
NamesList names = new NamesList();
names.add("CN=Paul Withers/O=Intec");
names.add("CN=Admin/O=Intec=PW");
newDoc.replaceItemValue("Names", names);
AuthorsList authors = new AuthorsList();
authors.addAll(names);
newDoc.replaceItemValue("Authors", authors);
ReadersList readers = new ReadersList();
readers.addAll(names);
newDoc.replaceItemValue("Readers", readers);
Item dt = newDoc.replaceItemValue("TestDate", "");
Vector<DateTime> dates = new Vector();
DateTime dt1 = sess.createDateTime("01/01/2017");
DateTime dt2 = sess.createDateTime("02/01/2017");
dates.add(dt1);
dates.add(dt2);
dt.setValues(dates);
newDoc.save();
}
use of org.openntf.domino.DocumentCollection in project org.openntf.domino by OpenNTF.
the class TestDocuments method testDocumentCollectionParent.
/**
* Tests for https://github.com/OpenNTF/org.openntf.domino/issues/55
*/
@Test
public void testDocumentCollectionParent() {
Session session = Factory.getSession();
Database database = session.getDatabase(AllTests.EMPTY_DB);
{
DocumentCollection docs = database.getAllDocuments();
assertTrue("docs parent should be a database", docs.getParent() instanceof Database);
}
{
Document doc = database.createDocument();
doc.save();
Document child = database.createDocument();
child.makeResponse(doc);
child.save();
DocumentCollection children = doc.getResponses();
assertTrue("children parent should be a database", children.getParent() instanceof Database);
}
}
use of org.openntf.domino.DocumentCollection in project org.openntf.domino by OpenNTF.
the class LargishSortedCollectionTest method run.
@Override
public void run() {
long testStartTime = System.nanoTime();
Session session = Factory.getSession(SessionType.CURRENT);
// Database db = session.getDatabase("", "events4.nsf");
Database db = session.getDatabase("", "events4.nsf");
// System.out.println("Starting build of byMod view");
// long vStartTime = System.nanoTime();
// View newView = db.createView("ModTest", "SELECT @All");
// ViewColumn modCol = newView.createColumn(1, "Modified", "@Modified");
// modCol.setSorted(true);
// newView.refresh();
// long vEndTime = System.nanoTime();
// System.out.println("Completed building byModView in " + ((vEndTime - vStartTime) / 1000000) + "ms");
// IndexDatabase index = new IndexDatabase(session.getDatabase("", "redpill/index.nsf"));
// Document indexDoc = index.getDbDocument(db.getReplicaID());
// System.out.println("UNSORTED");
List<String> criteria = new ArrayList<String>();
// criteria.add("@doclength");
criteria.add("@modifieddate");
try {
DocumentSorter sorter = null;
// if (indexDoc.hasItem("DocumentSorter")) {
// sorter = indexDoc.getItemValue("DocumentSorter", DocumentSorter.class);
// sorter.setDatabase(db);
// System.out.println("Starting resort of " + sorter.getCount() + " documents");
// } else {
DocumentCollection coll = db.getAllDocuments();
sorter = new DocumentSorter(coll, criteria);
System.out.println("Starting resort of " + coll.getCount() + " documents");
// }
// System.out.println("SORTING...");
long startTime = System.nanoTime();
DocumentCollection sortedColl = sorter.sort();
long endTime = System.nanoTime();
System.out.println("Completed resort of " + sortedColl.getCount() + " in " + ((endTime - startTime) / 1000000) + " ms");
// int count = 0;
// for (Document doc : sortedColl) {
// // System.out.println(doc.getLastModifiedDate().getTime() + " " + doc.getNoteID());
// if (++count > 500) {
// break;
// }
// }
// indexDoc.replaceItemValue("DocumentList", sortedColl);
// indexDoc.replaceItemValue("DocumentSorter", sorter);
// indexDoc.save();
// System.out.println("Saved sorter and result list to document of length " + (indexDoc.getSize() / 1024) + "KB");
// System.out.println("SORTED");
// for (Document doc : sortedColl) {
// System.out.println(doc.getItemValueString("MainSortValue") + " " + doc.getLastModifiedDate().getTime());
// }
} catch (Throwable t) {
t.printStackTrace();
}
long testEndTime = System.nanoTime();
System.out.println("Completed " + getClass().getSimpleName() + " run in " + ((testEndTime - testStartTime) / 1000000000) + " s");
// View modView = db.getView("AllByLengthMod");
// long startTime = System.nanoTime();
// if (modView != null) {
// modView.refresh();
// }
// long endTime = System.nanoTime();
// System.out.println("Completed view build in " + ((endTime - startTime) / 1000000) + "ms");
}
use of org.openntf.domino.DocumentCollection in project org.openntf.domino by OpenNTF.
the class Connect17Transaction method queueTransaction.
private void queueTransaction(final Database db, final String state) {
boolean toggle = true;
int count = 0;
View contacts = db.getView("AllContactsByState");
DocumentCollection dc = contacts.getAllDocumentsByKey(state, true);
for (Document doc : dc) {
if (toggle) {
doc.replaceItemValue("txnTest", new Date());
count += 1;
}
toggle = !toggle;
}
System.out.println("...Updated " + Integer.toString(count) + " Contacts pending committal.");
}
use of org.openntf.domino.DocumentCollection in project org.openntf.domino by OpenNTF.
the class Connect17SyncHelper method run.
@Override
public void run() {
Session sess = Factory.getSession(SessionType.NATIVE);
Database extLib = sess.getDatabase("odademo/oda_1.nsf");
java.util.Map<Object, String> syncMap = new java.util.HashMap<Object, String>();
syncMap.put("Key", "State");
syncMap.put("Name", "StateName");
syncMap.put("@Now", "LastSync");
DocumentSyncHelper helper = new DocumentSyncHelper(DocumentSyncHelper.Strategy.CREATE_AND_REPLACE, syncMap, extLib.getServer(), extLib.getFilePath(), "AllContactsByState", "Key");
View states = extLib.getView("AllStates");
DocumentCollection sourceCollection = states.getAllDocuments();
helper.process(sourceCollection);
System.out.println("Updated " + sourceCollection.getCount() + " documents");
}
Aggregations