- BinaryFunction<StatementEvaluation, ReadGraph, Statement> advisor, Map<Object, Object> copyMap)
- throws DatabaseException {
- return copy2(graph, source, 0, advisor, copyMap);
+ BiFunction<ReadGraph, Statement, StatementEvaluation> advisor,
+ Map<Object, Object> copyMap)
+ throws DatabaseException
+ {
+ Set<Statement4> pendingStatements = new THashSet<>();
+ Resource result = copy2(graph, source, 0, advisor, copyMap, pendingStatements);
+ postProcessStatements(graph, copyMap, pendingStatements);
+ return result;
+ }
+
+ /**
+ * Post-process pending statement
+ *
+ * Rule: If both the subject and object of a pending source statement have
+ * been copied, then the pending statement should also be copied.
+ */
+ private static void postProcessStatements(
+ WriteGraph graph,
+ Map<Object, Object> copyMap,
+ Set<Statement4> pendingStatements)
+ throws DatabaseException
+ {
+ if (pendingStatements.isEmpty())
+ return;
+
+ if (DEBUG_COPY)
+ System.out.println("post processing " + pendingStatements.size() + " pending statements");
+ for (Statement4 srcStm : pendingStatements) {
+ // At this point, it is certain that srcStm subject has been copied
+ // but test it anyway.
+ Resource subjectCopy = (Resource) copyMap.get(srcStm.stm.getSubject());
+ Resource objectCopy = (Resource) copyMap.get(srcStm.stm.getObject());
+ if (subjectCopy == null || objectCopy == null) {
+ if (DEBUG_COPY)
+ System.out.println("skipping pending statement: " + NameUtils.toString(graph, srcStm.stm));
+ continue;
+ }
+ if (DEBUG_COPY)
+ System.out.println("copying pending statement: " + NameUtils.toString(graph, srcStm.stm));
+ graph.claim(subjectCopy, srcStm.stm.getPredicate(), srcStm.inverse, objectCopy);
+ }