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
\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
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
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
\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
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