From 6326b65c5c6a785aadcb615cb95ceadd8f53964a Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Thu, 26 Jul 2018 23:04:13 +0300 Subject: [PATCH] Working towards multiple readers. 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 --- .../simantics/acorn/cluster/ClusterBig.java | 92 ++-- .../simantics/acorn/cluster/ClusterSmall.java | 52 +- .../ui/graph/impl/LazyGraphLabeler.java | 3 +- .../graph/impl/LazyParametrizedViewpoint.java | 15 +- .../impl/LazyResourceQueryContainer.java | 16 +- .../browsing/ui/graph/impl/LazyViewpoint.java | 12 +- .../CallbackViewpointContributionImpl.java | 2 +- .../FinalCheckedStateContributionImpl.java | 3 +- .../FinalImageDecoratorContributionImpl.java | 3 +- .../FinalImagerContributionImpl.java | 3 +- .../FinalLabelDecoratorContributionImpl.java | 3 +- .../FinalLabelerContributionImpl.java | 3 +- .../FinalViewpointContributionImpl.java | 2 +- .../META-INF/MANIFEST.MF | 1 - .../ForEachAssertedObject.java | 38 +- .../primitiverequest/RelationInfoRequest.java | 7 +- .../procedure/BlockingAsyncProcedure.java | 130 ----- .../single/SingleSetSyncListenerDelegate.java | 6 +- .../wrapper/NoneToSyncMultiListener.java | 51 ++ .../wrapper/NoneToSyncMultiProcedure.java | 46 ++ .../MergingGraphRequestProcessor.java | 56 +- .../db/common/processor/ProcessorBase.java | 23 +- .../db/common/request/UniqueAsyncRead.java | 28 + .../db/common/utils/OrderedSetUtils.java | 4 +- .../db/common/utils/Transaction.java | 5 +- .../db/impl/BlockingAsyncProcedure.java | 89 +++ .../src/org/simantics/db/impl/ClusterI.java | 4 +- .../impl/ForEachObjectContextProcedure.java | 17 +- .../db/impl/ForEachObjectProcedure.java | 17 +- ...rPossibleRelatedValueContextProcedure.java | 14 +- .../ForPossibleRelatedValueProcedure.java | 15 +- .../org/simantics/db/impl/TransientGraph.java | 8 +- .../db/impl/graph/AsyncBarrierImpl.java | 8 +- .../db/impl/graph/MultiIntProcedure.java | 6 +- .../db/impl/graph/ReadGraphImpl.java | 132 +++-- .../db/impl/graph/ReadGraphSupport.java | 14 +- .../ResultCallWrappedSyncQueryProcedure.java | 89 +++ .../db/impl/query/AsyncMultiReadEntry.java | 1 - .../db/impl/query/AsyncReadEntry.java | 1 - .../db/impl/query}/GraphSemaphore.java | 2 +- .../db/impl/query/MultiReadEntry.java | 24 +- .../simantics/db/impl/query/QueryCache.java | 5 +- .../db/impl/query/QueryCacheBase.java | 35 +- .../db/impl/query/QueryProcessor.java | 111 ++-- .../genericrelation/DependenciesRelation.java | 31 +- .../layer0/request/NamespaceRequirements.java | 4 +- .../db/layer0/request/OntologiesForModel.java | 6 +- .../request/combinations/Combinators.java | 48 +- .../db/layer0/util/ConsistsOfProcess.java | 56 +- .../ModelTransferableGraphSourceRequest.java | 6 +- .../procore/internal/ClusterWriteOnly.java | 4 +- .../internal/DirectQuerySupportImpl.java | 509 ++++++------------ .../procore/internal/QueryControlImpl.java | 2 +- .../procore/internal/QuerySupportImpl.java | 64 ++- .../procore/internal/SessionImplSocket.java | 118 ++-- .../db/procore/cluster/ClusterBig.java | 10 +- .../db/procore/cluster/ClusterSmall.java | 10 +- .../simantics/db/procore/cluster/IntHash.java | 8 +- .../db/procore/cluster/ObjectTable.java | 8 +- .../procore/cluster/ResourceElementSmall.java | 8 +- .../db/procore/cluster/ResourceTable.java | 11 +- .../procore/cluster/ResourceTableSmall.java | 8 +- .../db/procore/cluster/TableIntArraySet.java | 8 +- .../db/procore/cluster/TableIntSet.java | 4 +- .../.settings/org.eclipse.jdt.core.prefs | 7 + .../services/adaption/AdaptionService2.java | 43 +- .../reflection/AbstractReflectionAdapter.java | 2 +- .../reflection/ReflectionAdapter2.java | 14 +- .../src/org/simantics/db/AsyncReadGraph.java | 11 +- .../simantics/db/AsyncRequestProcessor.java | 14 +- .../db/AsyncRequestProcessorSpecific.java | 64 +-- .../src/org/simantics/db/ReadGraph.java | 8 +- .../org/simantics/db/RequestProcessor.java | 15 +- .../db/RequestProcessorSpecific.java | 68 ++- .../src/org/simantics/db/Session.java | 2 +- .../procedure/SyncContextMultiProcedure.java | 59 ++ .../db/procedure/SyncContextProcedure.java | 26 + .../org/simantics/db/request/MultiRead.java | 3 +- .../db/service/DirectQuerySupport.java | 48 +- .../simantics/db/service/QueryControl.java | 2 +- .../diagram/adapter/ConstantStyle.java | 2 +- .../adapter/DiagramContentRequest.java | 214 ++++---- .../adapter/GraphToDiagramSynchronizer.java | 32 +- .../diagram/adapter/MappedTypeGroup.java | 4 +- .../simantics/diagram/adapter/TypeGroup.java | 4 +- .../diagram/profile/DiagramElementGroup.java | 4 +- .../simantics/diagram/profile/StyleBase.java | 3 +- .../runtime/RuntimeDiagramManager.java | 4 +- .../simantics/document/server/Functions.java | 6 +- .../simantics/issues/common/IssueUtils.java | 4 +- .../layer0/utils/queries/QueryExecutor2.java | 2 +- .../diagram/monitor/MonitorClassFactory2.java | 2 +- .../scl/issue/SCLExpressionIssueProvider.java | 7 +- .../subscription/ModelHistoryCollector.java | 2 +- .../simantics/scenegraph/profile/Group.java | 3 +- .../simantics/scenegraph/profile/Style.java | 3 +- .../org/simantics/scl/db/SCLFunctions.java | 2 +- .../simantics/spreadsheet/graph/GraphUI.java | 58 +- .../spreadsheet/ui/SheetFactory.java | 6 +- .../ui/workbench/ResourceEditorInput2.java | 4 +- .../input/InputValidationCombinators.java | 9 +- 101 files changed, 1497 insertions(+), 1383 deletions(-) delete mode 100644 bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/BlockingAsyncProcedure.java create mode 100644 bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/wrapper/NoneToSyncMultiListener.java create mode 100644 bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/wrapper/NoneToSyncMultiProcedure.java create mode 100644 bundles/org.simantics.db.common/src/org/simantics/db/common/request/UniqueAsyncRead.java create mode 100644 bundles/org.simantics.db.impl/src/org/simantics/db/impl/BlockingAsyncProcedure.java create mode 100644 bundles/org.simantics.db.impl/src/org/simantics/db/impl/procedure/ResultCallWrappedSyncQueryProcedure.java rename bundles/{org.simantics.db.common/src/org/simantics/db/common => org.simantics.db.impl/src/org/simantics/db/impl/query}/GraphSemaphore.java (97%) create mode 100644 bundles/org.simantics.db.regressionsuite.ontology/.settings/org.eclipse.jdt.core.prefs create mode 100644 bundles/org.simantics.db/src/org/simantics/db/procedure/SyncContextMultiProcedure.java create mode 100644 bundles/org.simantics.db/src/org/simantics/db/procedure/SyncContextProcedure.java diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/cluster/ClusterBig.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/cluster/ClusterBig.java index 1de4006a7..063bcf548 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/cluster/ClusterBig.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/cluster/ClusterBig.java @@ -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 procedure, + public void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, SyncMultiProcedure 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 void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, C context, AsyncContextMultiProcedure procedure, + public void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, C context, SyncContextMultiProcedure 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 procedure) + int predicateKey, SyncMultiProcedure 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 diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/cluster/ClusterSmall.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/cluster/ClusterSmall.java index 117ab75a3..a964c90c9 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/cluster/ClusterSmall.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/cluster/ClusterSmall.java @@ -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 procedure, + public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, SyncMultiProcedure 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 void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, C context, AsyncContextMultiProcedure procedure, + public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, C context, SyncContextMultiProcedure 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 procedure) throws DatabaseException { + int predicateKey, SyncMultiProcedure 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 { diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyGraphLabeler.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyGraphLabeler.java index a7635bedf..639c90391 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyGraphLabeler.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyGraphLabeler.java @@ -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 source = updater.getDataSource(ReadGraph.class); + final DataSource source = updater.getDataSource(AsyncReadGraph.class); assert(source != null); source.schedule(graph -> graph.asyncRequest(labelQuery, procedure)); diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyParametrizedViewpoint.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyParametrizedViewpoint.java index 91aeb9c5d..c5d96a90a 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyParametrizedViewpoint.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyParametrizedViewpoint.java @@ -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 source = updater.getDataSource(ReadGraph.class); + DataSource 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 source = updater.getDataSource(ReadGraph.class); + DataSource source = updater.getDataSource(AsyncReadGraph.class); if (source != null) { - source.schedule(new Consumer() { - @Override - public void accept(ReadGraph source) { - source.asyncRequest(hasChildQuery, hasChildQueryProcedure); - } - }); + source.schedule(graph -> graph.asyncRequest(hasChildQuery, hasChildQueryProcedure)); } } - return hasChildren; } diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyResourceQueryContainer.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyResourceQueryContainer.java index c694ba2e8..808193a18 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyResourceQueryContainer.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyResourceQueryContainer.java @@ -11,14 +11,13 @@ *******************************************************************************/ 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 implements Container source = updater.getDataSource(ReadGraph.class); + final DataSource source = updater.getDataSource(AsyncReadGraph.class); assert(source != null); - source.schedule(new Consumer() { - - @Override - public void accept(ReadGraph source) { - - source.asyncRequest(query, procedure); - - } - - }); + source.schedule(graph -> graph.asyncRequest(query, procedure)); } diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyViewpoint.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyViewpoint.java index a760c848a..a86a172d8 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyViewpoint.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyViewpoint.java @@ -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 source = updater.getDataSource(ReadGraph.class); + DataSource source = updater.getDataSource(AsyncReadGraph.class); final Listener childProcedure = createListener(); - source.schedule(new Consumer() { - @Override - public void accept(ReadGraph source) { - source.asyncRequest(childQuery, childProcedure); - } - }); + source.schedule(graph -> graph.asyncRequest(childQuery, childProcedure)); } return children; diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/CallbackViewpointContributionImpl.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/CallbackViewpointContributionImpl.java index 68bf68913..d6813edbb 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/CallbackViewpointContributionImpl.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/CallbackViewpointContributionImpl.java @@ -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 source = updater.getDataSource(ReadGraph.class); + DataSource source = updater.getDataSource(AsyncReadGraph.class); if (source != null) { source.schedule(graph -> { ReadRequest childQuery = new ReadRequest() { diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalCheckedStateContributionImpl.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalCheckedStateContributionImpl.java index 4c28fae2b..9754fc806 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalCheckedStateContributionImpl.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalCheckedStateContributionImpl.java @@ -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 source = updater.getDataSource(ReadGraph.class); + final DataSource source = updater.getDataSource(AsyncReadGraph.class); assert(source != null); source.schedule(graph -> { diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImageDecoratorContributionImpl.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImageDecoratorContributionImpl.java index 6acaffa43..833db059c 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImageDecoratorContributionImpl.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImageDecoratorContributionImpl.java @@ -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 source = updater.getDataSource(ReadGraph.class); + final DataSource source = updater.getDataSource(AsyncReadGraph.class); assert(source != null); final Procedure procedure = createProcedure(); diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImagerContributionImpl.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImagerContributionImpl.java index b4d233e08..833e6ef19 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImagerContributionImpl.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImagerContributionImpl.java @@ -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 source = updater.getDataSource(ReadGraph.class); + final DataSource source = updater.getDataSource(AsyncReadGraph.class); assert(source != null); final Procedure> procedure = createProcedure(); diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalLabelDecoratorContributionImpl.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalLabelDecoratorContributionImpl.java index 345999000..fa1945dff 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalLabelDecoratorContributionImpl.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalLabelDecoratorContributionImpl.java @@ -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 source = updater.getDataSource(ReadGraph.class); + final DataSource source = updater.getDataSource(AsyncReadGraph.class); assert(source != null); final Procedure procedure = createProcedure(); diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalLabelerContributionImpl.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalLabelerContributionImpl.java index b283d662e..ed5688694 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalLabelerContributionImpl.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalLabelerContributionImpl.java @@ -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 source = updater.getDataSource(ReadGraph.class); + final DataSource source = updater.getDataSource(AsyncReadGraph.class); assert(source != null); final Procedure procedure = createProcedure(); diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalViewpointContributionImpl.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalViewpointContributionImpl.java index f514fa48c..e1dbd4f52 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalViewpointContributionImpl.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalViewpointContributionImpl.java @@ -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 source = updater.getDataSource(ReadGraph.class); + DataSource source = updater.getDataSource(AsyncReadGraph.class); if (source != null) { source.schedule(graph -> { if(childProcedure instanceof Listener) diff --git a/bundles/org.simantics.db.common/META-INF/MANIFEST.MF b/bundles/org.simantics.db.common/META-INF/MANIFEST.MF index b05ec52cd..f0ac2886d 100644 --- a/bundles/org.simantics.db.common/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.db.common/META-INF/MANIFEST.MF @@ -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, diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/ForEachAssertedObject.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/ForEachAssertedObject.java index 541aee94e..6e0a3c0b5 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/ForEachAssertedObject.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/ForEachAssertedObject.java @@ -11,50 +11,20 @@ *******************************************************************************/ 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> { +final public class ForEachAssertedObject extends ResourceAsyncMultiRead2 { public ForEachAssertedObject(Resource subject, Resource relation) { super(subject, relation); } @Override - public Collection perform(ReadGraph graph) throws DatabaseException { - CollectionSupport cs = graph.getService(CollectionSupport.class); - Collection result = cs.createSet(); - DataContainer throwable = new DataContainer(null); - graph.forEachAssertedObject(resource, resource2, new AsyncMultiProcedure() { - - @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 procedure) { + graph.forEachAssertedObject(resource, resource2, procedure); } } diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/RelationInfoRequest.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/RelationInfoRequest.java index 59a66aeaa..7064e09bc 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/RelationInfoRequest.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/RelationInfoRequest.java @@ -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 { @Override public void perform(AsyncReadGraph graph, AsyncProcedure 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 index da3ec4af8..000000000 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/BlockingAsyncProcedure.java +++ /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 implements AsyncProcedure { - - final private Object key; - private Result result = null; - private Throwable exception = null; - final private AsyncReadGraph graph; - final private AsyncProcedure procedure; - final private Semaphore semaphore = new Semaphore(0); -// final private AtomicBoolean latch; - - public BlockingAsyncProcedure(AsyncReadGraph graph, AsyncProcedure 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; - } - -} diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/single/SingleSetSyncListenerDelegate.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/single/SingleSetSyncListenerDelegate.java index 0628507d9..89b59d27d 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/single/SingleSetSyncListenerDelegate.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/single/SingleSetSyncListenerDelegate.java @@ -12,13 +12,13 @@ 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 extends SingleSetSyncListener { - 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 index 000000000..b116791b3 --- /dev/null +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/wrapper/NoneToSyncMultiListener.java @@ -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 implements SyncMultiListener { + + final private MultiListener procedure; + + public NoneToSyncMultiListener(MultiListener 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 index 000000000..bb7b30413 --- /dev/null +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/wrapper/NoneToSyncMultiProcedure.java @@ -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 implements SyncMultiProcedure { + + final private MultiProcedure procedure; + + public NoneToSyncMultiProcedure(MultiProcedure 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; + } + +} diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/processor/MergingGraphRequestProcessor.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/processor/MergingGraphRequestProcessor.java index bf72e0416..aeec2480e 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/processor/MergingGraphRequestProcessor.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/processor/MergingGraphRequestProcessor.java @@ -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 result = new ArrayList(); final DataContainer exception = new DataContainer(); - syncRequest(request, new AsyncMultiProcedureAdapter() { + syncRequest(request, new SyncMultiProcedureAdapter() { @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 Collection syncRequest(MultiRead request, AsyncMultiProcedure procedure) { - throw new UnsupportedOperationException("Not implemented"); - } - @Override public Collection syncRequest(MultiRead request, MultiProcedure procedure) { throw new UnsupportedOperationException("Not implemented"); @@ -967,11 +962,6 @@ public class MergingGraphRequestProcessor implements RequestProcessor { throw new UnsupportedOperationException("Not implemented"); } - @Override - public void asyncRequest(MultiRead request, AsyncMultiProcedure procedure) { - throw new UnsupportedOperationException("Not implemented"); - } - @Override public void asyncRequest(MultiRead request, MultiProcedure procedure) { throw new UnsupportedOperationException("Not implemented"); @@ -1103,11 +1093,11 @@ public class MergingGraphRequestProcessor implements RequestProcessor { } - @Override +/* @Override public Collection syncRequest(MultiRead arg0, AsyncMultiListener arg1) { throw new UnsupportedOperationException("Not implemented."); - } + }*/ @Override public Collection syncRequest(MultiRead arg0, SyncMultiListener arg1) { @@ -1153,12 +1143,6 @@ public class MergingGraphRequestProcessor implements RequestProcessor { } - @Override - public void asyncRequest(MultiRead arg0, AsyncMultiListener arg1) { - throw new UnsupportedOperationException("Not implemented."); - - } - @Override public void asyncRequest(MultiRead arg0, SyncMultiListener arg1) { throw new UnsupportedOperationException("Not implemented."); diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/processor/ProcessorBase.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/processor/ProcessorBase.java index 6e1aeabaa..62c359ff3 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/processor/ProcessorBase.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/processor/ProcessorBase.java @@ -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 void asyncRequest(AsyncMultiRead request, AsyncMultiProcedure procedure) { @@ -173,11 +173,6 @@ public class ProcessorBase implements RequestProcessor { throw new UnsupportedOperationException(); } - @Override - public Collection syncRequest(MultiRead request, AsyncMultiProcedure procedure) { - throw new UnsupportedOperationException(); - } - @Override public Collection syncRequest(MultiRead request, MultiProcedure procedure) { throw new UnsupportedOperationException(); @@ -193,11 +188,6 @@ public class ProcessorBase implements RequestProcessor { throw new UnsupportedOperationException(); } - @Override - public void asyncRequest(MultiRead request, AsyncMultiProcedure procedure) { - throw new UnsupportedOperationException(); - } - @Override public void asyncRequest(MultiRead request, MultiProcedure procedure) { throw new UnsupportedOperationException(); @@ -313,10 +303,10 @@ public class ProcessorBase implements RequestProcessor { throw new UnsupportedOperationException(); } - @Override +/* @Override public Collection syncRequest(MultiRead arg0, AsyncMultiListener arg1) { throw new UnsupportedOperationException(); - } + }*/ @Override public Collection syncRequest(MultiRead arg0, SyncMultiListener arg1) { @@ -355,11 +345,6 @@ public class ProcessorBase implements RequestProcessor { throw new UnsupportedOperationException(); } - @Override - public void asyncRequest(MultiRead arg0, AsyncMultiListener arg1) { - throw new UnsupportedOperationException(); - } - @Override public void asyncRequest(MultiRead arg0, SyncMultiListener 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 index 000000000..e71d5772d --- /dev/null +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/request/UniqueAsyncRead.java @@ -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 implements AsyncRead { + + @Override + public int getFlags() { + return 0; + } + + @Override + public int threadHash() { + return hashCode(); + } + +} diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/utils/OrderedSetUtils.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/utils/OrderedSetUtils.java index eb0ca24b6..4201cb80a 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/utils/OrderedSetUtils.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/utils/OrderedSetUtils.java @@ -238,7 +238,7 @@ public class OrderedSetUtils { /** * Converts ordered set into a list. */ - public static void forEach(AsyncReadGraph g, final Resource l, final AsyncMultiProcedure procedure) { + /*public static void forEach(AsyncReadGraph g, final Resource l, final AsyncMultiProcedure procedure) { g.asyncRequest(new ReadRequest() { @Override @@ -248,7 +248,7 @@ public class OrderedSetUtils { } }); - } + }*/ /** * Creates an empty ordered set. diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/utils/Transaction.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/utils/Transaction.java index 9e5d563a5..96d915482 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/utils/Transaction.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/utils/Transaction.java @@ -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 index 000000000..943322cd9 --- /dev/null +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/BlockingAsyncProcedure.java @@ -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 implements AsyncProcedure { + + final private Object key; + final private ReadGraphImpl graph; + final private AsyncProcedure procedure; + + private Result result = null; + private Throwable exception = null; + + public BlockingAsyncProcedure(ReadGraphImpl graph, AsyncProcedure 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; + } + +} diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ClusterI.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ClusterI.java index 87acea43d..a82a7490f 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ClusterI.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ClusterI.java @@ -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 int getSingleObject(int resourceKey, ForPossibleRelatedValueContextProcedure procedure, ClusterSupport support) throws DatabaseException; - public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, AsyncMultiProcedure procedure) + public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, SyncMultiProcedure procedure) throws DatabaseException; public void forObjects(ReadGraphImpl graph, int resourceKey, ForEachObjectProcedure procedure) diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectContextProcedure.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectContextProcedure.java index 188917994..6bec3b707 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectContextProcedure.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectContextProcedure.java @@ -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 implements AsyncContextMultiProcedure { +public final class ForEachObjectContextProcedure implements SyncContextMultiProcedure { public final int predicateKey; public final int[] clusterKey; @@ -14,9 +15,9 @@ public final class ForEachObjectContextProcedure implements AsyncContextMulti public final RelationInfo info; public final QueryProcessor processor; public final ClusterI.CompleteTypeEnum completeType; - private final AsyncContextMultiProcedure user; + private final SyncContextMultiProcedure user; - public ForEachObjectContextProcedure(int predicateKey, RelationInfo info, QueryProcessor processor, AsyncContextMultiProcedure user) { + public ForEachObjectContextProcedure(int predicateKey, RelationInfo info, QueryProcessor processor, SyncContextMultiProcedure user) { this.predicateKey = predicateKey; this.completeType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey); this.info = info; @@ -27,17 +28,17 @@ public final class ForEachObjectContextProcedure 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); } diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectProcedure.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectProcedure.java index 85790c4de..143d0a186 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectProcedure.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectProcedure.java @@ -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 { +public final class ForEachObjectProcedure implements SyncMultiProcedure { public final int predicateKey; public final int[] clusterKey; @@ -14,9 +15,9 @@ public final class ForEachObjectProcedure implements AsyncMultiProcedure user; + private final SyncMultiProcedure user; - public ForEachObjectProcedure(int predicateKey, RelationInfo info, QueryProcessor processor, AsyncMultiProcedure user) { + public ForEachObjectProcedure(int predicateKey, RelationInfo info, QueryProcessor processor, SyncMultiProcedure user) { this.predicateKey = predicateKey; this.completeType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey); this.info = info; @@ -27,17 +28,17 @@ public final class ForEachObjectProcedure implements AsyncMultiProcedure implements AsyncContextProcedure { +public final class ForPossibleRelatedValueContextProcedure implements SyncContextProcedure { public final int predicateKey; public final int[] clusterKey; public final int[] predicateReference; public final RelationInfo info; public final ClusterI.CompleteTypeEnum completeType; - private final AsyncContextProcedure user; + private final SyncContextProcedure user; - public ForPossibleRelatedValueContextProcedure(int predicateKey, RelationInfo info, AsyncContextProcedure user) { + public ForPossibleRelatedValueContextProcedure(int predicateKey, RelationInfo info, SyncContextProcedure user) { this.predicateKey = predicateKey; this.completeType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey); this.info = info; @@ -23,12 +23,12 @@ public final class ForPossibleRelatedValueContextProcedure 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); } diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForPossibleRelatedValueProcedure.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForPossibleRelatedValueProcedure.java index 6dcb0ea10..bd5e0ccaa 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForPossibleRelatedValueProcedure.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForPossibleRelatedValueProcedure.java @@ -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 implements AsyncProcedure { +public final class ForPossibleRelatedValueProcedure implements SyncProcedure { public final int predicateKey; public final int[] clusterKey; public final int[] predicateReference; public final RelationInfo info; public final ClusterI.CompleteTypeEnum completeType; - private final AsyncProcedure user; + private final SyncProcedure user; - public ForPossibleRelatedValueProcedure(int predicateKey, RelationInfo info, AsyncProcedure user) { + public ForPossibleRelatedValueProcedure(int predicateKey, RelationInfo info, SyncProcedure user) { this.predicateKey = predicateKey; this.completeType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey); this.info = info; @@ -23,12 +24,12 @@ public final class ForPossibleRelatedValueProcedure 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); } diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/TransientGraph.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/TransientGraph.java index f4e722fe5..adbad4ead 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/TransientGraph.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/TransientGraph.java @@ -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; diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/AsyncBarrierImpl.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/AsyncBarrierImpl.java index c1a172625..4b9f19a23 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/AsyncBarrierImpl.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/AsyncBarrierImpl.java @@ -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; diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/MultiIntProcedure.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/MultiIntProcedure.java index 4695b8b33..0f0ad8319 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/MultiIntProcedure.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/MultiIntProcedure.java @@ -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 procedure; + final private SyncMultiProcedure procedure; final private ReadGraphImpl impl; final private QuerySupport support; - public MultiIntProcedure(AsyncMultiProcedure procedure, ReadGraphImpl impl, QuerySupport support) { + public MultiIntProcedure(SyncMultiProcedure procedure, ReadGraphImpl impl, QuerySupport support) { this.procedure = procedure; this.impl = impl; this.support = support; diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java index 299396ed7..7070ee5b8 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java @@ -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 procedure = new AsyncReadProcedure(); + asyncBarrier = new AsyncBarrierImpl(null); BlockingAsyncProcedure ap = new BlockingAsyncProcedure<>(this, null, request); syncRequest(request, ap); return ap.get(); -// procedure.checkAndThrow(); -// return procedure.result; - -// return syncRequest(request, new AsyncProcedureAdapter()); } @@ -2132,6 +2130,8 @@ public class ReadGraphImpl implements ReadGraph { // final ResultCallWrappedSingleQueryProcedure4 wrapper = new ResultCallWrappedSingleQueryProcedure4( // 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 result = new ArrayList(); final DataContainer exception = new DataContainer(); - syncRequest(request, new AsyncMultiProcedure() { + syncRequest(request, new SyncMultiProcedure() { @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 Collection syncRequest(MultiRead request, AsyncMultiListener procedure) { return syncRequest(request, (AsyncMultiProcedure) procedure); - } + }*/ @Override public Collection syncRequest(MultiRead request, SyncMultiListener procedure) { - return syncRequest(request, new SyncToAsyncMultiListener(procedure)); + return syncRequest(request, (SyncMultiProcedure)procedure); } @Override public Collection syncRequest(MultiRead request, MultiListener procedure) { - return syncRequest(request, new NoneToAsyncMultiListener(procedure)); + return syncRequest(request, new NoneToSyncMultiListener(procedure)); } + /* @Override public Collection syncRequest(MultiRead request, AsyncMultiProcedure procedure) { @@ -2339,17 +2340,51 @@ public class ReadGraphImpl implements ReadGraph { return null; } + */ @Override public Collection syncRequest(MultiRead request, SyncMultiProcedure procedure) { - return syncRequest(request, new SyncToAsyncMultiProcedure(procedure)); + + assert (request != null); + + ListenerBase listener = getListenerBase(procedure); + + final ResultCallWrappedSyncQueryProcedure wrapper = new ResultCallWrappedSyncQueryProcedure(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 Collection syncRequest(MultiRead request, MultiProcedure procedure) { - return syncRequest(request, new NoneToAsyncMultiProcedure(procedure)); + return syncRequest(request, new NoneToSyncMultiProcedure(procedure)); } static class AsyncMultiReadProcedure extends ArrayList implements AsyncMultiProcedure { @@ -3327,18 +3362,18 @@ public class ReadGraphImpl implements ReadGraph { // } @Override - final public void forEachDirectPredicate(final Resource subject, final AsyncMultiProcedure procedure) { + final public void forEachDirectPredicate(final Resource subject, final AsyncProcedure> procedure) { processor.forEachDirectPredicate(this, subject, procedure); } @Override - public void forEachDirectPredicate(Resource subject, SyncMultiProcedure procedure) { - forEachDirectPredicate(subject, new SyncToAsyncMultiProcedure(procedure)); + final public void forEachDirectPredicate(final Resource subject, final SyncProcedure> procedure) { + forEachDirectPredicate(subject, new SyncToAsyncProcedure>(procedure)); } @Override - public void forEachDirectPredicate(Resource subject, MultiProcedure procedure) { - forEachDirectPredicate(subject, new NoneToAsyncMultiProcedure(procedure)); + public void forEachDirectPredicate(Resource subject, Procedure> procedure) { + forEachDirectPredicate(subject, new NoneToAsyncProcedure>(procedure)); } @Override @@ -5560,9 +5595,9 @@ public class ReadGraphImpl implements ReadGraph { assert (request != null); - asyncRequest(request, new AsyncMultiProcedureAdapter() { + asyncRequest(request, new SyncMultiProcedureAdapter() { @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 void asyncRequest(MultiRead request, - AsyncMultiListener procedure) { - asyncRequest(request, (AsyncMultiProcedure) procedure); - } - @Override public void asyncRequest(MultiRead request, SyncMultiListener procedure) { - asyncRequest(request, new SyncToAsyncMultiListener(procedure)); + asyncRequest(request, (SyncMultiProcedure)procedure); } @Override public void asyncRequest(MultiRead request, MultiListener procedure) { - asyncRequest(request, new NoneToAsyncMultiListener(procedure)); + asyncRequest(request, new NoneToSyncMultiListener(procedure)); } + @Override public void asyncRequest(final MultiRead request, - final AsyncMultiProcedure procedure) { + final SyncMultiProcedure 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 void asyncRequest(MultiRead request, - SyncMultiProcedure procedure) { - asyncRequest(request, new SyncToAsyncMultiProcedure(procedure)); - } - @Override public void asyncRequest(MultiRead request, MultiProcedure procedure) { - asyncRequest(request, new NoneToAsyncMultiProcedure(procedure)); + asyncRequest(request, new NoneToSyncMultiProcedure(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) { diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphSupport.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphSupport.java index 7bfe5b3d2..4975f2d57 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphSupport.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphSupport.java @@ -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 procedure); void forEachObject(ReadGraphImpl graph, Resource subject, Resource predicate, MultiProcedure procedure); void forEachObject(ReadGraphImpl graph, Resource subject, Resource predicate, AsyncMultiProcedure procedure); - void forEachDirectPredicate(ReadGraphImpl graph, Resource subject, AsyncMultiProcedure procedure); - void forEachDirectStatement(ReadGraphImpl graph, Resource subject, Procedure procedure); - void forEachDirectStatement(ReadGraphImpl graph, Resource subject, AsyncProcedure procedure, boolean ignoreVirtual); + void forEachDirectPredicate(ReadGraphImpl graph, Resource subject, AsyncProcedure> procedure); void forObjectSet(ReadGraphImpl graph, Resource subject, Resource predicate, AsyncSetListener procedure); void forPredicateSet(ReadGraphImpl graph, Resource subject, AsyncSetListener procedure); void forPrincipalTypeSet(ReadGraphImpl graph, Resource subject, AsyncSetListener procedure); @@ -64,7 +61,8 @@ public interface ReadGraphSupport { void forEachPrincipalType(ReadGraphImpl graph, Resource subject, AsyncMultiProcedure procedure); void forEachPrincipalType(ReadGraphImpl graph, Resource subject, MultiProcedure procedure); - void forRelationInfo(ReadGraphImpl graph, Resource subject, AsyncProcedure procedure); + RelationInfo getRelationInfo(ReadGraphImpl graph, Resource subject) throws DatabaseException; + void forTypes(ReadGraphImpl graph, Resource subject, AsyncProcedure> procedure); IntSet getTypes(ReadGraphImpl graph, Resource subject) throws Throwable; void forSupertypes(ReadGraphImpl graph, Resource subject, AsyncProcedure> procedure); @@ -86,7 +84,7 @@ public interface ReadGraphSupport { void forOrderedSet(ReadGraphImpl graph, Resource subject, AsyncMultiProcedure procedure); // T query(ReadGraphImpl graph, Read request, CacheEntry parent, AsyncProcedure procedure, ListenerBase listener) throws DatabaseException; - void query(ReadGraphImpl graph, MultiRead request, CacheEntry parent, AsyncMultiProcedure procedure, ListenerBase listener); + void query(ReadGraphImpl graph, MultiRead request, CacheEntry parent, SyncMultiProcedure procedure, ListenerBase listener); // void query(ReadGraphImpl graph, AsyncRead request, CacheEntry parent, AsyncProcedure procedure, ListenerBase listener) throws DatabaseException; void query(ReadGraphImpl graph, AsyncMultiRead request, CacheEntry parent, AsyncMultiProcedure procedure, ListenerBase listener); // void query(ReadGraphImpl graph, ExternalRead request, CacheEntry parent, Procedure 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 index 000000000..2e06a75ce --- /dev/null +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/procedure/ResultCallWrappedSyncQueryProcedure.java @@ -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 implements SyncMultiProcedure { + + final private ArrayList result; + private Throwable exception = null; + final private SyncMultiProcedure procedure; + final private AtomicBoolean latch; + + public ResultCallWrappedSyncQueryProcedure(SyncMultiProcedure procedure) { + this.procedure = procedure; + latch = new AtomicBoolean(false); + result = new ArrayList(); + } + + @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 get() { + return result; + } + + public Throwable getException() { + return exception; + } + + @Override + public String toString() { + return "ResultCallWrappedQueryProcedure4[" + procedure + "]"; + } + +} diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncMultiReadEntry.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncMultiReadEntry.java index 1791c50ac..8d1bbd204 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncMultiReadEntry.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncMultiReadEntry.java @@ -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; diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java index 69a85220b..195d2147f 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java @@ -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; diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/GraphSemaphore.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/GraphSemaphore.java 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 d5d7735aa..3b980fe65 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/GraphSemaphore.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/GraphSemaphore.java @@ -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; diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/MultiReadEntry.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/MultiReadEntry.java index f2fff24cf..5bc318de1 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/MultiReadEntry.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/MultiReadEntry.java @@ -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 extends CacheEntryBase> { +final public class MultiReadEntry extends CacheEntryBase> { protected MultiRead request; @@ -48,13 +48,11 @@ final public class MultiReadEntry extends CacheEntryBase, AsyncBarrier>> p = null; - - synchronized(this) { + synchronized(this) { setReady(); } @@ -84,19 +82,19 @@ final public class MultiReadEntry extends CacheEntryBase() { + request.perform(graph , new SyncMultiProcedure() { @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 extends CacheEntryBase proc) { + public Object performFromCache(ReadGraphImpl graph, SyncMultiProcedure proc) { if(isExcepted()) { @@ -205,7 +203,7 @@ final public class MultiReadEntry extends CacheEntryBase procedure) throws DatabaseException { + public Object compute(ReadGraphImpl graph, SyncMultiProcedure procedure) throws DatabaseException { return graph.processor.cache.performQuery(graph, request, this, procedure); } diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java index 146701551..7b591abb7 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java @@ -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 { diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java index 2d3c92d82..5a06ded0b 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java @@ -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 procedure = (AsyncMultiProcedure)procedure_; + MultiReadEntry entry = (MultiReadEntry)entry_; + SyncMultiProcedure procedure = (SyncMultiProcedure)procedure_; try { - query.perform(queryGraph, new AsyncMultiProcedure() { + query.perform(queryGraph, new SyncMultiProcedure() { @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 emptySyncMultiProcedure = new SyncMultiProcedure() { + + @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 emptyProcedureTypes = emptyIntSetProcedure; protected static InternalProcedure emptyProcedureSuperTypes = emptyIntSetProcedure; protected static InternalProcedure 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; diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java index 5945589a3..9c60691fa 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java @@ -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 void runMultiRead(final ReadGraphImpl graph, MultiReadEntry cached, final MultiRead query, final CacheEntry parent, final QueryProcessor provider, final ListenerBase listener, final AsyncMultiProcedure procedure) { + final void runMultiRead(final ReadGraphImpl graph, MultiReadEntry cached, final MultiRead query, final CacheEntry parent, final QueryProcessor provider, final ListenerBase listener, final SyncMultiProcedure procedure) { try { QueryCache.runnerMultiReadEntry(graph, query, parent, listener, procedure); @@ -666,7 +659,7 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap // // } - public void queryMultiRead(final ReadGraphImpl graph, final MultiRead query, final CacheEntry parent, final ListenerBase listener, final AsyncMultiProcedure procedure) throws DatabaseException { + public void queryMultiRead(final ReadGraphImpl graph, final MultiRead query, final CacheEntry parent, final ListenerBase listener, final SyncMultiProcedure 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 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 procedure) { + final public void forEachDirectPredicate(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure> 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() { - @Override - final public void forEachDirectStatement(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure 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 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 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() { - - @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 void query(final ReadGraphImpl impl, final MultiRead request, final CacheEntry parent, final AsyncMultiProcedure procedure, ListenerBase listener) { + final public void query(final ReadGraphImpl impl, final MultiRead request, final CacheEntry parent, final SyncMultiProcedure procedure, ListenerBase listener) { assert(request != null); assert(procedure != null); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java index fc3222208..2c63b2d03 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java @@ -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 result = new ArrayList(); - final AsyncContextMultiProcedure structure; - final AsyncContextProcedure names; - final AsyncContextProcedure type; + final SyncContextMultiProcedure structure; + final SyncContextProcedure names; + final SyncContextProcedure 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() { + names = dqs.compilePossibleRelatedValue(graph, L0.HasName, new SyncContextProcedure() { @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() { + type = new SyncContextProcedure() { @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() { + structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new SyncContextMultiProcedure() { @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()) diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/NamespaceRequirements.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/NamespaceRequirements.java index aebf657f1..05ac11e62 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/NamespaceRequirements.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/NamespaceRequirements.java @@ -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 { } @Override - public void perform(ReadGraph graph, AsyncMultiProcedure callback) throws DatabaseException { + public void perform(ReadGraph graph, SyncMultiProcedure callback) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); ProjectResource PROJ = ProjectResource.getInstance(graph); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/OntologiesForModel.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/OntologiesForModel.java index f1edc367e..2394db7ed 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/OntologiesForModel.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/OntologiesForModel.java @@ -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 { super(model); } - public void check(ReadGraph graph, Resource resource, AsyncMultiProcedure callback) throws DatabaseException { + public void check(ReadGraph graph, Resource resource, SyncMultiProcedure callback) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); ProjectResource PROJ = ProjectResource.getInstance(graph); @@ -51,7 +51,7 @@ public class OntologiesForModel extends ResourceMultiRead { } @Override - public void perform(ReadGraph graph, AsyncMultiProcedure callback) throws DatabaseException { + public void perform(ReadGraph graph, SyncMultiProcedure callback) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/combinations/Combinators.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/combinations/Combinators.java index bd2409f5d..1eea49e26 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/combinations/Combinators.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/combinations/Combinators.java @@ -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 callback) + SyncMultiProcedure 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 procedure = new SynchronizationProcedure(); - 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 procedure = new SynchronizationProcedure(); - 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 callback) throws DatabaseException { + public void perform(ReadGraph graph, final SyncMultiProcedure 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 callback) + public void perform(ReadGraph graph, SyncMultiProcedure 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 callback) throws DatabaseException { + public void perform(ReadGraph graph, final SyncMultiProcedure 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 callback) + public void perform(ReadGraph graph, SyncMultiProcedure callback) throws DatabaseException { callback.execute(graph, value); callback.finished(graph); @@ -640,29 +639,18 @@ public class Combinators { // ------------------------------------------------------------------------ - private static class Name implements Read { - Resource resource; + private static class Name extends ResourceRead { + public Name(Resource resource) { - this.resource = resource; + super(resource); } + @Override public String perform(ReadGraph graph) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); - SynchronizationProcedure procedure = new SynchronizationProcedure(); - 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 name(Resource resource) { return new Name(resource); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ConsistsOfProcess.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ConsistsOfProcess.java index 75c75764a..55fe1ac01 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ConsistsOfProcess.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ConsistsOfProcess.java @@ -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 result; final Set childrenWithNoName; - final AsyncContextMultiProcedure structure; - final AsyncContextMultiProcedure names; + final SyncContextMultiProcedure structure; + final SyncContextMultiProcedure names; public static Pair,Set> walk(ReadGraph graph, Collection 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() { + names = dqs.compileForEachObject(graph, L0.HasName, new SyncContextMultiProcedure() { @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() { - - @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() { + structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new SyncContextMultiProcedure() { @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); } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelTransferableGraphSourceRequest.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelTransferableGraphSourceRequest.java index 9832f9d08..c5cb20af2 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelTransferableGraphSourceRequest.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelTransferableGraphSourceRequest.java @@ -578,15 +578,15 @@ public class ModelTransferableGraphSourceRequest extends UniqueRead procedure) throws DatabaseException { + SyncMultiProcedure procedure) throws DatabaseException { throw new DatabaseException("Not implemented."); } @Override diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/DirectQuerySupportImpl.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/DirectQuerySupportImpl.java index 0b640861e..bad6916dd 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/DirectQuerySupportImpl.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/DirectQuerySupportImpl.java @@ -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 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 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 procedure) { forEachDirectStatement(graph, subject, new SyncToAsyncProcedure(procedure)); } @@ -66,9 +60,9 @@ public class DirectQuerySupportImpl implements DirectQuerySupport { public void forEachDirectStatement(AsyncReadGraph graph, Resource subject, Procedure procedure) { ReadGraphImpl impl = (ReadGraphImpl)graph; impl.processor.forEachDirectStatement(impl, subject, procedure); - } + }*/ - @Override + /*@Override public void forRelationInfo(AsyncReadGraph graph, Resource subject, AsyncProcedure 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 procedure) { forRelationInfo(graph, subject, new NoneToAsyncProcedure(procedure)); + }*/ + + @Override + public RelationInfo getRelationInfo(ReadGraph graph, Resource subject) throws DatabaseException { + ReadGraphImpl impl = (ReadGraphImpl)graph; + return impl.processor.getRelationInfo(impl, subject); } @Override - public AsyncMultiProcedure compileForEachObject(ReadGraph graph, final Resource relation, AsyncMultiProcedure user) { + public SyncMultiProcedure compileForEachObject(ReadGraph graph, final Resource relation, SyncMultiProcedure user) throws DatabaseException { - try { - RelationInfo info = graph.syncRequest(new AsyncRead() { - - @Override - public void perform(AsyncReadGraph graph, AsyncProcedure 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 AsyncContextMultiProcedure compileForEachObject(ReadGraph graph, final Resource relation, AsyncContextMultiProcedure user) { + public SyncContextMultiProcedure compileForEachObject(ReadGraph graph, final Resource relation, SyncContextMultiProcedure user) throws DatabaseException { - try { - RelationInfo info = graph.syncRequest(new AsyncRead() { - - @Override - public void perform(AsyncReadGraph graph, AsyncProcedure 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(predicateKey, info, session.queryProvider2, user); - } catch (DatabaseException e) { - return null; - } + RelationInfo info = getRelationInfo(graph, relation); + final int predicateKey = ((ResourceImpl)relation).id; + return new ForEachObjectContextProcedure(predicateKey, info, session.queryProvider2, user); } @Override - public AsyncProcedure compilePossibleRelatedValue(ReadGraph graph, final Resource relation, AsyncProcedure user) { + public SyncProcedure compilePossibleRelatedValue(ReadGraph graph, final Resource relation, SyncProcedure user) throws DatabaseException { - try { - RelationInfo info = graph.syncRequest(new AsyncRead() { - - @Override - public void perform(AsyncReadGraph graph, AsyncProcedure 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(predicateKey, info, user); - } catch (DatabaseException e) { - return null; - } + RelationInfo info = getRelationInfo(graph, relation); + final int predicateKey = ((ResourceImpl)relation).id; + return new ForPossibleRelatedValueProcedure(predicateKey, info, user); } @Override - public AsyncContextProcedure compilePossibleRelatedValue(ReadGraph graph, final Resource relation, AsyncContextProcedure user) { + public SyncContextProcedure compilePossibleRelatedValue(ReadGraph graph, final Resource relation, SyncContextProcedure user) throws DatabaseException { - try { - RelationInfo info = graph.syncRequest(new AsyncRead() { - - @Override - public void perform(AsyncReadGraph graph, AsyncProcedure 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(predicateKey, info, user); - } catch (DatabaseException e) { - return null; - } + RelationInfo info = getRelationInfo(graph, relation); + final int predicateKey = ((ResourceImpl)relation).id; + return new ForPossibleRelatedValueContextProcedure(predicateKey, info, user); } @Override - public void forEachObjectCompiled(AsyncReadGraph graph, Resource subject, final AsyncMultiProcedure procedure) { + public void forEachObjectCompiled(ReadGraph graph, Resource subject, final SyncMultiProcedure procedure) { assert(subject != null); @@ -261,7 +177,7 @@ public class DirectQuerySupportImpl implements DirectQuerySupport { } @Override - public void forEachObjectCompiled(AsyncReadGraph graph, Resource subject, C context, final AsyncContextMultiProcedure procedure) { + public void forEachObjectCompiled(ReadGraph graph, Resource subject, C context, final SyncContextMultiProcedure procedure) { assert(subject != null); @@ -285,7 +201,7 @@ public class DirectQuerySupportImpl implements DirectQuerySupport { } @Override - public void forPossibleRelatedValueCompiled(AsyncReadGraph graph, Resource subject, final AsyncProcedure procedure) { + public void forPossibleRelatedValueCompiled(ReadGraph graph, Resource subject, final SyncProcedure 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 void forPossibleRelatedValueCompiled(AsyncReadGraph graph, Resource subject, C context, final AsyncContextProcedure procedure) { + public void forPossibleRelatedValueCompiled(ReadGraph graph, Resource subject, C context, final SyncContextProcedure 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 void forPossibleType(final AsyncReadGraph graph, Resource subject, final AsyncProcedure procedure) { assert(subject != null); @@ -413,9 +348,11 @@ public class DirectQuerySupportImpl implements DirectQuerySupport { } + + */ @Override - public void forPossibleDirectType(final AsyncReadGraph graph, Resource subject, final C context, final AsyncContextProcedure procedure) { + public void forPossibleDirectType(final ReadGraph graph, Resource subject, final C context, final SyncContextProcedure procedure) { assert(subject != null); @@ -479,8 +416,7 @@ public class DirectQuerySupportImpl implements DirectQuerySupport { } - - private void getRelatedValue4(final ReadGraphImpl graph, final int subject, final C context, final ForPossibleRelatedValueContextProcedure procedure) { + private T getRelatedValue4(final ReadGraphImpl graph, final int subject, final C context, final ForPossibleRelatedValueContextProcedure 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 void getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final ForPossibleRelatedValueProcedure procedure) { + private T getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final ForPossibleRelatedValueProcedure 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 void getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure procedure) { + private T getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure 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 void getRelatedDirectValue4(final ReadGraphImpl graph, final ClusterImpl cluster, final int subject, final int result, final ForPossibleRelatedValueProcedure procedure) { + private T getRelatedDirectValue4(final ReadGraphImpl graph, final ClusterImpl cluster, final int subject, final int result, final ForPossibleRelatedValueProcedure 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 void getRelatedDirectValue4(final ReadGraphImpl graph, final ClusterImpl cluster, final int subject, final int result, final C context, final ForPossibleRelatedValueContextProcedure procedure) { - - try { + } + + private T getRelatedDirectValue4(final ReadGraphImpl graph, final ClusterImpl cluster, final int subject, final int result, final C context, final ForPossibleRelatedValueContextProcedure 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 void getRelatedValue4(final ReadGraphImpl graph, final int subject, final ForPossibleRelatedValueProcedure procedure) { + public T getRelatedValue4(final ReadGraphImpl graph, final int subject, final ForPossibleRelatedValueProcedure 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 void getDirectValue4(final ReadGraphImpl graph, final ClusterSmall cluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure procedure) { try { @@ -900,40 +742,16 @@ public class DirectQuerySupportImpl implements DirectQuerySupport { // graph.dec(); } + */ - private void getDirectValue4(final ReadGraphImpl graph, final ClusterBig cluster, final int subject, final ForPossibleRelatedValueProcedure procedure) { + private 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 void getDirectValue4(final ReadGraphImpl graph, final ClusterBig cluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure 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 void getDirectValue4(final ReadGraphImpl graph, final ClusterSmall cluster, final int subject, final ForPossibleRelatedValueProcedure procedure) { + private 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 { diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QueryControlImpl.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QueryControlImpl.java index d871720a8..7165abef3 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QueryControlImpl.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QueryControlImpl.java @@ -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); } diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QuerySupportImpl.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QuerySupportImpl.java index b3b403ea7..07282029a 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QuerySupportImpl.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QuerySupportImpl.java @@ -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) { // diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java index f48ccaf6b..6d34d9341 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java @@ -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 void scheduleRequest(final MultiRead request, final SyncMultiProcedure 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 wrapper = new ResultCallWrappedSyncQueryProcedure(procedure); + + try { + + request.perform(newGraph, wrapper); + + } catch (Throwable t) { + + t.printStackTrace(); + + } + + } + + } finally { + + fireSessionVariableChange(SessionVariables.QUEUED_READS); + + } + + } + + }); + + } + public void scheduleRequest(final AsyncMultiRead request, final AsyncMultiProcedure procedure, final Semaphore notify) { assert (request != null); @@ -3067,21 +3127,21 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule final ArrayList result = new ArrayList(); final DataContainer exception = new DataContainer(); - syncRequest(request, new AsyncMultiProcedure() { + syncRequest(request, new SyncMultiProcedure() { @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 Collection syncRequest(MultiRead request, AsyncMultiListener procedure) throws DatabaseException { + public Collection syncRequest(MultiRead arg0, SyncMultiProcedure arg1) throws DatabaseException { assertNotSession(); - return syncRequest(request, (AsyncMultiProcedure)procedure); + throw new Error("Not implemented!"); } @Override public Collection syncRequest(MultiRead request, SyncMultiListener procedure) throws DatabaseException { assertNotSession(); - return syncRequest(request, new SyncToAsyncMultiListener(procedure)); + return syncRequest(request, (SyncMultiProcedure)procedure); } @Override public Collection syncRequest(MultiRead request, MultiListener procedure) throws DatabaseException { assertNotSession(); - return syncRequest(request, new NoneToAsyncMultiListener(procedure)); - } - - @Override - public Collection syncRequest(MultiRead request, SyncMultiProcedure procedure) throws DatabaseException { - assertNotSession(); - return syncRequest(request, new SyncToAsyncMultiProcedure(procedure)); + return syncRequest(request, new NoneToSyncMultiListener(procedure)); } @Override public Collection syncRequest(MultiRead request, MultiProcedure procedure) throws DatabaseException { assertNotSession(); - return syncRequest(request, new NoneToAsyncMultiProcedure(procedure)); + return syncRequest(request, new NoneToSyncMultiProcedure(procedure)); } @Override @@ -3281,38 +3335,33 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule assert(request != null); - asyncRequest(request, new AsyncMultiProcedureAdapter() { + asyncRequest(request, new SyncMultiProcedureAdapter() { @Override - public void exception(AsyncReadGraph graph, Throwable t) { + public void exception(ReadGraph graph, Throwable t) { t.printStackTrace(); } }); } - @Override - public void asyncRequest(MultiRead request, AsyncMultiListener procedure) { - asyncRequest(request, (AsyncMultiProcedure)procedure); - } - @Override public void asyncRequest(MultiRead request, SyncMultiListener procedure) { - asyncRequest(request, new SyncToAsyncMultiListener(procedure)); + asyncRequest(request, (SyncMultiProcedure)procedure); } @Override public void asyncRequest(MultiRead request, MultiListener procedure) { - asyncRequest(request, new NoneToAsyncMultiListener(procedure)); + asyncRequest(request, new NoneToSyncMultiListener(procedure)); } @Override public void asyncRequest(MultiRead request, SyncMultiProcedure procedure) { - asyncRequest(request, new SyncToAsyncMultiProcedure(procedure)); + scheduleRequest(request, procedure, null); } @Override public void asyncRequest(MultiRead request, MultiProcedure procedure) { - asyncRequest(request, new NoneToAsyncMultiProcedure(procedure)); + asyncRequest(request, new NoneToSyncMultiProcedure(procedure)); } @Override @@ -3354,17 +3403,6 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule asyncRequest(request, new NoneToAsyncMultiProcedure(procedure)); } - @Override - public Collection syncRequest(MultiRead arg0, AsyncMultiProcedure arg1) throws DatabaseException { - assertNotSession(); - throw new Error("Not implemented!"); - } - - @Override - public void asyncRequest(MultiRead arg0, AsyncMultiProcedure arg1) { - throw new Error("Not implemented!"); - } - @Override final public void asyncRequest(final ExternalRead 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()); } diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterBig.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterBig.java index 29f34b45f..4cedb7947 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterBig.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterBig.java @@ -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 procedure, + public void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, SyncMultiProcedure 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 void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, C context, AsyncContextMultiProcedure procedure, + public void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, C context, SyncContextMultiProcedure 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 procedure) + int predicateKey, SyncMultiProcedure procedure) throws DatabaseException { SessionImplSocket session = (SessionImplSocket)graph.getSession(); diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterSmall.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterSmall.java index 51818048f..6063dc8d5 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterSmall.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterSmall.java @@ -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 procedure, + public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, SyncMultiProcedure 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 void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, C context, AsyncContextMultiProcedure procedure, + public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, C context, SyncContextMultiProcedure 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 procedure) throws DatabaseException { + int predicateKey, SyncMultiProcedure procedure) throws DatabaseException { if (deleted) return; SessionImplSocket session = (SessionImplSocket)graph.getSession(); ClusterSupport support = session.clusterTranslator; diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/IntHash.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/IntHash.java index c0ead5d07..48f46bb07 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/IntHash.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/IntHash.java @@ -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 procedure, Modifier modifier) throws DatabaseException { + static void foreachInt(final ReadGraphImpl graph, int[] table, int base, final SyncMultiProcedure 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 void foreachInt(final ReadGraphImpl graph, int[] table, int base, C context, final AsyncContextMultiProcedure procedure, Modifier modifier) throws DatabaseException { + static void foreachInt(final ReadGraphImpl graph, int[] table, int base, C context, final SyncContextMultiProcedure procedure, Modifier modifier) throws DatabaseException { int capacity = getRealSize(table, base); final int size = getUsedSize(table, base); diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ObjectTable.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ObjectTable.java index da3b7903e..458f7b04a 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ObjectTable.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ObjectTable.java @@ -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 { } final public void foreachObject( ReadGraphImpl graph, final int objectIndex, - final AsyncMultiProcedure procedure, Modifier modifier) throws DatabaseException { + final SyncMultiProcedure 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 { } final public void foreachObject( ReadGraphImpl graph, final int objectIndex, C context, - final AsyncContextMultiProcedure procedure, Modifier modifier) throws DatabaseException { + final SyncContextMultiProcedure procedure, Modifier modifier) throws DatabaseException { if (ClusterTraits.statementIndexIsDirect(objectIndex)) { int key = modifier.execute(objectIndex); procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), key)); diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceElementSmall.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceElementSmall.java index 90519a36c..d7f6abc49 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceElementSmall.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceElementSmall.java @@ -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 procedure, + final ReadGraphImpl graph, final SyncMultiProcedure 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 void foreachObject(long[] table, int index, - final ReadGraphImpl graph, final C context, final AsyncContextMultiProcedure procedure, + final ReadGraphImpl graph, final C context, final SyncContextMultiProcedure procedure, ClusterSupport support, final int pRef, ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, final Modifier modifier) throws DatabaseException { if (DEBUG) diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTable.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTable.java index e997b7318..d0619976d 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTable.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTable.java @@ -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 procedure, + final ReadGraphImpl graph, final SyncMultiProcedure 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 void foreachObject(long[] table, int index, - final ReadGraphImpl graph, final C context, final AsyncContextMultiProcedure procedure, + final ReadGraphImpl graph, final C context, final SyncContextMultiProcedure 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 { } public void foreachObject(int resourceIndex, ReadGraphImpl graph, - AsyncMultiProcedure procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, Modifier modifier) throws DatabaseException { + SyncMultiProcedure 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 void foreachObject(int resourceIndex, ReadGraphImpl graph, C context, - AsyncContextMultiProcedure procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, Modifier modifier) throws DatabaseException { + SyncContextMultiProcedure 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); diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTableSmall.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTableSmall.java index d72b79aa5..0278b1531 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTableSmall.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTableSmall.java @@ -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 { } public void foreachObject(int resourceIndex, ReadGraphImpl graph, - AsyncMultiProcedure procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum completeType, CompleteTable ct, Modifier modifier) throws DatabaseException { + SyncMultiProcedure 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 void foreachObject(int resourceIndex, ReadGraphImpl graph, C context, - AsyncContextMultiProcedure procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum completeType, CompleteTable ct, Modifier modifier) throws DatabaseException { + SyncContextMultiProcedure 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); diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntArraySet.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntArraySet.java index 2c57f3627..c0ba6ec61 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntArraySet.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntArraySet.java @@ -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 procedure, Modifier modifier) throws DatabaseException { + static void foreachInt(final int[] table, final int base, ReadGraphImpl graph, SyncMultiProcedure procedure, Modifier modifier) throws DatabaseException { final int size = -table[base + SIZE_OFFSET]; assert(size>0); @@ -170,7 +170,7 @@ final class TableIntArraySet { } - static void foreachInt(final int[] table, final int base, ReadGraphImpl graph, C context, AsyncContextMultiProcedure procedure, Modifier modifier) throws DatabaseException { + static void foreachInt(final int[] table, final int base, ReadGraphImpl graph, C context, SyncContextMultiProcedure procedure, Modifier modifier) throws DatabaseException { final int size = -table[base + SIZE_OFFSET]; assert(size>0); diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntSet.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntSet.java index f13042faa..a0e0eb14b 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntSet.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntSet.java @@ -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 procedure, Modifier modifier) throws DatabaseException { + static void foreachInt(int[] table, int base, QueryProcessor processor, ReadGraphImpl graph, SyncMultiProcedure 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 index 000000000..295926d96 --- /dev/null +++ b/bundles/org.simantics.db.regressionsuite.ontology/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/AdaptionService2.java b/bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/AdaptionService2.java index 859481727..ccc64fe9c 100644 --- a/bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/AdaptionService2.java +++ b/bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/AdaptionService2.java @@ -11,21 +11,16 @@ *******************************************************************************/ 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,Class>, AdapterDeclaration> adapters = new THashMap,Class>, AdapterDeclaration>(); @@ -588,14 +585,14 @@ public class AdaptionService2 implements AdaptionService { Adapter adapter = getAdapter(g, r, context, contextClass, targetClass, possible); if(adapter == null) return null; - BlockingAsyncProcedure ap = new BlockingAsyncProcedure(g, null, adapter); - -// SyncReadProcedure procedure = new SyncReadProcedure(); - adapter.adapt(g, r, context, ap); - - return ap.get(); -// procedure.checkAndThrow(); -// return procedure.result; + return g.syncRequest(new UniqueAsyncRead() { + + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure 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)); } } diff --git a/bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/reflection/AbstractReflectionAdapter.java b/bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/reflection/AbstractReflectionAdapter.java index bfef0a95a..e281a0294 100644 --- a/bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/reflection/AbstractReflectionAdapter.java +++ b/bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/reflection/AbstractReflectionAdapter.java @@ -41,7 +41,7 @@ public abstract class AbstractReflectionAdapter implements Adapter implements Adapter { try { for(int i=0;i procedure); + void forEachDirectPredicate(Resource subject, AsyncProcedure> procedure); /** * @see ReadGraph#getObjects(Resource, Resource) */ - void forEachDirectPredicate(Resource subject, SyncMultiProcedure procedure); + void forEachDirectPredicate(Resource subject, SyncProcedure> procedure); /** * @see ReadGraph#getObjects(Resource, Resource) */ - void forEachDirectPredicate(Resource subject, MultiProcedure procedure); + void forEachDirectPredicate(Resource subject, Procedure> procedure); /** * @see ReadGraph#getObjects(Resource, Resource) @@ -1129,12 +1129,9 @@ public interface AsyncReadGraph extends AsyncRequestProcessor { */ void forOrderedSet(Resource subject, MultiProcedure procedure); - int thread(); // void inc(); // void dec(); - boolean isImmutable(Resource resource) throws DatabaseException; - boolean performPending(); } diff --git a/bundles/org.simantics.db/src/org/simantics/db/AsyncRequestProcessor.java b/bundles/org.simantics.db/src/org/simantics/db/AsyncRequestProcessor.java index 3f17927e2..ded8292fa 100644 --- a/bundles/org.simantics.db/src/org/simantics/db/AsyncRequestProcessor.java +++ b/bundles/org.simantics.db/src/org/simantics/db/AsyncRequestProcessor.java @@ -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 { void async(ReadInterface r, Procedure procedure); void async(ReadInterface r, AsyncProcedure procedure); @@ -80,9 +73,4 @@ public interface AsyncRequestProcessor extends ServiceLocator, AsyncRequestProce void async(ReadInterface r, AsyncListener procedure); void async(ReadInterface r, SyncListener procedure); - void async(WriteInterface r); - void async(WriteInterface r, Procedure procedure); - - Object getModificationCounter(); - } diff --git a/bundles/org.simantics.db/src/org/simantics/db/AsyncRequestProcessorSpecific.java b/bundles/org.simantics.db/src/org/simantics/db/AsyncRequestProcessorSpecific.java index 429696cda..254174917 100644 --- a/bundles/org.simantics.db/src/org/simantics/db/AsyncRequestProcessorSpecific.java +++ b/bundles/org.simantics.db/src/org/simantics/db/AsyncRequestProcessorSpecific.java @@ -289,7 +289,7 @@ public interface AsyncRequestProcessorSpecific extends ServiceLocator { * @param request an instance of {@link MultiRead}. * @param procedure an instance of {@link AsyncMultiListener}. */ - void asyncRequest(MultiRead request, AsyncMultiListener procedure); + // void asyncRequest(MultiRead request, AsyncMultiListener 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}. */ - void asyncRequest(MultiRead request, AsyncMultiProcedure procedure); + // void asyncRequest(MultiRead request, AsyncMultiProcedure procedure); /** * Asynchronously supplies the result determined from the given @@ -463,65 +463,5 @@ public interface AsyncRequestProcessorSpecific extends ServiceLocator { void asyncRequest(ExternalRead request, Listener procedure); void asyncRequest(ExternalRead request, Procedure 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 callback); - - void asyncRequest(WriteResult r, Procedure 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 callback); - - void asyncRequest(DelayedWriteResult r, Procedure 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 callback); - - void asyncRequest(WriteOnlyResult r, Procedure procedure); } diff --git a/bundles/org.simantics.db/src/org/simantics/db/ReadGraph.java b/bundles/org.simantics.db/src/org/simantics/db/ReadGraph.java index 91bb052e9..c34a156c2 100644 --- a/bundles/org.simantics.db/src/org/simantics/db/ReadGraph.java +++ b/bundles/org.simantics.db/src/org/simantics/db/ReadGraph.java @@ -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(); + } diff --git a/bundles/org.simantics.db/src/org/simantics/db/RequestProcessor.java b/bundles/org.simantics.db/src/org/simantics/db/RequestProcessor.java index 68af4664b..5cc0157a3 100644 --- a/bundles/org.simantics.db/src/org/simantics/db/RequestProcessor.java +++ b/bundles/org.simantics.db/src/org/simantics/db/RequestProcessor.java @@ -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 sync(ReadInterface r) throws DatabaseException; T sync(WriteInterface r) throws DatabaseException; + void async(WriteInterface r); + void async(WriteInterface r, Procedure procedure); + + Object getModificationCounter(); + } diff --git a/bundles/org.simantics.db/src/org/simantics/db/RequestProcessorSpecific.java b/bundles/org.simantics.db/src/org/simantics/db/RequestProcessorSpecific.java index 523d41013..055b0b58f 100644 --- a/bundles/org.simantics.db/src/org/simantics/db/RequestProcessorSpecific.java +++ b/bundles/org.simantics.db/src/org/simantics/db/RequestProcessorSpecific.java @@ -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}. */ - Collection syncRequest(MultiRead request, AsyncMultiListener procedure) throws DatabaseException; + // Collection syncRequest(MultiRead request, AsyncMultiListener 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}. */ - Collection syncRequest(MultiRead request, AsyncMultiProcedure procedure) throws DatabaseException; + // Collection syncRequest(MultiRead request, AsyncMultiProcedure procedure) throws DatabaseException; /** * Synchronously supplies the result determined from the given @@ -497,4 +498,65 @@ public interface RequestProcessorSpecific extends AsyncRequestProcessor { */ T syncRequest(WriteOnlyResult 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 callback); + + void asyncRequest(WriteResult r, Procedure 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 callback); + + void asyncRequest(DelayedWriteResult r, Procedure 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 callback); + + void asyncRequest(WriteOnlyResult r, Procedure procedure); + } diff --git a/bundles/org.simantics.db/src/org/simantics/db/Session.java b/bundles/org.simantics.db/src/org/simantics/db/Session.java index 8e8b2d9bc..7a6e3a415 100644 --- a/bundles/org.simantics.db/src/org/simantics/db/Session.java +++ b/bundles/org.simantics.db/src/org/simantics/db/Session.java @@ -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 index 000000000..63f03143f --- /dev/null +++ b/bundles/org.simantics.db/src/org/simantics/db/procedure/SyncContextMultiProcedure.java @@ -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 the result object type accepted by the procedure + */ +public interface SyncContextMultiProcedure { + + /** + * Invoked once for each separate result of the request with potentially + * multiple results. It shall be guaranteed that all execute + * invocations have been completed when either + * {@link #finished(AsyncReadGraph)} or + * {@link #exception(AsyncReadGraph, Throwable)} are called and that no + * execute 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 index 000000000..93c745fb8 --- /dev/null +++ b/bundles/org.simantics.db/src/org/simantics/db/procedure/SyncContextProcedure.java @@ -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 { + + void execute(ReadGraph graph, Context context, Result result); + void exception(ReadGraph graph, Throwable throwable); + +} diff --git a/bundles/org.simantics.db/src/org/simantics/db/request/MultiRead.java b/bundles/org.simantics.db/src/org/simantics/db/request/MultiRead.java index b8a4c2012..0754ac73f 100644 --- a/bundles/org.simantics.db/src/org/simantics/db/request/MultiRead.java +++ b/bundles/org.simantics.db/src/org/simantics/db/request/MultiRead.java @@ -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 GraphRequest interface is used to create transaction @@ -91,6 +92,6 @@ public interface MultiRead { * @throws CancelTransactionException to indicate that the request needs to * be cancelled and any changes rolled back */ - void perform(ReadGraph graph, AsyncMultiProcedure callback) throws DatabaseException; + void perform(ReadGraph graph, SyncMultiProcedure callback) throws DatabaseException; } diff --git a/bundles/org.simantics.db/src/org/simantics/db/service/DirectQuerySupport.java b/bundles/org.simantics.db/src/org/simantics/db/service/DirectQuerySupport.java index 472eb9eee..7b932f3de 100644 --- a/bundles/org.simantics.db/src/org/simantics/db/service/DirectQuerySupport.java +++ b/bundles/org.simantics.db/src/org/simantics/db/service/DirectQuerySupport.java @@ -11,41 +11,43 @@ *******************************************************************************/ 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 procedure); + DirectStatements getDirectPersistentStatements(ReadGraph graph, Resource subject); + DirectStatements getDirectStatements(ReadGraph graph, Resource subject); - void forEachDirectStatement(AsyncReadGraph graph, Resource subject, AsyncProcedure procedure); - void forEachDirectStatement(AsyncReadGraph graph, Resource subject, SyncProcedure procedure); - void forEachDirectStatement(AsyncReadGraph graph, Resource subject, Procedure procedure); +// void forEachDirectPersistentStatement(ReadGraph graph, Resource subject, AsyncProcedure procedure); +// void forEachDirectStatement(ReadGraph graph, Resource subject, AsyncProcedure procedure); +// void forEachDirectStatement(ReadGraph graph, Resource subject, SyncProcedure procedure); +// void forEachDirectStatement(ReadGraph graph, Resource subject, Procedure procedure); - void forRelationInfo(AsyncReadGraph graph, Resource subject, AsyncProcedure procedure); - void forRelationInfo(AsyncReadGraph graph, Resource subject, SyncProcedure procedure); - void forRelationInfo(AsyncReadGraph graph, Resource subject, Procedure procedure); + RelationInfo getRelationInfo(ReadGraph graph, Resource subject) throws DatabaseException; - void forPossibleType(AsyncReadGraph graph, Resource subject, AsyncProcedure procedure); +// void forRelationInfo(AsyncReadGraph graph, Resource subject, AsyncProcedure procedure); +// void forRelationInfo(AsyncReadGraph graph, Resource subject, SyncProcedure procedure); +// void forRelationInfo(AsyncReadGraph graph, Resource subject, Procedure procedure); - AsyncMultiProcedure compileForEachObject(ReadGraph graph, Resource relation, AsyncMultiProcedure user); - AsyncContextMultiProcedure compileForEachObject(ReadGraph graph, Resource relation, AsyncContextMultiProcedure user); - AsyncProcedure compilePossibleRelatedValue(ReadGraph graph, Resource relation, AsyncProcedure user); - AsyncContextProcedure compilePossibleRelatedValue(ReadGraph graph, Resource relation, AsyncContextProcedure user); + // void forPossibleType(AsyncReadGraph graph, Resource subject, AsyncProcedure procedure); - void forEachObjectCompiled(AsyncReadGraph graph, Resource subject, AsyncMultiProcedure procedure); - void forEachObjectCompiled(AsyncReadGraph graph, Resource subject, C context, AsyncContextMultiProcedure procedure); - void forPossibleRelatedValueCompiled(AsyncReadGraph graph, Resource subject, AsyncProcedure procedure); - void forPossibleRelatedValueCompiled(AsyncReadGraph graph, Resource subject, C context, AsyncContextProcedure procedure); - void forPossibleDirectType(AsyncReadGraph graph, Resource subject, C context, AsyncContextProcedure procedure); + SyncMultiProcedure compileForEachObject(ReadGraph graph, Resource relation, SyncMultiProcedure user) throws DatabaseException; + SyncContextMultiProcedure compileForEachObject(ReadGraph graph, Resource relation, SyncContextMultiProcedure user) throws DatabaseException; + SyncProcedure compilePossibleRelatedValue(ReadGraph graph, Resource relation, SyncProcedure user) throws DatabaseException; + SyncContextProcedure compilePossibleRelatedValue(ReadGraph graph, Resource relation, SyncContextProcedure user) throws DatabaseException; + + void forEachObjectCompiled(ReadGraph graph, Resource subject, SyncMultiProcedure procedure); + void forEachObjectCompiled(ReadGraph graph, Resource subject, C context, SyncContextMultiProcedure procedure); + void forPossibleRelatedValueCompiled(ReadGraph graph, Resource subject, SyncProcedure procedure); + void forPossibleRelatedValueCompiled(ReadGraph graph, Resource subject, C context, SyncContextProcedure procedure); + void forPossibleDirectType(ReadGraph graph, Resource subject, C context, SyncContextProcedure procedure); } diff --git a/bundles/org.simantics.db/src/org/simantics/db/service/QueryControl.java b/bundles/org.simantics.db/src/org/simantics/db/service/QueryControl.java index 5cc3fa655..3da3c5aa3 100644 --- a/bundles/org.simantics.db/src/org/simantics/db/service/QueryControl.java +++ b/bundles/org.simantics.db/src/org/simantics/db/service/QueryControl.java @@ -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); diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ConstantStyle.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ConstantStyle.java index 428acc686..4a59f4b3c 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ConstantStyle.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ConstantStyle.java @@ -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; diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DiagramContentRequest.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DiagramContentRequest.java index 36e405157..843f907a8 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DiagramContentRequest.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DiagramContentRequest.java @@ -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(previousElementCount); - result.nodeSet = new THashSet(); - result.connectionSet = new THashSet(); - result.connectionSegments = new THashSet(); - result.branchPoints = new THashSet(); - result.routeGraphConnectionSet = new THashSet(); - result.routeLinks = new THashSet(); - result.routeLines = new THashSet(); - result.routePoints = new THashSet(); - - result.partToConnection = new THashMap(); // These help loading result.elements in the correct order. final AtomicInteger index = new AtomicInteger(); @@ -78,96 +67,113 @@ public class DiagramContentRequest extends BaseRequest 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 types = g.getTypes(component); - - if (types.contains(DIA.Connection)) { - if (types.contains(DIA.RouteGraphConnection)) { - g.asyncRequest(new RouteGraphConnectionPartRequest(errorHandler, DIA, component), - new ProcedureAdapter() { - @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() { - @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() { + + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure procedure) { + + DiagramContents result = new DiagramContents(); + procedure.execute(graph, result); + + result.elements = new ArrayList(previousElementCount); + result.nodeSet = new THashSet(); + result.connectionSet = new THashSet(); + result.connectionSegments = new THashSet(); + result.branchPoints = new THashSet(); + result.routeGraphConnectionSet = new THashSet(); + result.routeLinks = new THashSet(); + result.routeLines = new THashSet(); + result.routePoints = new THashSet(); + + result.partToConnection = new THashMap(); + + 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>() { + + @Override + public void execute(Set types) { + + if (types.contains(DIA.Connection)) { + if (types.contains(DIA.RouteGraphConnection)) { + graph.asyncRequest(new RouteGraphConnectionPartRequest(errorHandler, DIA, component), + new ProcedureAdapter() { + @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() { + @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(); diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java index 3e404cf56..55754f370 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java @@ -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() { - @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() { + @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, diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/MappedTypeGroup.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/MappedTypeGroup.java index 856631fa2..6e7d368b5 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/MappedTypeGroup.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/MappedTypeGroup.java @@ -68,13 +68,13 @@ public class MappedTypeGroup implements Group { } @Override - public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener listener) { + public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener listener) throws DatabaseException { if (types.isEmpty()) { System.out.println("MappedTypeGroup has no types!"); return; } - processor.asyncRequest(new BinaryRead, Collection>(runtimeDiagram, types) { + processor.syncRequest(new BinaryRead, Collection>(runtimeDiagram, types) { @Override public Set perform(ReadGraph graph) throws DatabaseException { diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/TypeGroup.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/TypeGroup.java index 8e2db2488..e025fb2dd 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/TypeGroup.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/TypeGroup.java @@ -63,13 +63,13 @@ public class TypeGroup implements Group { } @Override - public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener listener) { + public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener listener) throws DatabaseException { if (types.isEmpty()) { System.out.println("TypeGroup has no types!"); return; } - processor.asyncRequest(new BinaryRead, Collection>(runtimeDiagram, types) { + processor.syncRequest(new BinaryRead, Collection>(runtimeDiagram, types) { @Override public Set perform(ReadGraph graph) throws DatabaseException { diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/DiagramElementGroup.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/DiagramElementGroup.java index 059bb55fb..cc04927f6 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/DiagramElementGroup.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/DiagramElementGroup.java @@ -38,8 +38,8 @@ public abstract class DiagramElementGroup implements Group { } @Override - public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener listener) { - processor.asyncRequest(new BinaryRead, Resource, Collection>(getClass(), runtimeDiagram) { + public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener listener) throws DatabaseException { + processor.syncRequest(new BinaryRead, Resource, Collection>(getClass(), runtimeDiagram) { @Override public Set perform(ReadGraph graph) throws DatabaseException { diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/StyleBase.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/StyleBase.java index ee203616d..21071ba74 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/StyleBase.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/StyleBase.java @@ -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 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); diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/runtime/RuntimeDiagramManager.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/runtime/RuntimeDiagramManager.java index bfc439101..04e30f70d 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/runtime/RuntimeDiagramManager.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/runtime/RuntimeDiagramManager.java @@ -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() { + private void listenRequest(RequestProcessor processor, final Resource diagram) throws DatabaseException { + processor.syncRequest(new RuntimeVariableForInput(getResourceInput()), new AsyncListener() { @Override public void exception(AsyncReadGraph graph, Throwable throwable) { diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java index 0e56a7dd2..7837edcac 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java @@ -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)); diff --git a/bundles/org.simantics.issues.common/src/org/simantics/issues/common/IssueUtils.java b/bundles/org.simantics.issues.common/src/org/simantics/issues/common/IssueUtils.java index bb0c8a5b1..ecc6b20cc 100644 --- a/bundles/org.simantics.issues.common/src/org/simantics/issues/common/IssueUtils.java +++ b/bundles/org.simantics.issues.common/src/org/simantics/issues/common/IssueUtils.java @@ -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(issue, model, source) { + graph.syncRequest(new ResourceRead3(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)); } diff --git a/bundles/org.simantics.layer0.utils/src/org/simantics/layer0/utils/queries/QueryExecutor2.java b/bundles/org.simantics.layer0.utils/src/org/simantics/layer0/utils/queries/QueryExecutor2.java index 4753c0b3b..8608fc4d5 100644 --- a/bundles/org.simantics.layer0.utils/src/org/simantics/layer0/utils/queries/QueryExecutor2.java +++ b/bundles/org.simantics.layer0.utils/src/org/simantics/layer0/utils/queries/QueryExecutor2.java @@ -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); } diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/monitor/MonitorClassFactory2.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/monitor/MonitorClassFactory2.java index 17c26f483..597a125a8 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/monitor/MonitorClassFactory2.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/monitor/MonitorClassFactory2.java @@ -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); } } diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/issue/SCLExpressionIssueProvider.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/issue/SCLExpressionIssueProvider.java index 7e480d4ff..46142247f 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/issue/SCLExpressionIssueProvider.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/issue/SCLExpressionIssueProvider.java @@ -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> implements Disposable { + private static class ComponentSyncListenerAdapter extends AsyncListenerAdapter> implements Disposable { private ConcurrentHashMap currentlyListening = new ConcurrentHashMap<>(); private boolean disposed; @@ -195,7 +196,7 @@ public class SCLExpressionIssueProvider implements SCLIssueProvider { } @Override - public void execute(ReadGraph graph, Set newComponents) { + public void execute(AsyncReadGraph graph, Set newComponents) { if (currentlyListening.isEmpty() && newComponents.isEmpty()) { // we can stop here as nothing will change return; diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/subscription/ModelHistoryCollector.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/subscription/ModelHistoryCollector.java index 27c840467..a18fa7b46 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/subscription/ModelHistoryCollector.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/subscription/ModelHistoryCollector.java @@ -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(); } diff --git a/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/Group.java b/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/Group.java index 8d1a11124..27d6a0dbc 100644 --- a/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/Group.java +++ b/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/Group.java @@ -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 listener); + void trackItems(RequestProcessor processor, Resource runtimeDiagram, SetListener listener) throws DatabaseException; } diff --git a/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/Style.java b/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/Style.java index d18e623d0..c719df2d7 100644 --- a/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/Style.java +++ b/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/Style.java @@ -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 diff --git a/bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java b/bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java index 48dcd3824..f3d4c3430 100644 --- a/bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java +++ b/bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java @@ -299,7 +299,7 @@ public class SCLFunctions { } public static void subqueryL(ReadGraph graph, Function query, Function executeCallback, Function1 exceptionCallback, Function1 isDisposedCallback) throws DatabaseException { - graph.asyncRequest(new Subquery(query), new SyncListenerAdapter() { + graph.syncRequest(new Subquery(query), new SyncListenerAdapter() { @Override public void execute(ReadGraph graph, Object result) throws DatabaseException { Simantics.applySCLRead(graph, executeCallback, result); diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/GraphUI.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/GraphUI.java index 607661163..0b7d8aee2 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/GraphUI.java +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/GraphUI.java @@ -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() { + graph.syncRequest(new CellValue(property.second), new SyncListener() { @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); + } } diff --git a/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SheetFactory.java b/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SheetFactory.java index 4669fdf4d..7edd2e816 100644 --- a/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SheetFactory.java +++ b/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SheetFactory.java @@ -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); } diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorInput2.java b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorInput2.java index b33137b52..6b5a03552 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorInput2.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorInput2.java @@ -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 { diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/editor/input/InputValidationCombinators.java b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/editor/input/InputValidationCombinators.java index 9b2c1e06c..46a9ade3e 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/editor/input/InputValidationCombinators.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/editor/input/InputValidationCombinators.java @@ -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 procedure = new SynchronizationProcedure(); 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 procedure = new SynchronizationProcedure(); Resource relation = graph.getResource(relationURI); - graph.forSingleObject(subject, relation, procedure); - return procedure.getResult(); + return graph.getSingleObject(subject, relation); } @Override public int hashCode() { -- 2.45.2