// create a parent with a number of nodes initially
Node parent = session.getRootNode().addNode("testRoot");
session.save();
Stopwatch globalSw = new Stopwatch();
globalSw.start();
if (print) {
System.out.println("Starting to insert batches...");
}
for (int i = 0; i < insertBatches; i++) {
// reload the parent in the session after it was saved
parent = session.getNode("/testRoot");
createSubgraph(session, parent, 1, insertBatchSize, propertiesPerChild, true, 1);
}
globalSw.stop();
if (print) {
System.out.println("Inserted " + initialNodeCount + " nodes in: " + globalSw.getSimpleStatistics());
}
globalSw.reset();
globalSw.start();
Stopwatch readSW = new Stopwatch();
// add additional batches of nodes while reading the paths after each batch of children was added
int batchCount = 36;
int batchSize = 1000;
for (int i = 0; i < batchCount; i++) {
// creates batchSize
long childCountAtBatchStart = session.getNode("/testRoot").getNodes().getSize();
int newChildrenCount = createSubgraph(session, parent, 1, batchSize, propertiesPerChild, true, 1);
readSW.start();
// load each of the newly added children into the session and get their paths
final long newChildCount = childCountAtBatchStart + newChildrenCount;
for (long j = childCountAtBatchStart; j < newChildCount; j++) {
final String childAbsPath = "/testRoot/childNode[" + j + "]";
final Node child = session.getNode(childAbsPath);
child.getPath();
child.getName();
}
readSW.lap();
// change the parent & save so that it's flushed from the cache
session.getNode("/testRoot").setProperty("test", "test");
session.save();
// now get the paths of each child via parent relative path navigation
for (long j = childCountAtBatchStart; j <= newChildCount; j++) {
final String childName = "childNode[" + j + "]";
final Node child = session.getNode("/testRoot").getNode(childName);
child.getPath();
child.getName();
}
readSW.lap();
// change the parent & save so that it's flushed from the cache
session.getNode("/testRoot").setProperty("test", "test1");
session.save();
// iterate through all the children of the parent and read the path
NodeIterator nodeIterator = session.getNode("/testRoot").getNodes();
while (nodeIterator.hasNext()) {
final Node child = nodeIterator.nextNode();
child.getPath();
child.getName();
}
readSW.stop();
if (print) {
System.out.println("Time to read batch " + i + " : " + readSW.getSimpleStatistics());
}
readSW.reset();
// change the parent & save so that it's flushed from the cache
session.getNode("/testRoot").setProperty("test", "test2");
session.save();