]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelTransferableGraphSourceRequest.java
Merge "Multiple reader thread support for db client"
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / util / ModelTransferableGraphSourceRequest.java
index 5760f1a026cfa7ab2a5a054c27e6311b13cfe6e1..c5cb20af2c6d2ada95446a61cacdd3fa723747c0 100644 (file)
@@ -81,7 +81,8 @@ public class ModelTransferableGraphSourceRequest extends UniqueRead<ModelTransfe
 
        public static String LOG_FILE = "transferableGraph.log";
        final static boolean LOG = false;
-       final static private boolean DEBUG = false;
+       final static boolean PRINTDEBUG = false;
+       final static boolean DEBUG = LOG | PRINTDEBUG;
        final static boolean PROFILE = false;
        
        private TransferableGraphConfiguration2 configuration;
@@ -103,8 +104,10 @@ public class ModelTransferableGraphSourceRequest extends UniqueRead<ModelTransfe
        }
        
        static void log(String line) {
+               if (PRINTDEBUG) System.err.println(line);
                if (LOG) {
                        try {
+                               if(line.length() > 500) line = line.substring(0, 500);
                                log.writeUTF(line + "\n");
                        } catch (IOException e) {
                                e.printStackTrace();
@@ -438,8 +441,12 @@ public class ModelTransferableGraphSourceRequest extends UniqueRead<ModelTransfe
                                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) + ")");
@@ -447,6 +454,21 @@ public class ModelTransferableGraphSourceRequest extends UniqueRead<ModelTransfe
                        }
                }
 
+               // 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();
 
@@ -556,15 +578,15 @@ public class ModelTransferableGraphSourceRequest extends UniqueRead<ModelTransfe
 
                        final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
 
-                       final DomainStatementProcedure3 proc = new DomainStatementProcedure3(result);
+//                     final DomainStatementProcedure3 proc = new DomainStatementProcedure3(result);
 
                        if (ignoreVirtual) {
                                for(Resource r : roots) {
-                                       dqs.forEachDirectPersistentStatement(graph, r, proc);
+                                       result.add(dqs.getDirectPersistentStatements(graph, r));
                                }
                        } else {
                                for(Resource r : roots) {
-                                       dqs.forEachDirectStatement(graph, r, proc);
+                                       result.add(dqs.getDirectStatements(graph, r));
                                }
                        }