X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2Finternal%2FState.java;h=1e468f2c3f25e2e3e50cc6487fc02e57d3a7017e;hp=f30418a6a32869bf009fc661baa47244a4679a1b;hb=1f4133242efdb193390d76b0952ade00a3a88309;hpb=782dfcb9fc5ce3db46598f660abf642b9c8849b7 diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/State.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/State.java index f30418a6a..1e468f2c3 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/State.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/State.java @@ -17,12 +17,14 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.simantics.db.ChangeSet; +import org.simantics.db.Disposable; import org.simantics.db.Operation; import org.simantics.db.VirtualGraph; import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.InternalException; import org.simantics.db.exception.RuntimeDatabaseException; +import org.simantics.db.impl.graph.ReadGraphImpl; import org.simantics.db.impl.graph.WriteGraphImpl; import org.simantics.db.impl.query.QueryProcessor; import org.simantics.db.request.WriteOnly; @@ -193,7 +195,7 @@ class State { void stopReadTransaction() throws DatabaseException { lock.lock(); try { - assert (!queryProvider.hasScheduledUpdates()); + assert (!queryProvider.listening.hasScheduledUpdates()); assert (readCount == 1); session.writeSupport.gc(); transactionToken.stopReadTransaction(); @@ -286,16 +288,19 @@ class State { try { final boolean undo = false; if (!context.isOk(undo)) // this is a blocking operation - throw new InternalException("Cancel failed. This should never happen. Contact application support."); + throw new InternalException("Cancel failed. This should never happen."); // System.out.println("session cs: " + session.clientChanges); // System.out.println("reverse cs: " + cs); - queryProvider.performDirtyUpdates(graph); - queryProvider.performScheduledUpdates(graph); + queryProvider.propagateChangesInQueryCache(graph); + queryProvider.listening.fireListeners(graph); } catch (DatabaseException e) { Logger.defaultLogError(e); } // This will send and accept the reverse change set. transactionToken.cancelEnd(session.writeSupport, null, session.clusterStream); + } else { + queryProvider.propagateChangesInQueryCache(graph); + queryProvider.listening.fireListeners(graph); } } session.writeSupport.clearMetadata(); @@ -327,31 +332,27 @@ class State { if (vg != null && clusterStream.isDirty()) new Exception("Internal error: virtual transaction committed changes into core (" + request + ")").printStackTrace(); -// long start = System.nanoTime(); - if (null == vg) { - clusterStream.reallyFlush(); - // This was fired just before in handleUpdatesAndMetadata -// if (!writeOnly) -// session.fireMetadataListeners(graph, cs); - } else - clusterStream.clear(); - -// long duration = System.nanoTime() - start; -// System.out.println("reallyFlush " + 1e-9*duration + "s. "); + // This is needed even when the write targets a virtual graph - + // deny can always remove a persistent statement. + clusterStream.reallyFlush(); session.clientChanges = new ClientChangesImpl(session); // start = System.nanoTime(); - queryProvider.performScheduledUpdates(graph); + queryProvider.propagateChangesInQueryCache(graph); + ReadGraphImpl listenerGraph = graph.forRecompute(null); + listenerGraph.asyncBarrier.inc(); + queryProvider.listening.fireListeners(listenerGraph); + listenerGraph.asyncBarrier.dec(); // duration = System.nanoTime() - start; // System.out.println("performScheduledUpdates " + 1e-9*duration + "s. "); // Process updates as long as pending primitives exist while (session.dirtyPrimitives) { session.dirtyPrimitives = false; - queryProvider.performDirtyUpdates(graph); - queryProvider.performScheduledUpdates(graph); + queryProvider.propagateChangesInQueryCache(graph); + queryProvider.listening.fireListeners(graph); } if (!writeOnly) // TODO: fix me! FIX ME! Please fix me! Please! @@ -391,6 +392,7 @@ class State { this.close(); // Everything is lost anyway. throw new IllegalStateException(e); } finally { + Disposable.safeDispose(cs); lock.unlock(); } }