]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Working towards multiple readers.
authorAntti Villberg <antti.villberg@semantum.fi>
Thu, 26 Jul 2018 20:04:13 +0000 (23:04 +0300)
committerAntti Villberg <antti.villberg@semantum.fi>
Thu, 26 Jul 2018 21:01:42 +0000 (00:01 +0300)
Async is no longer a subset of sync but the other way around. Sync
invocation of async request waits until all computatations
initiated by the request are done.

Conflicts:
bundles/org.simantics.db.common/src/org/simantics/db/common/utils/CommonDBUtils.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/TGRemover.java

Change-Id: I347acba9289cb2629dc1d21d8666b37e49f6d936

101 files changed:
bundles/org.simantics.acorn/src/org/simantics/acorn/cluster/ClusterBig.java
bundles/org.simantics.acorn/src/org/simantics/acorn/cluster/ClusterSmall.java
bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyGraphLabeler.java
bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyParametrizedViewpoint.java
bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyResourceQueryContainer.java
bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyViewpoint.java
bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/CallbackViewpointContributionImpl.java
bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalCheckedStateContributionImpl.java
bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImageDecoratorContributionImpl.java
bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImagerContributionImpl.java
bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalLabelDecoratorContributionImpl.java
bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalLabelerContributionImpl.java
bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalViewpointContributionImpl.java
bundles/org.simantics.db.common/META-INF/MANIFEST.MF
bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/ForEachAssertedObject.java
bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/RelationInfoRequest.java
bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/BlockingAsyncProcedure.java [deleted file]
bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/single/SingleSetSyncListenerDelegate.java
bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/wrapper/NoneToSyncMultiListener.java [new file with mode: 0644]
bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/wrapper/NoneToSyncMultiProcedure.java [new file with mode: 0644]
bundles/org.simantics.db.common/src/org/simantics/db/common/processor/MergingGraphRequestProcessor.java
bundles/org.simantics.db.common/src/org/simantics/db/common/processor/ProcessorBase.java
bundles/org.simantics.db.common/src/org/simantics/db/common/request/UniqueAsyncRead.java [new file with mode: 0644]
bundles/org.simantics.db.common/src/org/simantics/db/common/utils/OrderedSetUtils.java
bundles/org.simantics.db.common/src/org/simantics/db/common/utils/Transaction.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/BlockingAsyncProcedure.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/ClusterI.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectContextProcedure.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectProcedure.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForPossibleRelatedValueContextProcedure.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForPossibleRelatedValueProcedure.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/TransientGraph.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/AsyncBarrierImpl.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/MultiIntProcedure.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphSupport.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/procedure/ResultCallWrappedSyncQueryProcedure.java [new file with mode: 0644]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncMultiReadEntry.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/GraphSemaphore.java [moved from bundles/org.simantics.db.common/src/org/simantics/db/common/GraphSemaphore.java with 97% similarity]
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/MultiReadEntry.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/NamespaceRequirements.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/OntologiesForModel.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/combinations/Combinators.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ConsistsOfProcess.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelTransferableGraphSourceRequest.java
bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterWriteOnly.java
bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/DirectQuerySupportImpl.java
bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QueryControlImpl.java
bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QuerySupportImpl.java
bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java
bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterBig.java
bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterSmall.java
bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/IntHash.java
bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ObjectTable.java
bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceElementSmall.java
bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTable.java
bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTableSmall.java
bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntArraySet.java
bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntSet.java
bundles/org.simantics.db.regressionsuite.ontology/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/AdaptionService2.java
bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/reflection/AbstractReflectionAdapter.java
bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/reflection/ReflectionAdapter2.java
bundles/org.simantics.db/src/org/simantics/db/AsyncReadGraph.java
bundles/org.simantics.db/src/org/simantics/db/AsyncRequestProcessor.java
bundles/org.simantics.db/src/org/simantics/db/AsyncRequestProcessorSpecific.java
bundles/org.simantics.db/src/org/simantics/db/ReadGraph.java
bundles/org.simantics.db/src/org/simantics/db/RequestProcessor.java
bundles/org.simantics.db/src/org/simantics/db/RequestProcessorSpecific.java
bundles/org.simantics.db/src/org/simantics/db/Session.java
bundles/org.simantics.db/src/org/simantics/db/procedure/SyncContextMultiProcedure.java [new file with mode: 0644]
bundles/org.simantics.db/src/org/simantics/db/procedure/SyncContextProcedure.java [new file with mode: 0644]
bundles/org.simantics.db/src/org/simantics/db/request/MultiRead.java
bundles/org.simantics.db/src/org/simantics/db/service/DirectQuerySupport.java
bundles/org.simantics.db/src/org/simantics/db/service/QueryControl.java
bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ConstantStyle.java
bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DiagramContentRequest.java
bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java
bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/MappedTypeGroup.java
bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/TypeGroup.java
bundles/org.simantics.diagram/src/org/simantics/diagram/profile/DiagramElementGroup.java
bundles/org.simantics.diagram/src/org/simantics/diagram/profile/StyleBase.java
bundles/org.simantics.diagram/src/org/simantics/diagram/runtime/RuntimeDiagramManager.java
bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java
bundles/org.simantics.issues.common/src/org/simantics/issues/common/IssueUtils.java
bundles/org.simantics.layer0.utils/src/org/simantics/layer0/utils/queries/QueryExecutor2.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/monitor/MonitorClassFactory2.java
bundles/org.simantics.modeling/src/org/simantics/modeling/scl/issue/SCLExpressionIssueProvider.java
bundles/org.simantics.modeling/src/org/simantics/modeling/subscription/ModelHistoryCollector.java
bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/Group.java
bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/Style.java
bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/GraphUI.java
bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SheetFactory.java
bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorInput2.java
bundles/org.simantics.ui/src/org/simantics/ui/workbench/editor/input/InputValidationCombinators.java

index 1de4006a72e630482a22dd5390c39b2e411fb15b..063bcf548fa27f687318a1e021fcae511f8bf668 100644 (file)
@@ -40,8 +40,8 @@ import org.simantics.db.impl.Table;
 import org.simantics.db.impl.TableHeader;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.impl.query.QueryProcessor;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.db.procore.cluster.ClusterMap;
 import org.simantics.db.procore.cluster.ClusterPrintDebugInfo;
 import org.simantics.db.procore.cluster.ClusterTraits;
@@ -54,6 +54,8 @@ import org.simantics.db.procore.cluster.ResourceTable;
 import org.simantics.db.procore.cluster.ValueTable;
 import org.simantics.db.service.ClusterUID;
 
+import fi.vtt.simantics.procore.internal.SessionImplSocket;
+
 final public class ClusterBig extends ClusterImpl {
     private static final int TABLE_HEADER_SIZE = TableHeader.HEADER_SIZE + TableHeader.EXTRA_SIZE;
     private static final int RESOURCE_TABLE_OFFSET = 0;
@@ -263,7 +265,7 @@ final public class ClusterBig extends ClusterImpl {
         return objectTable.getSingleObject(objectIndex, support, this);
     }
 
-    public void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, AsyncMultiProcedure<Resource> procedure,
+    public void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, SyncMultiProcedure<Resource> procedure,
             ClusterSupport support) throws DatabaseException {
         if (DEBUG)
             System.out.println("Cluster.forObjects1: rk=" + resourceKey + " pk=" + predicateKey);
@@ -276,7 +278,7 @@ final public class ClusterBig extends ClusterImpl {
         }
         objectTable.foreachObject(graph, objectIndex, procedure, this);
     }
-    public <C> void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, C context, AsyncContextMultiProcedure<C, Resource> procedure,
+    public <C> void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, C context, SyncContextMultiProcedure<C, Resource> procedure,
             ClusterSupport support) throws DatabaseException {
         if (DEBUG)
             System.out.println("Cluster.forObjects1: rk=" + resourceKey + " pk=" + predicateKey);
@@ -355,57 +357,53 @@ final public class ClusterBig extends ClusterImpl {
     
     @Override
     public void forObjects(ReadGraphImpl graph, int resourceKey,
-            int predicateKey, AsyncMultiProcedure<Resource> procedure)
+            int predicateKey, SyncMultiProcedure<Resource> procedure)
             throws DatabaseException {
         
-       throw new UnsupportedOperationException();
-       
-//        SessionImplSocket session = (SessionImplSocket)graph.getSession();
-//        ClusterSupport support = session.clusterTranslator;
-//        
-//        if (DEBUG)
-//            System.out.println("Cluster.forObjects3: rk=" + resourceKey + " pk=" + predicateKey);
-//        final int resourceIndex = getLocalReference(resourceKey);
-//        final int pRef = getInternalReferenceOrZero(predicateKey, support);
-//        final ClusterI.CompleteTypeEnum pCompleteType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey);
-//        if (ClusterI.CompleteTypeEnum.NotComplete != pCompleteType) {
-//            resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
-//            return;
-//        }
-//        final int predicateIndex = resourceTable.getPredicateIndex(resourceIndex);
-//        if (0 == predicateIndex) {
-//            resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
-//            return;
-//        }
-//        int objectIndex = predicateTable.getObjectIndex(predicateIndex, pRef);
-//        forObjects(resourceKey, predicateKey, objectIndex, graph.processor, graph, procedure, support);
+        SessionImplSocket session = (SessionImplSocket)graph.getSession();
+        ClusterSupport support = session.clusterTranslator;
+        
+        if (DEBUG)
+            System.out.println("Cluster.forObjects3: rk=" + resourceKey + " pk=" + predicateKey);
+        final int resourceIndex = getLocalReference(resourceKey);
+        final int pRef = getInternalReferenceOrZero(predicateKey, support);
+        final ClusterI.CompleteTypeEnum pCompleteType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey);
+        if (ClusterI.CompleteTypeEnum.NotComplete != pCompleteType) {
+            resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
+            return;
+        }
+        final int predicateIndex = resourceTable.getPredicateIndex(resourceIndex);
+        if (0 == predicateIndex) {
+            resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
+            return;
+        }
+        int objectIndex = predicateTable.getObjectIndex(predicateIndex, pRef);
+        forObjects(resourceKey, predicateKey, objectIndex, graph.processor, graph, procedure, support);
         
     }
     
     @Override
     public void forObjects(ReadGraphImpl graph, int resourceKey, ForEachObjectProcedure procedure) throws DatabaseException {
        
-       throw new UnsupportedOperationException();
-       
-//        SessionImplSocket session = (SessionImplSocket)graph.getSession();
-//        ClusterSupport support = session.clusterTranslator;
-//        final int predicateKey = procedure.predicateKey;
-//        if (DEBUG)
-//            System.out.println("Cluster.forObjects3: rk=" + resourceKey + " pk=" + predicateKey);
-//        final int resourceIndex = getLocalReference(resourceKey);
-//        final int pRef = getInternalReferenceOrZero(predicateKey, support);
-//        final ClusterI.CompleteTypeEnum pCompleteType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey);
-//        if (ClusterI.CompleteTypeEnum.NotComplete != pCompleteType) {
-//            resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
-//            return;
-//        }
-//        final int predicateIndex = resourceTable.getPredicateIndex(resourceIndex);
-//        if (0 == predicateIndex) {
-//            resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
-//            return;
-//        }
-//        int objectIndex = predicateTable.getObjectIndex(predicateIndex, pRef);
-//        forObjects(resourceKey, predicateKey, objectIndex, graph.processor, graph, procedure, support);
+        SessionImplSocket session = (SessionImplSocket)graph.getSession();
+        ClusterSupport support = session.clusterTranslator;
+        final int predicateKey = procedure.predicateKey;
+        if (DEBUG)
+            System.out.println("Cluster.forObjects3: rk=" + resourceKey + " pk=" + predicateKey);
+        final int resourceIndex = getLocalReference(resourceKey);
+        final int pRef = getInternalReferenceOrZero(predicateKey, support);
+        final ClusterI.CompleteTypeEnum pCompleteType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey);
+        if (ClusterI.CompleteTypeEnum.NotComplete != pCompleteType) {
+            resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
+            return;
+        }
+        final int predicateIndex = resourceTable.getPredicateIndex(resourceIndex);
+        if (0 == predicateIndex) {
+            resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
+            return;
+        }
+        int objectIndex = predicateTable.getObjectIndex(predicateIndex, pRef);
+        forObjects(resourceKey, predicateKey, objectIndex, graph.processor, graph, procedure, support);
         
     }
     @Override
index 117ab75a3fc723b66660cd48c6db6231b496a3d1..a964c90c98fbbb5bb64842d43563df7d54f76053 100644 (file)
@@ -38,8 +38,8 @@ import org.simantics.db.impl.IClusterTable;
 import org.simantics.db.impl.Table;
 import org.simantics.db.impl.TableHeader;
 import org.simantics.db.impl.graph.ReadGraphImpl;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.db.procore.cluster.ClusterMapSmall;
 import org.simantics.db.procore.cluster.ClusterTraits;
 import org.simantics.db.procore.cluster.ClusterTraitsSmall;
@@ -54,6 +54,7 @@ import org.simantics.db.service.Bytes;
 import org.simantics.db.service.ClusterUID;
 import org.simantics.db.service.ResourceUID;
 
+import fi.vtt.simantics.procore.internal.SessionImplSocket;
 import gnu.trove.map.hash.TIntShortHashMap;
 import gnu.trove.procedure.TIntProcedure;
 import gnu.trove.set.hash.TIntHashSet;
@@ -300,7 +301,7 @@ final public class ClusterSmall extends ClusterImpl {
         return objectTable.getSingleObject(objectIndex, support, this);
     }
 
