]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics/src/org/simantics/SimanticsPlatform.java
Always discard database undo history after each platform startup.
[simantics/platform.git] / bundles / org.simantics / src / org / simantics / SimanticsPlatform.java
index 91c34f0c788f59f4a35984aa764d184ad2d95f9f..211b286a9401e290c0f5819bf9c5d76c035f9a5b 100644 (file)
@@ -65,7 +65,6 @@ import org.simantics.db.VirtualGraph;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.ObjectsWithType;
 import org.simantics.db.common.request.Queries;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.ObjectsWithType;
 import org.simantics.db.common.request.Queries;
-import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.common.request.WriteResultRequest;
 import org.simantics.db.common.utils.Transaction;
 import org.simantics.db.exception.ClusterSetExistException;
 import org.simantics.db.common.request.WriteResultRequest;
 import org.simantics.db.common.utils.Transaction;
 import org.simantics.db.exception.ClusterSetExistException;
@@ -79,6 +78,7 @@ import org.simantics.db.layer0.util.TGTransferableGraphSource;
 import org.simantics.db.layer0.variable.VariableRepository;
 import org.simantics.db.management.SessionContext;
 import org.simantics.db.request.Read;
 import org.simantics.db.layer0.variable.VariableRepository;
 import org.simantics.db.management.SessionContext;
 import org.simantics.db.request.Read;
+import org.simantics.db.request.Write;
 import org.simantics.db.service.LifecycleSupport.LifecycleListener;
 import org.simantics.db.service.LifecycleSupport.LifecycleState;
 import org.simantics.db.service.QueryControl;
 import org.simantics.db.service.LifecycleSupport.LifecycleListener;
 import org.simantics.db.service.LifecycleSupport.LifecycleState;
 import org.simantics.db.service.QueryControl;
@@ -397,21 +397,18 @@ public class SimanticsPlatform implements LifecycleListener {
                         }
                         throw new PlatformException(sb.toString());
                     }
                         }
                         throw new PlatformException(sb.toString());
                     }
-                    
+
                     List<GraphBundle> sortedBundles = analyzer.getSortedGraphs();
                     if(!sortedBundles.isEmpty()) {
                     List<GraphBundle> sortedBundles = analyzer.getSortedGraphs();
                     if(!sortedBundles.isEmpty()) {
-                       
-                        session.syncRequest(new WriteRequest() {
-                            @Override
-                            public void perform(WriteGraph graph) throws DatabaseException {
-                                try {
-                                    graph.newClusterSet(graph.getRootLibrary());
-                                } catch (ClusterSetExistException e) {
-                                    // Cluster set exist already, no problem.
-                                }
-                                graph.setClusterSet4NewResource(graph.getRootLibrary());
-                                graph.flushCluster();
+
+                        session.syncRequest((Write) graph -> {
+                            try {
+                                graph.newClusterSet(graph.getRootLibrary());
+                            } catch (ClusterSetExistException e) {
+                                // Cluster set exist already, no problem.
                             }
                             }
+                            graph.setClusterSet4NewResource(graph.getRootLibrary());
+                            graph.flushCluster();
                         });
 
                         boolean mergedOntologies = false;
                         });
 
                         boolean mergedOntologies = false;
@@ -469,13 +466,10 @@ public class SimanticsPlatform implements LifecycleListener {
                                        }
                                }
                         }
                                        }
                                }
                         }
-                        
-                        session.syncRequest(new WriteRequest() {
-                            @Override
-                            public void perform(WriteGraph graph) throws DatabaseException {
-                                graph.setClusterSet4NewResource(graph.getRootLibrary());
-                                graph.flushCluster();
-                            }
+
+                        session.syncRequest((Write) graph -> {
+                            graph.setClusterSet4NewResource(graph.getRootLibrary());
+                            graph.flushCluster();
                         });
 
                         if (mergedOntologies)
                         });
 
                         if (mergedOntologies)
@@ -582,15 +576,10 @@ public class SimanticsPlatform implements LifecycleListener {
             Collection<GroupReference> groupsWithoutVersion = GroupReference.stripVersions(publishedFeatureGroups);
 
             try {
             Collection<GroupReference> groupsWithoutVersion = GroupReference.stripVersions(publishedFeatureGroups);
 
             try {
-                Transaction.startTransaction(session, true);
-                try {
-                    Projects.setProjectInstalledGroups(writeGraph(), projectResource, groupsWithoutVersion);
-                    Transaction.commit();
-                } finally {
-                    Transaction.endTransaction();
-                }
-                //session.getService( LifecycleSupport.class ).save();
-            } catch(DatabaseException ae) {
+                session.syncRequest(
+                        (Write) graph ->
+                        Projects.setProjectInstalledGroups(graph, projectResource, groupsWithoutVersion));
+            } catch (DatabaseException ae) {
                 throw new PlatformException("Failed to install features", ae);
             }
             progressMonitor.worked(10);
                 throw new PlatformException("Failed to install features", ae);
             }
             progressMonitor.worked(10);
@@ -854,7 +843,7 @@ public class SimanticsPlatform implements LifecycleListener {
         installProject = assertProject(progressMonitor, workspacePolicy, installProject);
 
         // 6. Install all features into project, if in debug mode
         installProject = assertProject(progressMonitor, workspacePolicy, installProject);
 
         // 6. Install all features into project, if in debug mode
-        updateInstalledGroups(progressMonitor, installProject);
+        updateInstalledGroups(progressMonitor, true); //installProject);
         TimeLogger.log("Installed all features into project");
 
         // 7. Assert L0.Session in database for this session
         TimeLogger.log("Installed all features into project");
 
         // 7. Assert L0.Session in database for this session
@@ -863,14 +852,9 @@ public class SimanticsPlatform implements LifecycleListener {
         session.getService(XSupport.class).setServiceMode(false, false);
 
         try {
         session.getService(XSupport.class).setServiceMode(false, false);
 
         try {
-            session.sync(new WriteRequest() {
-
-                @Override
-                public void perform(WriteGraph graph) throws DatabaseException {
-                    QueryControl qc = graph.getService(QueryControl.class);
-                    qc.flush(graph);
-                }
-
+            session.syncRequest((Write) graph -> {
+                QueryControl qc = graph.getService(QueryControl.class);
+                qc.flush(graph);
             });
             TimeLogger.log("Flushed queries");
         } catch (DatabaseException e) {
             });
             TimeLogger.log("Flushed queries");
         } catch (DatabaseException e) {
@@ -929,6 +913,12 @@ public class SimanticsPlatform implements LifecycleListener {
         // #7650: improve shutdown robustness in all applications that use the platform
         Runtime.getRuntime().addShutdownHook(shutdownHook);
 
         // #7650: improve shutdown robustness in all applications that use the platform
         Runtime.getRuntime().addShutdownHook(shutdownHook);
 
+        // Discard database session undo history at this point to prevent
+        // the user from undoing any initialization operations performed
+        // by the platform startup.
+        SimanticsPlatform.INSTANCE.discardSessionUndoHistory();
+        TimeLogger.log("Discarded session undo history");
+
         return sessionContext;
 
     }
         return sessionContext;
 
     }