]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
An attempt to resolve this issue for good 97/197/1
authorAntti Villberg <antti.villberg@semantum.fi>
Mon, 12 Dec 2016 09:56:51 +0000 (11:56 +0200)
committerAntti Villberg <antti.villberg@semantum.fi>
Mon, 12 Dec 2016 09:56:51 +0000 (11:56 +0200)
refs #6169

Change-Id: Ia06d08568fa37b9a575f924dc35be5fe3fa1a941

bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphImportProcess.java

index 3d4b78977af148de732ce03080e329e74d760c3f..a043e59f74ab8772d89d6aea2e5620d4bfbb68a0 100644 (file)
@@ -37,6 +37,7 @@ import org.simantics.db.VirtualGraph;
 import org.simantics.db.WriteOnlyGraph;\r
 import org.simantics.db.common.WriteBindings;\r
 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;\r
+import org.simantics.db.common.request.PossibleIndexRoot;\r
 import org.simantics.db.common.uri.UnescapedChildMapOfResource;\r
 import org.simantics.db.common.utils.Logger;\r
 import org.simantics.db.exception.DatabaseException;\r
@@ -210,7 +211,9 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap
        \r
        void prepare(ReadGraph graph) throws Exception {\r
 \r
-//             indexRoot = graph.syncRequest(new PossibleIndexRoot(((IImportAdvisor2)advisor).getTarget()));\r
+               Resource target = advisor.getTarget();\r
+               if(target != null)\r
+                       indexRoot = graph.syncRequest(new PossibleIndexRoot(target));\r
                \r
                findBuiltins(graph);\r
                readIdentities(graph);\r
@@ -316,7 +319,7 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap
            return resourceUtil.mayHaveResource(type);\r
        }\r
        \r
-       void findClusterSet(WriteOnlyGraph graph, Resource rootLibrary, Resource indexRoot, int[] clustering, int[] clusterSets, long[] clusters, int id) throws DatabaseException {\r
+       void findClusterSet(WriteOnlyGraph graph, Resource rootLibrary, int[] clustering, int[] clusterSets, long[] clusters, int id) throws DatabaseException {\r
                ClusteringSupport support = graph.getService(ClusteringSupport.class);\r
                if(id == Extensions.ROOT_LIBRARY_CLUSTER_SET || id == Extensions.INDEX_ROOT_CLUSTER_SET) return;\r
                for(int pos=0,index=0;index<clustering.length;index++) {\r
@@ -326,9 +329,12 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap
                                if(handles[id] == 0) {\r
                                        int csHandle = 0;\r
                                        if(cs == Extensions.ROOT_LIBRARY_CLUSTER_SET) csHandle = builder.handle(rootLibrary);\r
-                                       else if(cs == Extensions.INDEX_ROOT_CLUSTER_SET) csHandle = builder.handle(indexRoot);\r
+                                       else if(cs == Extensions.INDEX_ROOT_CLUSTER_SET) {\r
+                                               if(indexRoot == null) throw new DatabaseException("No index root was available in TG import.");\r
+                                               csHandle = builder.handle(indexRoot);\r
+                                       }\r
                                        else {\r
-                                               findClusterSet(graph, rootLibrary, indexRoot, clustering, clusterSets, clusters, cs);\r
+                                               findClusterSet(graph, rootLibrary, clustering, clusterSets, clusters, cs);\r
                                                csHandle = handles[cs];\r
                                        }\r
                                        \r
@@ -373,7 +379,7 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap
                                \r
                                // Create clustering\r
                                for(int i=0;i<clusterSets.length;i++) {\r
-                                       findClusterSet(graph, graph.getRootLibrary(), indexRoot, clustering, clusterSets, clusters, clusterSets[i]);\r
+                                       findClusterSet(graph, graph.getRootLibrary(), clustering, clusterSets, clusters, clusterSets[i]);\r
                                }\r
                                \r
                                // Then create all resources\r
@@ -384,8 +390,10 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap
                                int setHandle = 0;\r
                                        if(s == Extensions.ROOT_LIBRARY_CLUSTER_SET)\r
                                                setHandle = builder.handle(graph.getRootLibrary());\r
-                                       else if(s == Extensions.INDEX_ROOT_CLUSTER_SET)\r
+                                       else if(s == Extensions.INDEX_ROOT_CLUSTER_SET) {\r
+                                               if(indexRoot == null) throw new DatabaseException("No index root was available in TG import.");\r
                                                setHandle = builder.handle(indexRoot);\r
+                                       }\r
                                        else setHandle = handles[s];\r
                                        // Preserve clustering only for internal resources\r
                                        if(clusters[j] != 0)\r