-    public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, AsyncMultiProcedure<Resource> procedure,
+    public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, SyncMultiProcedure<Resource> procedure,
             ClusterSupport support) throws DatabaseException {
         if (DEBUG)
             System.out.println("ClusterSmall.forObjects1: rk=" + resourceKey + " pk=" + predicateKey);
@@ -314,7 +315,7 @@ final public class ClusterSmall extends ClusterImpl {
         objectTable.foreachObject(graph, objectIndex, procedure, this);
     }
 
-    public <C> void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, C context, AsyncContextMultiProcedure<C, Resource> procedure,
+    public <C> void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, C context, SyncContextMultiProcedure<C, Resource> procedure,
             ClusterSupport support) throws DatabaseException {
         if (DEBUG)
             System.out.println("ClusterSmall.forObjects1: rk=" + resourceKey + " pk=" + predicateKey);
@@ -408,29 +409,28 @@ final public class ClusterSmall extends ClusterImpl {
 
     @Override
     public void forObjects(ReadGraphImpl graph, int resourceKey,
-            int predicateKey, AsyncMultiProcedure<Resource> procedure) throws DatabaseException {
+            int predicateKey, SyncMultiProcedure<Resource> procedure) throws DatabaseException {
        
-       throw new UnsupportedOperationException();
-       
-//        SessionImplSocket session = (SessionImplSocket)graph.getSession();
-//        ClusterSupport support = session.clusterTranslator;
-//        if (DEBUG)
-//            System.out.println("ClusterSmall.forObjects3: rk=" + resourceKey + " pk=" + predicateKey);
-//        final int resourceIndex = ClusterTraitsBase.getResourceIndexFromResourceKey(resourceKey);
-//        final int pRef = getInternalReferenceOrZero2(predicateKey, support);
-//        final int completeType = ClusterTraitsBase.getCompleteTypeIntFromResourceKey(predicateKey);
-//        final ClusterI.CompleteTypeEnum pCompleteType = CompleteTypeEnum.make(completeType);
-//        if (completeType > 0) {
-//            resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
-//            return;
-//        }
-//        final int predicateIndex = (int)resourceTable.table[(resourceIndex<<1) - 1 + resourceTable.offset] & 0xFFFFFF;
-//        if (0 == predicateIndex) {
-//            resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
-//            return;
-//        }
-//        int objectIndex = predicateTable.getObjectIndex(predicateIndex, pRef & 0xFFFF);
-//        forObjects(graph, resourceKey, predicateKey, objectIndex, procedure, support);
+        SessionImplSocket session = (SessionImplSocket)graph.getSession();
+        ClusterSupport support = session.clusterTranslator;
+        if (DEBUG)
+            System.out.println("ClusterSmall.forObjects3: rk=" + resourceKey + " pk=" + predicateKey);
+        final int resourceIndex = ClusterTraitsBase.getResourceIndexFromResourceKey(resourceKey);
+        final int pRef = getInternalReferenceOrZero2(predicateKey, support);
+        final int completeType = ClusterTraitsBase.getCompleteTypeIntFromResourceKey(predicateKey);
+        final ClusterI.CompleteTypeEnum pCompleteType = CompleteTypeEnum.make(completeType);
+        if (completeType > 0) {
+            resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
+            return;
+        }
+        final int predicateIndex = (int)resourceTable.table[(resourceIndex<<1) - 1 + resourceTable.offset] & 0xFFFFFF;
+        if (0 == predicateIndex) {
+            resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
+            return;
+        }
+        int objectIndex = predicateTable.getObjectIndex(predicateIndex, pRef & 0xFFFF);
+        forObjects(graph, resourceKey, predicateKey, objectIndex, procedure, support);
+        
     }
 
     public void forObjects(ReadGraphImpl graph, int resourceKey, ForEachObjectProcedure procedure) throws DatabaseException {
index a7635bedfbb676c337870027bcb85550494766e5..639c90391f8c73351cb9c2e86211e7755d5953d0 100644 (file)
@@ -21,6 +21,7 @@ import org.simantics.browsing.ui.PrimitiveQueryUpdater;
 import org.simantics.browsing.ui.common.labelers.LabelerContent;
 import org.simantics.browsing.ui.common.labelers.LabelerStub;
 import org.simantics.browsing.ui.graph.impl.request.ResourceQuery;
+import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.procedure.Listener;
@@ -92,7 +93,7 @@ public abstract class LazyGraphLabeler extends LabelerStub {
 
         if (content == LabelerContent.NO_CONTENT) {
 
-            final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+            final DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
             assert(source != null);
             source.schedule(graph -> graph.asyncRequest(labelQuery, procedure));
 
index 91aeb9c5d4539b5e2e4e189fc703b5f2bdd6cb03..c5d96a90a81fac91b86f556acc421e61130eb153 100644 (file)
@@ -11,8 +11,6 @@
  *******************************************************************************/
 package org.simantics.browsing.ui.graph.impl;
 
-import java.util.function.Consumer;
-
 import org.simantics.browsing.ui.BuiltinKeys;
 import org.simantics.browsing.ui.DataSource;
 import org.simantics.browsing.ui.NodeContext;
@@ -20,6 +18,7 @@ import org.simantics.browsing.ui.PrimitiveQueryUpdater;
 import org.simantics.browsing.ui.common.viewpoints.ViewpointStub;
 import org.simantics.browsing.ui.content.Viewpoint;
 import org.simantics.browsing.ui.graph.impl.request.ParametrizedResourceQuery;
+import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.procedure.Listener;
@@ -135,7 +134,7 @@ public abstract class LazyParametrizedViewpoint extends ViewpointStub {
        @Override
        public NodeContext[] getChildren() {
                if (children == Viewpoint.PENDING_CHILDREN) {
-                       DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+                       DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
                        if (source != null) {
                                source.schedule(graph -> graph.asyncRequest(childQuery, childQueryProcedure));
                        }
@@ -147,17 +146,11 @@ public abstract class LazyParametrizedViewpoint extends ViewpointStub {
        @Override
        public Boolean getHasChildren() {
                if (hasChildren == Viewpoint.PENDING_HAS_CHILDREN) {
-                       DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+                       DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
                        if (source != null) {
-                               source.schedule(new Consumer<ReadGraph>() {
-                                       @Override
-                                       public void accept(ReadGraph source) {
-                                               source.asyncRequest(hasChildQuery, hasChildQueryProcedure);
-                                       }
-                               });
+                               source.schedule(graph -> graph.asyncRequest(hasChildQuery, hasChildQueryProcedure));
                        }
                }
-
                return hasChildren;
        }
 
index c694ba2e88291a52661a178438e60afc2ddc17be..808193a18982d11d672a26d7984dc34f20146e06 100644 (file)
  *******************************************************************************/
 package org.simantics.browsing.ui.graph.impl;
 
-import java.util.function.Consumer;
-
 import org.simantics.browsing.ui.DataSource;
 import org.simantics.browsing.ui.NodeContext;
 import org.simantics.browsing.ui.NodeContext.PrimitiveQueryKey;
 import org.simantics.browsing.ui.PrimitiveQueryProcessor;
 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
 import org.simantics.browsing.ui.graph.impl.request.ResourceQuery;
+import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.procedure.Listener;
@@ -113,19 +112,10 @@ public abstract class LazyResourceQueryContainer<Result> implements Container<Re
 
         if (!computed) {
 
-            final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+            final DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
             assert(source != null);
 
-            source.schedule(new Consumer<ReadGraph>() {
-
-                @Override
-                public void accept(ReadGraph source) {
-
-                    source.asyncRequest(query, procedure);
-
-                }
-
-            });
+            source.schedule(graph -> graph.asyncRequest(query, procedure));
 
         }
 
index a760c848a793d0d87fed012a684087e33930d5cb..a86a172d8911b5f530755ab900941b20e9c8e150 100644 (file)
@@ -11,8 +11,6 @@
  *******************************************************************************/
 package org.simantics.browsing.ui.graph.impl;
 
-import java.util.function.Consumer;
-
 import org.simantics.browsing.ui.BuiltinKeys;
 import org.simantics.browsing.ui.DataSource;
 import org.simantics.browsing.ui.NodeContext;
@@ -20,6 +18,7 @@ import org.simantics.browsing.ui.PrimitiveQueryUpdater;
 import org.simantics.browsing.ui.common.viewpoints.ViewpointStub;
 import org.simantics.browsing.ui.content.Viewpoint;
 import org.simantics.browsing.ui.graph.impl.request.ResourceQuery;
+import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.procedure.Listener;
@@ -149,14 +148,9 @@ public abstract class LazyViewpoint extends ViewpointStub {
     public NodeContext[] getChildren() {
 
         if (children == Viewpoint.PENDING_CHILDREN) {
-            DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+            DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
             final Listener<NodeContext[]> childProcedure = createListener();
-            source.schedule(new Consumer<ReadGraph>() {
-                @Override
-                public void accept(ReadGraph source) {
-                    source.asyncRequest(childQuery, childProcedure);
-                }
-            });
+            source.schedule(graph -> graph.asyncRequest(childQuery, childProcedure));
         }
 
         return children;
index 68bf689138841314bf6cf043ddfabc7ab63c7ea8..d6813edbbcabb6ee91878378bfa13794713ff07e 100644 (file)
@@ -69,7 +69,7 @@ abstract public class CallbackViewpointContributionImpl extends ContributionStub
         //System.out.println("LazyViewpoint2@" + System.identityHashCode(this) + " getChildren() = " + children.length);
 
         if (children == org.simantics.browsing.ui.content.ViewpointContribution.PENDING_CONTRIBUTION) {
-            DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+            DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
             if (source != null) {
                 source.schedule(graph -> {
                     ReadRequest childQuery = new ReadRequest() {
index 4c28fae2bb460f3b1a9aca3bd36c7be09ea2c8eb..9754fc8065ac7e4a0b547cf2ef829f74d3440d7f 100644 (file)
@@ -18,6 +18,7 @@ import org.simantics.browsing.ui.DataSource;
 import org.simantics.browsing.ui.NodeContext;
 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
 import org.simantics.browsing.ui.graph.impl.request.ResourceQuery;
+import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.procedure.Listener;
@@ -43,7 +44,7 @@ public abstract class FinalCheckedStateContributionImpl {
        
        if (state == null) {
 
-            final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+            final DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
             assert(source != null);
 
             source.schedule(graph -> {
index 6acaffa43963f941dedb5d0d187e36807dc30a66..833db059c8fc79056ada3cd495ac266a5c486a2d 100644 (file)
@@ -17,6 +17,7 @@ import org.simantics.browsing.ui.NodeContext;
 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
 import org.simantics.browsing.ui.content.ImageDecorator;
 import org.simantics.browsing.ui.graph.impl.request.ResourceQuery;
+import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.exception.PendingVariableException;
@@ -49,7 +50,7 @@ public abstract class FinalImageDecoratorContributionImpl implements ImageDecora
 
     private void request() {
 
-        final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+        final DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
         assert(source != null);
 
         final Procedure<ImageDecorator> procedure = createProcedure();
index b4d233e0882289b59862157d11f872871376e52f..833e6ef19a76dede68f037d557d4792a4820f5aa 100644 (file)
@@ -22,6 +22,7 @@ import org.simantics.browsing.ui.NodeContext;
 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
 import org.simantics.browsing.ui.content.Imager;
 import org.simantics.browsing.ui.graph.impl.request.ResourceQuery;
+import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.exception.PendingVariableException;
@@ -107,7 +108,7 @@ public abstract class FinalImagerContributionImpl implements Imager {
 
             content = PENDING;
 
-            final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+            final DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
             assert(source != null);
 
             final Procedure<Map<String, ImageDescriptor>> procedure = createProcedure();
index 3459990009ede231ba7259c4d8535638dd363a5c..fa1945dfff2b41e235922f667bcce31225465058 100644 (file)
@@ -17,6 +17,7 @@ import org.simantics.browsing.ui.NodeContext;
 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
 import org.simantics.browsing.ui.content.LabelDecorator;
 import org.simantics.browsing.ui.graph.impl.request.ResourceQuery;
+import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.procedure.Listener;
@@ -48,7 +49,7 @@ public abstract class FinalLabelDecoratorContributionImpl extends LabelDecorator
 
     private void request() {
 
-        final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+        final DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
         assert(source != null);
         
         final Procedure<LabelDecorator> procedure = createProcedure();
index b283d662e76f92b3b50148ecf6e264585a9adf4b..ed56886944644b453c3d6f07d6c4a7cfc9a3337c 100644 (file)
@@ -25,6 +25,7 @@ import org.simantics.browsing.ui.common.labelers.LabelerContent;
 import org.simantics.browsing.ui.common.labelers.LabelerStub;
 import org.simantics.browsing.ui.common.node.IModifiableNode;
 import org.simantics.browsing.ui.graph.impl.request.ResourceQuery;
+import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.UndoContext;
 import org.simantics.db.common.utils.Logger;
@@ -115,7 +116,7 @@ public abstract class FinalLabelerContributionImpl extends LabelerStub {
 
         if (content == LabelerContent.NO_CONTENT) {
 
-            final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+            final DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
             assert(source != null);
 
             final Procedure<LabelerContent> procedure = createProcedure();
index f514fa48c9aeee4daeda1684e2c1e158f47a35cd..e1dbd4f5234b21a8e12415b86b1591ee9b58cdcf 100644 (file)
@@ -130,7 +130,7 @@ abstract public class FinalViewpointContributionImpl extends ContributionStub im
         //System.out.println("LazyViewpoint2@" + System.identityHashCode(this) + " getChildren() = " + children.length);
 
         if (children == org.simantics.browsing.ui.content.ViewpointContribution.PENDING_CONTRIBUTION) {
-            DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+            DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
             if (source != null) {
                 source.schedule(graph -> {
                     if(childProcedure instanceof Listener<?>)
index b05ec52cd8dd199bf04d81dcfc7735d1dba87e19..f0ac2886df4121bcd59921b225dd35eab588285c 100644 (file)
@@ -25,7 +25,6 @@ Export-Package: org.simantics.db.common,
  org.simantics.db.common.internal.config;x-friends:="org.simantics.db.procore",
  org.simantics.db.common.issue,
  org.simantics.db.common.primitiverequest,
- org.simantics.db.common.procedure,
  org.simantics.db.common.procedure.adapter,
  org.simantics.db.common.procedure.guarded,
  org.simantics.db.common.procedure.single,
index 541aee94e10d31c50480f7a2508a3f432face183..6e0a3c0b5a6f126d8bde01fb739290adf844265f 100644 (file)
  *******************************************************************************/
 package org.simantics.db.common.primitiverequest;
 
-import java.util.Collection;
-
 import org.simantics.db.AsyncReadGraph;
-import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
-import org.simantics.db.common.request.ResourceRead2;
-import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.common.request.ResourceAsyncMultiRead2;
 import org.simantics.db.procedure.AsyncMultiProcedure;
-import org.simantics.db.service.CollectionSupport;
-import org.simantics.utils.DataContainer;
 
-final public class ForEachAssertedObject extends ResourceRead2<Collection<Resource>> {
+final public class ForEachAssertedObject extends ResourceAsyncMultiRead2<Resource> {
 
     public ForEachAssertedObject(Resource subject, Resource relation) {
         super(subject, relation);
     }
 
        @Override
-       public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
-               CollectionSupport cs = graph.getService(CollectionSupport.class);
-               Collection<Resource> result = cs.createSet();
-               DataContainer<Throwable> throwable = new DataContainer<Throwable>(null);
-               graph.forEachAssertedObject(resource, resource2, new AsyncMultiProcedure<Resource>() {
-                       
-                       @Override
-                       public void finished(AsyncReadGraph graph) {
-                       }
-                       
-                       @Override
-                       public void execute(AsyncReadGraph graph, Resource r) {
-                               result.add(r);
-                       }
-                       
-                       @Override
-                       public void exception(AsyncReadGraph graph, Throwable t) {
-                               throwable.set(t);
-                       }
-               });
-               Throwable t = throwable.get();
-               if(t != null)
-                       if(t instanceof DatabaseException)
-                               throw (DatabaseException)t;
-                       else throw new DatabaseException(t);
-               return result;
+       public void perform(AsyncReadGraph graph, AsyncMultiProcedure<Resource> procedure) {
+               graph.forEachAssertedObject(resource, resource2, procedure);
        }
 
 }
index 59a66aeaa7fb8ba7f61e50663c2835c68cb3d4db..7064e09bcddfe7d9936009ee720c6c1779c6c35d 100644 (file)
@@ -15,6 +15,7 @@ import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.RelationInfo;
 import org.simantics.db.Resource;
 import org.simantics.db.common.request.ResourceAsyncRead;
+import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.procedure.AsyncProcedure;
 import org.simantics.db.service.DirectQuerySupport;
 
@@ -27,7 +28,11 @@ final public class RelationInfoRequest extends ResourceAsyncRead<RelationInfo> {
        @Override
        public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
                DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
-               dqs.forRelationInfo(graph, resource, procedure);
+               try {
+                       procedure.execute(graph, dqs.getRelationInfo(graph, resource));
+               } catch (DatabaseException e) {
+                       procedure.exception(graph, e);
+               }
        }
        
 }
diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/BlockingAsyncProcedure.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/BlockingAsyncProcedure.java
deleted file mode 100644 (file)
index da3ec4a..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
- * in Industry THTH ry.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     VTT Technical Research Centre of Finland - initial API and implementation
- *******************************************************************************/
-package org.simantics.db.common.procedure;
-
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.simantics.db.AsyncReadGraph;
-import org.simantics.db.common.utils.Logger;
-import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.procedure.AsyncProcedure;
-
-public class BlockingAsyncProcedure<Result> implements AsyncProcedure<Result> {
-
-       final private Object key;
-    private Result result = null;
-    private Throwable exception = null;
-    final private AsyncReadGraph graph;
-    final private AsyncProcedure<Result> procedure;
-    final private Semaphore semaphore = new Semaphore(0);
-//    final private AtomicBoolean latch;
-    
-    public BlockingAsyncProcedure(AsyncReadGraph graph, AsyncProcedure<Result> procedure, Object key) {
-//     assert(procedure != null);
-       this.graph = graph;
-       this.key = key;
-        this.procedure = procedure;
-        if(key == null)
-               System.err.println("asd");
-        //System.err.println("BlockingAsyncProcedure " + key);
-//        latch = new AtomicBoolean(false);
-    }
-    
-    @Override
-    public void execute(AsyncReadGraph graph, Result result) {
-        this.result = result;
-        semaphore.release();
-//        if(latch.compareAndSet(false, true)) {
-               try {
-                       if(procedure != null) procedure.execute(graph, result);
-               } catch (Throwable throwable) {
-               Logger.defaultLogError("AsyncProcedure.execute threw for " + procedure, throwable);
-               }
-//             } finally {
-////                   System.err.println("ResultCallWrappedSingleQueryProcedure4 dec " + key);
-//             }
-//        } else {
-//             Logger.defaultLogError("Procedure was called many times (this time is execute)");
-//        }
-    }
-
-    @Override
-    public void exception(AsyncReadGraph graph, Throwable t) {
-        this.exception = t;
-        semaphore.release();
-//        if(latch.compareAndSet(false, true)) {
-               try {
-                       if(procedure != null) procedure.exception(graph, t);
-               } catch (Throwable throwable) {
-               Logger.defaultLogError("AsyncProcedure.exception threw for " + procedure, throwable);
-               } finally {
-               }
-//        } else {
-//             Logger.defaultLogError("Procedure was called many times (this time is exception)");
-//        }
-        
-    }
-    
-    private void waitFor() throws DatabaseException {
-
-       boolean success = false;
-       success = semaphore.tryAcquire();
-       if(success) return;
-       
-       while(!success) {
-               
-               if(graph.performPending()) {
-                       // Some task was done
-                       success = semaphore.tryAcquire();               
-               } else {
-                       // Nothing to do - just wait
-               try {
-                               success = semaphore.tryAcquire(10, TimeUnit.SECONDS);
-                               if(!success) throw new DatabaseException("Timeout while waiting for async request to complete: " + key);
-                       } catch (InterruptedException e) {
-                               throw new DatabaseException(e);
-                       }
-               }
-                               
-       }
-       
-    }
-    
-    public Result get() throws DatabaseException {
-
-       waitFor();
-       
-       if(exception != null) {
-               if(exception instanceof DatabaseException) throw (DatabaseException)exception;
-               throw new DatabaseException(exception);
-       } else {
-               return result;
-       }
-       
-    }
-    
-    public Result getResult() {
-        return result;
-    }
-    
-    public Throwable getException() {
-        return exception;
-    }
-       
-    @Override
-    public String toString() {
-        return "." + procedure; 
-    }
-    
-}
index 0628507d9e6fe7789b9b8cc5dc6cf12c36fad223..89b59d27d85e85e6fc08ec5c8fd8e2b921a4fbed 100644 (file)
 package org.simantics.db.common.procedure.single;
 
 import org.simantics.db.ReadGraph;
-import org.simantics.db.common.procedure.adapter.AsyncListenerSupport;
+import org.simantics.db.common.procedure.adapter.SyncListenerSupport;
 
 abstract public class SingleSetSyncListenerDelegate<T> extends SingleSetSyncListener<T> {
     
-    final private AsyncListenerSupport support;
+    final private SyncListenerSupport support;
     
-    public SingleSetSyncListenerDelegate(AsyncListenerSupport support) {
+    public SingleSetSyncListenerDelegate(SyncListenerSupport support) {
         this.support = support;
     }
 
diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/wrapper/NoneToSyncMultiListener.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/wrapper/NoneToSyncMultiListener.java
new file mode 100644 (file)
index 0000000..b116791
--- /dev/null
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.common.procedure.wrapper;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.procedure.MultiListener;
+import org.simantics.db.procedure.SyncMultiListener;
+
+public class NoneToSyncMultiListener<T> implements SyncMultiListener<T> {
+
+       final private MultiListener<T> procedure;
+
+       public NoneToSyncMultiListener(MultiListener<T> procedure) {
+               this.procedure = procedure;
+       }
+       
+       @Override
+       public void execute(ReadGraph graph, final T result) {
+           procedure.execute(result);
+       }
+
+       @Override
+       public void finished(ReadGraph graph) {
+           procedure.finished();
+       }
+
+       @Override
+       public void exception(ReadGraph graph, Throwable t) {
+           procedure.exception(t);
+       }
+
+    @Override
+    public boolean isDisposed() {
+        return procedure.isDisposed();
+    }
+
+    @Override
+    public String toString() {
+        return "NoneToAsyncMultiListener -> " + procedure;
+   }
+    
+}
diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/wrapper/NoneToSyncMultiProcedure.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/wrapper/NoneToSyncMultiProcedure.java
new file mode 100644 (file)
index 0000000..bb7b304
--- /dev/null
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.common.procedure.wrapper;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.procedure.MultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
+
+public class NoneToSyncMultiProcedure<T> implements SyncMultiProcedure<T> {
+
+       final private MultiProcedure<T> procedure;
+
+       public NoneToSyncMultiProcedure(MultiProcedure<T> procedure) {
+               this.procedure = procedure;
+       }
+       
+       @Override
+       public void execute(ReadGraph graph, final T result) {
+           procedure.execute(result);
+       }
+
+       @Override
+       public void finished(ReadGraph graph) {
+           procedure.finished();
+       }
+
+       @Override
+       public void exception(ReadGraph graph, Throwable t) {
+               procedure.exception(t);
+       }
+       
+    @Override
+    public String toString() {
+        return "NoneToAsyncMultiProcedure -> " + procedure;
+   }
+
+}
index bf72e041648e4d11c4e0e4b1de8506b8e8397cf2..aeec2480e207b68a0c69de6dbff724f697d51cd2 100644 (file)
@@ -24,12 +24,12 @@ import java.util.function.Consumer;
 import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.AsyncRequestProcessor;
 import org.simantics.db.ReadGraph;
-import org.simantics.db.RequestProcessor;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.procedure.adapter.AsyncMultiProcedureAdapter;
 import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
+import org.simantics.db.common.procedure.adapter.SyncMultiProcedureAdapter;
 import org.simantics.db.common.procedure.wrapper.NoneToAsyncProcedure;
 import org.simantics.db.common.request.ReadRequest;
 import org.simantics.db.common.request.WriteRequest;
@@ -64,7 +64,7 @@ import org.simantics.db.request.WriteResult;
 import org.simantics.utils.DataContainer;
 import org.simantics.utils.datastructures.Pair;
 
-public class MergingGraphRequestProcessor implements RequestProcessor {
+public class MergingGraphRequestProcessor implements AsyncRequestProcessor {
 
     private static class SyncWriteRequestAdapter implements Write {
 
@@ -264,11 +264,11 @@ public class MergingGraphRequestProcessor implements RequestProcessor {
 
                                Logger.defaultLogError(t);
 
-                        if(currentRequest.second instanceof AsyncProcedure<?>) {
-                            ((AsyncProcedure<?>)currentRequest.second).exception(graph, t);
-                        } else {
-                            ((AsyncMultiProcedure<?>)currentRequest.second).exception(graph, t);
-                        }
+//                        if(currentRequest.second instanceof AsyncProcedure<?>) {
+//                            ((AsyncProcedure<?>)currentRequest.second).exception(graph, t);
+//                        } else {
+//                            ((AsyncMultiProcedure<?>)currentRequest.second).exception(graph, t);
+//                        }
 
                     }
 
@@ -286,25 +286,25 @@ public class MergingGraphRequestProcessor implements RequestProcessor {
                         if(currentRequest.second instanceof AsyncProcedure<?>) {
                             if(currentRequest.first instanceof AsyncRead) {
                                 AsyncRead req = (AsyncRead)currentRequest.first;
-                                graph.asyncRequest(req, (AsyncProcedure<?>)currentRequest.second);
+                                graph.syncRequest(req, (AsyncProcedure<?>)currentRequest.second);
                             } else {
                                 Read req = (Read)currentRequest.first;
-                                graph.asyncRequest(req, (AsyncProcedure<?>)currentRequest.second);
+                                graph.syncRequest(req, (AsyncProcedure<?>)currentRequest.second);
                             }
                         } else {
                             AsyncMultiRead req = (AsyncMultiRead)currentRequest.first;
-                            graph.asyncRequest(req, (AsyncMultiProcedure<?>)currentRequest.second);
+                            graph.syncRequest(req, (AsyncMultiProcedure<?>)currentRequest.second);
                         }
 
                     } catch(Throwable t) {
 
                                Logger.defaultLogError(t);
 
-                        if(currentRequest.second instanceof AsyncProcedure<?>) {
-                            ((AsyncProcedure<?>)currentRequest.second).exception(graph, t);
-                        } else {
-                            ((AsyncMultiProcedure<?>)currentRequest.second).exception(graph, t);
-                        }
+//                        if(currentRequest.second instanceof AsyncProcedure<?>) {
+//                            ((AsyncProcedure<?>)currentRequest.second).exception(graph, t);
+//                        } else {
+//                            ((AsyncMultiProcedure<?>)currentRequest.second).exception(graph, t);
+//                        }
 
                     }
                 }
@@ -917,17 +917,17 @@ public class MergingGraphRequestProcessor implements RequestProcessor {
         final ArrayList<T> result = new ArrayList<T>();
         final DataContainer<Throwable> exception = new DataContainer<Throwable>();
 
-        syncRequest(request, new AsyncMultiProcedureAdapter<T>() {
+        syncRequest(request, new SyncMultiProcedureAdapter<T>() {
 
             @Override
-            public void execute(AsyncReadGraph graph, T t) {
+            public void execute(ReadGraph graph, T t) {
                 synchronized(result) {
                     result.add(t);
                 }
             }
 
             @Override
-            public void exception(AsyncReadGraph graph, Throwable t) {
+            public void exception(ReadGraph graph, Throwable t) {
                 exception.set(t);
             }
 
@@ -947,11 +947,6 @@ public class MergingGraphRequestProcessor implements RequestProcessor {
         return result;
     }
 
-    @Override
-    public <T> Collection<T> syncRequest(MultiRead<T> request, AsyncMultiProcedure<T> procedure)  {
-        throw new UnsupportedOperationException("Not implemented");
-    }
-
     @Override
     public <T> Collection<T> syncRequest(MultiRead<T> request, MultiProcedure<T> procedure) {
         throw new UnsupportedOperationException("Not implemented");
@@ -967,11 +962,6 @@ public class MergingGraphRequestProcessor implements RequestProcessor {
         throw new UnsupportedOperationException("Not implemented");
     }
 
-    @Override
-    public <T> void asyncRequest(MultiRead<T> request, AsyncMultiProcedure<T> procedure) {
-        throw new UnsupportedOperationException("Not implemented");
-    }
-
     @Override
     public <T> void asyncRequest(MultiRead<T> request, MultiProcedure<T> procedure) {
         throw new UnsupportedOperationException("Not implemented");
@@ -1103,11 +1093,11 @@ public class MergingGraphRequestProcessor implements RequestProcessor {
 
     }
 
-    @Override
+/*    @Override
     public <T> Collection<T> syncRequest(MultiRead<T> arg0, AsyncMultiListener<T> arg1) {
         throw new UnsupportedOperationException("Not implemented.");
 
-    }
+    }*/
 
     @Override
     public <T> Collection<T> syncRequest(MultiRead<T> arg0, SyncMultiListener<T> arg1) {
@@ -1153,12 +1143,6 @@ public class MergingGraphRequestProcessor implements RequestProcessor {
 
     }
 
-    @Override
-    public <T> void asyncRequest(MultiRead<T> arg0, AsyncMultiListener<T> arg1) {
-        throw new UnsupportedOperationException("Not implemented.");
-
-    }
-
     @Override
     public <T> void asyncRequest(MultiRead<T> arg0, SyncMultiListener<T> arg1) {
         throw new UnsupportedOperationException("Not implemented.");
index 6e1aeabaae4d3b47a8a3624e73c2e64a366c8854..62c359ff35cb31d536338d85e1a3e5982af52362 100644 (file)
@@ -14,7 +14,7 @@ package org.simantics.db.common.processor;
 import java.util.Collection;
 import java.util.function.Consumer;
 
-import org.simantics.db.RequestProcessor;
+import org.simantics.db.AsyncRequestProcessor;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.exception.DatabaseException;
@@ -44,7 +44,7 @@ import org.simantics.db.request.WriteOnly;
 import org.simantics.db.request.WriteOnlyResult;
 import org.simantics.db.request.WriteResult;
 
-public class ProcessorBase implements RequestProcessor {
+public class ProcessorBase implements AsyncRequestProcessor {
 
     @Override
     public <T> void asyncRequest(AsyncMultiRead<T> request, AsyncMultiProcedure<T> procedure) {
@@ -173,11 +173,6 @@ public class ProcessorBase implements RequestProcessor {
         throw new UnsupportedOperationException();
     }
 
-    @Override
-    public <T> Collection<T> syncRequest(MultiRead<T> request, AsyncMultiProcedure<T> procedure)  {
-        throw new UnsupportedOperationException();
-    }
-
     @Override
     public <T> Collection<T> syncRequest(MultiRead<T> request, MultiProcedure<T> procedure) {
         throw new UnsupportedOperationException();
@@ -193,11 +188,6 @@ public class ProcessorBase implements RequestProcessor {
         throw new UnsupportedOperationException();
     }
 
-    @Override
-    public <T> void asyncRequest(MultiRead<T> request, AsyncMultiProcedure<T> procedure) {
-        throw new UnsupportedOperationException();
-    }
-
     @Override
     public <T> void asyncRequest(MultiRead<T> request, MultiProcedure<T> procedure) {
         throw new UnsupportedOperationException();
@@ -313,10 +303,10 @@ public class ProcessorBase implements RequestProcessor {
         throw new UnsupportedOperationException();
     }
 
-    @Override
+/*    @Override
     public <T> Collection<T> syncRequest(MultiRead<T> arg0, AsyncMultiListener<T> arg1) {
         throw new UnsupportedOperationException();
-    }
+    }*/
 
     @Override
     public <T> Collection<T> syncRequest(MultiRead<T> arg0, SyncMultiListener<T> arg1) {
@@ -355,11 +345,6 @@ public class ProcessorBase implements RequestProcessor {
         throw new UnsupportedOperationException();
     }
 
-    @Override
-    public <T> void asyncRequest(MultiRead<T> arg0, AsyncMultiListener<T> arg1) {
-        throw new UnsupportedOperationException();
-    }
-
     @Override
     public <T> void asyncRequest(MultiRead<T> arg0, SyncMultiListener<T> arg1) {
         throw new UnsupportedOperationException();
diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/request/UniqueAsyncRead.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/request/UniqueAsyncRead.java
new file mode 100644 (file)
index 0000000..e71d577
--- /dev/null
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.common.request;
+
+import org.simantics.db.request.AsyncRead;
+
+public abstract class UniqueAsyncRead<T> implements AsyncRead<T> {
+
+    @Override
+    public int getFlags() {
+        return 0;
+    }
+
+    @Override
+    public int threadHash() {
+       return hashCode();
+    }
+
+}
index eb0ca24b6a5fa32e318936dfbfe54ce5a8a42f79..4201cb80a1cfc6684bf92afee35538ddc7a0b77f 100644 (file)
@@ -238,7 +238,7 @@ public class OrderedSetUtils {
     /**
      * Converts ordered set into a list.
      */
-    public static void forEach(AsyncReadGraph g, final Resource l, final AsyncMultiProcedure<Resource> procedure) {
+    /*public static void forEach(AsyncReadGraph g, final Resource l, final AsyncMultiProcedure<Resource> procedure) {
         g.asyncRequest(new ReadRequest() {
 
             @Override
@@ -248,7 +248,7 @@ public class OrderedSetUtils {
             }
 
         });
-    }
+    }*/
 
     /**
      * Creates an empty ordered set.
index 9e5d563a51205fd2855400458fac64bf69111ff5..96d915482e53b91efb9f5e536d7d0e0d480a3868 100644 (file)
@@ -18,6 +18,7 @@ import java.util.function.Consumer;
 import org.simantics.databoard.accessor.Accessor;
 import org.simantics.databoard.binding.Binding;
 import org.simantics.databoard.type.Datatype;
+import org.simantics.db.AsyncRequestProcessor;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.RequestProcessor;
 import org.simantics.db.Resource;
@@ -150,11 +151,11 @@ public class Transaction {
                }
        }
        
-       public static void startTransaction(RequestProcessor processor, boolean write) throws DatabaseException {
+       public static void startTransaction(AsyncRequestProcessor processor, boolean write) throws DatabaseException {
                startTransaction(processor, write ? Type.WRITE : Type.READ);
        }
        
-       public static void startTransaction(RequestProcessor processor, Type type) throws DatabaseException {
+       public static void startTransaction(AsyncRequestProcessor processor, Type type) throws DatabaseException {
                switch (type) {
                        case READ:
                        {
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/BlockingAsyncProcedure.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/BlockingAsyncProcedure.java
new file mode 100644 (file)
index 0000000..943322c
--- /dev/null
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.impl;
+
+import java.text.DecimalFormat;
+import java.util.concurrent.TimeUnit;
+
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.impl.graph.AsyncBarrierImpl;
+import org.simantics.db.impl.graph.ReadGraphImpl;
+import org.simantics.db.procedure.AsyncProcedure;
+
+public class BlockingAsyncProcedure<Result> implements AsyncProcedure<Result> {
+
+       final private Object key;
+    final private ReadGraphImpl graph;
+       final private AsyncProcedure<Result> procedure;
+       
+    private Result result = null;
+    private Throwable exception = null;
+    
+    public BlockingAsyncProcedure(ReadGraphImpl graph, AsyncProcedure<Result> procedure, Object key) {
+       this.procedure = procedure;
+       this.key = key;
+       this.graph = ReadGraphImpl.newAsync(graph);
+        this.graph.asyncBarrier.inc();
+    }
+    
+    @Override
+    public void execute(AsyncReadGraph graph, Result result) {
+        this.result = result;
+        this.graph.asyncBarrier.dec();
+        try {
+               if(procedure != null) procedure.execute(graph, result);
+        } catch (Throwable throwable) {
+               Logger.defaultLogError("AsyncProcedure.execute threw for " + procedure, throwable);
+        }
+    }
+
+    @Override
+    public void exception(AsyncReadGraph graph, Throwable t) {
+        this.exception = t;
+        try {
+               if(procedure != null) procedure.exception(graph, t);
+        } catch (Throwable throwable) {
+               Logger.defaultLogError("AsyncProcedure.exception threw for " + procedure, throwable);
+        } finally {
+        }
+        this.graph.asyncBarrier.dec();
+    }
+    
+    public Result get() throws DatabaseException {
+       
+       graph.asyncBarrier.waitBarrier(key, graph);
+       
+       if(exception != null) {
+               if(exception instanceof DatabaseException) throw (DatabaseException)exception;
+               throw new DatabaseException(exception);
+       } else {
+               return result;
+       }
+       
+    }
+    
+    public Result getResult() {
+        return result;
+    }
+    
+    public Throwable getException() {
+        return exception;
+    }
+       
+    @Override
+    public String toString() {
+        return "." + procedure; 
+    }
+    
+}
index 87acea43d4801c388154f5738b08f0b2428ed55d..a82a7490f3e1f506051b794c7cc17d3bf91fa5a1 100644 (file)
@@ -17,7 +17,7 @@ import java.util.function.Consumer;
 import org.simantics.db.Resource;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.impl.graph.ReadGraphImpl;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.db.service.ClusterUID;
 
 public interface ClusterI {
@@ -114,7 +114,7 @@ public interface ClusterI {
     public <C, T> int getSingleObject(int resourceKey, ForPossibleRelatedValueContextProcedure<C, T> procedure, ClusterSupport support)
     throws DatabaseException;
 
-    public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, AsyncMultiProcedure<Resource> procedure)
+    public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, SyncMultiProcedure<Resource> procedure)
     throws DatabaseException;
 
     public void forObjects(ReadGraphImpl graph, int resourceKey, ForEachObjectProcedure procedure)
index 188917994a26881ccafe58a313ac6cb4559c2a67..6bec3b7074b540f34f5970cd20bd73cbc113892f 100644 (file)
@@ -1,12 +1,13 @@
 package org.simantics.db.impl;
 
-import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
 import org.simantics.db.RelationInfo;
 import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.impl.query.QueryProcessor;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
 
-public final class ForEachObjectContextProcedure<C> implements AsyncContextMultiProcedure<C, Resource> {
+public final class ForEachObjectContextProcedure<C> implements SyncContextMultiProcedure<C, Resource> {
 
        public final int predicateKey;
        public final int[] clusterKey;
@@ -14,9 +15,9 @@ public final class ForEachObjectContextProcedure<C> implements AsyncContextMulti
        public final RelationInfo info;
        public final QueryProcessor processor;
        public final ClusterI.CompleteTypeEnum completeType;
-       private final AsyncContextMultiProcedure<C, Resource> user;
+       private final SyncContextMultiProcedure<C, Resource> user;
        
-       public ForEachObjectContextProcedure(int predicateKey, RelationInfo info, QueryProcessor processor, AsyncContextMultiProcedure<C, Resource> user) {
+       public ForEachObjectContextProcedure(int predicateKey, RelationInfo info, QueryProcessor processor, SyncContextMultiProcedure<C, Resource> user) {
                this.predicateKey = predicateKey;
                this.completeType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey); 
                this.info = info;
@@ -27,17 +28,17 @@ public final class ForEachObjectContextProcedure<C> implements AsyncContextMulti
        }
        
        @Override
-       public void execute(AsyncReadGraph graph, C context, Resource result) {
+       public void execute(ReadGraph graph, C context, Resource result) throws DatabaseException {
                user.execute(graph, context, result);
        }
 
        @Override
-       public void finished(AsyncReadGraph graph, C context) {
+       public void finished(ReadGraph graph, C context) throws DatabaseException {
                user.finished(graph, context);
        }
 
        @Override
-       public void exception(AsyncReadGraph graph, Throwable throwable) {
+       public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException {
                user.exception(graph, throwable);
        }
        
index 85790c4de02cbcce7b5b2d4b209a43ae6782625b..143d0a1868dc8b52be43ae91fff3b969b61a063b 100644 (file)
@@ -1,12 +1,13 @@
 package org.simantics.db.impl;
 
-import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
 import org.simantics.db.RelationInfo;
 import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.impl.query.QueryProcessor;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 
-public final class ForEachObjectProcedure implements AsyncMultiProcedure<Resource> {
+public final class ForEachObjectProcedure implements SyncMultiProcedure<Resource> {
 
        public final int predicateKey;
        public final int[] clusterKey;
@@ -14,9 +15,9 @@ public final class ForEachObjectProcedure implements AsyncMultiProcedure<Resourc
        public final RelationInfo info;
        public final QueryProcessor processor;
        public final ClusterI.CompleteTypeEnum completeType;
-       private final AsyncMultiProcedure<Resource> user;
+       private final SyncMultiProcedure<Resource> user;
        
-       public ForEachObjectProcedure(int predicateKey, RelationInfo info, QueryProcessor processor, AsyncMultiProcedure<Resource> user) {
+       public ForEachObjectProcedure(int predicateKey, RelationInfo info, QueryProcessor processor, SyncMultiProcedure<Resource> user) {
                this.predicateKey = predicateKey;
                this.completeType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey); 
                this.info = info;
@@ -27,17 +28,17 @@ public final class ForEachObjectProcedure implements AsyncMultiProcedure<Resourc
        }
        
        @Override
-       public void execute(AsyncReadGraph graph, Resource result) {
+       public void execute(ReadGraph graph, Resource result) throws DatabaseException {
                user.execute(graph, result);
        }
 
        @Override
-       public void finished(AsyncReadGraph graph) {
+       public void finished(ReadGraph graph) throws DatabaseException {
                user.finished(graph);
        }
 
        @Override
-       public void exception(AsyncReadGraph graph, Throwable throwable) {
+       public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException {
                user.exception(graph, throwable);
        }
        
index 0225656d5b9f3a7a584ea5811a65a8df6c4be0a9..d16853cdcbf1c380e7395201bef87a548eeee545 100644 (file)
@@ -1,19 +1,19 @@
 package org.simantics.db.impl;
 
-import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
 import org.simantics.db.RelationInfo;
-import org.simantics.db.procedure.AsyncContextProcedure;
+import org.simantics.db.procedure.SyncContextProcedure;
 
-public final class ForPossibleRelatedValueContextProcedure<C, T> implements AsyncContextProcedure<C, T> {
+public final class ForPossibleRelatedValueContextProcedure<C, T> implements SyncContextProcedure<C, T> {
 
        public final int predicateKey;
        public final int[] clusterKey;
        public final int[] predicateReference;
        public final RelationInfo info;
        public final ClusterI.CompleteTypeEnum completeType;
-       private final AsyncContextProcedure<C, T> user;
+       private final SyncContextProcedure<C, T> user;
        
-       public ForPossibleRelatedValueContextProcedure(int predicateKey, RelationInfo info, AsyncContextProcedure<C, T> user) {
+       public ForPossibleRelatedValueContextProcedure(int predicateKey, RelationInfo info, SyncContextProcedure<C, T> user) {
                this.predicateKey = predicateKey;
                this.completeType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey); 
                this.info = info;
@@ -23,12 +23,12 @@ public final class ForPossibleRelatedValueContextProcedure<C, T> implements Asyn
        }
        
        @Override
-       public void execute(AsyncReadGraph graph, C context, T result) {
+       public void execute(ReadGraph graph, C context, T result) {
                user.execute(graph, context, result);
        }
 
        @Override
-       public void exception(AsyncReadGraph graph, Throwable throwable) {
+       public void exception(ReadGraph graph, Throwable throwable) {
                user.exception(graph, throwable);
        }
        
index 6dcb0ea104b30da2fb7442b1ab31495f47029267..bd5e0ccaaac3f81716731f5035f2c8d6ebebbc45 100644 (file)
@@ -1,19 +1,20 @@
 package org.simantics.db.impl;
 
-import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
 import org.simantics.db.RelationInfo;
-import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.SyncProcedure;
 
-public final class ForPossibleRelatedValueProcedure<T> implements AsyncProcedure<T> {
+public final class ForPossibleRelatedValueProcedure<T> implements SyncProcedure<T> {
 
        public final int predicateKey;
        public final int[] clusterKey;
        public final int[] predicateReference;
        public final RelationInfo info;
        public final ClusterI.CompleteTypeEnum completeType;
-       private final AsyncProcedure<T> user;
+       private final SyncProcedure<T> user;
        
-       public ForPossibleRelatedValueProcedure(int predicateKey, RelationInfo info, AsyncProcedure<T> user) {
+       public ForPossibleRelatedValueProcedure(int predicateKey, RelationInfo info, SyncProcedure<T> user) {
                this.predicateKey = predicateKey;
                this.completeType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey); 
                this.info = info;
@@ -23,12 +24,12 @@ public final class ForPossibleRelatedValueProcedure<T> implements AsyncProcedure
        }
        
        @Override
-       public void execute(AsyncReadGraph graph, T result) {
+       public void execute(ReadGraph graph, T result) throws DatabaseException {
                user.execute(graph, result);
        }
 
        @Override
-       public void exception(AsyncReadGraph graph, Throwable throwable) {
+       public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException {
                user.exception(graph, throwable);
        }
        
index f4e722fe5adea864496e4a7864197ae7fb6e877d..adbad4ead40074847330dfab89062514f8d048b0 100644 (file)
@@ -423,7 +423,7 @@ public class TransientGraph implements VirtualGraphImpl, VirtualGraphContext {
     final private SerialisationSupport serialization;
     final private ResourceSupport resourceSupport;
     final private VirtualGraphServerSupport virtualGraphServerSupport;
-    final private RequestProcessor sessionRequestProcessor;
+    final private AsyncRequestProcessor sessionRequestProcessor;
     
     /*
      * Cluster array by index.
@@ -446,17 +446,17 @@ public class TransientGraph implements VirtualGraphImpl, VirtualGraphContext {
 
     int[] EMPTY = new int[0];
 
-    public static TransientGraph workspacePersistent(SerialisationSupport ss, VirtualGraphServerSupport vgss, ResourceSupport rs, RequestProcessor srp, String databaseId, String identifier) throws DatabaseException {
+    public static TransientGraph workspacePersistent(SerialisationSupport ss, VirtualGraphServerSupport vgss, ResourceSupport rs, AsyncRequestProcessor srp, String databaseId, String identifier) throws DatabaseException {
         TransientGraph graph = new TransientGraph(ss, vgss, rs, srp, databaseId, identifier, Persistency.WORKSPACE);
         graph.load();
         return graph;
     }
     
-    public static TransientGraph memoryPersistent(SerialisationSupport ss, VirtualGraphServerSupport vgss, ResourceSupport rs, RequestProcessor srp, String databaseId, String identifier) {
+    public static TransientGraph memoryPersistent(SerialisationSupport ss, VirtualGraphServerSupport vgss, ResourceSupport rs, AsyncRequestProcessor srp, String databaseId, String identifier) {
         return new TransientGraph(ss, vgss, rs, srp, databaseId, identifier, Persistency.MEMORY);
     }
     
-    private TransientGraph(SerialisationSupport ss, VirtualGraphServerSupport vgss, ResourceSupport rs, RequestProcessor srp, String databaseId, String identifier, Persistency persistency) {
+    private TransientGraph(SerialisationSupport ss, VirtualGraphServerSupport vgss, ResourceSupport rs, AsyncRequestProcessor srp, String databaseId, String identifier, Persistency persistency) {
         this.serialization = ss;
         this.virtualGraphServerSupport = vgss;
         this.sessionRequestProcessor = srp;
index c1a1726258eb71e1a4f575f406c967980e27f4f6..4b9f19a2314f3c34658d72e57376cab1ba58ca62 100644 (file)
@@ -15,6 +15,8 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Semaphore;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.simantics.db.common.utils.Logger;
@@ -38,6 +40,8 @@ final public class AsyncBarrierImpl extends AtomicInteger implements AsyncBarrie
        static final boolean RESTART_GUARD = false;
 
        final private AsyncBarrierImpl caller;
+       
+       final private Semaphore sema = new Semaphore(0);
 
        public AsyncBarrierImpl(AsyncBarrierImpl caller) {
                super(0);
@@ -293,8 +297,8 @@ final public class AsyncBarrierImpl extends AtomicInteger implements AsyncBarrie
                        long waitCount = 0;
 
                        while (get() != 0) {
-
-                               boolean executed = impl.processor.resume(impl);
+                               
+                               boolean executed = impl.performPending();
                                if(executed) waitCount = 0;
                                
                                ++waitCount;
index 4695b8b338c02b7a87e85c8985f83a20e54c301a..0f0ad8319413c997e2f932d70ffb4d7eb925f98f 100644 (file)
@@ -4,15 +4,15 @@ import org.simantics.db.Resource;
 import org.simantics.db.common.utils.Logger;
 import org.simantics.db.impl.query.IntProcedure;
 import org.simantics.db.impl.query.QuerySupport;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 
 public class MultiIntProcedure implements IntProcedure {
 
-       final private AsyncMultiProcedure<Resource> procedure;
+       final private SyncMultiProcedure<Resource> procedure;
        final private ReadGraphImpl impl;
        final private QuerySupport support;
        
-       public MultiIntProcedure(AsyncMultiProcedure<Resource> procedure, ReadGraphImpl impl, QuerySupport support) {
+       public MultiIntProcedure(SyncMultiProcedure<Resource> procedure, ReadGraphImpl impl, QuerySupport support) {
                this.procedure = procedure;
                this.impl = impl;
                this.support = support;
index 299396ed715a6fb514b2474fd4b29933ab982b12..7070ee5b8b9552ed0ab9317124b2861b23833bfc 100644 (file)
@@ -89,9 +89,9 @@ import org.simantics.db.common.primitiverequest.UniqueAdapter;
 import org.simantics.db.common.primitiverequest.Value;
 import org.simantics.db.common.primitiverequest.ValueImplied;
 import org.simantics.db.common.primitiverequest.VariantValueImplied;
-import org.simantics.db.common.procedure.BlockingAsyncProcedure;
 import org.simantics.db.common.procedure.adapter.AsyncMultiProcedureAdapter;
 import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
+import org.simantics.db.common.procedure.adapter.SyncMultiProcedureAdapter;
 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
 import org.simantics.db.common.procedure.adapter.TransientCacheListener;
 import org.simantics.db.common.procedure.single.SyncReadProcedure;
@@ -107,6 +107,8 @@ import org.simantics.db.common.procedure.wrapper.NoneToAsyncMultiListener;
 import org.simantics.db.common.procedure.wrapper.NoneToAsyncMultiProcedure;
 import org.simantics.db.common.procedure.wrapper.NoneToAsyncProcedure;
 import org.simantics.db.common.procedure.wrapper.NoneToAsyncSetProcedure;
+import org.simantics.db.common.procedure.wrapper.NoneToSyncMultiListener;
+import org.simantics.db.common.procedure.wrapper.NoneToSyncMultiProcedure;
 import org.simantics.db.common.procedure.wrapper.SyncToAsyncListener;
 import org.simantics.db.common.procedure.wrapper.SyncToAsyncMultiListener;
 import org.simantics.db.common.procedure.wrapper.SyncToAsyncMultiProcedure;
@@ -114,7 +116,6 @@ import org.simantics.db.common.procedure.wrapper.SyncToAsyncProcedure;
 import org.simantics.db.common.procedure.wrapper.SyncToAsyncSetProcedure;
 import org.simantics.db.common.request.AdaptValue;
 import org.simantics.db.common.request.ResourceRead;
-import org.simantics.db.common.utils.Functions;
 import org.simantics.db.common.utils.Logger;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.common.validation.L0Validations;
@@ -133,21 +134,19 @@ import org.simantics.db.exception.NoSingleResultException;
 import org.simantics.db.exception.ResourceNotFoundException;
 import org.simantics.db.exception.ServiceException;
 import org.simantics.db.exception.ValidationException;
+import org.simantics.db.impl.BlockingAsyncProcedure;
 import org.simantics.db.impl.RelationContextImpl;
 import org.simantics.db.impl.ResourceImpl;
 import org.simantics.db.impl.internal.RandomAccessValueSupport;
 import org.simantics.db.impl.internal.ResourceData;
-import org.simantics.db.impl.procedure.CallWrappedSingleQueryProcedure4;
-import org.simantics.db.impl.procedure.InternalProcedure;
-import org.simantics.db.impl.procedure.ResultCallWrappedQueryProcedure4;
-import org.simantics.db.impl.procedure.ResultCallWrappedSingleQueryProcedure4;
+import org.simantics.db.impl.procedure.ResultCallWrappedSyncQueryProcedure;
 import org.simantics.db.impl.query.CacheEntry;
 import org.simantics.db.impl.query.QueryCache;
 import org.simantics.db.impl.query.QueryCacheBase;
 import org.simantics.db.impl.query.QueryProcessor;
+import org.simantics.db.impl.query.QueryProcessor.SessionTask;
 import org.simantics.db.impl.query.QuerySupport;
 import org.simantics.db.impl.query.TripleIntProcedure;
-import org.simantics.db.impl.query.QueryProcessor.SessionTask;
 import org.simantics.db.impl.support.ResourceSupport;
 import org.simantics.db.procedure.AsyncListener;
 import org.simantics.db.procedure.AsyncMultiListener;
@@ -174,7 +173,6 @@ import org.simantics.db.request.ExternalRead;
 import org.simantics.db.request.MultiRead;
 import org.simantics.db.request.Read;
 import org.simantics.db.request.ReadInterface;
-import org.simantics.db.request.RequestFlags;
 import org.simantics.db.request.Write;
 import org.simantics.db.request.WriteInterface;
 import org.simantics.db.request.WriteOnly;
@@ -185,22 +183,26 @@ import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.exceptions.SCLTypeParseException;
 import org.simantics.scl.reflection.ReflectionUtils;
 import org.simantics.scl.reflection.ValueNotFoundException;
-import org.simantics.scl.runtime.function.Function1;
 import org.simantics.scl.runtime.function.Function3;
 import org.simantics.utils.DataContainer;
 import org.simantics.utils.Development;
 import org.simantics.utils.datastructures.Pair;
 import org.simantics.utils.datastructures.collections.CollectionUtils;
+import org.slf4j.LoggerFactory;
 
 import gnu.trove.map.hash.TObjectIntHashMap;
 
-public class ReadGraphImpl implements ReadGraph {
+public class ReadGraphImpl implements AsyncReadGraph {
+
+    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ReadGraphImpl.class);
 
     final static boolean EMPTY_RESOURCE_CHECK = false;
     
        final public CacheEntry parent;
        final public QueryProcessor processor;
        
+       public AsyncBarrierImpl asyncBarrier = null;
+       
        final static Binding DATA_TYPE_BINDING_INTERNAL = Bindings.getBindingUnchecked(Datatype.class);
        final static Serializer DATA_TYPE_SERIALIZER = Bindings.getSerializerUnchecked(DATA_TYPE_BINDING_INTERNAL);
 
@@ -2091,14 +2093,10 @@ public class ReadGraphImpl implements ReadGraph {
                        throws DatabaseException {
 
                assert (request != null);
-//             AsyncReadProcedure<T> procedure = new AsyncReadProcedure<T>();
+               asyncBarrier = new AsyncBarrierImpl(null);
                BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<>(this, null, request);
                syncRequest(request, ap);
                return ap.get();
-//             procedure.checkAndThrow();
-//             return procedure.result;
-               
-//             return syncRequest(request, new AsyncProcedureAdapter<T>());
 
        }
 
@@ -2132,6 +2130,8 @@ public class ReadGraphImpl implements ReadGraph {
                
 //             final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
 //                             procedure, request);
+
+               ReadGraphImpl async = ReadGraphImpl.newAsync(this);
                
                QueryCache.runnerAsyncReadEntry(this, request, parent, listener, ap, true);
                
@@ -2239,21 +2239,21 @@ public class ReadGraphImpl implements ReadGraph {
                final ArrayList<T> result = new ArrayList<T>();
                final DataContainer<Throwable> exception = new DataContainer<Throwable>();
 
-               syncRequest(request, new AsyncMultiProcedure<T>() {
+               syncRequest(request, new SyncMultiProcedure<T>() {
 
                        @Override
-                       public void execute(AsyncReadGraph graph, T t) {
+                       public void execute(ReadGraph graph, T t) {
                                synchronized (result) {
                                        result.add(t);
                                }
                        }
 
                        @Override
-                       public void finished(AsyncReadGraph graph) {
+                       public void finished(ReadGraph graph) {
                        }
 
                        @Override
-                       public void exception(AsyncReadGraph graph, Throwable t) {
+                       public void exception(ReadGraph graph, Throwable t) {
                                exception.set(t);
                        }
 
@@ -2278,24 +2278,25 @@ public class ReadGraphImpl implements ReadGraph {
 
        }
 
-       @Override
+/*     @Override
        public <T> Collection<T> syncRequest(MultiRead<T> request,
                        AsyncMultiListener<T> procedure) {
                return syncRequest(request, (AsyncMultiProcedure<T>) procedure);
-       }
+       }*/
 
        @Override
        public <T> Collection<T> syncRequest(MultiRead<T> request,
                        SyncMultiListener<T> procedure) {
-               return syncRequest(request, new SyncToAsyncMultiListener<T>(procedure));
+               return syncRequest(request, (SyncMultiProcedure<T>)procedure);
        }
 
        @Override
        public <T> Collection<T> syncRequest(MultiRead<T> request,
                        MultiListener<T> procedure) {
-               return syncRequest(request, new NoneToAsyncMultiListener<T>(procedure));
+               return syncRequest(request, new NoneToSyncMultiListener<T>(procedure));
        }
 
+       /*
        @Override
        public <T> Collection<T> syncRequest(MultiRead<T> request,
                        AsyncMultiProcedure<T> procedure) {
@@ -2339,17 +2340,51 @@ public class ReadGraphImpl implements ReadGraph {
                return null;
 
        }
+       */
 
        @Override
        public <T> Collection<T> syncRequest(MultiRead<T> request,
                        SyncMultiProcedure<T> procedure) {
-               return syncRequest(request, new SyncToAsyncMultiProcedure<T>(procedure));
+
+               assert (request != null);
+
+               ListenerBase listener = getListenerBase(procedure);
+
+               final ResultCallWrappedSyncQueryProcedure<T> wrapper = new ResultCallWrappedSyncQueryProcedure<T>(procedure);
+
+               if (parent != null || listener != null) {
+
+//                     Object syncParent = request;
+
+//                     final ReadGraphImpl newGraph = newSync();
+
+                       processor.query(this, request, parent, wrapper, listener);
+
+//                     newGraph.waitAsync(syncParent);
+
+               } else {
+
+//                     Object syncParent = request;
+
+//                     final ReadGraphImpl newGraph = newSync();
+
+
+                       try {
+                               request.perform(this, wrapper);
+                       } catch (Throwable t) {
+                               wrapper.exception(this, t);
+                       }
+
+               }
+
+               return wrapper.get();
+
        }
 
        @Override
        public <T> Collection<T> syncRequest(MultiRead<T> request,
                        MultiProcedure<T> procedure) {
-               return syncRequest(request, new NoneToAsyncMultiProcedure<T>(procedure));
+               return syncRequest(request, new NoneToSyncMultiProcedure<T>(procedure));
        }
 
        static class AsyncMultiReadProcedure<T> extends ArrayList<T> implements AsyncMultiProcedure<T> {
@@ -3327,18 +3362,18 @@ public class ReadGraphImpl implements ReadGraph {
 //     }
        
        @Override
-       final public void forEachDirectPredicate(final Resource subject, final AsyncMultiProcedure<Resource> procedure) {
+       final public void forEachDirectPredicate(final Resource subject, final AsyncProcedure<Set<Resource>> procedure) {
                processor.forEachDirectPredicate(this, subject, procedure);
        }
 
        @Override
-       public void forEachDirectPredicate(Resource subject, SyncMultiProcedure<Resource> procedure) {
-               forEachDirectPredicate(subject, new SyncToAsyncMultiProcedure<Resource>(procedure));
+       final public void forEachDirectPredicate(final Resource subject, final SyncProcedure<Set<Resource>> procedure) {
+               forEachDirectPredicate(subject, new SyncToAsyncProcedure<Set<Resource>>(procedure));
        }
 
        @Override
-       public void forEachDirectPredicate(Resource subject, MultiProcedure<Resource> procedure) {
-               forEachDirectPredicate(subject, new NoneToAsyncMultiProcedure<Resource>(procedure));
+       public void forEachDirectPredicate(Resource subject, Procedure<Set<Resource>> procedure) {
+               forEachDirectPredicate(subject, new NoneToAsyncProcedure<Set<Resource>>(procedure));
        }
 
        @Override
@@ -5560,9 +5595,9 @@ public class ReadGraphImpl implements ReadGraph {
 
                assert (request != null);
 
-               asyncRequest(request, new AsyncMultiProcedureAdapter<T>() {
+               asyncRequest(request, new SyncMultiProcedureAdapter<T>() {
                        @Override
-                       public void exception(AsyncReadGraph graph, Throwable t) {
+                       public void exception(ReadGraph graph, Throwable t) {
                        Logger.defaultLogError(t);
                        }
 
@@ -5574,27 +5609,22 @@ public class ReadGraphImpl implements ReadGraph {
 
        }
 
-       @Override
-       public <T> void asyncRequest(MultiRead<T> request,
-                       AsyncMultiListener<T> procedure) {
-               asyncRequest(request, (AsyncMultiProcedure<T>) procedure);
-       }
-
        @Override
        public <T> void asyncRequest(MultiRead<T> request,
                        SyncMultiListener<T> procedure) {
-               asyncRequest(request, new SyncToAsyncMultiListener<T>(procedure));
+               asyncRequest(request, (SyncMultiProcedure<T>)procedure);
        }
 
        @Override
        public <T> void asyncRequest(MultiRead<T> request,
                        MultiListener<T> procedure) {
-               asyncRequest(request, new NoneToAsyncMultiListener<T>(procedure));
+               asyncRequest(request, new NoneToSyncMultiListener<T>(procedure));
        }
 
+       
        @Override
        public <T> void asyncRequest(final MultiRead<T> request,
-                       final AsyncMultiProcedure<T> procedure) {
+                       final SyncMultiProcedure<T> procedure) {
 
                assert (request != null);
                assert (procedure != null);
@@ -5616,7 +5646,11 @@ public class ReadGraphImpl implements ReadGraph {
 
                    } catch (Throwable t) {
 
-                       procedure.exception(this, t);
+                       try {
+                                       procedure.exception(this, t);
+                               } catch (DatabaseException e) {
+                                       LOGGER.error("Unexpected exception while handling exception", e);
+                               }
 
                    }                           
 
@@ -5624,16 +5658,10 @@ public class ReadGraphImpl implements ReadGraph {
 
        }
 
-       @Override
-       public <T> void asyncRequest(MultiRead<T> request,
-                       SyncMultiProcedure<T> procedure) {
-               asyncRequest(request, new SyncToAsyncMultiProcedure<T>(procedure));
-       }
-
        @Override
        public <T> void asyncRequest(MultiRead<T> request,
                        MultiProcedure<T> procedure) {
-               asyncRequest(request, new NoneToAsyncMultiProcedure<T>(procedure));
+               asyncRequest(request, new NoneToSyncMultiProcedure<T>(procedure));
        }
 
        @Override
@@ -6019,6 +6047,12 @@ public class ReadGraphImpl implements ReadGraph {
        public static ReadGraphImpl create(QueryProcessor support) {
                return new ReadGraphImpl(null, support);
        }
+       
+       public static ReadGraphImpl newAsync(ReadGraphImpl parent) {
+               ReadGraphImpl result = new ReadGraphImpl(parent);
+               result.asyncBarrier = new AsyncBarrierImpl(parent.asyncBarrier);
+               return result;
+       }
 
        public ReadGraphImpl newRestart(ReadGraphImpl impl) {
 
index 7bfe5b3d2860d0680cce0da959aed4c71b5fefba..4975f2d57490f269cb56e6ccd11c6f5c4991aab9 100644 (file)
@@ -29,11 +29,10 @@ import org.simantics.db.procedure.ListenerBase;
 import org.simantics.db.procedure.MultiProcedure;
 import org.simantics.db.procedure.Procedure;
 import org.simantics.db.procedure.StatementProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
+import org.simantics.db.procedure.SyncProcedure;
 import org.simantics.db.request.AsyncMultiRead;
-import org.simantics.db.request.AsyncRead;
-import org.simantics.db.request.ExternalRead;
 import org.simantics.db.request.MultiRead;
-import org.simantics.db.request.Read;
 
 public interface ReadGraphSupport {
 
@@ -53,9 +52,7 @@ public interface ReadGraphSupport {
     void forEachAssertedStatement(ReadGraphImpl graph, Resource subject, Resource predicate, AsyncMultiProcedure<Statement> procedure);
     void forEachObject(ReadGraphImpl graph, Resource subject, Resource predicate, MultiProcedure<Resource> procedure);
     void forEachObject(ReadGraphImpl graph, Resource subject, Resource predicate, AsyncMultiProcedure<Resource> procedure);
-    void forEachDirectPredicate(ReadGraphImpl graph, Resource subject, AsyncMultiProcedure<Resource> procedure);
-    void forEachDirectStatement(ReadGraphImpl graph, Resource subject, Procedure<DirectStatements> procedure);
-    void forEachDirectStatement(ReadGraphImpl graph, Resource subject, AsyncProcedure<DirectStatements> procedure, boolean ignoreVirtual);
+    void forEachDirectPredicate(ReadGraphImpl graph, Resource subject, AsyncProcedure<Set<Resource>> procedure);
     void forObjectSet(ReadGraphImpl graph, Resource subject, Resource predicate, AsyncSetListener<Resource> procedure);
     void forPredicateSet(ReadGraphImpl graph, Resource subject, AsyncSetListener<Resource> procedure);
     void forPrincipalTypeSet(ReadGraphImpl graph, Resource subject, AsyncSetListener<Resource> procedure);
@@ -64,7 +61,8 @@ public interface ReadGraphSupport {
     void forEachPrincipalType(ReadGraphImpl graph, Resource subject, AsyncMultiProcedure<Resource> procedure);
     void forEachPrincipalType(ReadGraphImpl graph, Resource subject, MultiProcedure<Resource> procedure);
 
-    void forRelationInfo(ReadGraphImpl graph, Resource subject, AsyncProcedure<RelationInfo> procedure);
+    RelationInfo getRelationInfo(ReadGraphImpl graph, Resource subject) throws DatabaseException;
+    
     void forTypes(ReadGraphImpl graph, Resource subject, AsyncProcedure<Set<Resource>> procedure);
     IntSet getTypes(ReadGraphImpl graph, Resource subject) throws Throwable;
     void forSupertypes(ReadGraphImpl graph, Resource subject, AsyncProcedure<Set<Resource>> procedure);
@@ -86,7 +84,7 @@ public interface ReadGraphSupport {
     void forOrderedSet(ReadGraphImpl graph, Resource subject, AsyncMultiProcedure<Resource> procedure);
 
     //<T> T query(ReadGraphImpl graph, Read<T> request, CacheEntry parent, AsyncProcedure<T> procedure, ListenerBase listener) throws DatabaseException;
-    <T> void query(ReadGraphImpl graph, MultiRead<T> request, CacheEntry parent, AsyncMultiProcedure<T> procedure, ListenerBase listener);
+    <T> void query(ReadGraphImpl graph, MultiRead<T> request, CacheEntry parent, SyncMultiProcedure<T> procedure, ListenerBase listener);
 //    <T> void query(ReadGraphImpl graph, AsyncRead<T> request, CacheEntry parent, AsyncProcedure<T> procedure, ListenerBase listener) throws DatabaseException;
     <T> void query(ReadGraphImpl graph, AsyncMultiRead<T> request, CacheEntry parent, AsyncMultiProcedure<T> procedure, ListenerBase listener);
     //<T> void query(ReadGraphImpl graph, ExternalRead<T> request, CacheEntry parent, Procedure<T> procedure, ListenerBase listener);
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/procedure/ResultCallWrappedSyncQueryProcedure.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/procedure/ResultCallWrappedSyncQueryProcedure.java
new file mode 100644 (file)
index 0000000..2e06a75
--- /dev/null
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.impl.procedure;
+
+import java.util.ArrayList;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.SyncMultiProcedure;
+
+public class ResultCallWrappedSyncQueryProcedure<Result> implements SyncMultiProcedure<Result> {
+
+    final private ArrayList<Result> result;
+    private Throwable exception = null;
+    final private SyncMultiProcedure<Result> procedure;
+    final private AtomicBoolean latch;
+    
+    public ResultCallWrappedSyncQueryProcedure(SyncMultiProcedure<Result> procedure) {
+        this.procedure = procedure;
+        latch = new AtomicBoolean(false);
+        result = new ArrayList<Result>();
+    }
+    
+    @Override
+    public void execute(ReadGraph graph, Result result) {
+       try {
+            synchronized(this.result) {
+                this.result.add(result);
+            }
+               procedure.execute(graph, result);
+       } catch (Throwable t) {
+               Logger.defaultLogError("AsyncMultiProcedure.execute failed for " + procedure, t);
+       }
+    }
+    
+    @Override
+    public void finished(ReadGraph graph) {
+       if(latch.compareAndSet(false, true)) {
+               try {
+                procedure.finished(graph);
+               } catch (Throwable t) {
+                       Logger.defaultLogError("AsyncMultiProcedure.exception failed for " + procedure, t);
+               } finally {
+               }
+       } else {
+               Logger.defaultLogError("Finished or exception was called many times (this time is finished)");
+       }
+    }
+
+    @Override
+    public void exception(ReadGraph graph, Throwable t) {
+       if(latch.compareAndSet(false, true)) {
+               try {
+                this.exception = t;
+                procedure.exception(graph, t);
+               } catch (Throwable throwable) {
+                       Logger.defaultLogError("AsyncMultiProcedure.exception failed for " + procedure, throwable);
+               } finally {
+               }
+       } else {
+               Logger.defaultLogError("Finished or exception was called many times (this time is exception)");
+       }
+    }
+    
+    public ArrayList<Result> get() {
+       return result;
+    }
+    
+    public Throwable getException() {
+        return exception;
+    }
+
+    @Override
+    public String toString() {
+        return "ResultCallWrappedQueryProcedure4[" + procedure + "]"; 
+    }
+    
+}
index 1791c50acccb37eb0fb41dbf4c3c149e0fc1c6d7..8d1bbd2040c51a144b547fa9145cc064136c2f53 100644 (file)
@@ -14,7 +14,6 @@ package org.simantics.db.impl.query;
 import java.util.ArrayList;
 
 import org.simantics.db.AsyncReadGraph;
-import org.simantics.db.common.GraphSemaphore;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.procedure.AsyncMultiProcedure;
index 69a85220b954cac8d1dc0e24ef25ca07edd0c407..195d2147f1f3ead70bc64904f7f012ec7efb175f 100644 (file)
@@ -12,7 +12,6 @@
 package org.simantics.db.impl.query;
 
 import org.simantics.db.AsyncReadGraph;
-import org.simantics.db.common.GraphSemaphore;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.RuntimeDatabaseException;
 import org.simantics.db.impl.DebugPolicy;
similarity index 97%
rename from bundles/org.simantics.db.common/src/org/simantics/db/common/GraphSemaphore.java
rename to bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/GraphSemaphore.java
index d5d7735aad5d3188ce75253f20eb90fdebbcce2e..3b980fe657e081e374c9f07dcdfc222f3befd4f3 100644 (file)
@@ -1,4 +1,4 @@
-package org.simantics.db.common;
+package org.simantics.db.impl.query;
 
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
index f2fff24cfc7ac213de3890331806509d68808575..5bc318de1b26fd27dd7cb567ef3ce2c6f3e68c4f 100644 (file)
@@ -14,16 +14,16 @@ package org.simantics.db.impl.query;
 import java.util.ArrayList;
 
 import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
 import org.simantics.db.common.exception.DebugException;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.impl.graph.ReadGraphImpl;
-import org.simantics.db.impl.query.QueryProcessor.AsyncBarrier;
 import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.db.request.MultiRead;
 import org.simantics.db.request.RequestFlags;
-import org.simantics.utils.datastructures.Pair;
 
-final public class MultiReadEntry<T> extends CacheEntryBase<AsyncMultiProcedure<T>> {
+final public class MultiReadEntry<T> extends CacheEntryBase<SyncMultiProcedure<T>> {
 
     protected MultiRead<T> request;
     
@@ -48,13 +48,11 @@ final public class MultiReadEntry<T> extends CacheEntryBase<AsyncMultiProcedure<
        setResult(null);
     }
     
-    synchronized public void finish(AsyncReadGraph graph) {
+    synchronized public void finish(ReadGraph graph) {
        
        assert(isPending());
 
-        ArrayList<Pair<AsyncMultiProcedure<T>, AsyncBarrier>> p = null;
-
-        synchronized(this) {
+       synchronized(this) {
                setReady();
         }
         
@@ -84,19 +82,19 @@ final public class MultiReadEntry<T> extends CacheEntryBase<AsyncMultiProcedure<
                                
                                try {
 
-                                   request.perform(graph , new AsyncMultiProcedure<T>() {
+                                   request.perform(graph , new SyncMultiProcedure<T>() {
 
                         @Override
-                        public void execute(AsyncReadGraph graph, T result) {
+                        public void execute(ReadGraph graph, T result) {
                             addOrSet(result);
                         }
                         
-                        public void finished(AsyncReadGraph graph) {
+                        public void finished(ReadGraph graph) {
                                finish(graph);
                         };
                                        
                                        @Override
-                                       public void exception(AsyncReadGraph graph, Throwable t) {
+                                       public void exception(ReadGraph graph, Throwable t) {
                             except(t);
                            }
 
@@ -165,7 +163,7 @@ final public class MultiReadEntry<T> extends CacheEntryBase<AsyncMultiProcedure<
     }
     
        @Override
-       public Object performFromCache(ReadGraphImpl graph, AsyncMultiProcedure<T> proc) {
+       public Object performFromCache(ReadGraphImpl graph, SyncMultiProcedure<T> proc) {
                
         if(isExcepted()) {
             
@@ -205,7 +203,7 @@ final public class MultiReadEntry<T> extends CacheEntryBase<AsyncMultiProcedure<
        }
 
        //@Override
-       public Object compute(ReadGraphImpl graph, AsyncMultiProcedure<T> procedure) throws DatabaseException {
+       public Object compute(ReadGraphImpl graph, SyncMultiProcedure<T> procedure) throws DatabaseException {
        return graph.processor.cache.performQuery(graph, request, this, procedure);
        }
 
index 1467015512e38f81e6639fa8077f1808ec37865d..7b591abb7fd80e062308ce3df88c86e872cfe27e 100644 (file)
@@ -10,6 +10,7 @@ import org.simantics.db.impl.query.QueryProcessor.SessionTask;
 import org.simantics.db.procedure.AsyncMultiProcedure;
 import org.simantics.db.procedure.AsyncProcedure;
 import org.simantics.db.procedure.ListenerBase;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.db.request.AsyncMultiRead;
 import org.simantics.db.request.AsyncRead;
 import org.simantics.db.request.ExternalRead;
@@ -951,10 +952,10 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    public static void runnerMultiReadEntry(ReadGraphImpl graph, MultiRead<?> r, CacheEntry parent, ListenerBase listener, final AsyncMultiProcedure procedure) throws DatabaseException {
+    public static void runnerMultiReadEntry(ReadGraphImpl graph, MultiRead<?> r, CacheEntry parent, ListenerBase listener, final SyncMultiProcedure procedure) throws DatabaseException {
         QueryCache cache  = graph.processor.cache;
         MultiReadEntry entry = (MultiReadEntry)cache.getOrCreateMultiReadEntry(graph.processor, r);
-        AsyncMultiProcedure procedure_ = procedure != null ? procedure : emptyProcedureMultiReadEntry;
+        SyncMultiProcedure procedure_ = procedure != null ? procedure : emptyProcedureMultiReadEntry;
         ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
         if(entry.isReady()) entry.performFromCache(graph, procedure_);
         else {
index 2d3c92d8242ed3259ea0518520262666cbabd423..5a06ded0be4ce2915a5c3914ba1286b95f2dfce5 100644 (file)
@@ -7,6 +7,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ObjectResourceIdMap;
+import org.simantics.db.ReadGraph;
 import org.simantics.db.RelationInfo;
 import org.simantics.db.common.utils.Logger;
 import org.simantics.db.exception.DatabaseException;
@@ -19,6 +20,7 @@ import org.simantics.db.procedure.AsyncProcedure;
 import org.simantics.db.procedure.Listener;
 import org.simantics.db.procedure.ListenerBase;
 import org.simantics.db.procedure.Procedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.db.request.AsyncMultiRead;
 import org.simantics.db.request.AsyncRead;
 import org.simantics.db.request.ExternalRead;
@@ -320,15 +322,15 @@ public class QueryCacheBase {
 
                ReadGraphImpl queryGraph = parentGraph.withParent(entry_);
 
-               AsyncMultiReadEntry entry = (AsyncMultiReadEntry)entry_;
-               AsyncMultiProcedure<T> procedure = (AsyncMultiProcedure<T>)procedure_;
+               MultiReadEntry entry = (MultiReadEntry)entry_;
+               SyncMultiProcedure<T> procedure = (SyncMultiProcedure<T>)procedure_;
 
                try {
 
-                       query.perform(queryGraph, new AsyncMultiProcedure<T>() {
+                       query.perform(queryGraph, new SyncMultiProcedure<T>() {
 
                                @Override
-                               public void execute(AsyncReadGraph graph, T result) {
+                               public void execute(ReadGraph graph, T result) {
                                        ReadGraphImpl impl = (ReadGraphImpl)graph;
                                        entry.addOrSet(result);
                                        try {
@@ -339,7 +341,7 @@ public class QueryCacheBase {
                                }
 
                                @Override
-                               public void finished(AsyncReadGraph graph) {
+                               public void finished(ReadGraph graph) {
                                        ReadGraphImpl impl = (ReadGraphImpl)graph;
                                        entry.finish(parentGraph);
                                        try {
@@ -350,9 +352,9 @@ public class QueryCacheBase {
                                }
 
                                @Override
-                               public void exception(AsyncReadGraph graph, Throwable t) {
+                               public void exception(ReadGraph graph, Throwable t) {
                                        ReadGraphImpl impl = (ReadGraphImpl)graph;
-                                       entry.except(parentGraph, t);
+                                       entry.except((DatabaseException)t);
                                        try {
                                                procedure.exception(parentGraph, t);
                                        } catch (Throwable t2) {
@@ -890,6 +892,23 @@ public class QueryCacheBase {
                
        }; 
 
+    protected static SyncMultiProcedure<Object> emptySyncMultiProcedure = new SyncMultiProcedure<Object>() {
+
+               @Override
+               public void execute(ReadGraph graph, Object result) {
+               }
+
+               @Override
+               public void finished(ReadGraph graph) {
+               }
+
+               @Override
+               public void exception(ReadGraph graph, Throwable throwable) {
+               }
+
+               
+       }; 
+
        protected static InternalProcedure<IntSet> emptyProcedureTypes = emptyIntSetProcedure;
     protected static InternalProcedure<IntSet> emptyProcedureSuperTypes = emptyIntSetProcedure;
     protected static InternalProcedure<IntSet> emptyProcedureTypeHierarchy = emptyIntSetProcedure;
@@ -916,7 +935,7 @@ public class QueryCacheBase {
 
     protected static AsyncProcedure emptyProcedureReadEntry = emptyAsyncProcedure;
     protected static AsyncProcedure emptyProcedureAsyncReadEntry = emptyAsyncProcedure;
-    protected static AsyncMultiProcedure emptyProcedureMultiReadEntry = emptyAsyncMultiProcedure;
+    protected static SyncMultiProcedure emptyProcedureMultiReadEntry = emptySyncMultiProcedure;
     protected static AsyncMultiProcedure emptyProcedureAsyncMultiReadEntry = emptyAsyncMultiProcedure;
     protected static AsyncProcedure emptyProcedureExternalReadEntry = emptyAsyncProcedure;
        
index 5945589a331c2460f83e0479f4f56f2b7425ebf2..9c60691fad7a0a850228997e85ffb47168ca1aae 100644 (file)
@@ -16,7 +16,6 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.PrintStream;
-import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -32,8 +31,6 @@ import java.util.Set;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReentrantLock;
 
 import org.simantics.databoard.Bindings;
 import org.simantics.db.AsyncReadGraph;
@@ -54,7 +51,6 @@ import org.simantics.db.exception.NoInverseException;
 import org.simantics.db.exception.ResourceNotFoundException;
 import org.simantics.db.impl.DebugPolicy;
 import org.simantics.db.impl.ResourceImpl;
-import org.simantics.db.impl.graph.MultiIntProcedure;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.impl.graph.ReadGraphSupport;
 import org.simantics.db.impl.graph.WriteGraphImpl;
@@ -68,15 +64,12 @@ import org.simantics.db.procedure.AsyncProcedure;
 import org.simantics.db.procedure.AsyncSetListener;
 import org.simantics.db.procedure.ListenerBase;
 import org.simantics.db.procedure.MultiProcedure;
-import org.simantics.db.procedure.Procedure;
 import org.simantics.db.procedure.StatementProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.db.request.AsyncMultiRead;
-import org.simantics.db.request.AsyncRead;
 import org.simantics.db.request.ExternalRead;
 import org.simantics.db.request.MultiRead;
-import org.simantics.db.request.Read;
 import org.simantics.db.request.RequestFlags;
-import org.simantics.db.request.WriteTraits;
 import org.simantics.layer0.Layer0;
 import org.simantics.utils.DataContainer;
 import org.simantics.utils.Development;
@@ -634,7 +627,7 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
 
        }
 
-       final <T> void runMultiRead(final ReadGraphImpl graph, MultiReadEntry cached, final MultiRead<T> query, final CacheEntry parent, final QueryProcessor provider, final ListenerBase listener, final AsyncMultiProcedure<T> procedure) {
+       final <T> void runMultiRead(final ReadGraphImpl graph, MultiReadEntry cached, final MultiRead<T> query, final CacheEntry parent, final QueryProcessor provider, final ListenerBase listener, final SyncMultiProcedure<T> procedure) {
 
                try {
                        QueryCache.runnerMultiReadEntry(graph, query, parent, listener, procedure);
@@ -666,7 +659,7 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
 //
 //     }
 
-       public <T> void queryMultiRead(final ReadGraphImpl graph, final MultiRead<T> query, final CacheEntry parent, final ListenerBase listener, final AsyncMultiProcedure<T> procedure) throws DatabaseException {
+       public <T> void queryMultiRead(final ReadGraphImpl graph, final MultiRead<T> query, final CacheEntry parent, final ListenerBase listener, final SyncMultiProcedure<T> procedure) throws DatabaseException {
 
                QueryCache.runnerMultiReadEntry(graph, query, parent, listener, procedure);
 
@@ -2762,51 +2755,60 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
        }
 
        @Override
-       final public void forEachDirectPredicate(final ReadGraphImpl impl, final Resource subject, final AsyncMultiProcedure<Resource> procedure) {
-
-               throw new UnsupportedOperationException();
-               
-//             assert(subject != null);
-//             assert(procedure != null);
-//
-//             final ListenerBase listener = getListenerBase(procedure);
-//
-//             MultiIntProcedure proc = new MultiIntProcedure(procedure, impl, querySupport);
-//
-//             int sId = querySupport.getId(subject);
-//
-//             try {
-//                     QueryCache.runnerDirectPredicates(impl, sId, impl.parent, listener, proc);
-//             } catch (DatabaseException e) {
-//                     Logger.defaultLogError(e);
-//             }
-
-       }
-
-       @Override
-       final public void forEachDirectStatement(final ReadGraphImpl impl, final Resource subject, final Procedure<DirectStatements> procedure) {
+       final public void forEachDirectPredicate(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure<Set<Resource>> procedure) {
 
                assert(subject != null);
                assert(procedure != null);
 
                final ListenerBase listener = getListenerBase(procedure);
 
-               org.simantics.db.impl.query.DirectStatements.queryEach(impl, querySupport.getId(subject), this, impl.parent, listener, procedure);
+               int sId = querySupport.getId(subject);
 
-       }
+               try {
+                       QueryCache.runnerDirectPredicates(impl, sId, impl.parent, listener, new InternalProcedure<IntSet>() {
 
-       @Override
-       final public void forEachDirectStatement(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure<DirectStatements> procedure, boolean ignoreVirtual) {
+                               @Override
+                               public void execute(ReadGraphImpl graph, IntSet result) throws DatabaseException {
+                                       procedure.execute(graph, result);
+                               }
 
-               assert(subject != null);
-               assert(procedure != null);
+                               @Override
+                               public void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException {
+                                       procedure.exception(graph, throwable);
+                               }
+                               
+                       });
+               } catch (DatabaseException e) {
+                       Logger.defaultLogError(e);
+               }
 
-               final ListenerBase listener = getListenerBase(procedure);
+       }
 
-               org.simantics.db.impl.query.DirectStatements.queryEach(impl, querySupport.getId(subject), this, impl.parent, listener, procedure, ignoreVirtual);
+       final public DirectStatements getDirectStatements(final ReadGraphImpl impl, final Resource subject, final boolean ignoreVirtual) {
+
+//             assert(subject != null);
+//             assert(procedure != null);
+//
+//             final ListenerBase listener = getListenerBase(procedure);
+//
+//             org.simantics.db.impl.query.DirectStatements.queryEach(impl, querySupport.getId(subject), this, impl.parent, listener, procedure);
+               
+               return querySupport.getStatements(impl, querySupport.getId(subject), this, ignoreVirtual);
 
        }
 
+//     @Override
+//     final public void forEachDirectStatement(final ReadGraphImpl impl, final Resource subject, final SyncProcedure<DirectStatements> procedure, boolean ignoreVirtual) {
+//
+//             assert(subject != null);
+//             assert(procedure != null);
+//
+//             final ListenerBase listener = getListenerBase(procedure);
+//
+//             org.simantics.db.impl.query.DirectStatements.queryEach(impl, querySupport.getId(subject), this, impl.parent, listener, procedure, ignoreVirtual);
+//
+//     }
+       
        private static final Resource INVALID_RESOURCE = new ResourceImpl(null, Integer.MIN_VALUE);
 
        @Override
@@ -3492,32 +3494,11 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
        }
 
        @Override
-       final public void forRelationInfo(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure<RelationInfo> procedure) {
+       final public RelationInfo getRelationInfo(final ReadGraphImpl impl, final Resource subject) throws DatabaseException {
                
                assert(subject != null);
-               assert(procedure != null);
-
-               final ListenerBase listener = getListenerBase(procedure);
-               assert(listener == null);
-
-               try {
-                       
-                       QueryCache.runnerRelationInfoQuery(impl, querySupport.getId(subject), impl.parent, listener, new InternalProcedure<RelationInfo>() {
-
-                               @Override
-                               public void execute(final ReadGraphImpl graph, RelationInfo set) {
-                                       procedure.execute(graph, set);                                  
-                               }
 
-                               @Override
-                               public void exception(ReadGraphImpl graph, Throwable t) {
-                                       procedure.exception(graph, t);
-                               }
-
-                       });
-               } catch (DatabaseException e) {
-                       Logger.defaultLogError(e);
-               }
+               return QueryCache.resultRelationInfoQuery(impl, querySupport.getId(subject), impl.parent, null);
 
        }
 
@@ -4311,7 +4292,7 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
 //     }
 
        @Override
-       final public <T> void query(final ReadGraphImpl impl, final MultiRead<T> request, final CacheEntry parent, final AsyncMultiProcedure<T> procedure, ListenerBase listener) {
+       final public <T> void query(final ReadGraphImpl impl, final MultiRead<T> request, final CacheEntry parent, final SyncMultiProcedure<T> procedure, ListenerBase listener) {
 
                assert(request != null);
                assert(procedure != null);
index fc32222084c0f7e08509c152a882b893e7bd5b61..2c63b2d0304ddb8a3ef7ec78e53e84ef1108971d 100644 (file)
@@ -23,7 +23,6 @@ import java.util.UUID;
 import org.simantics.databoard.Bindings;
 import org.simantics.databoard.util.ObjectUtils;
 import org.simantics.datatypes.literal.GUID;
-import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ChangeSet;
 import org.simantics.db.ChangeSet.StatementChange;
 import org.simantics.db.MetadataI;
@@ -51,8 +50,8 @@ import org.simantics.db.layer0.genericrelation.DependencyChanges.ComponentAdditi
 import org.simantics.db.layer0.genericrelation.DependencyChanges.ComponentModification;
 import org.simantics.db.layer0.genericrelation.DependencyChanges.ComponentRemoval;
 import org.simantics.db.layer0.genericrelation.DependencyChanges.LinkChange;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
-import org.simantics.db.procedure.AsyncContextProcedure;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
+import org.simantics.db.procedure.SyncContextProcedure;
 import org.simantics.db.service.CollectionSupport;
 import org.simantics.db.service.DirectQuerySupport;
 import org.simantics.db.service.GraphChangeListenerSupport;
@@ -95,9 +94,9 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic
        class Process {
 
                final ArrayList<Entry> result = new ArrayList<Entry>();
-               final AsyncContextMultiProcedure<Resource, Resource> structure;
-               final AsyncContextProcedure<Entry, String> names;
-               final AsyncContextProcedure<Entry, Resource> type;
+               final SyncContextMultiProcedure<Resource, Resource> structure;
+               final SyncContextProcedure<Entry, String> names;
+               final SyncContextProcedure<Entry, Resource> type;
 
                Process(ReadGraph graph, final Resource resource) throws DatabaseException {
 
@@ -105,38 +104,38 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic
                        final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
                        final CollectionSupport cs = graph.getService(CollectionSupport.class);
 
-                       names = dqs.compilePossibleRelatedValue(graph, L0.HasName, new AsyncContextProcedure<Entry, String>() {
+                       names = dqs.compilePossibleRelatedValue(graph, L0.HasName, new SyncContextProcedure<Entry, String>() {
 
                                @Override
-                               public void execute(AsyncReadGraph graph, Entry entry, String name) {
+                               public void execute(ReadGraph graph, Entry entry, String name) {
                                        entry.name = name;
                                }
 
                                @Override
-                               public void exception(AsyncReadGraph graph, Throwable throwable) {
+                               public void exception(ReadGraph graph, Throwable throwable) {
                                        LOGGER.error("Could not compile possible related value for resource {}", resource, throwable);
                                }
 
                        });
 
-                       type = new AsyncContextProcedure<Entry, Resource>() {
+                       type = new SyncContextProcedure<Entry, Resource>() {
 
                                @Override
-                               public void execute(AsyncReadGraph graph, Entry entry, Resource type) {
+                               public void execute(ReadGraph graph, Entry entry, Resource type) {
                                        entry.principalType = type;
                                }
 
                                @Override
-                               public void exception(AsyncReadGraph graph, Throwable throwable) {
+                               public void exception(ReadGraph graph, Throwable throwable) {
                                        LOGGER.error("Could not find type for resource {}", resource, throwable);
                                }
 
                        };
 
-                       structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new AsyncContextMultiProcedure<Resource, Resource>() {
+                       structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new SyncContextMultiProcedure<Resource, Resource>() {
 
                                @Override
-                               public void execute(AsyncReadGraph graph, Resource parent, Resource child) {
+                               public void execute(ReadGraph graph, Resource parent, Resource child) {
                                        // WORKAROUND: don't browse virtual child resources
                                        if(!child.isPersistent()) return;
                                        Entry entry = new Entry(parent, child, "", "", "");
@@ -147,11 +146,11 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic
                                }
 
                                @Override
-                               public void finished(AsyncReadGraph graph, Resource parent) {
+                               public void finished(ReadGraph graph, Resource parent) {
                                }
 
                                @Override
-                               public void exception(AsyncReadGraph graph, Throwable throwable) {
+                               public void exception(ReadGraph graph, Throwable throwable) {
                                    if (throwable instanceof NoSingleResultException) {
                                        // Ignore
                                        if (LOGGER.isDebugEnabled())
index aebf657f1b7f4f432c523d16a9fd46c9ea5e5f0b..05ac11e62093851c5c3cc0fff70322015ef6a042 100644 (file)
@@ -16,7 +16,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.common.request.ObjectsWithType;
 import org.simantics.db.common.request.ResourceMultiRead;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.layer0.Layer0;
 import org.simantics.project.ontology.ProjectResource;
 
@@ -30,7 +30,7 @@ public class NamespaceRequirements extends ResourceMultiRead<Resource> {
     }
 
     @Override
-    public void perform(ReadGraph graph, AsyncMultiProcedure<Resource> callback) throws DatabaseException {
+    public void perform(ReadGraph graph, SyncMultiProcedure<Resource> callback) throws DatabaseException {
         Layer0 L0 = Layer0.getInstance(graph);
         ProjectResource PROJ = ProjectResource.getInstance(graph);
 
index f1edc367ed7d217c5d2db004285f85e35a19702d..2394db7ed6f27a916c966f90d3c4f73d4d117698 100644 (file)
@@ -16,7 +16,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.common.request.ResourceMultiRead;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.ResourceNotFoundException;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.layer0.Layer0;
 import org.simantics.project.ontology.ProjectResource;
 
@@ -29,7 +29,7 @@ public class OntologiesForModel extends ResourceMultiRead<Resource> {
         super(model);
     }
 
-    public void check(ReadGraph graph, Resource resource, AsyncMultiProcedure<Resource> callback) throws DatabaseException {
+    public void check(ReadGraph graph, Resource resource, SyncMultiProcedure<Resource> callback) throws DatabaseException {
 
         Layer0 L0 = Layer0.getInstance(graph);
         ProjectResource PROJ = ProjectResource.getInstance(graph);
@@ -51,7 +51,7 @@ public class OntologiesForModel extends ResourceMultiRead<Resource> {
     }
 
     @Override
-    public void perform(ReadGraph graph, AsyncMultiProcedure<Resource> callback) throws DatabaseException {
+    public void perform(ReadGraph graph, SyncMultiProcedure<Resource> callback) throws DatabaseException {
 
         Layer0 L0 = Layer0.getInstance(graph);
 
index bd2409f5d9b2eecde6a5f369562a141365938adb..1eea49e26d466cf582e79bdd0b0245afd9bc96cb 100644 (file)
@@ -17,9 +17,10 @@ import java.util.Map;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.request.ParametrizedRead;
+import org.simantics.db.common.request.ResourceRead;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.procedure.AsyncMultiProcedure;
 import org.simantics.db.procedure.Procedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.db.request.MultiRead;
 import org.simantics.db.request.Read;
 import org.simantics.layer0.Layer0;
@@ -41,9 +42,11 @@ public class Combinators {
                }
                @Override
                public void perform(ReadGraph graph,
-                               AsyncMultiProcedure<Resource> callback)
+                               SyncMultiProcedure<Resource> callback)
                                throws DatabaseException {
-                       graph.forEachObject(subject, relation, callback);
+                       for(Resource object : graph.getObjects(subject, relation)) {
+                               callback.execute(graph, object);
+                       }
                }               
            @Override
            public int hashCode() {
@@ -138,9 +141,7 @@ public class Combinators {
                }
                @Override
                public Resource perform(ReadGraph graph) throws DatabaseException {
-                       SynchronizationProcedure<Resource> procedure = new SynchronizationProcedure<Resource>();
-                       graph.forPossibleObject(subject, relation, procedure);
-                       return procedure.getResult();
+                       return graph.getPossibleObject(subject, relation);
                }       
            @Override
            public int hashCode() {
@@ -204,9 +205,7 @@ public class Combinators {
                }
                @Override
                public Resource perform(ReadGraph graph) throws DatabaseException {
-                       SynchronizationProcedure<Resource> procedure = new SynchronizationProcedure<Resource>();
-                       graph.forSingleObject(subject, relation, procedure);
-                       return procedure.getResult();
+                       return graph.getSingleObject(subject, relation);
                }       
            @Override
            public int hashCode() {
@@ -327,7 +326,7 @@ public class Combinators {
                        this.f = f;
                        this.g = g;
                }
-               public void perform(ReadGraph graph, final AsyncMultiProcedure<Y> callback)     throws DatabaseException {
+               public void perform(ReadGraph graph, final SyncMultiProcedure<Y> callback)      throws DatabaseException {
                    try {
                                for(X x : graph.syncRequest(g))
                                        callback.execute(graph, graph.syncRequest(f.get(x)));
@@ -410,7 +409,7 @@ public class Combinators {
                        this.g = g;
                }
                @Override
-               public void perform(ReadGraph graph, AsyncMultiProcedure<Y> callback)
+               public void perform(ReadGraph graph, SyncMultiProcedure<Y> callback)
                                throws DatabaseException {
                        graph.syncRequest(f.get(graph.syncRequest(g)), callback);
                }
@@ -469,7 +468,7 @@ public class Combinators {
                        this.f = f;
                        this.g = g;
                }
-               public void perform(ReadGraph graph, final AsyncMultiProcedure<Y> callback)     throws DatabaseException {
+               public void perform(ReadGraph graph, final SyncMultiProcedure<Y> callback)      throws DatabaseException {
                    try {
                                for(X x : graph.syncRequest(g))
                                        for(Y y : graph.syncRequest(f.get(x)))
@@ -614,7 +613,7 @@ public class Combinators {
                        this.value = value;
                }
                @Override
-               public void perform(ReadGraph graph, AsyncMultiProcedure<T> callback)
+               public void perform(ReadGraph graph, SyncMultiProcedure<T> callback)
                                throws DatabaseException {
                        callback.execute(graph, value);
                        callback.finished(graph);
@@ -640,29 +639,18 @@ public class Combinators {
        
        // ------------------------------------------------------------------------
        
-       private static class Name implements Read<String> {
-               Resource resource;
+       private static class Name extends ResourceRead<String> {
+               
                public Name(Resource resource) {
-                       this.resource = resource;
+                       super(resource);
                }
+               
                @Override
                public String perform(ReadGraph graph) throws DatabaseException {
                Layer0 L0 = Layer0.getInstance(graph);
-                       SynchronizationProcedure<String> procedure = new SynchronizationProcedure<String>();
-                       graph.forRelatedValue(resource, L0.HasName, procedure);
-                       return procedure.getResult();
+               return graph.getRelatedValue(resource, L0.HasName);
                }
-           @Override
-           public int hashCode() {
-               return getClass().hashCode() + 31 * resource.hashCode();
-           }
-               @Override
-               public boolean equals(Object obj) {
-                       if(obj == this) return true;
-                       if(obj == null || obj.getClass() != getClass()) return false;
-                       Name other = (Name)obj;
-                       return resource.equals(other.resource);
-               }               
+               
        }       
        public static Read<String> name(Resource resource) {
                return new Name(resource);
index 75c75764adb2b5668ef0e8736818cf4718cb6fa9..55fe1ac0111f008f90c3d0b816720b01ce34ce03 100644 (file)
@@ -6,7 +6,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
-import org.simantics.db.AsyncReadGraph;
+import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.ResourceMap;
@@ -16,8 +16,7 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.adapter.SubgraphExtent.ExtentStatus;
 import org.simantics.db.layer0.util.TransferableGraphConfiguration2.SeedSpec;
 import org.simantics.db.layer0.util.TransferableGraphConfiguration2.SeedSpec.SeedSpecType;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
-import org.simantics.db.procedure.Procedure;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
 import org.simantics.db.service.DirectQuerySupport;
 import org.simantics.layer0.Layer0;
 import org.simantics.utils.datastructures.Pair;
@@ -26,8 +25,8 @@ class ConsistsOfProcess {
 
        final List<ConsistsOfProcessEntry> result;
        final Set<Resource> childrenWithNoName;
-       final AsyncContextMultiProcedure<ConsistsOfProcessEntry, Resource> structure;
-       final AsyncContextMultiProcedure<ConsistsOfProcessEntry, Resource> names;
+       final SyncContextMultiProcedure<ConsistsOfProcessEntry, Resource> structure;
+       final SyncContextMultiProcedure<ConsistsOfProcessEntry, Resource> names;
 
        public static Pair<List<ConsistsOfProcessEntry>,Set<Resource>> walk(ReadGraph graph, Collection<SeedSpec> specs, boolean ignoreVirtual) throws DatabaseException {
                return walk(graph, null, specs, ignoreVirtual);
@@ -58,44 +57,35 @@ class ConsistsOfProcess {
                
                result = new ArrayList<>();
                childrenWithNoName = new HashSet<>();
-               names = dqs.compileForEachObject(graph, L0.HasName, new AsyncContextMultiProcedure<ConsistsOfProcessEntry, Resource>() {
+               names = dqs.compileForEachObject(graph, L0.HasName, new SyncContextMultiProcedure<ConsistsOfProcessEntry, Resource>() {
 
                        @Override
-                       public void execute(AsyncReadGraph graph, ConsistsOfProcessEntry entry, Resource nameResource) {
+                       public void execute(ReadGraph graph, ConsistsOfProcessEntry entry, Resource nameResource) throws DatabaseException {
                
                                if(status != null)
                                        status.put(nameResource, ExtentStatus.EXCLUDED);
                                
-                               graph.forPossibleValue(nameResource, new Procedure<String>() {
-
-                                       @Override
-                                       public void execute(String name) {
-                                           if(!entry.valid) return;
-                                           
-                                           if(name == null) {
-                                               entry.valid = false;
-                                           } else if (entry.name != null) {
-                                               entry.valid = false;
-                                           } else {
-                                               entry.name = name;
-                                           }
-                                       }
+                           if(!entry.valid) return;
+
+                               String name = graph.getValue(nameResource, Bindings.STRING);
+                               if(name == null) {
+                                       entry.valid = false;
+                               } else if (entry.name != null) {
+                                       entry.valid = false;
+                               } else {
+                                       entry.name = name;
+                               }
 
-                                       @Override
-                                       public void exception(Throwable t) {
-                                               Logger.defaultLogError(t);
-                                       }
-                                       
-                               });
+                               
                        }
 
                        @Override
-                       public void exception(AsyncReadGraph graph, Throwable throwable) {
+                       public void exception(ReadGraph graph, Throwable throwable) {
                                Logger.defaultLogError(throwable);
                        }
 
                        @Override
-                       public void finished(AsyncReadGraph graph, ConsistsOfProcessEntry entry) {
+                       public void finished(ReadGraph graph, ConsistsOfProcessEntry entry) {
                            if(entry.valid) {
                                if(entry.name != null) {
                                    result.add(entry);
@@ -110,10 +100,10 @@ class ConsistsOfProcess {
                        }
                });
                
-               structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new AsyncContextMultiProcedure<ConsistsOfProcessEntry, Resource>() {
+               structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new SyncContextMultiProcedure<ConsistsOfProcessEntry, Resource>() {
 
                        @Override
-                       public void execute(AsyncReadGraph graph, ConsistsOfProcessEntry parent, Resource child) {
+                       public void execute(ReadGraph graph, ConsistsOfProcessEntry parent, Resource child) {
 
                                if(status != null)
                                        if(ExtentStatus.EXCLUDED.equals(status.get(child))) return;
@@ -127,11 +117,11 @@ class ConsistsOfProcess {
                        }
 
                        @Override
-                       public void finished(AsyncReadGraph graph, ConsistsOfProcessEntry parent) {
+                       public void finished(ReadGraph graph, ConsistsOfProcessEntry parent) {
                        }
 
                        @Override
-                       public void exception(AsyncReadGraph graph, Throwable throwable) {
+                       public void exception(ReadGraph graph, Throwable throwable) {
                                Logger.defaultLogError(throwable);
                        }
 
index 9832f9d08be6815f2aaa6c24f6e0d64910a54e22..c5cb20af2c6d2ada95446a61cacdd3fa723747c0 100644 (file)
@@ -578,15 +578,15 @@ public class ModelTransferableGraphSourceRequest extends UniqueRead<ModelTransfe
 
                        final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
 
-                       final DomainStatementProcedure3 proc = new DomainStatementProcedure3(result);
+//                     final DomainStatementProcedure3 proc = new DomainStatementProcedure3(result);
 
                        if (ignoreVirtual) {
                                for(Resource r : roots) {
-                                       dqs.forEachDirectPersistentStatement(graph, r, proc);
+                                       result.add(dqs.getDirectPersistentStatements(graph, r));
                                }
                        } else {
                                for(Resource r : roots) {
-                                       dqs.forEachDirectStatement(graph, r, proc);
+                                       result.add(dqs.getDirectStatements(graph, r));
                                }
                        }
                        
index f7e3a20cf4a9311e1cef6c7e3efe7b77757f5aea..5dea700c85e8733215192f6efcfa545145ebd003 100644 (file)
@@ -25,7 +25,7 @@ import org.simantics.db.impl.ForPossibleRelatedValueContextProcedure;
 import org.simantics.db.impl.ForPossibleRelatedValueProcedure;
 import org.simantics.db.impl.Table;
 import org.simantics.db.impl.graph.ReadGraphImpl;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.db.procore.cluster.ClusterBig;
 import org.simantics.db.procore.cluster.ClusterImpl;
 import org.simantics.db.procore.cluster.ClusterTraits;
@@ -226,7 +226,7 @@ final public class ClusterWriteOnly extends ClusterImpl {
     }
     @Override
     public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey,
-            AsyncMultiProcedure<Resource> procedure) throws DatabaseException {
+            SyncMultiProcedure<Resource> procedure) throws DatabaseException {
         throw new DatabaseException("Not implemented.");
     }
     @Override
index 0b640861e1d6af93255b25114c429b2f374ce54f..bad6916dd3727927ebb1c3e44d06ec50bd25b98e 100644 (file)
@@ -1,12 +1,9 @@
 package fi.vtt.simantics.procore.internal;
 
-import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.DirectStatements;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.RelationInfo;
 import org.simantics.db.Resource;
-import org.simantics.db.common.procedure.wrapper.NoneToAsyncProcedure;
-import org.simantics.db.common.procedure.wrapper.SyncToAsyncProcedure;
 import org.simantics.db.exception.AssumptionException;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.NoSingleResultException;
@@ -19,18 +16,15 @@ import org.simantics.db.impl.ForPossibleRelatedValueProcedure;
 import org.simantics.db.impl.ResourceImpl;
 import org.simantics.db.impl.TransientGraph;
 import org.simantics.db.impl.graph.ReadGraphImpl;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
-import org.simantics.db.procedure.AsyncContextProcedure;
-import org.simantics.db.procedure.AsyncMultiProcedure;
-import org.simantics.db.procedure.AsyncProcedure;
-import org.simantics.db.procedure.Procedure;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
+import org.simantics.db.procedure.SyncContextProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.db.procedure.SyncProcedure;
 import org.simantics.db.procore.cluster.ClusterBig;
 import org.simantics.db.procore.cluster.ClusterImpl;
 import org.simantics.db.procore.cluster.ClusterSmall;
 import org.simantics.db.procore.cluster.ResourceTableSmall;
 import org.simantics.db.procore.cluster.ValueTableSmall;
-import org.simantics.db.request.AsyncRead;
 import org.simantics.db.service.DirectQuerySupport;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -46,18 +40,18 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
        }
 
        @Override
-       final public void forEachDirectPersistentStatement(AsyncReadGraph graph, final Resource subject, final AsyncProcedure<DirectStatements> procedure) {
+       final public DirectStatements getDirectPersistentStatements(ReadGraph graph, final Resource subject) {
                ReadGraphImpl impl = (ReadGraphImpl)graph;
-               impl.processor.forEachDirectStatement(impl, subject, procedure, true);
+               return impl.processor.getDirectStatements(impl, subject, true);
        }
 
        @Override
-       final public void forEachDirectStatement(AsyncReadGraph graph, final Resource subject, final AsyncProcedure<DirectStatements> procedure) {
+       final public DirectStatements getDirectStatements(ReadGraph graph, final Resource subject) {
                ReadGraphImpl impl = (ReadGraphImpl)graph;
-               impl.processor.forEachDirectStatement(impl, subject, procedure, false);
+               return impl.processor.getDirectStatements(impl, subject, false);
        }
 
-       @Override
+       /*@Override
        public void forEachDirectStatement(AsyncReadGraph graph, Resource subject, SyncProcedure<DirectStatements> procedure) {
                forEachDirectStatement(graph, subject, new SyncToAsyncProcedure<DirectStatements>(procedure));
        }
@@ -66,9 +60,9 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
        public void forEachDirectStatement(AsyncReadGraph graph, Resource subject, Procedure<DirectStatements> procedure) {
                ReadGraphImpl impl = (ReadGraphImpl)graph;
                impl.processor.forEachDirectStatement(impl, subject, procedure);
-       }
+       }*/
 
-       @Override
+       /*@Override
        public void forRelationInfo(AsyncReadGraph graph, Resource subject, AsyncProcedure<RelationInfo> procedure) {
                ReadGraphImpl impl = (ReadGraphImpl)graph;
                impl.processor.forRelationInfo(impl, subject, procedure);
@@ -82,130 +76,52 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
        @Override
        public void forRelationInfo(AsyncReadGraph graph, Resource subject, Procedure<RelationInfo> procedure) {
                forRelationInfo(graph, subject, new NoneToAsyncProcedure<RelationInfo>(procedure));
+       }*/
+       
+       @Override
+       public RelationInfo getRelationInfo(ReadGraph graph, Resource subject) throws DatabaseException {
+               ReadGraphImpl impl = (ReadGraphImpl)graph;
+               return impl.processor.getRelationInfo(impl, subject);
        }
 
        @Override
-       public AsyncMultiProcedure<Resource> compileForEachObject(ReadGraph graph, final Resource relation, AsyncMultiProcedure<Resource> user) {
+       public SyncMultiProcedure<Resource> compileForEachObject(ReadGraph graph, final Resource relation, SyncMultiProcedure<Resource> user) throws DatabaseException {
                
-               try {
-                       RelationInfo info = graph.syncRequest(new AsyncRead<RelationInfo>() {
-
-                               @Override
-                               public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
-                                       forRelationInfo(graph, relation, procedure);
-                               }
-
-                @Override
-                   public int threadHash() {
-                       return hashCode();
-                   }
-
-                               @Override
-                               public int getFlags() {
-                                       return 0;
-                               }
-
-                       });
-               final int predicateKey = ((ResourceImpl)relation).id;
-                       return new ForEachObjectProcedure(predicateKey, info, session.queryProvider2, user);
-               } catch (DatabaseException e) {
-                       return null;
-               }               
+               RelationInfo info = getRelationInfo(graph, relation);
+               final int predicateKey = ((ResourceImpl)relation).id;
+               return new ForEachObjectProcedure(predicateKey, info, session.queryProvider2, user);
         
        }
 
        @Override
-       public <C> AsyncContextMultiProcedure<C, Resource> compileForEachObject(ReadGraph graph, final Resource relation, AsyncContextMultiProcedure<C, Resource> user) {
+       public <C> SyncContextMultiProcedure<C, Resource> compileForEachObject(ReadGraph graph, final Resource relation, SyncContextMultiProcedure<C, Resource> user) throws DatabaseException {
                
-               try {
-                       RelationInfo info = graph.syncRequest(new AsyncRead<RelationInfo>() {
-
-                               @Override
-                               public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
-                                       forRelationInfo(graph, relation, procedure);
-                               }
-
-                @Override
-                   public int threadHash() {
-                       return hashCode();
-                   }
-
-                               @Override
-                               public int getFlags() {
-                                       return 0;
-                               }
-
-                       });
-               final int predicateKey = ((ResourceImpl)relation).id;
-                       return new ForEachObjectContextProcedure<C>(predicateKey, info, session.queryProvider2, user);
-               } catch (DatabaseException e) {
-                       return null;
-               }               
+               RelationInfo info = getRelationInfo(graph, relation);
+               final int predicateKey = ((ResourceImpl)relation).id;
+               return new ForEachObjectContextProcedure<C>(predicateKey, info, session.queryProvider2, user);
         
        }
        
        @Override
-       public <T> AsyncProcedure<T> compilePossibleRelatedValue(ReadGraph graph, final Resource relation, AsyncProcedure<T> user) {
+       public <T> SyncProcedure<T> compilePossibleRelatedValue(ReadGraph graph, final Resource relation, SyncProcedure<T> user) throws DatabaseException {
                
-               try {
-                       RelationInfo info = graph.syncRequest(new AsyncRead<RelationInfo>() {
-
-                               @Override
-                               public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
-                                       forRelationInfo(graph, relation, procedure);
-                               }
-
-                @Override
-                   public int threadHash() {
-                       return hashCode();
-                   }
-
-                               @Override
-                               public int getFlags() {
-                                       return 0;
-                               }
-
-                       });
-               final int predicateKey = ((ResourceImpl)relation).id;
-                       return new ForPossibleRelatedValueProcedure<T>(predicateKey, info, user);
-               } catch (DatabaseException e) {
-                       return null;
-               }               
+               RelationInfo info = getRelationInfo(graph, relation);
+               final int predicateKey = ((ResourceImpl)relation).id;
+               return new ForPossibleRelatedValueProcedure<T>(predicateKey, info, user);
         
        }
 
        @Override
-       public <C, T> AsyncContextProcedure<C, T> compilePossibleRelatedValue(ReadGraph graph, final Resource relation, AsyncContextProcedure<C, T> user) {
+       public <C, T> SyncContextProcedure<C, T> compilePossibleRelatedValue(ReadGraph graph, final Resource relation, SyncContextProcedure<C, T> user) throws DatabaseException {
                
-               try {
-                       RelationInfo info = graph.syncRequest(new AsyncRead<RelationInfo>() {
-
-                               @Override
-                               public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
-                                       forRelationInfo(graph, relation, procedure);
-                               }
-
-                @Override
-                   public int threadHash() {
-                       return hashCode();
-                   }
-
-                               @Override
-                               public int getFlags() {
-                                       return 0;
-                               }
-
-                       });
-               final int predicateKey = ((ResourceImpl)relation).id;
-                       return new ForPossibleRelatedValueContextProcedure<C, T>(predicateKey, info, user);
-               } catch (DatabaseException e) {
-                       return null;
-               }               
+               RelationInfo info = getRelationInfo(graph, relation);
+               final int predicateKey = ((ResourceImpl)relation).id;
+               return new ForPossibleRelatedValueContextProcedure<C, T>(predicateKey, info, user);
         
        }
        
        @Override
-       public void forEachObjectCompiled(AsyncReadGraph graph, Resource subject, final AsyncMultiProcedure<Resource> procedure) {
+       public void forEachObjectCompiled(ReadGraph graph, Resource subject, final SyncMultiProcedure<Resource> procedure) {
                
         assert(subject != null);
         
@@ -261,7 +177,7 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
        }
 
        @Override
-       public <C> void forEachObjectCompiled(AsyncReadGraph graph, Resource subject, C context, final AsyncContextMultiProcedure<C, Resource> procedure) {
+       public <C> void forEachObjectCompiled(ReadGraph graph, Resource subject, C context, final SyncContextMultiProcedure<C, Resource> procedure) {
                
                assert(subject != null);
 
@@ -285,7 +201,7 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
        }
        
        @Override
-       public <T> void forPossibleRelatedValueCompiled(AsyncReadGraph graph, Resource subject, final AsyncProcedure<T> procedure) {
+       public <T> void forPossibleRelatedValueCompiled(ReadGraph graph, Resource subject, final SyncProcedure<T> procedure) {
                
                assert(subject != null);
 
@@ -302,11 +218,24 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
         
 //        if(callerThread == suggestSchedule) {
                
-               if(info.isFunctional) {
-                       getRelatedValue4(impl, subjectId, proc);
-               } else {
-                       getRelatedValue4(impl, subjectId, proc);
+//             if(info.isFunctional) {
+        try {
+               T result = getRelatedValue4(impl, subjectId, proc);
+               try {
+                       proc.execute(graph, result);
+               } catch (DatabaseException e2) {
+                       LOGGER.error("Unexpected exception while handling related value", e2);
                }
+        } catch (DatabaseException e) {
+               try {
+                       proc.exception(graph, e);
+               } catch (DatabaseException e2) {
+                       LOGGER.error("Unexpected exception while handling related value", e2);
+               }
+        }
+//             } else {
+//                     getRelatedValue4(impl, subjectId, proc);
+//             }
                
 //        } else {
 //             
@@ -341,7 +270,7 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
        }
 
        @Override
-       public <C, T> void forPossibleRelatedValueCompiled(AsyncReadGraph graph, Resource subject, C context, final AsyncContextProcedure<C, T> procedure) {
+       public <C, T> void forPossibleRelatedValueCompiled(ReadGraph graph, Resource subject, C context, final SyncContextProcedure<C, T> procedure) {
                
                assert(subject != null);
 
@@ -356,15 +285,21 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
         
 //        impl.inc();
                
-        if(info.isFunctional) {
-               getRelatedValue4(impl, subjectId, context, proc);
-        } else {
-               getRelatedValue4(impl, subjectId, context, proc);
-        }
+//        if(info.isFunctional) {
+//        } else {
+//             getRelatedValue4(impl, subjectId, context, proc);
+//        }
+
+               try {
+                       T result = getRelatedValue4(impl, subjectId, context, proc);
+               proc.execute(graph, context, result);
+               } catch (DatabaseException e) {
+               proc.exception(graph, e);
+               }
                
        }
        
-       @Override
+/*     @Override
        public <T> void forPossibleType(final AsyncReadGraph graph, Resource subject, final AsyncProcedure<Resource> procedure) {
                
         assert(subject != null);
@@ -413,9 +348,11 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
        
                
        }
+       
+       */
 
        @Override
-       public <C> void forPossibleDirectType(final AsyncReadGraph graph, Resource subject, final C context, final AsyncContextProcedure<C, Resource> procedure) {
+       public <C> void forPossibleDirectType(final ReadGraph graph, Resource subject, final C context, final SyncContextProcedure<C, Resource> procedure) {
                
         assert(subject != null);
 
@@ -479,8 +416,7 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
                
        }
        
-       
-       private <C, T> void getRelatedValue4(final ReadGraphImpl graph, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
+       private <C, T> T getRelatedValue4(final ReadGraphImpl graph, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) throws DatabaseException {
                
                int result = 0;
                
@@ -489,18 +425,14 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
                if(subject < 0) {
 
                        if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject, predicate)) {
-                           SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate,
-                                   g -> getRelatedValue4(g, subject, context, procedure)
-                               );
-                               return;
+                           SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate, g -> {});
+                           return getRelatedValue4(graph, subject, context, procedure);
                        }
                        
                        for(TransientGraph g : session.virtualGraphServerSupport.providers) {
                 for (int id : g.getObjects(subject, predicate)) {
                        if(result != 0) {
-                               procedure.exception(graph, new DatabaseException("Multiple objects"));
-//                             graph.dec();
-                               return;
+                               throw new DatabaseException("Multiple objects");
                        } else {
                                result = id;
                        }
@@ -508,121 +440,93 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
                        }
                        
                        if(result == 0) {
-                               
-                       procedure.exception(graph, new DatabaseException("No objects for " + subject ));
-//                     graph.dec();
-                       return;
-                       
+                               throw new DatabaseException("No objects for " + subject );
                        } else {
-                               
-                               getValue4(graph, null, result, context, procedure);
-                               return;
-                               
+                               return getValue4(graph, null, result, context, procedure);
                        }
                        
                } 
                
         final org.simantics.db.procore.cluster.ClusterImpl cluster = session.clusterTable.getClusterByResourceKey(subject);
         if(!cluster.isLoaded()) {
-               cluster.load(session.clusterTranslator, () -> getRelatedValue4(graph, subject, context, procedure));
-               return;
+               cluster.load();
+               return getRelatedValue4(graph, subject, context, procedure);
         }
         
         if(cluster.hasVirtual() && session.virtualGraphServerSupport.virtuals.contains(subject)) {
                        
                        if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject, predicate)) {
-                           SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate,
-                                   g -> getRelatedValue4(g, subject, context, procedure)
-                               );
-                               return;
+                           SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate, g -> {});
+                               return getRelatedValue4(graph, subject, context, procedure);
                        }
                
                        for(TransientGraph g : session.virtualGraphServerSupport.providers) {
                 for (int id : g.getObjects(subject, predicate)) {
                        if(result != 0) {
-                               procedure.exception(graph, new DatabaseException("Multiple objects"));
-//                             graph.dec();
-                               return;
+                               throw new DatabaseException("Multiple objects");
                        } else {
                                result = id;
                        }
                 }
                        }
                        
-                       getRelatedDirectValue4(graph, cluster, subject, result, context, procedure);
+                       return getRelatedDirectValue4(graph, cluster, subject, result, context, procedure);
                        
                } else {
                        
-                       getRelatedDirectValue4(graph, cluster, subject, 0, context, procedure);
+                       return getRelatedDirectValue4(graph, cluster, subject, 0, context, procedure);
                        
                }
                
        }
        
-       private <T> void getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) {
+       private <T> T getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) throws DatabaseException {
                
                Object result = null;
        
                if(subject < 0) {
 
                        if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject)) {
-                           SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, 
-                                   g -> getValue4(g, containerCluster, subject, procedure)
-                           );
-                               return;
+                           SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, g -> {});
+                           return getValue4(graph, containerCluster, subject, procedure);
                        }
                        
                        for(TransientGraph g : session.virtualGraphServerSupport.providers) {
                                Object value = g.getValue(subject);
                                if(value != null) {
                                        if(result != null) {
-                                               procedure.exception(graph, new DatabaseException("Multiple values"));
-//                                             graph.dec();
-                                               return;
+                                               throw new DatabaseException("Multiple values");
                                        } else {
                                                result = value;
                                        }
                                }
                        }
-
-                       procedure.execute(graph, (T)"name");
-//                     graph.dec();
-                       return;
-
+                       
+                       return (T)"name";
+                       
                }
                
                ClusterImpl cluster = containerCluster;
                if(!containerCluster.contains(subject)) {
                        cluster = session.clusterTable.getClusterByResourceKey(subject);
                        if(!cluster.isLoaded()) {
-                               cluster.load(session.clusterTranslator, new Runnable() {
-
-                                       @Override
-                                       public void run() {
-                                               getValue4(graph, containerCluster, subject, procedure);
-                                       }
-
-                               });
-                               return;
+                               cluster.load();
+                               return getValue4(graph, containerCluster, subject, procedure);
                        }
                }
                
         if(cluster.hasVirtual() && session.virtualGraphServerSupport.virtuals.contains(subject)) {
 
                        if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject)) {
-                           SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject,
-                           g -> getValue4(g, containerCluster, subject, procedure)
-                           );
-                               return;
+                           SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, g -> {});
+                           return getValue4(graph, containerCluster, subject, procedure);
                        }
                
                        for(TransientGraph g : session.virtualGraphServerSupport.providers) {
                                Object value = g.getValue(subject);
                                if(value != null) {
                                        if(result != null) {
-                                               procedure.exception(graph, new DatabaseException("Multiple values"));
-//                                             graph.dec();
-                                               return;
+                                               throw new DatabaseException("Multiple values");
                                        } else {
                                                result = value;
                                        }
@@ -630,93 +534,72 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
                        }
                        
                        if(result != null) {
-                               
-                               procedure.execute(graph, (T)result);
-//                             graph.state.barrier.dec();
-                               
+                               return (T)result;
                        } else {
-                               
                                if(ClusterTypeEnum.SMALL == cluster.getType())
-                                       getDirectValue4(graph, (ClusterSmall)cluster, subject, procedure);
+                                       return getDirectValue4(graph, (ClusterSmall)cluster, subject);
                                else 
-                                       getDirectValue4(graph, (ClusterBig)cluster, subject, procedure);
+                                       return getDirectValue4(graph, (ClusterBig)cluster, subject);
                        }
 
                } else {
 
                        if(ClusterTypeEnum.SMALL == cluster.getType())
-                               getDirectValue4(graph, (ClusterSmall)cluster, subject, procedure);
+                               return getDirectValue4(graph, (ClusterSmall)cluster, subject);
                        else 
-                               getDirectValue4(graph, (ClusterBig)cluster, subject, procedure);
+                               return getDirectValue4(graph, (ClusterBig)cluster, subject);
 
                }
        
        }
        
-       private <C, T> void getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
+       private <C, T> T getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) throws DatabaseException {
                
                Object result = null;
        
                if(subject < 0) {
 
                        if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject)) {
-                           SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject,
-                                   g -> getValue4(g, containerCluster, subject, context, procedure)
-                           );
-                               return;
+                           SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, g -> {});
+                           return getValue4(graph, containerCluster, subject, context, procedure);
                        }
                        
                        for(TransientGraph g : session.virtualGraphServerSupport.providers) {
                                Object value = g.getValue(subject);
                                if(value != null) {
                                        if(result != null) {
-                                               procedure.exception(graph, new DatabaseException("Multiple values"));
-//                                             graph.dec();
-                                               return;
+                                               throw new DatabaseException("Multiple values");
                                        } else {
                                                result = value;
                                        }
                                }
                        }
 
-                       procedure.execute(graph, context, (T)"name");
-//                     graph.dec();
-                       return;
-
+                       return (T)"name";
+                       
                }
                
                ClusterImpl cluster = containerCluster;
                if(!containerCluster.contains(subject)) {
                        cluster = session.clusterTable.getClusterByResourceKey(subject);
                        if(!cluster.isLoaded()) {
-                               cluster.load(session.clusterTranslator, new Runnable() {
-
-                                       @Override
-                                       public void run() {
-                                               getValue4(graph, containerCluster, subject, context, procedure);
-                                       }
-
-                               });
-                               return;
+                               cluster.load();
+                               return getValue4(graph, containerCluster, subject, context, procedure);
                        }
                }
                
         if(cluster.hasVirtual() && session.virtualGraphServerSupport.virtuals.contains(subject)) {
 
                        if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject)) {
-                           SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject,
-                                    g -> getValue4(g, containerCluster, subject, context, procedure)
-                           );
-                               return;
+                           SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, g -> {});
+                           return getValue4(graph, containerCluster, subject, context, procedure);
                        }
                
                        for(TransientGraph g : session.virtualGraphServerSupport.providers) {
                                Object value = g.getValue(subject);
                                if(value != null) {
                                        if(result != null) {
-                                               procedure.exception(graph, new DatabaseException("Multiple values"));
-//                                             graph.dec();
-                                               return;
+                                               throw new DatabaseException("Multiple values");
                                        } else {
                                                result = value;
                                        }
@@ -724,84 +607,64 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
                        }
                        
                        if(result != null) {
-                               
-                               procedure.execute(graph, context, (T)result);
-//                             graph.state.barrier.dec();
-                               
+                               return (T)result;
                        } else {
-                               
                                if(ClusterTypeEnum.SMALL == cluster.getType())
-                                       getDirectValue4(graph, (ClusterSmall)cluster, subject, context, procedure);
+                                       return getDirectValue4(graph, (ClusterSmall)cluster, subject);
                                else 
-                                       getDirectValue4(graph, (ClusterBig)cluster, subject, context, procedure);
+                                       return getDirectValue4(graph, (ClusterBig)cluster, subject);
                        }
 
                } else {
 
                        if(ClusterTypeEnum.SMALL == cluster.getType())
-                               getDirectValue4(graph, (ClusterSmall)cluster, subject, context, procedure);
+                               return getDirectValue4(graph, (ClusterSmall)cluster, subject);
                        else 
-                               getDirectValue4(graph, (ClusterBig)cluster, subject, context, procedure);
+                               return getDirectValue4(graph, (ClusterBig)cluster, subject);
 
                }
        
        }
 
-       private <T> void getRelatedDirectValue4(final ReadGraphImpl graph, final ClusterImpl cluster, final int subject, final int result, final ForPossibleRelatedValueProcedure<T> procedure) {
+       private <T> T getRelatedDirectValue4(final ReadGraphImpl graph, final ClusterImpl cluster, final int subject, final int result, final ForPossibleRelatedValueProcedure<T> procedure) throws DatabaseException {
 
-               try {
-
-                       int so = cluster.getSingleObject(subject, procedure, session.clusterTranslator);
-                       if(so == 0) {
-                               if(result == 0) {
-                                       procedure.exception(graph, new DatabaseException("No objects " + subject + " " + procedure.predicateKey));
-//                                     graph.dec();
-                               } else {
-                                       getValue4(graph, cluster, result, procedure);
-                               }
+               int so = cluster.getSingleObject(subject, procedure, session.clusterTranslator);
+               if(so == 0) {
+                       if(result == 0) {
+                               throw new DatabaseException("No objects " + subject + " " + procedure.predicateKey);
                        } else {
-                               if(result == 0) {
-                                       getValue4(graph, cluster, so, procedure);
-                               } else {
-                                       procedure.exception(graph, new DatabaseException("Multiple objects"));
-//                                     graph.dec();
-                               }
+                               return getValue4(graph, cluster, result, procedure);
+                       }
+               } else {
+                       if(result == 0) {
+                               return getValue4(graph, cluster, so, procedure);
+                       } else {
+                               throw new DatabaseException("Multiple objects");
                        }
-
-               } catch (DatabaseException e) {
-                       e.printStackTrace();
                }
-               
-       }
 
-       private <C, T> void getRelatedDirectValue4(final ReadGraphImpl graph, final ClusterImpl cluster, final int subject, final int result, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
-
-               try {
+       }
+       
+       private <C, T> T getRelatedDirectValue4(final ReadGraphImpl graph, final ClusterImpl cluster, final int subject, final int result, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) throws DatabaseException {
 
-                       int so = cluster.getSingleObject(subject, procedure, session.clusterTranslator);
-                       if(so == 0) {
-                               if(result == 0) {
-                                       procedure.exception(graph, new NoSingleResultException("No objects " + subject + " " + procedure.predicateKey, result));
-//                                     graph.dec();
-                               } else {
-                                       getValue4(graph, cluster, result, context, procedure);
-                               }
+               int so = cluster.getSingleObject(subject, procedure, session.clusterTranslator);
+               if(so == 0) {
+                       if(result == 0) {
+                               throw new NoSingleResultException("No objects " + subject + " " + procedure.predicateKey, result);
                        } else {
-                               if(result == 0) {
-                                       getValue4(graph, cluster, so, context, procedure);
-                               } else {
-                                       procedure.exception(graph, new NoSingleResultException("Multiple objects for " + subject + " " + procedure.predicateKey, result));
-//                                     graph.dec();
-                               }
+                               return getValue4(graph, cluster, result, context, procedure);
+                       }
+               } else {
+                       if(result == 0) {
+                               return getValue4(graph, cluster, so, context, procedure);
+                       } else {
+                               throw new NoSingleResultException("Multiple objects for " + subject + " " + procedure.predicateKey, result);
                        }
-
-               } catch (DatabaseException e) {
-                       LOGGER.error("Could not compute related value for subject {} with predicate {}", subject, procedure.predicateKey);
                }
                
        }
        
-       public <T> void getRelatedValue4(final ReadGraphImpl graph, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) {
+       public <T> T getRelatedValue4(final ReadGraphImpl graph, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) throws DatabaseException {
                
                int result = 0;
                
@@ -810,18 +673,14 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
                if(subject < 0) {
 
                        if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject, predicate)) {
-                           SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate,
-                                   g -> getRelatedValue4(g, subject, procedure)
-                           );
-                               return;
+                           SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate, g -> {});
+                           return getRelatedValue4(graph, subject, procedure);
                        }
                        
                        for(TransientGraph g : session.virtualGraphServerSupport.providers) {
                 for (int id : g.getObjects(subject, predicate)) {
                        if(result != 0) {
-                               procedure.exception(graph, new DatabaseException("Multiple objects"));
-//                             graph.dec();
-                               return;
+                               throw new DatabaseException("Multiple objects");
                        } else {
                                result = id;
                        }
@@ -829,64 +688,47 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
                        }
                        
                        if(result == 0) {
-                               
-                       procedure.exception(graph, new DatabaseException("No objects for " + subject ));
-//                     graph.dec();
-                       return;
-                       
+                               throw new DatabaseException("No objects for " + subject );
                        } else {
-                               
-                               getValue4(graph, null, result, procedure);
-                               return;
-                               
+                               return getValue4(graph, null, result, procedure);
                        }
                        
                } 
                
         final org.simantics.db.procore.cluster.ClusterImpl cluster = session.clusterTable.getClusterByResourceKey(subject);
         if(!cluster.isLoaded()) {
-               cluster.load(session.clusterTranslator, new Runnable() {
-
-                               @Override
-                               public void run() {
-                                       getRelatedValue4(graph, subject, procedure);
-                               }
-                       
-               });
-               return;
+               cluster.load();
+               return getRelatedValue4(graph, subject, procedure);
         }
         
         if(cluster.hasVirtual() && session.virtualGraphServerSupport.virtuals.contains(subject)) {
                        
                        if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject, predicate)) {
-                           SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate,
-                                   g -> getRelatedValue4(graph, subject, procedure)
-                           );
-                               return;
+                           SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate, g -> {});
+                           return getRelatedValue4(graph, subject, procedure);
                        }
                
                        for(TransientGraph g : session.virtualGraphServerSupport.providers) {
                 for (int id : g.getObjects(subject, predicate)) {
                        if(result != 0) {
-                               procedure.exception(graph, new DatabaseException("Multiple objects"));
-//                             graph.dec();
-                               return;
+                               throw new DatabaseException("Multiple objects");
                        } else {
                                result = id;
                        }
                 }
                        }
                        
-                       getRelatedDirectValue4(graph, cluster, subject, result, procedure);
+                       return getRelatedDirectValue4(graph, cluster, subject, result, procedure);
                        
                } else {
                        
-                       getRelatedDirectValue4(graph, cluster, subject, 0, procedure);
+                       return getRelatedDirectValue4(graph, cluster, subject, 0, procedure);
                        
                }
                
        }
-       
+
+       /*
        private <C, T> void getDirectValue4(final ReadGraphImpl graph, final ClusterSmall cluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
                
                try {
@@ -900,40 +742,16 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
 //             graph.dec();
                
        }
+       */
 
-       private <T> void getDirectValue4(final ReadGraphImpl graph, final ClusterBig cluster, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) {
+       private <T> T getDirectValue4(final ReadGraphImpl graph, final ClusterBig cluster, final int subject) throws DatabaseException {
                
-               try {
-                       byte[] bytes = cluster.getValue(subject, session.clusterTranslator);
-                       T value = (T)utf(bytes);
-                       procedure.execute(graph, value);
-               } catch (DatabaseException e) {
-                       procedure.execute(graph, null);
-               }
-
-//             graph.dec();
+               byte[] bytes = cluster.getValue(subject, session.clusterTranslator);
+               return (T)utf(bytes);
                
        }
 
-       private <C, T> void getDirectValue4(final ReadGraphImpl graph, final ClusterBig cluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
-               
-               try {
-                       byte[] bytes = cluster.getValue(subject, session.clusterTranslator);
-                       if(bytes == null) {
-                               procedure.execute(graph, context, null);
-                       } else {
-                               T value = (T)utf(bytes);
-                               procedure.execute(graph, context, value);
-                       }
-               } catch (DatabaseException e) {
-                       procedure.execute(graph, context, null);
-               }
-
-//             graph.dec();
-               
-       }
-       
-       private <T> void getDirectValue4(final ReadGraphImpl graph, final ClusterSmall cluster, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) {
+       private <T> T getDirectValue4(final ReadGraphImpl graph, final ClusterSmall cluster, final int subject) {
 
                ResourceTableSmall rt = cluster.resourceTable;
                ValueTableSmall vt = cluster.valueTable;
@@ -941,7 +759,7 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
                byte[] bs = vt.table;
                long[] ls = rt.table;
 
-               int index = ((subject&0xFFFF) << 1) - 1 + rt.offset;
+               int index = ((subject&0xFFF) << 1) - 1 + rt.offset;
 
                int valueIndex = (int)(ls[index] >>> 24) & 0x3FFFFF + vt.offset;
 
@@ -952,11 +770,8 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
                        chars[i] = (char)bs[valueIndex++];
                }
 
-               T value = (T)new String(chars);
+               return (T)new String(chars);
 
-               procedure.execute(graph, value);
-//             graph.dec();
-               
        }
 
        final private String utf(byte[] bytes) throws AssumptionException {
index d871720a8b714e51781cf7100c4f2d4b84f7b235..7165abef3547478f88dde81ba84c9cf15e7d90ef 100644 (file)
@@ -149,7 +149,7 @@ public class QueryControlImpl implements QueryControl {
        }
        
        @Override
-       public boolean resume(AsyncReadGraph graph) {
+       public boolean resume(ReadGraph graph) {
                ReadGraphImpl impl = (ReadGraphImpl)graph;
                return impl.processor.querySupport.resume(impl);
        }
index b3b403ea7175cdf94bb98f15d58d87e9ca53e572..07282029a77d94e46cf1d29fd6f78314d225e81d 100644 (file)
@@ -33,11 +33,14 @@ import org.simantics.db.procore.cluster.ClusterImpl;
 import org.simantics.db.procore.cluster.ClusterSmall;
 import org.simantics.db.service.SerialisationSupport;
 import org.simantics.utils.DataContainer;
+import org.slf4j.LoggerFactory;
 
 import gnu.trove.set.hash.TIntHashSet;
 
 public class QuerySupportImpl implements QuerySupport {
-       
+
+    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(QuerySupportImpl.class);
+
        final SessionImplSocket session;
        final State state;
        final ClusterTable clusterTable;
@@ -212,7 +215,11 @@ public class QuerySupportImpl implements QuerySupport {
 
 //                    int suggestSchedule = graph.processor.processor.resourceThread(id);
 //                    if(graph.callerThread == suggestSchedule) {
-                       procedure.execute(graph, new ResourceImpl(resourceSupport, id));
+                       try {
+                                                       procedure.execute(graph, new ResourceImpl(resourceSupport, id));
+                                               } catch (DatabaseException e) {
+                                                       LOGGER.error("Unexpected exception while handling object", e);
+                                               }
 //                    } else {
 //                     graph.processor.processor.schedule(graph.callerThread, new SessionTask(suggestSchedule) {
 //             
@@ -226,7 +233,11 @@ public class QuerySupportImpl implements QuerySupport {
                        
                 }
                        }
-                       procedure.finished(graph);
+               try {
+                       procedure.finished(graph);
+                       } catch (DatabaseException e) {
+                               LOGGER.error("Unexpected exception while handling objects", e);
+                       }
 //             graph.dec();
                return;
                
@@ -234,14 +245,12 @@ public class QuerySupportImpl implements QuerySupport {
                
         final ClusterImpl cluster = (ClusterImpl)clusterTable.getClusterByResourceKey(subject);
         if(!cluster.isLoaded()) {
-               cluster.load(session.clusterTranslator, new Runnable() {
-
-                               @Override
-                               public void run() {
-                                       getObjects4(graph, subject, procedure);
-                               }
-                       
-               });
+               try {
+                               cluster.load();
+                       } catch (DatabaseException e) {
+                               LOGGER.error("Unexpected exception while handling objects", e);
+                       }
+               getObjects4(graph, subject, procedure);
                return;
         }
                
@@ -249,9 +258,15 @@ public class QuerySupportImpl implements QuerySupport {
                        
                        for(TransientGraph g : virtualGraphServerSupport.providers) {
                 for (final int id : g.getObjects(subject, procedure.predicateKey)) {
+                       try {
+                       procedure.execute(graph, new ResourceImpl(resourceSupport, id));
+                               } catch (DatabaseException e) {
+                                       LOGGER.error("Unexpected exception while handling objects", e);
+                               }
+                       
+                       
 //                    int suggestSchedule = graph.processor.processor.resourceThread(id);
 //                    if(graph.callerThread == suggestSchedule) {
-                       procedure.execute(graph, new ResourceImpl(resourceSupport, id));
 //                    } else {
 //                     graph.processor.processor.schedule(graph.callerThread, new SessionTask(suggestSchedule) {
 //             
@@ -292,7 +307,15 @@ public class QuerySupportImpl implements QuerySupport {
 
 //                    int suggestSchedule = graph.processor.processor.resourceThread(id);
 //                    if(graph.callerThread == suggestSchedule) {
-                       procedure.execute(graph, context, new ResourceImpl(resourceSupport, id));
+                       
+                       try {
+                               procedure.execute(graph, context, new ResourceImpl(resourceSupport, id));
+                               } catch (DatabaseException e) {
+                                       LOGGER.error("Unexpected exception while handling objects", e);
+                               }
+                       
+                       
+                       
 //                    } else {
 //                     graph.processor.processor.schedule(graph.callerThread, new SessionTask(suggestSchedule) {
 //             
@@ -306,7 +329,14 @@ public class QuerySupportImpl implements QuerySupport {
                        
                 }
                        }
-                       procedure.finished(graph, context);
+                       
+               try {
+                       procedure.finished(graph, context);
+                       } catch (DatabaseException e) {
+                               LOGGER.error("Unexpected exception while handling objects", e);
+                       }
+
+                       
 //             graph.dec();
                return;
                
@@ -331,7 +361,11 @@ public class QuerySupportImpl implements QuerySupport {
                 for (final int id : g.getObjects(subject, procedure.predicateKey)) {
 //                    int suggestSchedule = graph.processor.processor.resourceThread(id);
 //                    if(graph.callerThread == suggestSchedule) {
-                       procedure.execute(graph, context, new ResourceImpl(resourceSupport, id));
+                       try {
+                               procedure.execute(graph, context, new ResourceImpl(resourceSupport, id));
+                               } catch (DatabaseException e) {
+                                       LOGGER.error("Unexpected exception while handling objects", e);
+                               }
 //                    } else {
 //                     graph.processor.processor.schedule(graph.callerThread, new SessionTask(suggestSchedule) {
 //             
index f48ccaf6b799a8348a2b8e0341b26a79bb243cee..6d34d9341c425bbdd465616af54a12d6e3e62cf4 100644 (file)
@@ -39,6 +39,7 @@ import org.simantics.db.ExternalValueSupport;
 import org.simantics.db.Metadata;
 import org.simantics.db.MonitorContext;
 import org.simantics.db.MonitorHandler;
+import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.ResourceSerializer;
 import org.simantics.db.Session;
@@ -50,13 +51,15 @@ import org.simantics.db.authentication.UserAuthenticationAgent;
 import org.simantics.db.authentication.UserAuthenticator;
 import org.simantics.db.common.Indexing;
 import org.simantics.db.common.TransactionPolicyRelease;
-import org.simantics.db.common.procedure.BlockingAsyncProcedure;
 import org.simantics.db.common.procedure.adapter.AsyncMultiProcedureAdapter;
 import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
+import org.simantics.db.common.procedure.adapter.SyncMultiProcedureAdapter;
 import org.simantics.db.common.procedure.wrapper.NoneToAsyncListener;
 import org.simantics.db.common.procedure.wrapper.NoneToAsyncMultiListener;
 import org.simantics.db.common.procedure.wrapper.NoneToAsyncMultiProcedure;
 import org.simantics.db.common.procedure.wrapper.NoneToAsyncProcedure;
+import org.simantics.db.common.procedure.wrapper.NoneToSyncMultiListener;
+import org.simantics.db.common.procedure.wrapper.NoneToSyncMultiProcedure;
 import org.simantics.db.common.procedure.wrapper.SyncToAsyncListener;
 import org.simantics.db.common.procedure.wrapper.SyncToAsyncMultiListener;
 import org.simantics.db.common.procedure.wrapper.SyncToAsyncMultiProcedure;
@@ -76,6 +79,7 @@ import org.simantics.db.exception.ResourceNotFoundException;
 import org.simantics.db.exception.RuntimeDatabaseException;
 import org.simantics.db.exception.ServiceException;
 import org.simantics.db.exception.ServiceNotFoundException;
+import org.simantics.db.impl.BlockingAsyncProcedure;
 import org.simantics.db.impl.ClusterBase;
 import org.simantics.db.impl.ClusterI;
 import org.simantics.db.impl.ClusterTraitsBase;
@@ -89,7 +93,7 @@ import org.simantics.db.impl.graph.WriteGraphImpl;
 import org.simantics.db.impl.graph.WriteSupport;
 import org.simantics.db.impl.internal.RandomAccessValueSupport;
 import org.simantics.db.impl.procedure.ResultCallWrappedQueryProcedure4;
-import org.simantics.db.impl.procedure.ResultCallWrappedSingleQueryProcedure4;
+import org.simantics.db.impl.procedure.ResultCallWrappedSyncQueryProcedure;
 import org.simantics.db.impl.query.QueryCache;
 import org.simantics.db.impl.query.QueryCacheBase;
 import org.simantics.db.impl.query.QueryProcessor;
@@ -1674,6 +1678,62 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule
 
     }
 
+    public <T> void scheduleRequest(final MultiRead<T> request, final SyncMultiProcedure<T> procedure, final Semaphore notify) {
+
+        assert (request != null);
+        assert (procedure != null);
+
+        int thread = request.hashCode() & queryProvider2.THREAD_MASK;
+
+        int sync = notify != null ? thread : -1;
+
+        requestManager.scheduleRead(new SessionRead(null, notify) {
+
+            @Override
+            public void run(int thread) {
+
+                fireSessionVariableChange(SessionVariables.QUEUED_READS);
+
+                ListenerBase listener = getListenerBase(procedure);
+
+                final ReadGraphImpl newGraph = ReadGraphImpl.create(getQueryProvider2());
+
+                try {
+
+                    if (listener != null) {
+
+                        newGraph.processor.query(newGraph, request, null, procedure, listener);
+
+//                        newGraph.waitAsync(request);
+
+                    } else {
+
+                        final ResultCallWrappedSyncQueryProcedure<T> wrapper = new ResultCallWrappedSyncQueryProcedure<T>(procedure);
+
+                        try {
+
+                            request.perform(newGraph, wrapper);
+
+                        } catch (Throwable t) {
+
+                            t.printStackTrace();
+
+                        }
+
+                    }
+
+                } finally {
+
+                    fireSessionVariableChange(SessionVariables.QUEUED_READS);
+
+                }
+
+            }
+
+        });
+
+    }
+    
     public <T> void scheduleRequest(final AsyncMultiRead<T> request, final AsyncMultiProcedure<T> procedure, final Semaphore notify) {
 
         assert (request != null);
@@ -3067,21 +3127,21 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule
         final ArrayList<T> result = new ArrayList<T>();
         final DataContainer<Throwable> exception = new DataContainer<Throwable>();
 
-        syncRequest(request, new AsyncMultiProcedure<T>() {
+        syncRequest(request, new SyncMultiProcedure<T>() {
 
             @Override
-            public void execute(AsyncReadGraph graph, T t) {
+            public void execute(ReadGraph graph, T t) {
                 synchronized(result) {
                     result.add(t);
                 }
             }
 
             @Override
-            public void finished(AsyncReadGraph graph) {
+            public void finished(ReadGraph graph) {
             }
 
             @Override
-            public void exception(AsyncReadGraph graph, Throwable t) {
+            public void exception(ReadGraph graph, Throwable t) {
                 exception.set(t);
             }
 
@@ -3099,33 +3159,27 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule
     }
 
     @Override
-    public <T> Collection<T> syncRequest(MultiRead<T> request, AsyncMultiListener<T> procedure) throws DatabaseException {
+    public <T> Collection<T> syncRequest(MultiRead<T> arg0, SyncMultiProcedure<T> arg1) throws DatabaseException {
         assertNotSession();
-        return syncRequest(request, (AsyncMultiProcedure<T>)procedure);
+        throw new Error("Not implemented!");
     }
 
     @Override
     public <T> Collection<T> syncRequest(MultiRead<T> request, SyncMultiListener<T> procedure) throws DatabaseException {
         assertNotSession();
-        return syncRequest(request, new SyncToAsyncMultiListener<T>(procedure));
+        return syncRequest(request, (SyncMultiProcedure<T>)procedure);
     }
 
     @Override
     public <T> Collection<T> syncRequest(MultiRead<T> request, MultiListener<T> procedure) throws DatabaseException {
         assertNotSession();
-        return syncRequest(request, new NoneToAsyncMultiListener<T>(procedure));
-    }
-
-    @Override
-    public <T> Collection<T> syncRequest(MultiRead<T> request, SyncMultiProcedure<T> procedure) throws DatabaseException {
-        assertNotSession();
-        return syncRequest(request, new SyncToAsyncMultiProcedure<T>(procedure));
+        return syncRequest(request, new NoneToSyncMultiListener<T>(procedure));
     }
 
     @Override
     public <T> Collection<T> syncRequest(MultiRead<T> request, MultiProcedure<T> procedure) throws DatabaseException {
         assertNotSession();
-        return syncRequest(request, new NoneToAsyncMultiProcedure<T>(procedure));
+        return syncRequest(request, new NoneToSyncMultiProcedure<T>(procedure));
     }
 
     @Override
@@ -3281,38 +3335,33 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule
 
         assert(request != null);
 
-        asyncRequest(request, new AsyncMultiProcedureAdapter<T>() {
+        asyncRequest(request, new SyncMultiProcedureAdapter<T>() {
             @Override
-            public void exception(AsyncReadGraph graph, Throwable t) {
+            public void exception(ReadGraph graph, Throwable t) {
                 t.printStackTrace();
             }
         });
 
     }
 
-    @Override
-    public <T> void asyncRequest(MultiRead<T> request, AsyncMultiListener<T> procedure) {
-        asyncRequest(request, (AsyncMultiProcedure<T>)procedure);
-    }
-
     @Override
     public <T> void asyncRequest(MultiRead<T> request, SyncMultiListener<T> procedure) {
-        asyncRequest(request, new SyncToAsyncMultiListener<T>(procedure));
+        asyncRequest(request, (SyncMultiProcedure<T>)procedure);
     }
 
     @Override
     public <T> void asyncRequest(MultiRead<T> request, MultiListener<T> procedure) {
-        asyncRequest(request, new NoneToAsyncMultiListener<T>(procedure));
+        asyncRequest(request, new NoneToSyncMultiListener<T>(procedure));
     }
 
     @Override
     public <T> void asyncRequest(MultiRead<T> request, SyncMultiProcedure<T> procedure) {
-        asyncRequest(request, new SyncToAsyncMultiProcedure<T>(procedure));
+       scheduleRequest(request, procedure, null);
     }
 
     @Override
     public <T> void asyncRequest(MultiRead<T> request, MultiProcedure<T> procedure) {
-        asyncRequest(request, new NoneToAsyncMultiProcedure<T>(procedure));
+        asyncRequest(request, new NoneToSyncMultiProcedure<T>(procedure));
     }
 
     @Override
@@ -3354,17 +3403,6 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule
         asyncRequest(request, new NoneToAsyncMultiProcedure<T>(procedure));
     }
 
-    @Override
-    public <T> Collection<T> syncRequest(MultiRead<T> arg0, AsyncMultiProcedure<T> arg1) throws DatabaseException {
-        assertNotSession();
-        throw new Error("Not implemented!");
-    }
-
-    @Override
-    public <T> void asyncRequest(MultiRead<T> arg0, AsyncMultiProcedure<T> arg1) {
-        throw new Error("Not implemented!");
-    }
-
     @Override
     final public <T> void asyncRequest(final ExternalRead<T> request) {
 
@@ -3524,7 +3562,7 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule
 
     public int getAmountOfQueryThreads() {
         // This must be a power of two
-        return 16;
+        return 1;
 //        return Integer.highestOneBit(Runtime.getRuntime().availableProcessors());
     }
 
index 29f34b45f9904527412db0817c0dfeb6702b2c0e..4cedb79470d93a18abadb846296f04dd40041cc3 100644 (file)
@@ -31,8 +31,8 @@ import org.simantics.db.impl.Table;
 import org.simantics.db.impl.TableHeader;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.impl.query.QueryProcessor;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.db.service.ClusterUID;
 
 import fi.vtt.simantics.procore.DebugPolicy;
@@ -250,7 +250,7 @@ final public class ClusterBig extends ClusterImpl {
         return objectTable.getSingleObject(objectIndex, support, this);
     }
 
-    public void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, AsyncMultiProcedure<Resource> procedure,
+    public void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, SyncMultiProcedure<Resource> procedure,
             ClusterSupport support) throws DatabaseException {
         if (DEBUG)
             System.out.println("Cluster.forObjects1: rk=" + resourceKey + " pk=" + predicateKey);
@@ -263,7 +263,7 @@ final public class ClusterBig extends ClusterImpl {
         }
         objectTable.foreachObject(graph, objectIndex, procedure, this);
     }
-    public <C> void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, C context, AsyncContextMultiProcedure<C, Resource> procedure,
+    public <C> void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, C context, SyncContextMultiProcedure<C, Resource> procedure,
             ClusterSupport support) throws DatabaseException {
         if (DEBUG)
             System.out.println("Cluster.forObjects1: rk=" + resourceKey + " pk=" + predicateKey);
@@ -342,7 +342,7 @@ final public class ClusterBig extends ClusterImpl {
 
     @Override
     public void forObjects(ReadGraphImpl graph, int resourceKey,
-            int predicateKey, AsyncMultiProcedure<Resource> procedure)
+            int predicateKey, SyncMultiProcedure<Resource> procedure)
             throws DatabaseException {
 
         SessionImplSocket session = (SessionImplSocket)graph.getSession();
index 51818048f4f644c08714f29c8dab8b9feeff4dfa..6063dc8d5dde24a8026ae742d20b573553973367 100644 (file)
@@ -29,8 +29,8 @@ import org.simantics.db.impl.ForPossibleRelatedValueProcedure;
 import org.simantics.db.impl.Table;
 import org.simantics.db.impl.TableHeader;
 import org.simantics.db.impl.graph.ReadGraphImpl;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.db.service.ClusterUID;
 import org.simantics.db.service.ResourceUID;
 import org.slf4j.Logger;
@@ -272,7 +272,7 @@ final public class ClusterSmall extends ClusterImpl {
         return objectTable.getSingleObject(objectIndex, support, this);
     }
 
-    public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, AsyncMultiProcedure<Resource> procedure,
+    public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, SyncMultiProcedure<Resource> procedure,
             ClusterSupport support) throws DatabaseException {
         if (deleted) return;
         if (DEBUG)
@@ -287,7 +287,7 @@ final public class ClusterSmall extends ClusterImpl {
         objectTable.foreachObject(graph, objectIndex, procedure, this);
     }
 
-    public <C> void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, C context, AsyncContextMultiProcedure<C, Resource> procedure,
+    public <C> void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, C context, SyncContextMultiProcedure<C, Resource> procedure,
             ClusterSupport support) throws DatabaseException {
         if (DEBUG)
             System.out.println("ClusterSmall.forObjects1: rk=" + resourceKey + " pk=" + predicateKey);
@@ -386,7 +386,7 @@ final public class ClusterSmall extends ClusterImpl {
 
     @Override
     public void forObjects(ReadGraphImpl graph, int resourceKey,
-            int predicateKey, AsyncMultiProcedure<Resource> procedure) throws DatabaseException {
+            int predicateKey, SyncMultiProcedure<Resource> procedure) throws DatabaseException {
         if (deleted) return;
         SessionImplSocket session = (SessionImplSocket)graph.getSession();
         ClusterSupport support = session.clusterTranslator;
index c0ead5d073744444305acdf0247903c5f2593337..48f46bb07321267278ab761807bb2f575f1381d2 100644 (file)
@@ -18,8 +18,8 @@ import org.simantics.db.impl.IntAllocatorI;
 import org.simantics.db.impl.Modifier;
 import org.simantics.db.impl.ResourceImpl;
 import org.simantics.db.impl.graph.ReadGraphImpl;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 
 import gnu.trove.impl.PrimeFinder;
 
@@ -208,7 +208,7 @@ public class IntHash extends IntHashTrait {
     }
 
     
-    static void foreachInt(final ReadGraphImpl graph, int[] table, int base, final AsyncMultiProcedure<Resource> procedure, Modifier modifier) throws DatabaseException {
+    static void foreachInt(final ReadGraphImpl graph, int[] table, int base, final SyncMultiProcedure<Resource> procedure, Modifier modifier) throws DatabaseException {
 
        int capacity = getRealSize(table, base);
         final int size = getUsedSize(table, base);
@@ -285,7 +285,7 @@ public class IntHash extends IntHashTrait {
         assert(size == count);
     }
 
-    static <C> void foreachInt(final ReadGraphImpl graph, int[] table, int base, C context, final AsyncContextMultiProcedure<C, Resource> procedure, Modifier modifier) throws DatabaseException {
+    static <C> void foreachInt(final ReadGraphImpl graph, int[] table, int base, C context, final SyncContextMultiProcedure<C, Resource> procedure, Modifier modifier) throws DatabaseException {
 
        int capacity = getRealSize(table, base);
        final int size = getUsedSize(table, base);
index da3b7903e7e270f2f1f6f5885ba12a3900700690..458f7b04abd2c94eba1552f4d72e07d7b93cf9cb 100644 (file)
@@ -26,8 +26,8 @@ import org.simantics.db.impl.TableFactory;
 import org.simantics.db.impl.TableIntAllocatorAdapter;
 import org.simantics.db.impl.TableSizeListener;
 import org.simantics.db.impl.graph.ReadGraphImpl;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.db.procore.cluster.TableIntArraySet.Ints;
 
 import gnu.trove.map.hash.TIntIntHashMap;
@@ -146,7 +146,7 @@ public final class ObjectTable extends Table<int[]> {
     }
 
     final public void foreachObject( ReadGraphImpl graph, final int objectIndex, 
-            final AsyncMultiProcedure<Resource> procedure, Modifier modifier) throws DatabaseException {
+            final SyncMultiProcedure<Resource> procedure, Modifier modifier) throws DatabaseException {
        if (ClusterTraits.statementIndexIsDirect(objectIndex)) {
                int key = modifier.execute(objectIndex);
             procedure.execute(graph, new ResourceImpl(graph.getResourceSupport(), key));
@@ -163,7 +163,7 @@ public final class ObjectTable extends Table<int[]> {
     }
 
     final public <C> void foreachObject( ReadGraphImpl graph, final int objectIndex, C context, 
-            final AsyncContextMultiProcedure<C, Resource> procedure, Modifier modifier) throws DatabaseException {
+            final SyncContextMultiProcedure<C, Resource> procedure, Modifier modifier) throws DatabaseException {
        if (ClusterTraits.statementIndexIsDirect(objectIndex)) {
                int key = modifier.execute(objectIndex);
             procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), key));
index 90519a36c3f6cb5916c7429c5af8e8ca41414deb..d7f6abc49a39642279b30d20fb050bd7420c1954 100644 (file)
@@ -9,8 +9,8 @@ import org.simantics.db.impl.ClusterTraitsBase;
 import org.simantics.db.impl.Modifier;
 import org.simantics.db.impl.ResourceImpl;
 import org.simantics.db.impl.graph.ReadGraphImpl;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 
 
 public final class ResourceElementSmall {
@@ -394,7 +394,7 @@ public final class ResourceElementSmall {
     }
 
     public static void foreachObject(long[] table, int index,
-            final ReadGraphImpl graph, final AsyncMultiProcedure<Resource> procedure,
+            final ReadGraphImpl graph, final SyncMultiProcedure<Resource> procedure,
             ClusterSupport support, final int pRef, ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, final Modifier modifier)
     throws DatabaseException {
         if (DEBUG)
@@ -469,7 +469,7 @@ public final class ResourceElementSmall {
     }
     
     public static <C> void foreachObject(long[] table, int index,
-            final ReadGraphImpl graph, final C context, final AsyncContextMultiProcedure<C, Resource> procedure,
+            final ReadGraphImpl graph, final C context, final SyncContextMultiProcedure<C, Resource> procedure,
             ClusterSupport support, final int pRef, ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, final Modifier modifier)
     throws DatabaseException {
         if (DEBUG)
index e997b731870159486a38cfebab9a2b7eb64f7c36..d0619976d4775421d4bd5b915d4dbe23b6063081 100644 (file)
@@ -33,7 +33,8 @@ import org.simantics.db.impl.TableFactory;
 import org.simantics.db.impl.TableSizeListener;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.procedure.AsyncContextMultiProcedure;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.db.procore.cluster.PredicateTable.Status;
 
 
@@ -413,7 +414,7 @@ final class ResourceElement {
     }
     
     public static void foreachObject(long[] table, int index,
-               final ReadGraphImpl graph, final AsyncMultiProcedure<Resource> procedure,
+               final ReadGraphImpl graph, final SyncMultiProcedure<Resource> procedure,
                final ClusterSupport support, final int pRef, final ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, final Modifier modifier)
     throws DatabaseException {
         if (DEBUG)
@@ -506,7 +507,7 @@ final class ResourceElement {
     }
 
     public static <C> void foreachObject(long[] table, int index,
-               final ReadGraphImpl graph, final C context, final AsyncContextMultiProcedure<C, Resource> procedure,
+               final ReadGraphImpl graph, final C context, final SyncContextMultiProcedure<C, Resource> procedure,
                final ClusterSupport support, final int pRef, final ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, final Modifier modifier)
     throws DatabaseException {
         if (DEBUG)
@@ -1021,14 +1022,14 @@ public final class ResourceTable extends Table<long[]> {
     }
 
     public void foreachObject(int resourceIndex, ReadGraphImpl graph,
-               AsyncMultiProcedure<Resource> procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, Modifier modifier) throws DatabaseException {
+               SyncMultiProcedure<Resource> procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, Modifier modifier) throws DatabaseException {
         int realIndex = checkIndexAndGetRealIndex(resourceIndex);
         ResourceElement.foreachObject(table, realIndex, graph, procedure, support,
                        pRef, pCompleteType, ct, modifier);
     }
 
     public <C> void foreachObject(int resourceIndex, ReadGraphImpl graph, C context,
-               AsyncContextMultiProcedure<C, Resource> procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, Modifier modifier) throws DatabaseException {
+               SyncContextMultiProcedure<C, Resource> procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, Modifier modifier) throws DatabaseException {
         int realIndex = checkIndexAndGetRealIndex(resourceIndex);
         ResourceElement.foreachObject(table, realIndex, graph, context, procedure, support,
                        pRef, pCompleteType, ct, modifier);
index d72b79aa567d5d582e23e90f132c9c45edee7599..0278b15312540dd42d88bf580056e3e1c3a748c9 100644 (file)
@@ -28,8 +28,8 @@ import org.simantics.db.impl.Table;
 import org.simantics.db.impl.TableFactory;
 import org.simantics.db.impl.TableSizeListener;
 import org.simantics.db.impl.graph.ReadGraphImpl;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.db.procore.cluster.PredicateTable.Status;
 
 
@@ -201,14 +201,14 @@ public final class ResourceTableSmall extends Table<long[]> {
     }
 
     public void foreachObject(int resourceIndex, ReadGraphImpl graph,
-            AsyncMultiProcedure<Resource> procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum completeType, CompleteTable ct, Modifier modifier) throws DatabaseException {
+            SyncMultiProcedure<Resource> procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum completeType, CompleteTable ct, Modifier modifier) throws DatabaseException {
         int realIndex = checkIndexAndGetRealIndex(resourceIndex);
         ResourceElementSmall.foreachObject(table, realIndex, graph, procedure, support,
                 pRef, completeType, ct, modifier);
     }
 
     public <C> void foreachObject(int resourceIndex, ReadGraphImpl graph, C context,
-            AsyncContextMultiProcedure<C, Resource> procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum completeType, CompleteTable ct, Modifier modifier) throws DatabaseException {
+            SyncContextMultiProcedure<C, Resource> procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum completeType, CompleteTable ct, Modifier modifier) throws DatabaseException {
         int realIndex = checkIndexAndGetRealIndex(resourceIndex);
         ResourceElementSmall.foreachObject(table, realIndex, graph, context, procedure, support,
                 pRef, completeType, ct, modifier);
index 2c57f3627323ebdfcb88d050df524c32fd09fcf3..c0ba6ec61a0344e3abce91d05611231490a64605 100644 (file)
@@ -18,8 +18,8 @@ import org.simantics.db.impl.IntAllocatorI;
 import org.simantics.db.impl.Modifier;
 import org.simantics.db.impl.ResourceImpl;
 import org.simantics.db.impl.graph.ReadGraphImpl;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 
 final class TableIntArraySet {
     public static final int HeaderSize = 1; 
@@ -151,7 +151,7 @@ final class TableIntArraySet {
         return size + HeaderSize;
     }
     
-    static void foreachInt(final int[] table, final int base, ReadGraphImpl graph, AsyncMultiProcedure<Resource> procedure, Modifier modifier) throws DatabaseException {
+    static void foreachInt(final int[] table, final int base, ReadGraphImpl graph, SyncMultiProcedure<Resource> procedure, Modifier modifier) throws DatabaseException {
        
         final int size = -table[base + SIZE_OFFSET];
         assert(size>0);
@@ -170,7 +170,7 @@ final class TableIntArraySet {
         
     }
 
-    static <C> void foreachInt(final int[] table, final int base, ReadGraphImpl graph, C context, AsyncContextMultiProcedure<C, Resource> procedure, Modifier modifier) throws DatabaseException {
+    static <C> void foreachInt(final int[] table, final int base, ReadGraphImpl graph, C context, SyncContextMultiProcedure<C, Resource> procedure, Modifier modifier) throws DatabaseException {
        
         final int size = -table[base + SIZE_OFFSET];
         assert(size>0);
index f13042faa0a39ecdc21f5fa532c6f958d55ad707..a0e0eb14bb813de23b83ecb43362571ddd0c1898 100644 (file)
@@ -18,7 +18,7 @@ import org.simantics.db.impl.IntAllocatorI;
 import org.simantics.db.impl.Modifier;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.impl.query.QueryProcessor;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 
 final class TableIntSet {
     public static final int HeaderSize = IntHash.HeaderSize;
@@ -57,7 +57,7 @@ final class TableIntSet {
         return IntHash.getAllocatedSize(table, base);
     }
     
-    static void foreachInt(int[] table, int base, QueryProcessor processor, ReadGraphImpl graph, AsyncMultiProcedure<Resource> procedure, Modifier modifier) throws DatabaseException {
+    static void foreachInt(int[] table, int base, QueryProcessor processor, ReadGraphImpl graph, SyncMultiProcedure<Resource> procedure, Modifier modifier) throws DatabaseException {
         IntHash.foreachInt(graph, table, base, procedure, modifier);
     }
 
diff --git a/bundles/org.simantics.db.regressionsuite.ontology/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.db.regressionsuite.ontology/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..295926d
--- /dev/null
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1\r
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\r
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8\r
+org.eclipse.jdt.core.compiler.compliance=1.8\r
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\r
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error\r
+org.eclipse.jdt.core.compiler.source=1.8\r
index 859481727bfe9f701f53cbe462dc5ecb6219b83b..ccc64fe9c487599e6c50fa8e89a32f773b412734 100644 (file)
  *******************************************************************************/
 package org.simantics.db.services.adaption;
 
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.procedure.TObjectObjectProcedure;
-import gnu.trove.set.hash.THashSet;
-
 import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.adaption.Adapter;
 import org.simantics.db.adaption.AdaptionService;
-import org.simantics.db.common.procedure.BlockingAsyncProcedure;
 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
-import org.simantics.db.common.procedure.single.SyncReadProcedure;
 import org.simantics.db.common.request.BinaryRead;
 import org.simantics.db.common.request.ReadRequest;
 import org.simantics.db.common.request.TernaryRead;
+import org.simantics.db.common.request.UniqueAsyncRead;
 import org.simantics.db.common.uri.ResourceToURI;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.AdaptionException;
@@ -38,9 +33,11 @@ import org.simantics.db.request.Read;
 import org.simantics.layer0.Layer0;
 import org.simantics.utils.datastructures.Pair;
 
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.procedure.TObjectObjectProcedure;
+import gnu.trove.set.hash.THashSet;
+
 public class AdaptionService2 implements AdaptionService {
-       
-       int foobaz;
 
     THashMap<Pair<Class<?>,Class<?>>, AdapterDeclaration<?>> adapters =
         new THashMap<Pair<Class<?>,Class<?>>, AdapterDeclaration<?>>();
@@ -588,14 +585,14 @@ public class AdaptionService2 implements AdaptionService {
        Adapter<T,C> adapter = getAdapter(g, r, context, contextClass, targetClass, possible);
        if(adapter == null) return null;
        
-       BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<T>(g, null, adapter);
-       
-//             SyncReadProcedure<T> procedure = new SyncReadProcedure<T>();
-       adapter.adapt(g, r, context, ap);
-       
-       return ap.get();
-//             procedure.checkAndThrow();
-//             return procedure.result;
+       return g.syncRequest(new UniqueAsyncRead<T>() {
+
+                       @Override
+                       public void perform(AsyncReadGraph graph, AsyncProcedure<T> procedure) {
+                               adapter.adapt(graph, r, context, procedure);
+                       }
+                       
+               });
        
     }
     
@@ -873,23 +870,23 @@ public class AdaptionService2 implements AdaptionService {
 
                 if(decl == null) {
                     if(possible) {
-                        procedure.execute(graph, null);
+                        procedure.execute(g, null);
                     } else {
-                        procedure.exception(graph, new AdaptionException("There are no adapters declared or defined for class " + clazz + "."));
+                        procedure.exception(g, new AdaptionException("There are no adapters declared or defined for class " + clazz + "."));
                     }
                 } else {
                     try {
-                        procedure.execute(graph, decl.adaptNew(graph, r, possible));
+                        procedure.execute(g, decl.adaptNew(graph, r, possible));
                     } catch (AdaptionException e) {
                         if(possible) {
-                            procedure.execute(graph, null);
+                            procedure.execute(g, null);
                         } else {
-                            procedure.exception(graph, e);
+                            procedure.exception(g, e);
                         }
                     } catch (ValidationException e) {
-                        procedure.exception(graph, e);
+                        procedure.exception(g, e);
                     } catch (DatabaseException e2) {
-                        procedure.exception(graph, new ServiceException(e2));
+                        procedure.exception(g, new ServiceException(e2));
                     }
                 }
 
index bfef0a95ac823adbc455a495a9471461222fa485..e281a02944a4b50a3578afb3641d98b5379ab3c0 100644 (file)
@@ -41,7 +41,7 @@ public abstract class AbstractReflectionAdapter<T> implements Adapter<T,Resource
                     Object[] args = new Object[parameters.length];
                     for(int i=0;i<parameters.length;++i)
                         args[i] = parameters[i].adapt(graph, r);
-                    construct(graph, procedure, args);
+                    construct(g, procedure, args);
                 }
                 
             });
index 251cb764296ca486421cd51a4f300056f4a8ab69..ed750f538f615140b893d3ece55f3711d670226d 100644 (file)
@@ -88,24 +88,24 @@ public class ReflectionAdapter2<T> implements Adapter<T, Resource> {
                     try {
                        for(int i=0;i<parameters.length;++i)
                                args[i] = parameters[i].adapt(graph, r);
-                       procedure.execute(graph, constructor.newInstance(args));
+                       procedure.execute(g, constructor.newInstance(args));
                                } catch (IllegalArgumentException e) {
-                                   procedure.exception(graph, e);
+                                   procedure.exception(g, e);
                                        e.printStackTrace();
                                } catch (InstantiationException e) {
-                        procedure.exception(graph, e);
+                        procedure.exception(g, e);
                                        e.printStackTrace();
                                } catch (IllegalAccessException e) {
-                        procedure.exception(graph, e);
+                        procedure.exception(g, e);
                                        e.printStackTrace();
                                } catch (InvocationTargetException e) {
-                        procedure.exception(graph, e.getCause());
+                        procedure.exception(g, e.getCause());
                                        e.getCause().printStackTrace();
                                } catch (DatabaseException e) {
-                        procedure.exception(graph, e);
+                        procedure.exception(g, e);
                                        e.printStackTrace();
                                } catch (Throwable t) {
-                                   procedure.exception(graph, t);
+                                   procedure.exception(g, t);
                                    t.printStackTrace();
                                }
                 }
index 35e3d0d8a899f9afd9a0e04033578a7ca505ff98..f7ab9d62c759843ef6543cbe3172dac218f01a37 100644 (file)
@@ -55,7 +55,7 @@ import org.simantics.db.request.Read;
  * @see Resource
  * @see Statement
  */
-public interface AsyncReadGraph extends AsyncRequestProcessor {
+public interface AsyncReadGraph extends ReadGraph, AsyncRequestProcessor {
 
     /**
      * @see ReadGraph#getURI(Resource)
@@ -355,15 +355,15 @@ public interface AsyncReadGraph extends AsyncRequestProcessor {
     /**
      * @see ReadGraph#getObjects(Resource, Resource)
      */
-    void forEachDirectPredicate(Resource subject, AsyncMultiProcedure<Resource> procedure);
+    void forEachDirectPredicate(Resource subject, AsyncProcedure<Set<Resource>> procedure);
     /**
      * @see ReadGraph#getObjects(Resource, Resource)
      */
-    void forEachDirectPredicate(Resource subject, SyncMultiProcedure<Resource> procedure);
+    void forEachDirectPredicate(Resource subject, SyncProcedure<Set<Resource>> procedure);
     /**
      * @see ReadGraph#getObjects(Resource, Resource)
      */
-    void forEachDirectPredicate(Resource subject, MultiProcedure<Resource> procedure);
+    void forEachDirectPredicate(Resource subject, Procedure<Set<Resource>> procedure);
 
     /**
      * @see ReadGraph#getObjects(Resource, Resource)
@@ -1129,12 +1129,9 @@ public interface AsyncReadGraph extends AsyncRequestProcessor {
      */
     void forOrderedSet(Resource subject, MultiProcedure<Resource> procedure);
 
-    int thread();
 //    void inc();
 //    void dec();
     
-    boolean isImmutable(Resource resource) throws DatabaseException;
-    
     boolean performPending();
     
 }
index 3f17927e223693752142a51645fdf7565412765a..ded8292faab41b102d8ef09484975ee620f077fd 100644 (file)
@@ -64,14 +64,7 @@ import org.simantics.db.request.WriteOnly;
  * @see MergingGraphRequestProcessor
  * @see RequestProcessor
  */
-public interface AsyncRequestProcessor extends ServiceLocator, AsyncRequestProcessorSpecific {
-
-       Resource getRootLibrary();
-       
-    /**
-     * @return the {@link Session} for which this processor is based on.
-     */
-    Session getSession();
+public interface AsyncRequestProcessor extends RequestProcessor, AsyncRequestProcessorSpecific {
     
     <T> void async(ReadInterface<T> r, Procedure<T> procedure);
     <T> void async(ReadInterface<T> r, AsyncProcedure<T> procedure);
@@ -80,9 +73,4 @@ public interface AsyncRequestProcessor extends ServiceLocator, AsyncRequestProce
     <T> void async(ReadInterface<T> r, AsyncListener<T> procedure);
     <T> void async(ReadInterface<T> r, SyncListener<T> procedure);
     
-    <T> void async(WriteInterface<T> r);
-    <T> void async(WriteInterface<T> r, Procedure<T> procedure);
-    
-    Object getModificationCounter();
-    
 }
index 429696cda867a078c72ade8baef22733b2786be5..254174917cea5ebb7affb46069f94a6401645df1 100644 (file)
@@ -289,7 +289,7 @@ public interface AsyncRequestProcessorSpecific extends ServiceLocator {
      * @param request an instance of {@link MultiRead}.
      * @param procedure an instance of {@link AsyncMultiListener}.
      */
-    <T> void asyncRequest(MultiRead<T> request, AsyncMultiListener<T> procedure);
+    //<T> void asyncRequest(MultiRead<T> request, AsyncMultiListener<T> procedure);
 
     /**
      * Asynchronously registers the given {@link SyncMultiListener} (as
@@ -329,7 +329,7 @@ public interface AsyncRequestProcessorSpecific extends ServiceLocator {
      * @param request an instance of {@link MultiRead}.
      * @param procedure an instance of {@link AsyncMultiProcedure}.
      */
-    <T> void asyncRequest(MultiRead<T> request, AsyncMultiProcedure<T> procedure);
+    //<T> void asyncRequest(MultiRead<T> request, AsyncMultiProcedure<T> procedure);
 
     /**
      * Asynchronously supplies the result determined from the given
@@ -463,65 +463,5 @@ public interface AsyncRequestProcessorSpecific extends ServiceLocator {
     <T> void asyncRequest(ExternalRead<T> request, Listener<T> procedure);
     <T> void asyncRequest(ExternalRead<T> request, Procedure<T> procedure);
     
-    /**
-     * Asynchronously performs the given {@link Write}. The outcome of the
-     * request will be lost.
-     * 
-     * @param request an instance of {@link Write}.
-     */
-    void asyncRequest(Write request);
-
-    /**
-     * Asynchronously performs the given {@link Write}. The outcome of the
-     * request will be reported to given {@link Consumer} in the form of a
-     * DatabaseException raised during request processing or null upon success.
-     * 
-     * @param request an instance of {@link Write}.
-     * @param request an instance of {@link Consumer}.
-     */
-    void asyncRequest(Write request, Consumer<DatabaseException> callback);
-    
-    <T> void asyncRequest(WriteResult<T> r, Procedure<T> procedure);
-    
-
-    /**
-     * Asynchronously performs the given {@link WriteOnly}. The outcome of the
-     * request will be lost.
-     * 
-     * @param request an instance of {@link Write}.
-     */
-    void asyncRequest(DelayedWrite request);
-
-    /**
-     * Asynchronously performs the given {@link WriteOnly}. The outcome of the
-     * request will be reported to given {@link Consumer} in the form of a
-     * DatabaseException raised during request processing or null upon success.
-     * 
-     * @param request an instance of {@link WriteOnly}.
-     * @param request an instance of {@link Consumer}.
-     */
-    void asyncRequest(DelayedWrite request, Consumer<DatabaseException> callback);
-
-    <T> void asyncRequest(DelayedWriteResult<T> r, Procedure<T> procedure);
-
-    /**
-     * Asynchronously performs the given {@link WriteOnly}. The outcome of the
-     * request will be lost.
-     * 
-     * @param request an instance of {@link Write}.
-     */
-    void asyncRequest(WriteOnly r);
-
-    /**
-     * Asynchronously performs the given {@link WriteOnly}. The outcome of the
-     * request will be reported to given {@link Consumer} in the form of a
-     * DatabaseException raised during request processing or null upon success.
-     * 
-     * @param request an instance of {@link WriteOnly}.
-     * @param request an instance of {@link Consumer}.
-     */
-    void asyncRequest(WriteOnly r, Consumer<DatabaseException> callback);
-    
-    <T> void asyncRequest(WriteOnlyResult<T> r, Procedure<T> procedure);
     
 }
index 91bb052e95aea782bf60ffc7383491316902d2ca..c34a156c2bdea729e32be32ec56897f79eeb4fff 100644 (file)
@@ -37,7 +37,6 @@ import org.simantics.db.procedure.SyncMultiListener;
 import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.db.procedure.SyncProcedure;
 import org.simantics.db.procedure.SyncSetListener;
-import org.simantics.db.request.MultiRead;
 import org.simantics.db.request.Read;
 import org.simantics.scl.compiler.types.Type;
 
@@ -68,7 +67,7 @@ import org.simantics.scl.compiler.types.Type;
  * @see Statement
  * @noimplement
  */
-public interface ReadGraph extends AsyncReadGraph, RequestProcessor {
+public interface ReadGraph extends RequestProcessor {
 
     /**
      * 
@@ -1084,4 +1083,9 @@ public interface ReadGraph extends AsyncReadGraph, RequestProcessor {
     
     boolean setSynchronous(boolean value);
     boolean getSynchronous();
+    
+    boolean isImmutable(Resource resource) throws DatabaseException;
+
+       int thread();
+       
 }
index 68af4664b856442d0b1c7e38ed27d17cb5f74293..5cc0157a3fc9b2ed313ca81f011a3954db319ce6 100644 (file)
@@ -12,6 +12,7 @@
 package org.simantics.db;
 
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.Procedure;
 import org.simantics.db.request.ReadInterface;
 import org.simantics.db.request.WriteInterface;
 
@@ -61,9 +62,21 @@ import org.simantics.db.request.WriteInterface;
  * @see MergingGraphRequestProcessor
  * @see AsyncRequestProcessor
  */
-public interface RequestProcessor extends AsyncRequestProcessor, RequestProcessorSpecific {
+public interface RequestProcessor extends RequestProcessorSpecific, ServiceLocator {
+
+       Resource getRootLibrary();
+       
+    /**
+     * @return the {@link Session} for which this processor is based on.
+     */
+    Session getSession();
 
     <T> T sync(ReadInterface<T> r) throws DatabaseException;
     <T> T sync(WriteInterface<T> r) throws DatabaseException;
     
+    <T> void async(WriteInterface<T> r);
+    <T> void async(WriteInterface<T> r, Procedure<T> procedure);
+    
+    Object getModificationCounter();
+    
 }
index 523d410137a1341bec5e5b3e23f554a338b5c019..055b0b58f5b0be5446c9215e79dbfc80756aecbb 100644 (file)
@@ -12,6 +12,7 @@
 package org.simantics.db;
 
 import java.util.Collection;
+import java.util.function.Consumer;
 
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.procedure.AsyncListener;
@@ -82,7 +83,7 @@ import org.simantics.db.request.WriteResult;
  * @see MergingGraphRequestProcessor
  * @see AsyncRequestProcessor
  */
-public interface RequestProcessorSpecific extends AsyncRequestProcessor {
+public interface RequestProcessorSpecific {
 
     /**
      * Synchronously determines and returns the result of the given {@link Read}
@@ -288,7 +289,7 @@ public interface RequestProcessorSpecific extends AsyncRequestProcessor {
      * @param request an instance of {@link MultiRead}.
      * @param procedure an instance of {@link AsyncMultiListener}.
      */
-    <T> Collection<T> syncRequest(MultiRead<T> request, AsyncMultiListener<T> procedure) throws DatabaseException;
+    //<T> Collection<T> syncRequest(MultiRead<T> request, AsyncMultiListener<T> procedure) throws DatabaseException;
 
     /**
      * Synchronously registers the given {@link SyncMultiListener} (as
@@ -328,7 +329,7 @@ public interface RequestProcessorSpecific extends AsyncRequestProcessor {
      * @param request an instance of {@link MultiRead}.
      * @param procedure an instance of {@link AsyncMultiProcedure}.
      */
-    <T> Collection<T> syncRequest(MultiRead<T> request, AsyncMultiProcedure<T> procedure) throws DatabaseException;
+    //<T> Collection<T> syncRequest(MultiRead<T> request, AsyncMultiProcedure<T> procedure) throws DatabaseException;
 
     /**
      * Synchronously supplies the result determined from the given
@@ -497,4 +498,65 @@ public interface RequestProcessorSpecific extends AsyncRequestProcessor {
      */
     <T> T syncRequest(WriteOnlyResult<T> r) throws DatabaseException;
     
+    /**
+     * Asynchronously performs the given {@link Write}. The outcome of the
+     * request will be lost.
+     * 
+     * @param request an instance of {@link Write}.
+     */
+    void asyncRequest(Write request);
+
+    /**
+     * Asynchronously performs the given {@link Write}. The outcome of the
+     * request will be reported to given {@link Consumer} in the form of a
+     * DatabaseException raised during request processing or null upon success.
+     * 
+     * @param request an instance of {@link Write}.
+     * @param request an instance of {@link Consumer}.
+     */
+    void asyncRequest(Write request, Consumer<DatabaseException> callback);
+    
+    <T> void asyncRequest(WriteResult<T> r, Procedure<T> procedure);
+    
+
+    /**
+     * Asynchronously performs the given {@link WriteOnly}. The outcome of the
+     * request will be lost.
+     * 
+     * @param request an instance of {@link Write}.
+     */
+    void asyncRequest(DelayedWrite request);
+
+    /**
+     * Asynchronously performs the given {@link WriteOnly}. The outcome of the
+     * request will be reported to given {@link Consumer} in the form of a
+     * DatabaseException raised during request processing or null upon success.
+     * 
+     * @param request an instance of {@link WriteOnly}.
+     * @param request an instance of {@link Consumer}.
+     */
+    void asyncRequest(DelayedWrite request, Consumer<DatabaseException> callback);
+
+    <T> void asyncRequest(DelayedWriteResult<T> r, Procedure<T> procedure);
+
+    /**
+     * Asynchronously performs the given {@link WriteOnly}. The outcome of the
+     * request will be lost.
+     * 
+     * @param request an instance of {@link Write}.
+     */
+    void asyncRequest(WriteOnly r);
+
+    /**
+     * Asynchronously performs the given {@link WriteOnly}. The outcome of the
+     * request will be reported to given {@link Consumer} in the form of a
+     * DatabaseException raised during request processing or null upon success.
+     * 
+     * @param request an instance of {@link WriteOnly}.
+     * @param request an instance of {@link Consumer}.
+     */
+    void asyncRequest(WriteOnly r, Consumer<DatabaseException> callback);
+    
+    <T> void asyncRequest(WriteOnlyResult<T> r, Procedure<T> procedure);
+    
 }
index 8e8b2d9bc7149121c46e87c9c4633b972f606c98..7a6e3a4153a27cc29caece09f54c8e652f082d96 100644 (file)
@@ -23,7 +23,7 @@ package org.simantics.db;
  * @see SessionManager
  * @see Session
  */
-public interface Session extends RequestProcessor {    
+public interface Session extends AsyncRequestProcessor {    
     /**
      * Marks the current database state or the beginning of the current ongoing
      * write transaction as an undo point. Calling this method several times
diff --git a/bundles/org.simantics.db/src/org/simantics/db/procedure/SyncContextMultiProcedure.java b/bundles/org.simantics.db/src/org/simantics/db/procedure/SyncContextMultiProcedure.java
new file mode 100644 (file)
index 0000000..63f0314
--- /dev/null
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.procedure;
+
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.exception.DatabaseException;
+
+/**
+ * @author Antti Villberg
+ * 
+ * First execute is called k times. After this finished or exception is called exactly once.
+ *
+ * @param <Result> the result object type accepted by the procedure
+ */
+public interface SyncContextMultiProcedure<Context, Result> {
+
+    /**
+     * Invoked once for each separate result of the request with potentially
+     * multiple results. It shall be guaranteed that all <code>execute</code>
+     * invocations have been completed when either
+     * {@link #finished(AsyncReadGraph)} or
+     * {@link #exception(AsyncReadGraph, Throwable)} are called and that no
+     * <code>execute</code> invocations will follow afterwards.
+     * 
+     * @param graph asynchronous graph access
+     * @param result a single result of the multiresult procedure
+     */
+    void execute(ReadGraph graph, Context context, Result result) throws DatabaseException;
+
+    /**
+     * Invoked after all {@link #execute(AsyncReadGraph, Object)} calls have
+     * been finished successfully. This method will not be invoked if case of
+     * errors in {@link #execute(AsyncReadGraph, Object)} or the performed
+     * request that provides the results to this procedure.
+     * 
+     * @param graph asynchronous graph access
+     */
+    void finished(ReadGraph graph, Context context) throws DatabaseException;
+
+    /**
+     * If an error occurs in the processing of the database request that
+     * produces the results for this procedure.
+     * 
+     * @param graph asynchronous graph access
+     * @param throwable the exception that occurred
+     */
+    void exception(ReadGraph graph, Throwable throwable) throws DatabaseException;
+
+}
diff --git a/bundles/org.simantics.db/src/org/simantics/db/procedure/SyncContextProcedure.java b/bundles/org.simantics.db/src/org/simantics/db/procedure/SyncContextProcedure.java
new file mode 100644 (file)
index 0000000..93c745f
--- /dev/null
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.procedure;
+
+import org.simantics.db.ReadGraph;
+
+/*
+ * 
+ * Execute or exception is called exactly once.
+ * 
+ */
+public interface SyncContextProcedure<Context, Result> {
+    
+    void execute(ReadGraph graph, Context context, Result result);
+    void exception(ReadGraph graph, Throwable throwable);
+       
+}
index b8a4c201277d6c5cbd7cf119d5a619538900c019..0754ac73f77ded327440c062d855a63ba85fa712 100644 (file)
@@ -16,6 +16,7 @@ import org.simantics.db.Session;
 import org.simantics.db.exception.CancelTransactionException;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 
 /**
  * The <code>GraphRequest</code> interface is used to create transaction
@@ -91,6 +92,6 @@ public interface MultiRead<Result> {
      * @throws CancelTransactionException to indicate that the request needs to
      *         be cancelled and any changes rolled back
      */
-    void perform(ReadGraph graph, AsyncMultiProcedure<Result> callback) throws DatabaseException;
+    void perform(ReadGraph graph, SyncMultiProcedure<Result> callback) throws DatabaseException;
     
  }
index 472eb9eee9dac914c0ce7cc5af9b1adaeea1a4a7..7b932f3dea1c361248c87850c84a6625b4b3161f 100644 (file)
  *******************************************************************************/
 package org.simantics.db.service;
 
-import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.DirectStatements;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.RelationInfo;
 import org.simantics.db.Resource;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
-import org.simantics.db.procedure.AsyncContextProcedure;
-import org.simantics.db.procedure.AsyncMultiProcedure;
-import org.simantics.db.procedure.AsyncProcedure;
-import org.simantics.db.procedure.Procedure;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
+import org.simantics.db.procedure.SyncContextProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
 import org.simantics.db.procedure.SyncProcedure;
 
 public interface DirectQuerySupport {
 
-    void forEachDirectPersistentStatement(AsyncReadGraph graph, Resource subject, AsyncProcedure<DirectStatements> procedure);
+    DirectStatements getDirectPersistentStatements(ReadGraph graph, Resource subject);
+    DirectStatements getDirectStatements(ReadGraph graph, Resource subject);
 
-    void forEachDirectStatement(AsyncReadGraph graph, Resource subject, AsyncProcedure<DirectStatements> procedure);
-    void forEachDirectStatement(AsyncReadGraph graph, Resource subject, SyncProcedure<DirectStatements> procedure);
-    void forEachDirectStatement(AsyncReadGraph graph, Resource subject, Procedure<DirectStatements> procedure);
+//     void forEachDirectPersistentStatement(ReadGraph graph, Resource subject, AsyncProcedure<DirectStatements> procedure);
+//    void forEachDirectStatement(ReadGraph graph, Resource subject, AsyncProcedure<DirectStatements> procedure);
+//    void forEachDirectStatement(ReadGraph graph, Resource subject, SyncProcedure<DirectStatements> procedure);
+//    void forEachDirectStatement(ReadGraph graph, Resource subject, Procedure<DirectStatements> procedure);
 
-    void forRelationInfo(AsyncReadGraph graph, Resource subject, AsyncProcedure<RelationInfo> procedure);
-    void forRelationInfo(AsyncReadGraph graph, Resource subject, SyncProcedure<RelationInfo> procedure);
-    void forRelationInfo(AsyncReadGraph graph, Resource subject, Procedure<RelationInfo> procedure);
+    RelationInfo getRelationInfo(ReadGraph graph, Resource subject) throws DatabaseException;
     
-    <T> void forPossibleType(AsyncReadGraph graph, Resource subject, AsyncProcedure<Resource> procedure);
+//    void forRelationInfo(AsyncReadGraph graph, Resource subject, AsyncProcedure<RelationInfo> procedure);
+//    void forRelationInfo(AsyncReadGraph graph, Resource subject, SyncProcedure<RelationInfo> procedure);
+//    void forRelationInfo(AsyncReadGraph graph, Resource subject, Procedure<RelationInfo> procedure);
     
-    AsyncMultiProcedure<Resource> compileForEachObject(ReadGraph graph, Resource relation, AsyncMultiProcedure<Resource> user);
-    <C> AsyncContextMultiProcedure<C, Resource> compileForEachObject(ReadGraph graph, Resource relation, AsyncContextMultiProcedure<C, Resource> user);
-    <T> AsyncProcedure<T> compilePossibleRelatedValue(ReadGraph graph, Resource relation, AsyncProcedure<T> user);
-    <C,T> AsyncContextProcedure<C,T> compilePossibleRelatedValue(ReadGraph graph, Resource relation, AsyncContextProcedure<C,T> user);
+    //<T> void forPossibleType(AsyncReadGraph graph, Resource subject, AsyncProcedure<Resource> procedure);
     
-    void forEachObjectCompiled(AsyncReadGraph graph, Resource subject, AsyncMultiProcedure<Resource> procedure);
-    <C> void forEachObjectCompiled(AsyncReadGraph graph, Resource subject, C context, AsyncContextMultiProcedure<C, Resource> procedure);
-    <T> void forPossibleRelatedValueCompiled(AsyncReadGraph graph, Resource subject, AsyncProcedure<T> procedure);
-    <C,T> void forPossibleRelatedValueCompiled(AsyncReadGraph graph, Resource subject, C context, AsyncContextProcedure<C,T> procedure);
-    <C> void forPossibleDirectType(AsyncReadGraph graph, Resource subject, C context, AsyncContextProcedure<C,Resource> procedure);
+    SyncMultiProcedure<Resource> compileForEachObject(ReadGraph graph, Resource relation, SyncMultiProcedure<Resource> user) throws DatabaseException;
+    <C> SyncContextMultiProcedure<C, Resource> compileForEachObject(ReadGraph graph, Resource relation, SyncContextMultiProcedure<C, Resource> user) throws DatabaseException;
+    <T> SyncProcedure<T> compilePossibleRelatedValue(ReadGraph graph, Resource relation, SyncProcedure<T> user) throws DatabaseException;
+    <C,T> SyncContextProcedure<C,T> compilePossibleRelatedValue(ReadGraph graph, Resource relation, SyncContextProcedure<C,T> user) throws DatabaseException;
+    
+    void forEachObjectCompiled(ReadGraph graph, Resource subject, SyncMultiProcedure<Resource> procedure);
+    <C> void forEachObjectCompiled(ReadGraph graph, Resource subject, C context, SyncContextMultiProcedure<C, Resource> procedure);
+    <T> void forPossibleRelatedValueCompiled(ReadGraph graph, Resource subject, SyncProcedure<T> procedure);
+    <C,T> void forPossibleRelatedValueCompiled(ReadGraph graph, Resource subject, C context, SyncContextProcedure<C,T> procedure);
+    <C> void forPossibleDirectType(ReadGraph graph, Resource subject, C context, SyncContextProcedure<C,Resource> procedure);
     
 }
index 5cc3fa65589cadbd71ade1236e4db2899cf8e28c..3da3c5aa3baa8f71e50bb1615939dcc8ef8a7fae 100644 (file)
@@ -74,7 +74,7 @@ public interface QueryControl {
 
     int getGraphThread(AsyncReadGraph graph);
     
-    boolean resume(AsyncReadGraph graph);
+    boolean resume(ReadGraph graph);
 
     void schedule(AsyncReadGraph graph, int targetThread, ControlProcedure procedure);
 
index 428acc6863952455759b9c3ddd6f2ad2b470afa5..4a59f4b3c8e96268a2097746cfc7accbeb452e56 100644 (file)
@@ -72,7 +72,7 @@ public class ConstantStyle implements Style {
     }
 
     @Override
-    public void activate(RequestProcessor backend, Resource diagram, Resource entry, Group group, final EvaluationContext observer) {
+    public void activate(RequestProcessor backend, Resource diagram, Resource entry, Group group, final EvaluationContext observer) throws DatabaseException {
 
         if (listener != null && !listener.isDisposed())
             return;
index 36e4051571534a7d92094d47667470f91fffb188..843f907a8bedd526f95a0552c9dfe62144320135 100644 (file)
@@ -16,12 +16,14 @@ import java.util.Collection;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
-import org.simantics.db.common.GraphSemaphore;
 import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
+import org.simantics.db.common.request.UniqueAsyncRead;
 import org.simantics.db.common.utils.OrderedSetUtils;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.AsyncProcedure;
 import org.simantics.diagram.content.ConnectionPartData;
 import org.simantics.diagram.content.ConnectionPartRequest;
 import org.simantics.diagram.content.DiagramContents;
@@ -58,19 +60,6 @@ public class DiagramContentRequest extends BaseRequest<Resource, DiagramContents
     public DiagramContents perform(ReadGraph g) throws DatabaseException {
 
         final DiagramResource DIA = DiagramResource.getInstance(g);
-        final DiagramContents result = new DiagramContents();
-
-        result.elements =   new ArrayList<Resource>(previousElementCount);
-        result.nodeSet = new THashSet<Resource>();
-        result.connectionSet = new THashSet<Resource>();
-        result.connectionSegments = new THashSet<EdgeResource>();
-        result.branchPoints = new THashSet<Resource>();
-        result.routeGraphConnectionSet = new THashSet<Resource>();
-        result.routeLinks = new THashSet<EdgeResource>();
-        result.routeLines = new THashSet<Resource>();
-        result.routePoints = new THashSet<Resource>();
-
-        result.partToConnection = new THashMap<Object, Resource>();
 
         // These help loading result.elements in the correct order.
         final AtomicInteger index = new AtomicInteger();
@@ -78,96 +67,113 @@ public class DiagramContentRequest extends BaseRequest<Resource, DiagramContents
         
         Collection<Resource> components = OrderedSetUtils.toList(g, data);
         
-        GraphSemaphore s = new GraphSemaphore(g, 0);
-        
-        for(Resource component : components) {
-               
-            // Must add the elements to the result set here in order to
-            // keep their order the same as in the ordered set.
-            final int elementIndex = index.getAndIncrement();
-            result.elements.add(component);
-
-               Set<Resource> types = g.getTypes(component);
-               
-                if (types.contains(DIA.Connection)) {
-                 if (types.contains(DIA.RouteGraphConnection)) {
-                     g.asyncRequest(new RouteGraphConnectionPartRequest(errorHandler, DIA, component),
-                             new ProcedureAdapter<RouteGraphConnectionPartData>() {
-                         @Override
-                         public void execute(RouteGraphConnectionPartData partData) {
-                             synchronized (result) {
-                                 for (EdgeResource link : partData.links) {
-                                     result.routeLinks.add(link);
-                                     result.partToConnection.put(link, component);
-                                     result.connectionToParts.add(component, link);
-                                 }
-                                 for (Resource line : partData.routeLines) {
-                                     result.routeLines.add(line);
-                                     result.connectionToParts.add(component, line);
-                                     result.partToConnection.put(line, component);
-                                 }
-                                 for (Resource point : partData.routePoints) {
-                                     result.routePoints.add(point);
-                                     result.connectionToParts.add(component, point);
-                                     result.partToConnection.put(point, component);
-                                 }
-                             }
-                             s.release();
-                         }
-                     });
-
-                     synchronized (result.routeGraphConnectionSet) {
-                         result.routeGraphConnectionSet.add(component);
-                     }
-                 } else {
-                     g.asyncRequest(new ConnectionPartRequest(errorHandler, DIA, component),
-                             new ProcedureAdapter<ConnectionPartData>() {
-                         @Override
-                         public void execute(ConnectionPartData partData) {
-                             synchronized (result) {
-                                 for (EdgeResource er : partData.edges) {
-                                     result.connectionSegments.add(er);
-                                     result.partToConnection.put(er, component);
-                                     result.connectionToParts.add(component, er);
-                                 }
-                                 for (Resource bp : partData.branchPoints) {
-                                     result.branchPoints.add(bp);
-                                     result.connectionToParts.add(component, bp);
-                                     result.partToConnection.put(bp, component);
-                                 }
-                             }
-                             s.release();
-                         }
-                     });
-
-                     synchronized (result.connectionSet) {
-                         result.connectionSet.add(component);
-                     }
-                 }
-             }
-             else if (types.contains(DIA.Element)) {
-                 synchronized (result.nodeSet) {
-                     result.nodeSet.add(component);
-                 }
-                 s.release();
-
-             }
-             else {
-                 synchronized (unrecognizedElementIndices) {
-                     // Unrecognized element, mark it to be
-                     // removed after everything is processed.
-                     unrecognizedElementIndices.add(elementIndex);
-                 }
-                 s.release();
-             }         
-               
-        }
-
-        try {
-            s.waitFor(components.size());
-        } catch (InterruptedException e) {
-            LOGGER.error("An error occured while waiting for diagram to load", e);
-        }
+        DiagramContents result = g.syncRequest(new UniqueAsyncRead<DiagramContents>() {
+
+               @Override
+               public void perform(AsyncReadGraph graph, AsyncProcedure<DiagramContents> procedure) {
+
+                       DiagramContents result = new DiagramContents();
+                       procedure.execute(graph, result);
+
+                       result.elements =   new ArrayList<Resource>(previousElementCount);
+                       result.nodeSet = new THashSet<Resource>();
+                       result.connectionSet = new THashSet<Resource>();
+                       result.connectionSegments = new THashSet<EdgeResource>();
+                       result.branchPoints = new THashSet<Resource>();
+                       result.routeGraphConnectionSet = new THashSet<Resource>();
+                       result.routeLinks = new THashSet<EdgeResource>();
+                       result.routeLines = new THashSet<Resource>();
+                       result.routePoints = new THashSet<Resource>();
+
+                       result.partToConnection = new THashMap<Object, Resource>();
+
+                       for(final Resource component : components) {
+
+                               // Must add the elements to the result set here in order to
+                               // keep their order the same as in the ordered set.
+                               final int elementIndex = index.getAndIncrement();
+                               result.elements.add(component);
+
+                               graph.forTypes(component, new ProcedureAdapter<Set<Resource>>() {
+
+                                       @Override
+                                       public void execute(Set<Resource> types) {
+
+                                               if (types.contains(DIA.Connection)) {
+                                                       if (types.contains(DIA.RouteGraphConnection)) {
+                                                               graph.asyncRequest(new RouteGraphConnectionPartRequest(errorHandler, DIA, component),
+                                                                               new ProcedureAdapter<RouteGraphConnectionPartData>() {
+                                                                       @Override
+                                                                       public void execute(RouteGraphConnectionPartData partData) {
+                                                                               synchronized (result) {
+                                                                                       for (EdgeResource link : partData.links) {
+                                                                                               result.routeLinks.add(link);
+                                                                                               result.partToConnection.put(link, component);
+                                                                                               result.connectionToParts.add(component, link);
+                                                                                       }
+                                                                                       for (Resource line : partData.routeLines) {
+                                                                                               result.routeLines.add(line);
+                                                                                               result.connectionToParts.add(component, line);
+                                                                                               result.partToConnection.put(line, component);
+                                                                                       }
+                                                                                       for (Resource point : partData.routePoints) {
+                                                                                               result.routePoints.add(point);
+                                                                                               result.connectionToParts.add(component, point);
+                                                                                               result.partToConnection.put(point, component);
+                                                                                       }
+                                                                               }
+                                                                       }
+                                                               });
+
+                                                               synchronized (result.routeGraphConnectionSet) {
+                                                                       result.routeGraphConnectionSet.add(component);
+                                                               }
+                                                       } else {
+                                                               graph.asyncRequest(new ConnectionPartRequest(errorHandler, DIA, component),
+                                                                               new ProcedureAdapter<ConnectionPartData>() {
+                                                                       @Override
+                                                                       public void execute(ConnectionPartData partData) {
+                                                                               synchronized (result) {
+                                                                                       for (EdgeResource er : partData.edges) {
+                                                                                               result.connectionSegments.add(er);
+                                                                                               result.partToConnection.put(er, component);
+                                                                                               result.connectionToParts.add(component, er);
+                                                                                       }
+                                                                                       for (Resource bp : partData.branchPoints) {
+                                                                                               result.branchPoints.add(bp);
+                                                                                               result.connectionToParts.add(component, bp);
+                                                                                               result.partToConnection.put(bp, component);
+                                                                                       }
+                                                                               }
+                                                                       }
+                                                               });
+
+                                                               synchronized (result.connectionSet) {
+                                                                       result.connectionSet.add(component);
+                                                               }
+                                                       }
+                                               }
+                                               else if (types.contains(DIA.Element)) {
+                                                       synchronized (result.nodeSet) {
+                                                               result.nodeSet.add(component);
+                                                       }
+                                               }
+                                               else {
+                                                       synchronized (unrecognizedElementIndices) {
+                                                               // Unrecognized element, mark it to be
+                                                               // removed after everything is processed.
+                                                               unrecognizedElementIndices.add(elementIndex);
+                                                       }
+                                               }               
+
+                                       }
+
+                               });
+
+                       }
+               }
+
+        });
 
         // Remove elements that were not recognized in descending order.
         unrecognizedElementIndices.sort();
index 3e404cf565b96163ad27d1c3532169e14b243bd8..55754f370e647222013bcbcca664e3edcf4e8b97 100644 (file)
@@ -51,6 +51,7 @@ import org.simantics.db.common.procedure.adapter.ListenerSupport;
 import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
 import org.simantics.db.common.request.AsyncReadRequest;
 import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.common.request.UniqueAsyncRead;
 import org.simantics.db.common.session.SessionEventListenerAdapter;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.CancelTransactionException;
@@ -1339,7 +1340,13 @@ public class GraphToDiagramSynchronizer extends AbstractDisposable implements ID
                             ArrayMap.keys(ProfileKeys.DIAGRAM, ProfileKeys.CANVAS, ProfileKeys.NODE_MAP).values(GraphToDiagramSynchronizer.this.diagram, canvas, dn),
                             new CanvasNotification(canvas));
 
-                    profileObserver.listen(g, GraphToDiagramSynchronizer.this);
+                    g.getSession().asyncRequest(new AsyncReadRequest() {
+                                               
+                                               @Override
+                                               public void run(AsyncReadGraph graph) {
+                                   profileObserver.listen(graph, GraphToDiagramSynchronizer.this);
+                                               }
+                                       });
 
                     return d;
 
@@ -2475,15 +2482,20 @@ public class GraphToDiagramSynchronizer extends AbstractDisposable implements ID
                     return;
                 }
 
-                // NOTICE: Layer information is loaded from the connection entity resource
-                // that is shared by all segments of the same connection.
-                ElementFactoryUtil.loadLayersForElement(graph, layerManager, diagram, edge, info.connection,
-                        new AsyncProcedureAdapter<IElement>() {
-                    @Override
-                    public void exception(AsyncReadGraph graph, Throwable t) {
-                        error("failed to load layers for connection segment", t);
-                    }
-                });
+                graph.syncRequest(new AsyncReadRequest() {
+                                       @Override
+                                       public void run(AsyncReadGraph graph) {
+                               // NOTICE: Layer information is loaded from the connection entity resource
+                               // that is shared by all segments of the same connection.
+                               ElementFactoryUtil.loadLayersForElement(graph, layerManager, diagram, edge, info.connection,
+                                       new AsyncProcedureAdapter<IElement>() {
+                                   @Override
+                                   public void exception(AsyncReadGraph graph, Throwable t) {
+                                       error("failed to load layers for connection segment", t);
+                                   }
+                               });
+                                       }
+                               });
 
                 edge.setHintWithoutNotification(KEY_CONNECTION_BEGIN_PLACEHOLDER, new PlaceholderConnection(
                         EdgeEnd.Begin,
index 856631fa22d4105c32e0549997dfe0d09b890a34..6e7d368b58d61629015f080237a07e5f3205ec17 100644 (file)
@@ -68,13 +68,13 @@ public class MappedTypeGroup implements Group {
     }
 
     @Override
-    public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener<Resource> listener) {
+    public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener<Resource> listener) throws DatabaseException {
         if (types.isEmpty()) {
             System.out.println("MappedTypeGroup has no types!");
             return;
         }
 
-        processor.asyncRequest(new BinaryRead<Resource, Collection<Resource>, Collection<Resource>>(runtimeDiagram, types) {
+        processor.syncRequest(new BinaryRead<Resource, Collection<Resource>, Collection<Resource>>(runtimeDiagram, types) {
 
             @Override
             public Set<Resource> perform(ReadGraph graph) throws DatabaseException {
index 8e2db2488381c4caf6dbb137f34e6425b080ecc5..e025fb2ddf16927783a2fc353817b87c9c068155 100644 (file)
@@ -63,13 +63,13 @@ public class TypeGroup implements Group {
     }
 
     @Override
-    public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener<Resource> listener) {
+    public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener<Resource> listener) throws DatabaseException {
         if (types.isEmpty()) {
             System.out.println("TypeGroup has no types!");
             return;
         }
 
-        processor.asyncRequest(new BinaryRead<Resource, Collection<Resource>, Collection<Resource>>(runtimeDiagram, types) {
+        processor.syncRequest(new BinaryRead<Resource, Collection<Resource>, Collection<Resource>>(runtimeDiagram, types) {
 
             @Override
             public Set<Resource> perform(ReadGraph graph) throws DatabaseException {
index 059bb55fbec0aed9c89a3ffbb2c9305bfdd12891..cc04927f6ef7249c7cb5a33a0620db04f48b22d5 100644 (file)
@@ -38,8 +38,8 @@ public abstract class DiagramElementGroup implements Group {
     }
 
     @Override
-    public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener<Resource> listener) {
-        processor.asyncRequest(new BinaryRead<Class<?>, Resource, Collection<Resource>>(getClass(), runtimeDiagram) {
+    public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener<Resource> listener) throws DatabaseException {
+        processor.syncRequest(new BinaryRead<Class<?>, Resource, Collection<Resource>>(getClass(), runtimeDiagram) {
 
             @Override
             public Set<Resource> perform(ReadGraph graph) throws DatabaseException {
index ee203616da950f31d0fa1f1abbfae793de988f2d..21071ba74bd9453e9c3bdf166c0240bd46156c54 100644 (file)
@@ -47,7 +47,6 @@ import org.simantics.scenegraph.profile.impl.DebugPolicy;
 import org.simantics.scl.runtime.tuple.Tuple;
 import org.simantics.scl.runtime.tuple.Tuple2;
 import org.simantics.utils.datastructures.Pair;
-import org.simantics.utils.threads.AWTThread;
 
 /**
  * For most style implementations it should be enough to override the following
@@ -298,7 +297,7 @@ public abstract class StyleBase<Result> implements Style {
      * @see org.simantics.diagram.profile.Style#activate(org.simantics.db.RequestProcessor, org.simantics.db.Resource, org.simantics.db.layer0.variable.Variable, org.simantics.diagram.profile.Group, org.simantics.diagram.profile.Observer)
      */
     @Override
-    public final void activate(RequestProcessor backend, final Resource runtimeDiagram, final Resource entry, final Group group, final EvaluationContext observer) {
+    public final void activate(RequestProcessor backend, final Resource runtimeDiagram, final Resource entry, final Group group, final EvaluationContext observer) throws DatabaseException {
 
         ObserverGroupListener listener = getListener(runtimeDiagram, group);
 
index bfc439101a81593c895d29da41a6183c0bbfec5c..04e30f70d44621e0c9b7e025ff5aba228e09631b 100644 (file)
@@ -276,8 +276,8 @@ public class RuntimeDiagramManager {
         return createRuntimeDiagram(graph, diagram, desc);
     }
 
-    private void listenRequest(RequestProcessor processor, final Resource diagram) {
-        processor.asyncRequest(new RuntimeVariableForInput(getResourceInput()), new AsyncListener<RuntimeDiagramDesc>() {
+    private void listenRequest(RequestProcessor processor, final Resource diagram) throws DatabaseException {
+        processor.syncRequest(new RuntimeVariableForInput(getResourceInput()), new AsyncListener<RuntimeDiagramDesc>() {
 
             @Override
             public void exception(AsyncReadGraph graph, Throwable throwable) {
index 0e56a7dd2569f5e9ef8efa1cbef0e2eac1ebf52d..7837edcacc99662a4edf7639a366b0f3de4912d9 100644 (file)
@@ -204,11 +204,11 @@ public class Functions {
                 }
                 
                 DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
-                PrimitivePropertyStatementsProcedure foo = new PrimitivePropertyStatementsProcedure();
+                //PrimitivePropertyStatementsProcedure foo = new PrimitivePropertyStatementsProcedure();
 
-                dqs.forEachDirectPersistentStatement(graph, parentRes, foo);
+                DirectStatements ds = dqs.getDirectPersistentStatements(graph, parentRes);
 
-                for(Statement stm : foo.result) {
+                for(Statement stm : ds) {
                     Resource predicate = stm.getPredicate();
                     PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate));
 
index bb0c8a5b189c1ee5f0b11905f18e3cad4bae1183..ecc6b20cc9c517b6e04a8e0691821466b4961478 100644 (file)
@@ -184,7 +184,7 @@ public class IssueUtils {
         public void add(ReadGraph graph, final Resource issue) throws DatabaseException {
             IssueValidityListener listener = new IssueValidityListener(issue);
 
-            graph.asyncRequest(new ResourceRead3<Boolean>(issue, model, source) {
+            graph.syncRequest(new ResourceRead3<Boolean>(issue, model, source) {
 
                 @Override
                 public Boolean perform(ReadGraph graph) throws DatabaseException {
@@ -250,7 +250,7 @@ public class IssueUtils {
             sources.put(source, Pair.make(is, listener));
 
             if (isListeningTracker) {
-                graph.asyncRequest(
+                graph.syncRequest(
                         new Objects(source, ISSUE.IssueSource_Manages),
                         new IssueSourceManagedIssuesListener(disposed, source, model));
             }
index 4753c0b3b79d9c254cf245ce71246f3e4862da9c..8608fc4d595559c91cc4c682bc1c62838c5b70d2 100644 (file)
@@ -67,7 +67,7 @@ public abstract class QueryExecutor2 extends ReadRequest implements AsyncListene
                }; 
                
                if(processor instanceof WriteGraph) processor.syncRequest(request, procedure);
-               else processor.asyncRequest(request, procedure);
+               else processor.syncRequest(request, procedure);
                
        }
 
index 17c26f48386e6455ae85301da8506b0fcd4b35d2..597a125a896594690d392394faa64c19acd9c18a 100644 (file)
@@ -219,7 +219,7 @@ public class MonitorClassFactory2 extends SyncElementFactory {
             }
 
             if(monitorVariable != null)
-               graph.asyncRequest(new MonitorVariableValueRequest(diagramRuntime, element), monitorListener);
+               graph.syncRequest(new MonitorVariableValueRequest(diagramRuntime, element), monitorListener);
             
         }
     }
index 7e480d4ffa1218276448b00fbcf8a64e48cebdec..46142247f47855efcb3a78ca351568a3404d89da 100644 (file)
@@ -12,12 +12,13 @@ import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.simantics.Simantics;
+import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.Disposable;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
+import org.simantics.db.common.procedure.adapter.AsyncListenerAdapter;
 import org.simantics.db.common.procedure.adapter.DisposableListener;
 import org.simantics.db.common.procedure.adapter.DisposableSyncListener;
-import org.simantics.db.common.procedure.adapter.SyncListenerAdapter;
 import org.simantics.db.common.request.TernaryRead;
 import org.simantics.db.common.request.UnaryRead;
 import org.simantics.db.common.request.UniqueRead;
@@ -184,7 +185,7 @@ public class SCLExpressionIssueProvider implements SCLIssueProvider {
         }
     }
     
-    private static class ComponentSyncListenerAdapter extends SyncListenerAdapter<Set<Resource>> implements Disposable {
+    private static class ComponentSyncListenerAdapter extends AsyncListenerAdapter<Set<Resource>> implements Disposable {
 
         private ConcurrentHashMap<Resource, SCLValueDisposableSyncListener> currentlyListening = new ConcurrentHashMap<>();
         private boolean disposed;
@@ -195,7 +196,7 @@ public class SCLExpressionIssueProvider implements SCLIssueProvider {
         }
         
         @Override
-        public void execute(ReadGraph graph, Set<Resource> newComponents) {
+        public void execute(AsyncReadGraph graph, Set<Resource> newComponents) {
             if (currentlyListening.isEmpty() && newComponents.isEmpty()) {
                 // we can stop here as nothing will change
                 return;
index 27c840467a96a9d56bbf17968b2d136cc848de7c..a18fa7b4625f42f3a3218914691a96a5f97bdce3 100644 (file)
@@ -324,7 +324,7 @@ public class ModelHistoryCollector {
             if (variableListener == null) {
                 variableListener = new VariableSetListener(this);
                 initMutex = new Semaphore(0);
-                processor.asyncRequest( subscriptionFunction.get(), variableListener );
+                processor.syncRequest( subscriptionFunction.get(), variableListener );
                 // Force synchronous initialization.
                 initMutex.acquire();
             }
index 8d1a111244aea56b2caf6a63d0629882870b7411..27d6a0dbcb79331a529d962970f7241c186f1411 100644 (file)
@@ -13,6 +13,7 @@ package org.simantics.scenegraph.profile;
 
 import org.simantics.db.RequestProcessor;
 import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.procedure.SetListener;
 
 
@@ -37,6 +38,6 @@ public interface Group {
      *        objects. Usually one just delegates normal database listener
      *        events to this listener.
      */
-    void trackItems(RequestProcessor processor, Resource runtimeDiagram, SetListener<Resource> listener);
+    void trackItems(RequestProcessor processor, Resource runtimeDiagram, SetListener<Resource> listener) throws DatabaseException;
 
 }
index d18e623d049eda44b5e7b113024741f22233544e..c719df2d7aaf862afa12b9dee67aeee6b7b3fa2b 100644 (file)
@@ -13,6 +13,7 @@ package org.simantics.scenegraph.profile;
 
 import org.simantics.db.RequestProcessor;
 import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
 
 /**
  * This interface is not intended to be implemented directly. Extend
@@ -36,7 +37,7 @@ public interface Style {
      * @param group
      * @param observer
      */
-    void activate(RequestProcessor backend, Resource runtimeDiagram, Resource entry, Group group, EvaluationContext observer);
+    void activate(RequestProcessor backend, Resource runtimeDiagram, Resource entry, Group group, EvaluationContext observer) throws DatabaseException;
 
     /**
      * Deactivates this style. Intended to stop tracking the currently tracked
index 48dcd3824b9096439509a9866a04d1fbd45f4060..f3d4c34306d71a7bce5c9779ddee01added2ec60 100644 (file)
@@ -299,7 +299,7 @@ public class SCLFunctions {
     }
     
     public static void subqueryL(ReadGraph graph, Function query, Function executeCallback, Function1<Throwable, Tuple> exceptionCallback, Function1<Tuple0, Boolean> isDisposedCallback) throws DatabaseException {
-        graph.asyncRequest(new Subquery(query), new SyncListenerAdapter<Object>() {
+        graph.syncRequest(new Subquery(query), new SyncListenerAdapter<Object>() {
             @Override
             public void execute(ReadGraph graph, Object result) throws DatabaseException {
                 Simantics.applySCLRead(graph, executeCallback, result);
index 607661163f5f138701da9e08acf46ea61d48cb46..0b7d8aee211fe2859a677734da05ac52dd16c767 100644 (file)
@@ -135,7 +135,7 @@ public class GraphUI implements Adaptable, ListenerSupport, AsyncListenerSupport
                    listener = propertyListener(client, childName);
                    listenerCache.put(child.first, listener);
            }
-               graph.asyncRequest(new FilteredVariableProperties(child.second), listener);
+               graph.syncRequest(new FilteredVariableProperties(child.second), listener);
        }
 
     }
@@ -347,7 +347,7 @@ public class GraphUI implements Adaptable, ListenerSupport, AsyncListenerSupport
         private String childName;
         private boolean listenerDisposed;
 
-        public PropertyListener(AsyncListenerSupport support, ClientModel client, String childName) {
+        public PropertyListener(SyncListenerSupport support, ClientModel client, String childName) {
             super(support);
             this.client = client;
             this.childName = childName;
@@ -359,7 +359,7 @@ public class GraphUI implements Adaptable, ListenerSupport, AsyncListenerSupport
             if(DEBUG)
                 System.out.println("GraphUI adds property  " + property.second.getURI(graph));
 
-            graph.asyncRequest(new CellValue(property.second), new SyncListener<Object>() {
+            graph.syncRequest(new CellValue(property.second), new SyncListener<Object>() {
 
                 @Override
                 public void execute(ReadGraph graph, final Object value) throws DatabaseException {
@@ -456,37 +456,41 @@ public class GraphUI implements Adaptable, ListenerSupport, AsyncListenerSupport
                                @Override
                                public void handle(final String location) {
                                        
-                               processor.asyncRequest(new ReadRequest() {
-
-                                   @Override
-                                   public void run(ReadGraph graph) throws DatabaseException {
-                                       
-                                                       Variable cellVariable = run.getPossibleChild(graph, location);
-                                                       if(cellVariable != null) {
-                                                               final Resource config = cellVariable.getPossiblePropertyValue(graph, "Represents");
-                                                               if(config != null) {
-                                                                       
-                                                                       graph.asyncRequest(new WriteRequest() {
+                               try {
+                                               processor.syncRequest(new ReadRequest() {
+
+                                                   @Override
+                                                   public void run(ReadGraph graph) throws DatabaseException {
+                                                       
+                                                               Variable cellVariable = run.getPossibleChild(graph, location);
+                                                               if(cellVariable != null) {
+                                                                       final Resource config = cellVariable.getPossiblePropertyValue(graph, "Represents");
+                                                                       if(config != null) {
+                                                                               
+                                                                               graph.asyncRequest(new WriteRequest() {
 
-                                                                               @Override
-                                                                               public void perform(WriteGraph graph) throws DatabaseException {
-                                                                                       
-                                                                                       Layer0 l0 = Layer0.getInstance(graph);
+                                                                                       @Override
+                                                                                       public void perform(WriteGraph graph) throws DatabaseException {
+                                                                                               
+                                                                                               Layer0 l0 = Layer0.getInstance(graph);
 //                                                                                     SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);
-                                                                                       graph.deny(config, l0.PartOf);
+                                                                                               graph.deny(config, l0.PartOf);
 //                                                                                     graph.deny(config, sr.RowOf);
 //                                                                                     graph.deny(config, sr.ColumnOf);
+                                                                                               
+                                                                                       }
                                                                                        
-                                                                               }
+                                                                               });
                                                                                
-                                                                       });
-                                                                       
+                                                                       }
                                                                }
-                                                       }
-                                                       
-                                   }
-                                   
-                               });
+                                                               
+                                                   }
+                                                   
+                                               });
+                                       } catch (DatabaseException e) {
+                                               LOGGER.error("Unexpected exception while removing cell", e);
+                                       }
                                        
                                }
                
index 4669fdf4da1d4078372665d510a0f35effd354da..7edd2e81661c80c741f8162074b9f56ac572d890 100644 (file)
@@ -76,11 +76,11 @@ public class SheetFactory implements ElementFactory {
             }
 
             @Override
-            public void execute(AsyncReadGraph graph, final Resource sheet) {
+            public void execute(AsyncReadGraph g, final Resource sheet) {
 
                 if (sheet != null) {
 
-                    graph.asyncRequest(new ReadRequest() {
+                    g.asyncRequest(new ReadRequest() {
 
                         @Override
                         public void run(ReadGraph graph) throws DatabaseException {
@@ -138,7 +138,7 @@ public class SheetFactory implements ElementFactory {
                             // This is called too early as backend.load is
                             // definitely not complete at this time, but right now that is
                             // acceptable from the implementation point-of-view.
-                            procedure.execute(graph, element);
+                            procedure.execute(g, element);
 
                         }
 
index b33137b529b41def27aaad61d836301d8cdf361c..6b5a0355268c983faf3c2db6348dc1359ae9cc6b 100644 (file)
@@ -20,8 +20,8 @@ import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.IMemento;
 import org.eclipse.ui.IPersistableElement;
 import org.simantics.Simantics;
+import org.simantics.db.AsyncRequestProcessor;
 import org.simantics.db.ReadGraph;
-import org.simantics.db.RequestProcessor;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.common.ResourceArray;
@@ -384,7 +384,7 @@ public class ResourceEditorInput2 extends PlatformObject implements IResourceEdi
         return true;
     }
 
-    private void updateCaches(RequestProcessor processor, boolean sync) throws DatabaseException {
+    private void updateCaches(AsyncRequestProcessor processor, boolean sync) throws DatabaseException {
         ReadRequest req = new ReadRequest() {
             @Override
             public void run(ReadGraph g) throws DatabaseException {
index 9b2c1e06ccebf16650796d94b20c2ba768219e45..46a9ade3e3f33936d56ffd6ba64d4fc2365f2293 100644 (file)
@@ -20,7 +20,6 @@ import org.simantics.db.common.request.Queries;
 import org.simantics.db.common.request.UnaryRead;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.request.combinations.Combinators;
-import org.simantics.db.layer0.request.combinations.Combinators.SynchronizationProcedure;
 import org.simantics.db.request.Read;
 import org.simantics.ui.workbench.IResourceEditorInput;
 
@@ -208,10 +207,8 @@ public final class InputValidationCombinators {
         }
         @Override
         public Resource perform(ReadGraph graph) throws DatabaseException {
-            SynchronizationProcedure<Resource> procedure = new SynchronizationProcedure<Resource>();
             Resource relation = graph.getResource(relationURI);
-            graph.forPossibleObject(subject, relation, procedure);
-            return procedure.getResult();
+            return graph.getPossibleObject(subject, relation);
         }
         @Override
         public int hashCode() {
@@ -270,10 +267,8 @@ public final class InputValidationCombinators {
         }
         @Override
         public Resource perform(ReadGraph graph) throws DatabaseException {
-            SynchronizationProcedure<Resource> procedure = new SynchronizationProcedure<Resource>();
             Resource relation = graph.getResource(relationURI);
-            graph.forSingleObject(subject, relation, procedure);
-            return procedure.getResult();
+               return graph.getSingleObject(subject, relation);
         }
         @Override
         public int hashCode() {