import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import org.simantics.db.Resource;
import org.simantics.db.ResourceMap;
import org.simantics.db.Statement;
+import org.simantics.db.common.StandardStatement;
import org.simantics.db.common.primitiverequest.Value;
import org.simantics.db.common.procedure.adapter.TransientCacheListener;
import org.simantics.db.common.utils.NameUtils;
Map<Resource,Boolean> isRelatedToPredicates = null;
Set<Resource> deadPredicates = null;
Set<Resource> strongInverseSet = null;
-
+ List<Statement> unresolvedWeakLinks = new ArrayList<>();
TIntIntHashMap ids = null;
ResourceMap<ExtentStatus> status = null;
Map<Datatype, byte[]> bindings = new HashMap<Datatype, byte[]>();
// The inverse is also weak (or there is no inverse)
if(!strongInverseSet.contains(predicate)) {
-
- addToStream(predicate, object);
+
+ unresolvedWeakLinks.add(new StandardStatement(subject, predicate, object));
+ //addToStream(predicate, object);
if(objectStatus == null) {
status.put(object, ExtentStatus.PENDING);
state.externals.add(transientId);
} else if(ExtentStatus.PENDING == status) {
String uri = graph.getPossibleURI(r);
- if(uri != null)
- state.externals.add(transientId);
+ if(uri != null) {
+ // All internal resources with uri have been discovered already => this must then be external
+ //state.externals.add(transientId);
+ // Pending resources are found through weak links - if they are still pending at this stage do not add an external
+ processor.status.put(r, ExtentStatus.EXTERNAL);
+ }
else {
state.pending.add(transientId);
System.err.println("Pending status in export: " + NameUtils.getSafeName(graph, r, true) + " (" + graph.getPossibleURI(r) + ")");
}
}
+ // Now that we know the status of the resources lets process weak statements
+ for(Statement stm : processor.unresolvedWeakLinks) {
+ ExtentStatus status = processor.status.get(stm.getObject());
+ if(ExtentStatus.INTERNAL == status) {
+ // Weak links between internals are exported
+ int transientId = support.getTransientId(stm.getSubject());
+ processor.addToStream(stm.getPredicate(), stm.getObject());
+ try {
+ processor.flushStatementStream(transientId, state);
+ } catch (IOException e) {
+ throw new DatabaseException(e);
+ }
+ }
+ }
+
if (state.monitor.isCanceled())
throw new CancelTransactionException();