]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/MigrationStateImpl.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / migration / MigrationStateImpl.java
index 06dae94d3fd796690f2ffc22ca18d33a6c0ca0b0..fdd6f9132fe4b78d45d6874275778ccdc4481465 100644 (file)
@@ -33,6 +33,7 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.WriteOnlyGraph;
 import org.simantics.db.common.request.WriteResultRequest;
 import org.simantics.db.common.utils.Logger;
+import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.AssumptionException;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;
@@ -105,12 +106,10 @@ public class MigrationStateImpl implements MigrationState {
                    return (T)tg;
                }
                
-            TransferableGraphFileReader reader = null;
             try {
                 File modelFile = getProperty(MigrationStateKeys.MODEL_FILE);
-                reader = new TransferableGraphFileReader(modelFile);
                 TimeLogger.log(MigrationStateImpl.class, "reading TG into memory from " + modelFile);
-                TransferableGraph1 tg = reader.readTG();
+                TransferableGraph1 tg = TransferableGraphFileReader.read(modelFile, false);
                 TimeLogger.log(MigrationStateImpl.class, "read TG into memory from " + modelFile);
                 setProperty(MigrationStateKeys.CURRENT_TG, tg);
                 return (T)tg;
@@ -118,8 +117,6 @@ public class MigrationStateImpl implements MigrationState {
                 throw e;
             } catch (Throwable t) {
                 throw new DatabaseException(t);
-            } finally {
-                uncheckedClose(reader);
             }
                
         } else if (MigrationStateKeys.CURRENT_TGS.equals(key)) {
@@ -221,6 +218,7 @@ public class MigrationStateImpl implements MigrationState {
 
         Resource indexRoot = graph.newResource();
         String indexRootName = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(new Date());
+        indexRootName = NameUtils.findFreshName(graph, indexRootName, temp, L0.ConsistsOf, "%s-%d");
         graph.claim(indexRoot, L0.InstanceOf, L0.IndexRoot);
         graph.addLiteral(indexRoot, L0.HasName, L0.String, indexRootName, Bindings.STRING);
         graph.claim(temp, L0.ConsistsOf, indexRoot);