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;
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;
return objectTable.getSingleObject(objectIndex, support, this);
}
- public void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, AsyncMultiProcedure<Resource> procedure,
+ public void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, SyncMultiProcedure<Resource> procedure,
ClusterSupport support) throws DatabaseException {
if (DEBUG)
System.out.println("Cluster.forObjects1: rk=" + resourceKey + " pk=" + predicateKey);
}
objectTable.foreachObject(graph, objectIndex, procedure, this);
}
- public <C> void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, C context, AsyncContextMultiProcedure<C, Resource> procedure,
+ public <C> void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, C context, SyncContextMultiProcedure<C, Resource> procedure,
ClusterSupport support) throws DatabaseException {
if (DEBUG)
System.out.println("Cluster.forObjects1: rk=" + resourceKey + " pk=" + predicateKey);
@Override
public void forObjects(ReadGraphImpl graph, int resourceKey,
- int predicateKey, AsyncMultiProcedure<Resource> procedure)
+ int predicateKey, SyncMultiProcedure<Resource> procedure)
throws DatabaseException {
- throw new UnsupportedOperationException();
-
-// SessionImplSocket session = (SessionImplSocket)graph.getSession();
-// ClusterSupport support = session.clusterTranslator;
-//
-// if (DEBUG)
-// System.out.println("Cluster.forObjects3: rk=" + resourceKey + " pk=" + predicateKey);
-// final int resourceIndex = getLocalReference(resourceKey);
-// final int pRef = getInternalReferenceOrZero(predicateKey, support);
-// final ClusterI.CompleteTypeEnum pCompleteType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey);
-// if (ClusterI.CompleteTypeEnum.NotComplete != pCompleteType) {
-// resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
-// return;
-// }
-// final int predicateIndex = resourceTable.getPredicateIndex(resourceIndex);
-// if (0 == predicateIndex) {
-// resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
-// return;
-// }
-// int objectIndex = predicateTable.getObjectIndex(predicateIndex, pRef);
-// forObjects(resourceKey, predicateKey, objectIndex, graph.processor, graph, procedure, support);
+ SessionImplSocket session = (SessionImplSocket)graph.getSession();
+ ClusterSupport support = session.clusterTranslator;
+
+ if (DEBUG)
+ System.out.println("Cluster.forObjects3: rk=" + resourceKey + " pk=" + predicateKey);
+ final int resourceIndex = getLocalReference(resourceKey);
+ final int pRef = getInternalReferenceOrZero(predicateKey, support);
+ final ClusterI.CompleteTypeEnum pCompleteType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey);
+ if (ClusterI.CompleteTypeEnum.NotComplete != pCompleteType) {
+ resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
+ return;
+ }
+ final int predicateIndex = resourceTable.getPredicateIndex(resourceIndex);
+ if (0 == predicateIndex) {
+ resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
+ return;
+ }
+ int objectIndex = predicateTable.getObjectIndex(predicateIndex, pRef);
+ forObjects(resourceKey, predicateKey, objectIndex, graph.processor, graph, procedure, support);
}
@Override
public void forObjects(ReadGraphImpl graph, int resourceKey, ForEachObjectProcedure procedure) throws DatabaseException {
- throw new UnsupportedOperationException();
-
-// SessionImplSocket session = (SessionImplSocket)graph.getSession();
-// ClusterSupport support = session.clusterTranslator;
-// final int predicateKey = procedure.predicateKey;
-// if (DEBUG)
-// System.out.println("Cluster.forObjects3: rk=" + resourceKey + " pk=" + predicateKey);
-// final int resourceIndex = getLocalReference(resourceKey);
-// final int pRef = getInternalReferenceOrZero(predicateKey, support);
-// final ClusterI.CompleteTypeEnum pCompleteType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey);
-// if (ClusterI.CompleteTypeEnum.NotComplete != pCompleteType) {
-// resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
-// return;
-// }
-// final int predicateIndex = resourceTable.getPredicateIndex(resourceIndex);
-// if (0 == predicateIndex) {
-// resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
-// return;
-// }
-// int objectIndex = predicateTable.getObjectIndex(predicateIndex, pRef);
-// forObjects(resourceKey, predicateKey, objectIndex, graph.processor, graph, procedure, support);
+ SessionImplSocket session = (SessionImplSocket)graph.getSession();
+ ClusterSupport support = session.clusterTranslator;
+ final int predicateKey = procedure.predicateKey;
+ if (DEBUG)
+ System.out.println("Cluster.forObjects3: rk=" + resourceKey + " pk=" + predicateKey);
+ final int resourceIndex = getLocalReference(resourceKey);
+ final int pRef = getInternalReferenceOrZero(predicateKey, support);
+ final ClusterI.CompleteTypeEnum pCompleteType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey);
+ if (ClusterI.CompleteTypeEnum.NotComplete != pCompleteType) {
+ resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
+ return;
+ }
+ final int predicateIndex = resourceTable.getPredicateIndex(resourceIndex);
+ if (0 == predicateIndex) {
+ resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
+ return;
+ }
+ int objectIndex = predicateTable.getObjectIndex(predicateIndex, pRef);
+ forObjects(resourceKey, predicateKey, objectIndex, graph.processor, graph, procedure, support);
}
@Override
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;
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;
return objectTable.getSingleObject(objectIndex, support, this);
}
- public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, AsyncMultiProcedure<Resource> procedure,
+ public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, SyncMultiProcedure<Resource> procedure,
ClusterSupport support) throws DatabaseException {
if (DEBUG)
System.out.println("ClusterSmall.forObjects1: rk=" + resourceKey + " pk=" + predicateKey);
objectTable.foreachObject(graph, objectIndex, procedure, this);
}
- public <C> void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, C context, AsyncContextMultiProcedure<C, Resource> procedure,
+ public <C> void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, C context, SyncContextMultiProcedure<C, Resource> procedure,
ClusterSupport support) throws DatabaseException {
if (DEBUG)
System.out.println("ClusterSmall.forObjects1: rk=" + resourceKey + " pk=" + predicateKey);
@Override
public void forObjects(ReadGraphImpl graph, int resourceKey,
- int predicateKey, AsyncMultiProcedure<Resource> procedure) throws DatabaseException {
+ int predicateKey, SyncMultiProcedure<Resource> procedure) throws DatabaseException {
- throw new UnsupportedOperationException();
-
-// SessionImplSocket session = (SessionImplSocket)graph.getSession();
-// ClusterSupport support = session.clusterTranslator;
-// if (DEBUG)
-// System.out.println("ClusterSmall.forObjects3: rk=" + resourceKey + " pk=" + predicateKey);
-// final int resourceIndex = ClusterTraitsBase.getResourceIndexFromResourceKey(resourceKey);
-// final int pRef = getInternalReferenceOrZero2(predicateKey, support);
-// final int completeType = ClusterTraitsBase.getCompleteTypeIntFromResourceKey(predicateKey);
-// final ClusterI.CompleteTypeEnum pCompleteType = CompleteTypeEnum.make(completeType);
-// if (completeType > 0) {
-// resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
-// return;
-// }
-// final int predicateIndex = (int)resourceTable.table[(resourceIndex<<1) - 1 + resourceTable.offset] & 0xFFFFFF;
-// if (0 == predicateIndex) {
-// resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
-// return;
-// }
-// int objectIndex = predicateTable.getObjectIndex(predicateIndex, pRef & 0xFFFF);
-// forObjects(graph, resourceKey, predicateKey, objectIndex, procedure, support);
+ SessionImplSocket session = (SessionImplSocket)graph.getSession();
+ ClusterSupport support = session.clusterTranslator;
+ if (DEBUG)
+ System.out.println("ClusterSmall.forObjects3: rk=" + resourceKey + " pk=" + predicateKey);
+ final int resourceIndex = ClusterTraitsBase.getResourceIndexFromResourceKey(resourceKey);
+ final int pRef = getInternalReferenceOrZero2(predicateKey, support);
+ final int completeType = ClusterTraitsBase.getCompleteTypeIntFromResourceKey(predicateKey);
+ final ClusterI.CompleteTypeEnum pCompleteType = CompleteTypeEnum.make(completeType);
+ if (completeType > 0) {
+ resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
+ return;
+ }
+ final int predicateIndex = (int)resourceTable.table[(resourceIndex<<1) - 1 + resourceTable.offset] & 0xFFFFFF;
+ if (0 == predicateIndex) {
+ resourceTable.foreachObject(resourceIndex, graph, procedure, support, pRef, pCompleteType, completeTable, this);
+ return;
+ }
+ int objectIndex = predicateTable.getObjectIndex(predicateIndex, pRef & 0xFFFF);
+ forObjects(graph, resourceKey, predicateKey, objectIndex, procedure, support);
+
}
public void forObjects(ReadGraphImpl graph, int resourceKey, ForEachObjectProcedure procedure) throws DatabaseException {
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;
if (content == LabelerContent.NO_CONTENT) {
- final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+ final DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
assert(source != null);
source.schedule(graph -> graph.asyncRequest(labelQuery, procedure));
*******************************************************************************/
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;
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;
@Override
public NodeContext[] getChildren() {
if (children == Viewpoint.PENDING_CHILDREN) {
- DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+ DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
if (source != null) {
source.schedule(graph -> graph.asyncRequest(childQuery, childQueryProcedure));
}
@Override
public Boolean getHasChildren() {
if (hasChildren == Viewpoint.PENDING_HAS_CHILDREN) {
- DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+ DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
if (source != null) {
- source.schedule(new Consumer<ReadGraph>() {
- @Override
- public void accept(ReadGraph source) {
- source.asyncRequest(hasChildQuery, hasChildQueryProcedure);
- }
- });
+ source.schedule(graph -> graph.asyncRequest(hasChildQuery, hasChildQueryProcedure));
}
}
-
return hasChildren;
}
*******************************************************************************/
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;
if (!computed) {
- final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+ final DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
assert(source != null);
- source.schedule(new Consumer<ReadGraph>() {
-
- @Override
- public void accept(ReadGraph source) {
-
- source.asyncRequest(query, procedure);
-
- }
-
- });
+ source.schedule(graph -> graph.asyncRequest(query, procedure));
}
*******************************************************************************/
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;
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;
public NodeContext[] getChildren() {
if (children == Viewpoint.PENDING_CHILDREN) {
- DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+ DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
final Listener<NodeContext[]> childProcedure = createListener();
- source.schedule(new Consumer<ReadGraph>() {
- @Override
- public void accept(ReadGraph source) {
- source.asyncRequest(childQuery, childProcedure);
- }
- });
+ source.schedule(graph -> graph.asyncRequest(childQuery, childProcedure));
}
return children;
//System.out.println("LazyViewpoint2@" + System.identityHashCode(this) + " getChildren() = " + children.length);
if (children == org.simantics.browsing.ui.content.ViewpointContribution.PENDING_CONTRIBUTION) {
- DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+ DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
if (source != null) {
source.schedule(graph -> {
ReadRequest childQuery = new ReadRequest() {
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;
if (state == null) {
- final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+ final DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
assert(source != null);
source.schedule(graph -> {
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;
private void request() {
- final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+ final DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
assert(source != null);
final Procedure<ImageDecorator> procedure = createProcedure();
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;
content = PENDING;
- final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+ final DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
assert(source != null);
final Procedure<Map<String, ImageDescriptor>> procedure = createProcedure();
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;
private void request() {
- final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+ final DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
assert(source != null);
final Procedure<LabelDecorator> procedure = createProcedure();
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;
if (content == LabelerContent.NO_CONTENT) {
- final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+ final DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
assert(source != null);
final Procedure<LabelerContent> procedure = createProcedure();
//System.out.println("LazyViewpoint2@" + System.identityHashCode(this) + " getChildren() = " + children.length);
if (children == org.simantics.browsing.ui.content.ViewpointContribution.PENDING_CONTRIBUTION) {
- DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+ DataSource<AsyncReadGraph> source = updater.getDataSource(AsyncReadGraph.class);
if (source != null) {
source.schedule(graph -> {
if(childProcedure instanceof Listener<?>)
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,
*******************************************************************************/
package org.simantics.db.common.primitiverequest;
-import java.util.Collection;
-
import org.simantics.db.AsyncReadGraph;
-import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
-import org.simantics.db.common.request.ResourceRead2;
-import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.common.request.ResourceAsyncMultiRead2;
import org.simantics.db.procedure.AsyncMultiProcedure;
-import org.simantics.db.service.CollectionSupport;
-import org.simantics.utils.DataContainer;
-final public class ForEachAssertedObject extends ResourceRead2<Collection<Resource>> {
+final public class ForEachAssertedObject extends ResourceAsyncMultiRead2<Resource> {
public ForEachAssertedObject(Resource subject, Resource relation) {
super(subject, relation);
}
@Override
- public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
- CollectionSupport cs = graph.getService(CollectionSupport.class);
- Collection<Resource> result = cs.createSet();
- DataContainer<Throwable> throwable = new DataContainer<Throwable>(null);
- graph.forEachAssertedObject(resource, resource2, new AsyncMultiProcedure<Resource>() {
-
- @Override
- public void finished(AsyncReadGraph graph) {
- }
-
- @Override
- public void execute(AsyncReadGraph graph, Resource r) {
- result.add(r);
- }
-
- @Override
- public void exception(AsyncReadGraph graph, Throwable t) {
- throwable.set(t);
- }
- });
- Throwable t = throwable.get();
- if(t != null)
- if(t instanceof DatabaseException)
- throw (DatabaseException)t;
- else throw new DatabaseException(t);
- return result;
+ public void perform(AsyncReadGraph graph, AsyncMultiProcedure<Resource> procedure) {
+ graph.forEachAssertedObject(resource, resource2, procedure);
}
}
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;
@Override
public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
- dqs.forRelationInfo(graph, resource, procedure);
+ try {
+ procedure.execute(graph, dqs.getRelationInfo(graph, resource));
+ } catch (DatabaseException e) {
+ procedure.exception(graph, e);
+ }
}
}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
- * in Industry THTH ry.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * VTT Technical Research Centre of Finland - initial API and implementation
- *******************************************************************************/
-package org.simantics.db.common.procedure;
-
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.simantics.db.AsyncReadGraph;
-import org.simantics.db.common.utils.Logger;
-import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.procedure.AsyncProcedure;
-
-public class BlockingAsyncProcedure<Result> implements AsyncProcedure<Result> {
-
- final private Object key;
- private Result result = null;
- private Throwable exception = null;
- final private AsyncReadGraph graph;
- final private AsyncProcedure<Result> procedure;
- final private Semaphore semaphore = new Semaphore(0);
-// final private AtomicBoolean latch;
-
- public BlockingAsyncProcedure(AsyncReadGraph graph, AsyncProcedure<Result> procedure, Object key) {
-// assert(procedure != null);
- this.graph = graph;
- this.key = key;
- this.procedure = procedure;
- if(key == null)
- System.err.println("asd");
- //System.err.println("BlockingAsyncProcedure " + key);
-// latch = new AtomicBoolean(false);
- }
-
- @Override
- public void execute(AsyncReadGraph graph, Result result) {
- this.result = result;
- semaphore.release();
-// if(latch.compareAndSet(false, true)) {
- try {
- if(procedure != null) procedure.execute(graph, result);
- } catch (Throwable throwable) {
- Logger.defaultLogError("AsyncProcedure.execute threw for " + procedure, throwable);
- }
-// } finally {
-//// System.err.println("ResultCallWrappedSingleQueryProcedure4 dec " + key);
-// }
-// } else {
-// Logger.defaultLogError("Procedure was called many times (this time is execute)");
-// }
- }
-
- @Override
- public void exception(AsyncReadGraph graph, Throwable t) {
- this.exception = t;
- semaphore.release();
-// if(latch.compareAndSet(false, true)) {
- try {
- if(procedure != null) procedure.exception(graph, t);
- } catch (Throwable throwable) {
- Logger.defaultLogError("AsyncProcedure.exception threw for " + procedure, throwable);
- } finally {
- }
-// } else {
-// Logger.defaultLogError("Procedure was called many times (this time is exception)");
-// }
-
- }
-
- private void waitFor() throws DatabaseException {
-
- boolean success = false;
- success = semaphore.tryAcquire();
- if(success) return;
-
- while(!success) {
-
- if(graph.performPending()) {
- // Some task was done
- success = semaphore.tryAcquire();
- } else {
- // Nothing to do - just wait
- try {
- success = semaphore.tryAcquire(10, TimeUnit.SECONDS);
- if(!success) throw new DatabaseException("Timeout while waiting for async request to complete: " + key);
- } catch (InterruptedException e) {
- throw new DatabaseException(e);
- }
- }
-
- }
-
- }
-
- public Result get() throws DatabaseException {
-
- waitFor();
-
- if(exception != null) {
- if(exception instanceof DatabaseException) throw (DatabaseException)exception;
- throw new DatabaseException(exception);
- } else {
- return result;
- }
-
- }
-
- public Result getResult() {
- return result;
- }
-
- public Throwable getException() {
- return exception;
- }
-
- @Override
- public String toString() {
- return "." + procedure;
- }
-
-}
package org.simantics.db.common.procedure.single;
import org.simantics.db.ReadGraph;
-import org.simantics.db.common.procedure.adapter.AsyncListenerSupport;
+import org.simantics.db.common.procedure.adapter.SyncListenerSupport;
abstract public class SingleSetSyncListenerDelegate<T> extends SingleSetSyncListener<T> {
- final private AsyncListenerSupport support;
+ final private SyncListenerSupport support;
- public SingleSetSyncListenerDelegate(AsyncListenerSupport support) {
+ public SingleSetSyncListenerDelegate(SyncListenerSupport support) {
this.support = support;
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.common.procedure.wrapper;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.procedure.MultiListener;
+import org.simantics.db.procedure.SyncMultiListener;
+
+public class NoneToSyncMultiListener<T> implements SyncMultiListener<T> {
+
+ final private MultiListener<T> procedure;
+
+ public NoneToSyncMultiListener(MultiListener<T> procedure) {
+ this.procedure = procedure;
+ }
+
+ @Override
+ public void execute(ReadGraph graph, final T result) {
+ procedure.execute(result);
+ }
+
+ @Override
+ public void finished(ReadGraph graph) {
+ procedure.finished();
+ }
+
+ @Override
+ public void exception(ReadGraph graph, Throwable t) {
+ procedure.exception(t);
+ }
+
+ @Override
+ public boolean isDisposed() {
+ return procedure.isDisposed();
+ }
+
+ @Override
+ public String toString() {
+ return "NoneToAsyncMultiListener -> " + procedure;
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.common.procedure.wrapper;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.procedure.MultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
+
+public class NoneToSyncMultiProcedure<T> implements SyncMultiProcedure<T> {
+
+ final private MultiProcedure<T> procedure;
+
+ public NoneToSyncMultiProcedure(MultiProcedure<T> procedure) {
+ this.procedure = procedure;
+ }
+
+ @Override
+ public void execute(ReadGraph graph, final T result) {
+ procedure.execute(result);
+ }
+
+ @Override
+ public void finished(ReadGraph graph) {
+ procedure.finished();
+ }
+
+ @Override
+ public void exception(ReadGraph graph, Throwable t) {
+ procedure.exception(t);
+ }
+
+ @Override
+ public String toString() {
+ return "NoneToAsyncMultiProcedure -> " + procedure;
+ }
+
+}
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;
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 {
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);
+// }
}
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);
+// }
}
}
final ArrayList<T> result = new ArrayList<T>();
final DataContainer<Throwable> exception = new DataContainer<Throwable>();
- syncRequest(request, new AsyncMultiProcedureAdapter<T>() {
+ syncRequest(request, new SyncMultiProcedureAdapter<T>() {
@Override
- public void execute(AsyncReadGraph graph, T t) {
+ public void execute(ReadGraph graph, T t) {
synchronized(result) {
result.add(t);
}
}
@Override
- public void exception(AsyncReadGraph graph, Throwable t) {
+ public void exception(ReadGraph graph, Throwable t) {
exception.set(t);
}
return result;
}
- @Override
- public <T> Collection<T> syncRequest(MultiRead<T> request, AsyncMultiProcedure<T> procedure) {
- throw new UnsupportedOperationException("Not implemented");
- }
-
@Override
public <T> Collection<T> syncRequest(MultiRead<T> request, MultiProcedure<T> procedure) {
throw new UnsupportedOperationException("Not implemented");
throw new UnsupportedOperationException("Not implemented");
}
- @Override
- public <T> void asyncRequest(MultiRead<T> request, AsyncMultiProcedure<T> procedure) {
- throw new UnsupportedOperationException("Not implemented");
- }
-
@Override
public <T> void asyncRequest(MultiRead<T> request, MultiProcedure<T> procedure) {
throw new UnsupportedOperationException("Not implemented");
}
- @Override
+/* @Override
public <T> Collection<T> syncRequest(MultiRead<T> arg0, AsyncMultiListener<T> arg1) {
throw new UnsupportedOperationException("Not implemented.");
- }
+ }*/
@Override
public <T> Collection<T> syncRequest(MultiRead<T> arg0, SyncMultiListener<T> arg1) {
}
- @Override
- public <T> void asyncRequest(MultiRead<T> arg0, AsyncMultiListener<T> arg1) {
- throw new UnsupportedOperationException("Not implemented.");
-
- }
-
@Override
public <T> void asyncRequest(MultiRead<T> arg0, SyncMultiListener<T> arg1) {
throw new UnsupportedOperationException("Not implemented.");
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;
import org.simantics.db.request.WriteOnlyResult;
import org.simantics.db.request.WriteResult;
-public class ProcessorBase implements RequestProcessor {
+public class ProcessorBase implements AsyncRequestProcessor {
@Override
public <T> void asyncRequest(AsyncMultiRead<T> request, AsyncMultiProcedure<T> procedure) {
throw new UnsupportedOperationException();
}
- @Override
- public <T> Collection<T> syncRequest(MultiRead<T> request, AsyncMultiProcedure<T> procedure) {
- throw new UnsupportedOperationException();
- }
-
@Override
public <T> Collection<T> syncRequest(MultiRead<T> request, MultiProcedure<T> procedure) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException();
}
- @Override
- public <T> void asyncRequest(MultiRead<T> request, AsyncMultiProcedure<T> procedure) {
- throw new UnsupportedOperationException();
- }
-
@Override
public <T> void asyncRequest(MultiRead<T> request, MultiProcedure<T> procedure) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException();
}
- @Override
+/* @Override
public <T> Collection<T> syncRequest(MultiRead<T> arg0, AsyncMultiListener<T> arg1) {
throw new UnsupportedOperationException();
- }
+ }*/
@Override
public <T> Collection<T> syncRequest(MultiRead<T> arg0, SyncMultiListener<T> arg1) {
throw new UnsupportedOperationException();
}
- @Override
- public <T> void asyncRequest(MultiRead<T> arg0, AsyncMultiListener<T> arg1) {
- throw new UnsupportedOperationException();
- }
-
@Override
public <T> void asyncRequest(MultiRead<T> arg0, SyncMultiListener<T> arg1) {
throw new UnsupportedOperationException();
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.common.request;
+
+import org.simantics.db.request.AsyncRead;
+
+public abstract class UniqueAsyncRead<T> implements AsyncRead<T> {
+
+ @Override
+ public int getFlags() {
+ return 0;
+ }
+
+ @Override
+ public int threadHash() {
+ return hashCode();
+ }
+
+}
/**
* Converts ordered set into a list.
*/
- public static void forEach(AsyncReadGraph g, final Resource l, final AsyncMultiProcedure<Resource> procedure) {
+ /*public static void forEach(AsyncReadGraph g, final Resource l, final AsyncMultiProcedure<Resource> procedure) {
g.asyncRequest(new ReadRequest() {
@Override
}
});
- }
+ }*/
/**
* Creates an empty ordered set.
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;
}
}
- 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:
{
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.impl;
+
+import java.text.DecimalFormat;
+import java.util.concurrent.TimeUnit;
+
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.impl.graph.AsyncBarrierImpl;
+import org.simantics.db.impl.graph.ReadGraphImpl;
+import org.simantics.db.procedure.AsyncProcedure;
+
+public class BlockingAsyncProcedure<Result> implements AsyncProcedure<Result> {
+
+ final private Object key;
+ final private ReadGraphImpl graph;
+ final private AsyncProcedure<Result> procedure;
+
+ private Result result = null;
+ private Throwable exception = null;
+
+ public BlockingAsyncProcedure(ReadGraphImpl graph, AsyncProcedure<Result> procedure, Object key) {
+ this.procedure = procedure;
+ this.key = key;
+ this.graph = ReadGraphImpl.newAsync(graph);
+ this.graph.asyncBarrier.inc();
+ }
+
+ @Override
+ public void execute(AsyncReadGraph graph, Result result) {
+ this.result = result;
+ this.graph.asyncBarrier.dec();
+ try {
+ if(procedure != null) procedure.execute(graph, result);
+ } catch (Throwable throwable) {
+ Logger.defaultLogError("AsyncProcedure.execute threw for " + procedure, throwable);
+ }
+ }
+
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable t) {
+ this.exception = t;
+ try {
+ if(procedure != null) procedure.exception(graph, t);
+ } catch (Throwable throwable) {
+ Logger.defaultLogError("AsyncProcedure.exception threw for " + procedure, throwable);
+ } finally {
+ }
+ this.graph.asyncBarrier.dec();
+ }
+
+ public Result get() throws DatabaseException {
+
+ graph.asyncBarrier.waitBarrier(key, graph);
+
+ if(exception != null) {
+ if(exception instanceof DatabaseException) throw (DatabaseException)exception;
+ throw new DatabaseException(exception);
+ } else {
+ return result;
+ }
+
+ }
+
+ public Result getResult() {
+ return result;
+ }
+
+ public Throwable getException() {
+ return exception;
+ }
+
+ @Override
+ public String toString() {
+ return "." + procedure;
+ }
+
+}
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 {
public <C, T> int getSingleObject(int resourceKey, ForPossibleRelatedValueContextProcedure<C, T> procedure, ClusterSupport support)
throws DatabaseException;
- public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, AsyncMultiProcedure<Resource> procedure)
+ public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, SyncMultiProcedure<Resource> procedure)
throws DatabaseException;
public void forObjects(ReadGraphImpl graph, int resourceKey, ForEachObjectProcedure procedure)
package org.simantics.db.impl;
-import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
import org.simantics.db.RelationInfo;
import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.query.QueryProcessor;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
-public final class ForEachObjectContextProcedure<C> implements AsyncContextMultiProcedure<C, Resource> {
+public final class ForEachObjectContextProcedure<C> implements SyncContextMultiProcedure<C, Resource> {
public final int predicateKey;
public final int[] clusterKey;
public final RelationInfo info;
public final QueryProcessor processor;
public final ClusterI.CompleteTypeEnum completeType;
- private final AsyncContextMultiProcedure<C, Resource> user;
+ private final SyncContextMultiProcedure<C, Resource> user;
- public ForEachObjectContextProcedure(int predicateKey, RelationInfo info, QueryProcessor processor, AsyncContextMultiProcedure<C, Resource> user) {
+ public ForEachObjectContextProcedure(int predicateKey, RelationInfo info, QueryProcessor processor, SyncContextMultiProcedure<C, Resource> user) {
this.predicateKey = predicateKey;
this.completeType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey);
this.info = info;
}
@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);
}
package org.simantics.db.impl;
-import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
import org.simantics.db.RelationInfo;
import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.query.QueryProcessor;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
-public final class ForEachObjectProcedure implements AsyncMultiProcedure<Resource> {
+public final class ForEachObjectProcedure implements SyncMultiProcedure<Resource> {
public final int predicateKey;
public final int[] clusterKey;
public final RelationInfo info;
public final QueryProcessor processor;
public final ClusterI.CompleteTypeEnum completeType;
- private final AsyncMultiProcedure<Resource> user;
+ private final SyncMultiProcedure<Resource> user;
- public ForEachObjectProcedure(int predicateKey, RelationInfo info, QueryProcessor processor, AsyncMultiProcedure<Resource> user) {
+ public ForEachObjectProcedure(int predicateKey, RelationInfo info, QueryProcessor processor, SyncMultiProcedure<Resource> user) {
this.predicateKey = predicateKey;
this.completeType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey);
this.info = info;
}
@Override
- public void execute(AsyncReadGraph graph, Resource result) {
+ public void execute(ReadGraph graph, Resource result) throws DatabaseException {
user.execute(graph, result);
}
@Override
- public void finished(AsyncReadGraph graph) {
+ public void finished(ReadGraph graph) throws DatabaseException {
user.finished(graph);
}
@Override
- public void exception(AsyncReadGraph graph, Throwable throwable) {
+ public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException {
user.exception(graph, throwable);
}
package org.simantics.db.impl;
-import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
import org.simantics.db.RelationInfo;
-import org.simantics.db.procedure.AsyncContextProcedure;
+import org.simantics.db.procedure.SyncContextProcedure;
-public final class ForPossibleRelatedValueContextProcedure<C, T> implements AsyncContextProcedure<C, T> {
+public final class ForPossibleRelatedValueContextProcedure<C, T> implements SyncContextProcedure<C, T> {
public final int predicateKey;
public final int[] clusterKey;
public final int[] predicateReference;
public final RelationInfo info;
public final ClusterI.CompleteTypeEnum completeType;
- private final AsyncContextProcedure<C, T> user;
+ private final SyncContextProcedure<C, T> user;
- public ForPossibleRelatedValueContextProcedure(int predicateKey, RelationInfo info, AsyncContextProcedure<C, T> user) {
+ public ForPossibleRelatedValueContextProcedure(int predicateKey, RelationInfo info, SyncContextProcedure<C, T> user) {
this.predicateKey = predicateKey;
this.completeType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey);
this.info = info;
}
@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);
}
package org.simantics.db.impl;
-import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
import org.simantics.db.RelationInfo;
-import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.SyncProcedure;
-public final class ForPossibleRelatedValueProcedure<T> implements AsyncProcedure<T> {
+public final class ForPossibleRelatedValueProcedure<T> implements SyncProcedure<T> {
public final int predicateKey;
public final int[] clusterKey;
public final int[] predicateReference;
public final RelationInfo info;
public final ClusterI.CompleteTypeEnum completeType;
- private final AsyncProcedure<T> user;
+ private final SyncProcedure<T> user;
- public ForPossibleRelatedValueProcedure(int predicateKey, RelationInfo info, AsyncProcedure<T> user) {
+ public ForPossibleRelatedValueProcedure(int predicateKey, RelationInfo info, SyncProcedure<T> user) {
this.predicateKey = predicateKey;
this.completeType = ClusterTraitsBase.getCompleteTypeFromResourceKey(predicateKey);
this.info = info;
}
@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);
}
final private SerialisationSupport serialization;
final private ResourceSupport resourceSupport;
final private VirtualGraphServerSupport virtualGraphServerSupport;
- final private RequestProcessor sessionRequestProcessor;
+ final private AsyncRequestProcessor sessionRequestProcessor;
/*
* Cluster array by index.
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;
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;
static final boolean RESTART_GUARD = false;
final private AsyncBarrierImpl caller;
+
+ final private Semaphore sema = new Semaphore(0);
public AsyncBarrierImpl(AsyncBarrierImpl caller) {
super(0);
long waitCount = 0;
while (get() != 0) {
-
- boolean executed = impl.processor.resume(impl);
+
+ boolean executed = impl.performPending();
if(executed) waitCount = 0;
++waitCount;
import org.simantics.db.common.utils.Logger;
import org.simantics.db.impl.query.IntProcedure;
import org.simantics.db.impl.query.QuerySupport;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
public class MultiIntProcedure implements IntProcedure {
- final private AsyncMultiProcedure<Resource> procedure;
+ final private SyncMultiProcedure<Resource> procedure;
final private ReadGraphImpl impl;
final private QuerySupport support;
- public MultiIntProcedure(AsyncMultiProcedure<Resource> procedure, ReadGraphImpl impl, QuerySupport support) {
+ public MultiIntProcedure(SyncMultiProcedure<Resource> procedure, ReadGraphImpl impl, QuerySupport support) {
this.procedure = procedure;
this.impl = impl;
this.support = support;
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;
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;
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;
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;
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;
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);
throws DatabaseException {
assert (request != null);
-// AsyncReadProcedure<T> procedure = new AsyncReadProcedure<T>();
+ asyncBarrier = new AsyncBarrierImpl(null);
BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<>(this, null, request);
syncRequest(request, ap);
return ap.get();
-// procedure.checkAndThrow();
-// return procedure.result;
-
-// return syncRequest(request, new AsyncProcedureAdapter<T>());
}
// final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
// procedure, request);
+
+ ReadGraphImpl async = ReadGraphImpl.newAsync(this);
QueryCache.runnerAsyncReadEntry(this, request, parent, listener, ap, true);
final ArrayList<T> result = new ArrayList<T>();
final DataContainer<Throwable> exception = new DataContainer<Throwable>();
- syncRequest(request, new AsyncMultiProcedure<T>() {
+ syncRequest(request, new SyncMultiProcedure<T>() {
@Override
- public void execute(AsyncReadGraph graph, T t) {
+ public void execute(ReadGraph graph, T t) {
synchronized (result) {
result.add(t);
}
}
@Override
- public void finished(AsyncReadGraph graph) {
+ public void finished(ReadGraph graph) {
}
@Override
- public void exception(AsyncReadGraph graph, Throwable t) {
+ public void exception(ReadGraph graph, Throwable t) {
exception.set(t);
}
}
- @Override
+/* @Override
public <T> Collection<T> syncRequest(MultiRead<T> request,
AsyncMultiListener<T> procedure) {
return syncRequest(request, (AsyncMultiProcedure<T>) procedure);
- }
+ }*/
@Override
public <T> Collection<T> syncRequest(MultiRead<T> request,
SyncMultiListener<T> procedure) {
- return syncRequest(request, new SyncToAsyncMultiListener<T>(procedure));
+ return syncRequest(request, (SyncMultiProcedure<T>)procedure);
}
@Override
public <T> Collection<T> syncRequest(MultiRead<T> request,
MultiListener<T> procedure) {
- return syncRequest(request, new NoneToAsyncMultiListener<T>(procedure));
+ return syncRequest(request, new NoneToSyncMultiListener<T>(procedure));
}
+ /*
@Override
public <T> Collection<T> syncRequest(MultiRead<T> request,
AsyncMultiProcedure<T> procedure) {
return null;
}
+ */
@Override
public <T> Collection<T> syncRequest(MultiRead<T> request,
SyncMultiProcedure<T> procedure) {
- return syncRequest(request, new SyncToAsyncMultiProcedure<T>(procedure));
+
+ assert (request != null);
+
+ ListenerBase listener = getListenerBase(procedure);
+
+ final ResultCallWrappedSyncQueryProcedure<T> wrapper = new ResultCallWrappedSyncQueryProcedure<T>(procedure);
+
+ if (parent != null || listener != null) {
+
+// Object syncParent = request;
+
+// final ReadGraphImpl newGraph = newSync();
+
+ processor.query(this, request, parent, wrapper, listener);
+
+// newGraph.waitAsync(syncParent);
+
+ } else {
+
+// Object syncParent = request;
+
+// final ReadGraphImpl newGraph = newSync();
+
+
+ try {
+ request.perform(this, wrapper);
+ } catch (Throwable t) {
+ wrapper.exception(this, t);
+ }
+
+ }
+
+ return wrapper.get();
+
}
@Override
public <T> Collection<T> syncRequest(MultiRead<T> request,
MultiProcedure<T> procedure) {
- return syncRequest(request, new NoneToAsyncMultiProcedure<T>(procedure));
+ return syncRequest(request, new NoneToSyncMultiProcedure<T>(procedure));
}
static class AsyncMultiReadProcedure<T> extends ArrayList<T> implements AsyncMultiProcedure<T> {
// }
@Override
- final public void forEachDirectPredicate(final Resource subject, final AsyncMultiProcedure<Resource> procedure) {
+ final public void forEachDirectPredicate(final Resource subject, final AsyncProcedure<Set<Resource>> procedure) {
processor.forEachDirectPredicate(this, subject, procedure);
}
@Override
- public void forEachDirectPredicate(Resource subject, SyncMultiProcedure<Resource> procedure) {
- forEachDirectPredicate(subject, new SyncToAsyncMultiProcedure<Resource>(procedure));
+ final public void forEachDirectPredicate(final Resource subject, final SyncProcedure<Set<Resource>> procedure) {
+ forEachDirectPredicate(subject, new SyncToAsyncProcedure<Set<Resource>>(procedure));
}
@Override
- public void forEachDirectPredicate(Resource subject, MultiProcedure<Resource> procedure) {
- forEachDirectPredicate(subject, new NoneToAsyncMultiProcedure<Resource>(procedure));
+ public void forEachDirectPredicate(Resource subject, Procedure<Set<Resource>> procedure) {
+ forEachDirectPredicate(subject, new NoneToAsyncProcedure<Set<Resource>>(procedure));
}
@Override
assert (request != null);
- asyncRequest(request, new AsyncMultiProcedureAdapter<T>() {
+ asyncRequest(request, new SyncMultiProcedureAdapter<T>() {
@Override
- public void exception(AsyncReadGraph graph, Throwable t) {
+ public void exception(ReadGraph graph, Throwable t) {
Logger.defaultLogError(t);
}
}
- @Override
- public <T> void asyncRequest(MultiRead<T> request,
- AsyncMultiListener<T> procedure) {
- asyncRequest(request, (AsyncMultiProcedure<T>) procedure);
- }
-
@Override
public <T> void asyncRequest(MultiRead<T> request,
SyncMultiListener<T> procedure) {
- asyncRequest(request, new SyncToAsyncMultiListener<T>(procedure));
+ asyncRequest(request, (SyncMultiProcedure<T>)procedure);
}
@Override
public <T> void asyncRequest(MultiRead<T> request,
MultiListener<T> procedure) {
- asyncRequest(request, new NoneToAsyncMultiListener<T>(procedure));
+ asyncRequest(request, new NoneToSyncMultiListener<T>(procedure));
}
+
@Override
public <T> void asyncRequest(final MultiRead<T> request,
- final AsyncMultiProcedure<T> procedure) {
+ final SyncMultiProcedure<T> procedure) {
assert (request != null);
assert (procedure != null);
} catch (Throwable t) {
- procedure.exception(this, t);
+ try {
+ procedure.exception(this, t);
+ } catch (DatabaseException e) {
+ LOGGER.error("Unexpected exception while handling exception", e);
+ }
}
}
- @Override
- public <T> void asyncRequest(MultiRead<T> request,
- SyncMultiProcedure<T> procedure) {
- asyncRequest(request, new SyncToAsyncMultiProcedure<T>(procedure));
- }
-
@Override
public <T> void asyncRequest(MultiRead<T> request,
MultiProcedure<T> procedure) {
- asyncRequest(request, new NoneToAsyncMultiProcedure<T>(procedure));
+ asyncRequest(request, new NoneToSyncMultiProcedure<T>(procedure));
}
@Override
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) {
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 {
void forEachAssertedStatement(ReadGraphImpl graph, Resource subject, Resource predicate, AsyncMultiProcedure<Statement> procedure);
void forEachObject(ReadGraphImpl graph, Resource subject, Resource predicate, MultiProcedure<Resource> procedure);
void forEachObject(ReadGraphImpl graph, Resource subject, Resource predicate, AsyncMultiProcedure<Resource> procedure);
- void forEachDirectPredicate(ReadGraphImpl graph, Resource subject, AsyncMultiProcedure<Resource> procedure);
- void forEachDirectStatement(ReadGraphImpl graph, Resource subject, Procedure<DirectStatements> procedure);
- void forEachDirectStatement(ReadGraphImpl graph, Resource subject, AsyncProcedure<DirectStatements> procedure, boolean ignoreVirtual);
+ void forEachDirectPredicate(ReadGraphImpl graph, Resource subject, AsyncProcedure<Set<Resource>> procedure);
void forObjectSet(ReadGraphImpl graph, Resource subject, Resource predicate, AsyncSetListener<Resource> procedure);
void forPredicateSet(ReadGraphImpl graph, Resource subject, AsyncSetListener<Resource> procedure);
void forPrincipalTypeSet(ReadGraphImpl graph, Resource subject, AsyncSetListener<Resource> procedure);
void forEachPrincipalType(ReadGraphImpl graph, Resource subject, AsyncMultiProcedure<Resource> procedure);
void forEachPrincipalType(ReadGraphImpl graph, Resource subject, MultiProcedure<Resource> procedure);
- void forRelationInfo(ReadGraphImpl graph, Resource subject, AsyncProcedure<RelationInfo> procedure);
+ RelationInfo getRelationInfo(ReadGraphImpl graph, Resource subject) throws DatabaseException;
+
void forTypes(ReadGraphImpl graph, Resource subject, AsyncProcedure<Set<Resource>> procedure);
IntSet getTypes(ReadGraphImpl graph, Resource subject) throws Throwable;
void forSupertypes(ReadGraphImpl graph, Resource subject, AsyncProcedure<Set<Resource>> procedure);
void forOrderedSet(ReadGraphImpl graph, Resource subject, AsyncMultiProcedure<Resource> procedure);
//<T> T query(ReadGraphImpl graph, Read<T> request, CacheEntry parent, AsyncProcedure<T> procedure, ListenerBase listener) throws DatabaseException;
- <T> void query(ReadGraphImpl graph, MultiRead<T> request, CacheEntry parent, AsyncMultiProcedure<T> procedure, ListenerBase listener);
+ <T> void query(ReadGraphImpl graph, MultiRead<T> request, CacheEntry parent, SyncMultiProcedure<T> procedure, ListenerBase listener);
// <T> void query(ReadGraphImpl graph, AsyncRead<T> request, CacheEntry parent, AsyncProcedure<T> procedure, ListenerBase listener) throws DatabaseException;
<T> void query(ReadGraphImpl graph, AsyncMultiRead<T> request, CacheEntry parent, AsyncMultiProcedure<T> procedure, ListenerBase listener);
//<T> void query(ReadGraphImpl graph, ExternalRead<T> request, CacheEntry parent, Procedure<T> procedure, ListenerBase listener);
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.impl.procedure;
+
+import java.util.ArrayList;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.SyncMultiProcedure;
+
+public class ResultCallWrappedSyncQueryProcedure<Result> implements SyncMultiProcedure<Result> {
+
+ final private ArrayList<Result> result;
+ private Throwable exception = null;
+ final private SyncMultiProcedure<Result> procedure;
+ final private AtomicBoolean latch;
+
+ public ResultCallWrappedSyncQueryProcedure(SyncMultiProcedure<Result> procedure) {
+ this.procedure = procedure;
+ latch = new AtomicBoolean(false);
+ result = new ArrayList<Result>();
+ }
+
+ @Override
+ public void execute(ReadGraph graph, Result result) {
+ try {
+ synchronized(this.result) {
+ this.result.add(result);
+ }
+ procedure.execute(graph, result);
+ } catch (Throwable t) {
+ Logger.defaultLogError("AsyncMultiProcedure.execute failed for " + procedure, t);
+ }
+ }
+
+ @Override
+ public void finished(ReadGraph graph) {
+ if(latch.compareAndSet(false, true)) {
+ try {
+ procedure.finished(graph);
+ } catch (Throwable t) {
+ Logger.defaultLogError("AsyncMultiProcedure.exception failed for " + procedure, t);
+ } finally {
+ }
+ } else {
+ Logger.defaultLogError("Finished or exception was called many times (this time is finished)");
+ }
+ }
+
+ @Override
+ public void exception(ReadGraph graph, Throwable t) {
+ if(latch.compareAndSet(false, true)) {
+ try {
+ this.exception = t;
+ procedure.exception(graph, t);
+ } catch (Throwable throwable) {
+ Logger.defaultLogError("AsyncMultiProcedure.exception failed for " + procedure, throwable);
+ } finally {
+ }
+ } else {
+ Logger.defaultLogError("Finished or exception was called many times (this time is exception)");
+ }
+ }
+
+ public ArrayList<Result> get() {
+ return result;
+ }
+
+ public Throwable getException() {
+ return exception;
+ }
+
+ @Override
+ public String toString() {
+ return "ResultCallWrappedQueryProcedure4[" + procedure + "]";
+ }
+
+}
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;
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;
-package org.simantics.db.common;
+package org.simantics.db.impl.query;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.ArrayList;
import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
import org.simantics.db.common.exception.DebugException;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.graph.ReadGraphImpl;
-import org.simantics.db.impl.query.QueryProcessor.AsyncBarrier;
import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
import org.simantics.db.request.MultiRead;
import org.simantics.db.request.RequestFlags;
-import org.simantics.utils.datastructures.Pair;
-final public class MultiReadEntry<T> extends CacheEntryBase<AsyncMultiProcedure<T>> {
+final public class MultiReadEntry<T> extends CacheEntryBase<SyncMultiProcedure<T>> {
protected MultiRead<T> request;
setResult(null);
}
- synchronized public void finish(AsyncReadGraph graph) {
+ synchronized public void finish(ReadGraph graph) {
assert(isPending());
- ArrayList<Pair<AsyncMultiProcedure<T>, AsyncBarrier>> p = null;
-
- synchronized(this) {
+ synchronized(this) {
setReady();
}
try {
- request.perform(graph , new AsyncMultiProcedure<T>() {
+ request.perform(graph , new SyncMultiProcedure<T>() {
@Override
- public void execute(AsyncReadGraph graph, T result) {
+ public void execute(ReadGraph graph, T result) {
addOrSet(result);
}
- public void finished(AsyncReadGraph graph) {
+ public void finished(ReadGraph graph) {
finish(graph);
};
@Override
- public void exception(AsyncReadGraph graph, Throwable t) {
+ public void exception(ReadGraph graph, Throwable t) {
except(t);
}
}
@Override
- public Object performFromCache(ReadGraphImpl graph, AsyncMultiProcedure<T> proc) {
+ public Object performFromCache(ReadGraphImpl graph, SyncMultiProcedure<T> proc) {
if(isExcepted()) {
}
//@Override
- public Object compute(ReadGraphImpl graph, AsyncMultiProcedure<T> procedure) throws DatabaseException {
+ public Object compute(ReadGraphImpl graph, SyncMultiProcedure<T> procedure) throws DatabaseException {
return graph.processor.cache.performQuery(graph, request, this, procedure);
}
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;
}
}
- 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 {
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;
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;
ReadGraphImpl queryGraph = parentGraph.withParent(entry_);
- AsyncMultiReadEntry entry = (AsyncMultiReadEntry)entry_;
- AsyncMultiProcedure<T> procedure = (AsyncMultiProcedure<T>)procedure_;
+ MultiReadEntry entry = (MultiReadEntry)entry_;
+ SyncMultiProcedure<T> procedure = (SyncMultiProcedure<T>)procedure_;
try {
- query.perform(queryGraph, new AsyncMultiProcedure<T>() {
+ query.perform(queryGraph, new SyncMultiProcedure<T>() {
@Override
- public void execute(AsyncReadGraph graph, T result) {
+ public void execute(ReadGraph graph, T result) {
ReadGraphImpl impl = (ReadGraphImpl)graph;
entry.addOrSet(result);
try {
}
@Override
- public void finished(AsyncReadGraph graph) {
+ public void finished(ReadGraph graph) {
ReadGraphImpl impl = (ReadGraphImpl)graph;
entry.finish(parentGraph);
try {
}
@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) {
};
+ protected static SyncMultiProcedure<Object> emptySyncMultiProcedure = new SyncMultiProcedure<Object>() {
+
+ @Override
+ public void execute(ReadGraph graph, Object result) {
+ }
+
+ @Override
+ public void finished(ReadGraph graph) {
+ }
+
+ @Override
+ public void exception(ReadGraph graph, Throwable throwable) {
+ }
+
+
+ };
+
protected static InternalProcedure<IntSet> emptyProcedureTypes = emptyIntSetProcedure;
protected static InternalProcedure<IntSet> emptyProcedureSuperTypes = emptyIntSetProcedure;
protected static InternalProcedure<IntSet> emptyProcedureTypeHierarchy = emptyIntSetProcedure;
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;
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;
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;
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;
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;
}
- final <T> void runMultiRead(final ReadGraphImpl graph, MultiReadEntry cached, final MultiRead<T> query, final CacheEntry parent, final QueryProcessor provider, final ListenerBase listener, final AsyncMultiProcedure<T> procedure) {
+ final <T> void runMultiRead(final ReadGraphImpl graph, MultiReadEntry cached, final MultiRead<T> query, final CacheEntry parent, final QueryProcessor provider, final ListenerBase listener, final SyncMultiProcedure<T> procedure) {
try {
QueryCache.runnerMultiReadEntry(graph, query, parent, listener, procedure);
//
// }
- public <T> void queryMultiRead(final ReadGraphImpl graph, final MultiRead<T> query, final CacheEntry parent, final ListenerBase listener, final AsyncMultiProcedure<T> procedure) throws DatabaseException {
+ public <T> void queryMultiRead(final ReadGraphImpl graph, final MultiRead<T> query, final CacheEntry parent, final ListenerBase listener, final SyncMultiProcedure<T> procedure) throws DatabaseException {
QueryCache.runnerMultiReadEntry(graph, query, parent, listener, procedure);
}
@Override
- final public void forEachDirectPredicate(final ReadGraphImpl impl, final Resource subject, final AsyncMultiProcedure<Resource> procedure) {
-
- throw new UnsupportedOperationException();
-
-// assert(subject != null);
-// assert(procedure != null);
-//
-// final ListenerBase listener = getListenerBase(procedure);
-//
-// MultiIntProcedure proc = new MultiIntProcedure(procedure, impl, querySupport);
-//
-// int sId = querySupport.getId(subject);
-//
-// try {
-// QueryCache.runnerDirectPredicates(impl, sId, impl.parent, listener, proc);
-// } catch (DatabaseException e) {
-// Logger.defaultLogError(e);
-// }
-
- }
-
- @Override
- final public void forEachDirectStatement(final ReadGraphImpl impl, final Resource subject, final Procedure<DirectStatements> procedure) {
+ final public void forEachDirectPredicate(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure<Set<Resource>> procedure) {
assert(subject != null);
assert(procedure != null);
final ListenerBase listener = getListenerBase(procedure);
- org.simantics.db.impl.query.DirectStatements.queryEach(impl, querySupport.getId(subject), this, impl.parent, listener, procedure);
+ int sId = querySupport.getId(subject);
- }
+ try {
+ QueryCache.runnerDirectPredicates(impl, sId, impl.parent, listener, new InternalProcedure<IntSet>() {
- @Override
- final public void forEachDirectStatement(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure<DirectStatements> procedure, boolean ignoreVirtual) {
+ @Override
+ public void execute(ReadGraphImpl graph, IntSet result) throws DatabaseException {
+ procedure.execute(graph, result);
+ }
- assert(subject != null);
- assert(procedure != null);
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException {
+ procedure.exception(graph, throwable);
+ }
+
+ });
+ } catch (DatabaseException e) {
+ Logger.defaultLogError(e);
+ }
- final ListenerBase listener = getListenerBase(procedure);
+ }
- org.simantics.db.impl.query.DirectStatements.queryEach(impl, querySupport.getId(subject), this, impl.parent, listener, procedure, ignoreVirtual);
+ final public DirectStatements getDirectStatements(final ReadGraphImpl impl, final Resource subject, final boolean ignoreVirtual) {
+
+// assert(subject != null);
+// assert(procedure != null);
+//
+// final ListenerBase listener = getListenerBase(procedure);
+//
+// org.simantics.db.impl.query.DirectStatements.queryEach(impl, querySupport.getId(subject), this, impl.parent, listener, procedure);
+
+ return querySupport.getStatements(impl, querySupport.getId(subject), this, ignoreVirtual);
}
+// @Override
+// final public void forEachDirectStatement(final ReadGraphImpl impl, final Resource subject, final SyncProcedure<DirectStatements> procedure, boolean ignoreVirtual) {
+//
+// assert(subject != null);
+// assert(procedure != null);
+//
+// final ListenerBase listener = getListenerBase(procedure);
+//
+// org.simantics.db.impl.query.DirectStatements.queryEach(impl, querySupport.getId(subject), this, impl.parent, listener, procedure, ignoreVirtual);
+//
+// }
+
private static final Resource INVALID_RESOURCE = new ResourceImpl(null, Integer.MIN_VALUE);
@Override
}
@Override
- final public void forRelationInfo(final ReadGraphImpl impl, final Resource subject, final AsyncProcedure<RelationInfo> procedure) {
+ final public RelationInfo getRelationInfo(final ReadGraphImpl impl, final Resource subject) throws DatabaseException {
assert(subject != null);
- assert(procedure != null);
-
- final ListenerBase listener = getListenerBase(procedure);
- assert(listener == null);
-
- try {
-
- QueryCache.runnerRelationInfoQuery(impl, querySupport.getId(subject), impl.parent, listener, new InternalProcedure<RelationInfo>() {
-
- @Override
- public void execute(final ReadGraphImpl graph, RelationInfo set) {
- procedure.execute(graph, set);
- }
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) {
- procedure.exception(graph, t);
- }
-
- });
- } catch (DatabaseException e) {
- Logger.defaultLogError(e);
- }
+ return QueryCache.resultRelationInfoQuery(impl, querySupport.getId(subject), impl.parent, null);
}
// }
@Override
- final public <T> void query(final ReadGraphImpl impl, final MultiRead<T> request, final CacheEntry parent, final AsyncMultiProcedure<T> procedure, ListenerBase listener) {
+ final public <T> void query(final ReadGraphImpl impl, final MultiRead<T> request, final CacheEntry parent, final SyncMultiProcedure<T> procedure, ListenerBase listener) {
assert(request != null);
assert(procedure != null);
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;
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;
class Process {
final ArrayList<Entry> result = new ArrayList<Entry>();
- final AsyncContextMultiProcedure<Resource, Resource> structure;
- final AsyncContextProcedure<Entry, String> names;
- final AsyncContextProcedure<Entry, Resource> type;
+ final SyncContextMultiProcedure<Resource, Resource> structure;
+ final SyncContextProcedure<Entry, String> names;
+ final SyncContextProcedure<Entry, Resource> type;
Process(ReadGraph graph, final Resource resource) throws DatabaseException {
final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
final CollectionSupport cs = graph.getService(CollectionSupport.class);
- names = dqs.compilePossibleRelatedValue(graph, L0.HasName, new AsyncContextProcedure<Entry, String>() {
+ names = dqs.compilePossibleRelatedValue(graph, L0.HasName, new SyncContextProcedure<Entry, String>() {
@Override
- public void execute(AsyncReadGraph graph, Entry entry, String name) {
+ public void execute(ReadGraph graph, Entry entry, String name) {
entry.name = name;
}
@Override
- public void exception(AsyncReadGraph graph, Throwable throwable) {
+ public void exception(ReadGraph graph, Throwable throwable) {
LOGGER.error("Could not compile possible related value for resource {}", resource, throwable);
}
});
- type = new AsyncContextProcedure<Entry, Resource>() {
+ type = new SyncContextProcedure<Entry, Resource>() {
@Override
- public void execute(AsyncReadGraph graph, Entry entry, Resource type) {
+ public void execute(ReadGraph graph, Entry entry, Resource type) {
entry.principalType = type;
}
@Override
- public void exception(AsyncReadGraph graph, Throwable throwable) {
+ public void exception(ReadGraph graph, Throwable throwable) {
LOGGER.error("Could not find type for resource {}", resource, throwable);
}
};
- structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new AsyncContextMultiProcedure<Resource, Resource>() {
+ structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new SyncContextMultiProcedure<Resource, Resource>() {
@Override
- public void execute(AsyncReadGraph graph, Resource parent, Resource child) {
+ public void execute(ReadGraph graph, Resource parent, Resource child) {
// WORKAROUND: don't browse virtual child resources
if(!child.isPersistent()) return;
Entry entry = new Entry(parent, child, "", "", "");
}
@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())
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;
}
@Override
- public void perform(ReadGraph graph, AsyncMultiProcedure<Resource> callback) throws DatabaseException {
+ public void perform(ReadGraph graph, SyncMultiProcedure<Resource> callback) throws DatabaseException {
Layer0 L0 = Layer0.getInstance(graph);
ProjectResource PROJ = ProjectResource.getInstance(graph);
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;
super(model);
}
- public void check(ReadGraph graph, Resource resource, AsyncMultiProcedure<Resource> callback) throws DatabaseException {
+ public void check(ReadGraph graph, Resource resource, SyncMultiProcedure<Resource> callback) throws DatabaseException {
Layer0 L0 = Layer0.getInstance(graph);
ProjectResource PROJ = ProjectResource.getInstance(graph);
}
@Override
- public void perform(ReadGraph graph, AsyncMultiProcedure<Resource> callback) throws DatabaseException {
+ public void perform(ReadGraph graph, SyncMultiProcedure<Resource> callback) throws DatabaseException {
Layer0 L0 = Layer0.getInstance(graph);
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;
}
@Override
public void perform(ReadGraph graph,
- AsyncMultiProcedure<Resource> callback)
+ SyncMultiProcedure<Resource> callback)
throws DatabaseException {
- graph.forEachObject(subject, relation, callback);
+ for(Resource object : graph.getObjects(subject, relation)) {
+ callback.execute(graph, object);
+ }
}
@Override
public int hashCode() {
}
@Override
public Resource perform(ReadGraph graph) throws DatabaseException {
- SynchronizationProcedure<Resource> procedure = new SynchronizationProcedure<Resource>();
- graph.forPossibleObject(subject, relation, procedure);
- return procedure.getResult();
+ return graph.getPossibleObject(subject, relation);
}
@Override
public int hashCode() {
}
@Override
public Resource perform(ReadGraph graph) throws DatabaseException {
- SynchronizationProcedure<Resource> procedure = new SynchronizationProcedure<Resource>();
- graph.forSingleObject(subject, relation, procedure);
- return procedure.getResult();
+ return graph.getSingleObject(subject, relation);
}
@Override
public int hashCode() {
this.f = f;
this.g = g;
}
- public void perform(ReadGraph graph, final AsyncMultiProcedure<Y> callback) throws DatabaseException {
+ public void perform(ReadGraph graph, final SyncMultiProcedure<Y> callback) throws DatabaseException {
try {
for(X x : graph.syncRequest(g))
callback.execute(graph, graph.syncRequest(f.get(x)));
this.g = g;
}
@Override
- public void perform(ReadGraph graph, AsyncMultiProcedure<Y> callback)
+ public void perform(ReadGraph graph, SyncMultiProcedure<Y> callback)
throws DatabaseException {
graph.syncRequest(f.get(graph.syncRequest(g)), callback);
}
this.f = f;
this.g = g;
}
- public void perform(ReadGraph graph, final AsyncMultiProcedure<Y> callback) throws DatabaseException {
+ public void perform(ReadGraph graph, final SyncMultiProcedure<Y> callback) throws DatabaseException {
try {
for(X x : graph.syncRequest(g))
for(Y y : graph.syncRequest(f.get(x)))
this.value = value;
}
@Override
- public void perform(ReadGraph graph, AsyncMultiProcedure<T> callback)
+ public void perform(ReadGraph graph, SyncMultiProcedure<T> callback)
throws DatabaseException {
callback.execute(graph, value);
callback.finished(graph);
// ------------------------------------------------------------------------
- private static class Name implements Read<String> {
- Resource resource;
+ private static class Name extends ResourceRead<String> {
+
public Name(Resource resource) {
- this.resource = resource;
+ super(resource);
}
+
@Override
public String perform(ReadGraph graph) throws DatabaseException {
Layer0 L0 = Layer0.getInstance(graph);
- SynchronizationProcedure<String> procedure = new SynchronizationProcedure<String>();
- graph.forRelatedValue(resource, L0.HasName, procedure);
- return procedure.getResult();
+ return graph.getRelatedValue(resource, L0.HasName);
}
- @Override
- public int hashCode() {
- return getClass().hashCode() + 31 * resource.hashCode();
- }
- @Override
- public boolean equals(Object obj) {
- if(obj == this) return true;
- if(obj == null || obj.getClass() != getClass()) return false;
- Name other = (Name)obj;
- return resource.equals(other.resource);
- }
+
}
public static Read<String> name(Resource resource) {
return new Name(resource);
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;
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;
final List<ConsistsOfProcessEntry> result;
final Set<Resource> childrenWithNoName;
- final AsyncContextMultiProcedure<ConsistsOfProcessEntry, Resource> structure;
- final AsyncContextMultiProcedure<ConsistsOfProcessEntry, Resource> names;
+ final SyncContextMultiProcedure<ConsistsOfProcessEntry, Resource> structure;
+ final SyncContextMultiProcedure<ConsistsOfProcessEntry, Resource> names;
public static Pair<List<ConsistsOfProcessEntry>,Set<Resource>> walk(ReadGraph graph, Collection<SeedSpec> specs, boolean ignoreVirtual) throws DatabaseException {
return walk(graph, null, specs, ignoreVirtual);
result = new ArrayList<>();
childrenWithNoName = new HashSet<>();
- names = dqs.compileForEachObject(graph, L0.HasName, new AsyncContextMultiProcedure<ConsistsOfProcessEntry, Resource>() {
+ names = dqs.compileForEachObject(graph, L0.HasName, new SyncContextMultiProcedure<ConsistsOfProcessEntry, Resource>() {
@Override
- public void execute(AsyncReadGraph graph, ConsistsOfProcessEntry entry, Resource nameResource) {
+ public void execute(ReadGraph graph, ConsistsOfProcessEntry entry, Resource nameResource) throws DatabaseException {
if(status != null)
status.put(nameResource, ExtentStatus.EXCLUDED);
- graph.forPossibleValue(nameResource, new Procedure<String>() {
-
- @Override
- public void execute(String name) {
- if(!entry.valid) return;
-
- if(name == null) {
- entry.valid = false;
- } else if (entry.name != null) {
- entry.valid = false;
- } else {
- entry.name = name;
- }
- }
+ if(!entry.valid) return;
+
+ String name = graph.getValue(nameResource, Bindings.STRING);
+ if(name == null) {
+ entry.valid = false;
+ } else if (entry.name != null) {
+ entry.valid = false;
+ } else {
+ entry.name = name;
+ }
- @Override
- public void exception(Throwable t) {
- Logger.defaultLogError(t);
- }
-
- });
+
}
@Override
- public void exception(AsyncReadGraph graph, Throwable throwable) {
+ public void exception(ReadGraph graph, Throwable throwable) {
Logger.defaultLogError(throwable);
}
@Override
- public void finished(AsyncReadGraph graph, ConsistsOfProcessEntry entry) {
+ public void finished(ReadGraph graph, ConsistsOfProcessEntry entry) {
if(entry.valid) {
if(entry.name != null) {
result.add(entry);
}
});
- structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new AsyncContextMultiProcedure<ConsistsOfProcessEntry, Resource>() {
+ structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new SyncContextMultiProcedure<ConsistsOfProcessEntry, Resource>() {
@Override
- public void execute(AsyncReadGraph graph, ConsistsOfProcessEntry parent, Resource child) {
+ public void execute(ReadGraph graph, ConsistsOfProcessEntry parent, Resource child) {
if(status != null)
if(ExtentStatus.EXCLUDED.equals(status.get(child))) return;
}
@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);
}
final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
- final DomainStatementProcedure3 proc = new DomainStatementProcedure3(result);
+// final DomainStatementProcedure3 proc = new DomainStatementProcedure3(result);
if (ignoreVirtual) {
for(Resource r : roots) {
- dqs.forEachDirectPersistentStatement(graph, r, proc);
+ result.add(dqs.getDirectPersistentStatements(graph, r));
}
} else {
for(Resource r : roots) {
- dqs.forEachDirectStatement(graph, r, proc);
+ result.add(dqs.getDirectStatements(graph, r));
}
}
import org.simantics.db.impl.ForPossibleRelatedValueProcedure;
import org.simantics.db.impl.Table;
import org.simantics.db.impl.graph.ReadGraphImpl;
-import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
import org.simantics.db.procore.cluster.ClusterBig;
import org.simantics.db.procore.cluster.ClusterImpl;
import org.simantics.db.procore.cluster.ClusterTraits;
}
@Override
public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey,
- AsyncMultiProcedure<Resource> procedure) throws DatabaseException {
+ SyncMultiProcedure<Resource> procedure) throws DatabaseException {
throw new DatabaseException("Not implemented.");
}
@Override
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;
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;
}
@Override
- final public void forEachDirectPersistentStatement(AsyncReadGraph graph, final Resource subject, final AsyncProcedure<DirectStatements> procedure) {
+ final public DirectStatements getDirectPersistentStatements(ReadGraph graph, final Resource subject) {
ReadGraphImpl impl = (ReadGraphImpl)graph;
- impl.processor.forEachDirectStatement(impl, subject, procedure, true);
+ return impl.processor.getDirectStatements(impl, subject, true);
}
@Override
- final public void forEachDirectStatement(AsyncReadGraph graph, final Resource subject, final AsyncProcedure<DirectStatements> procedure) {
+ final public DirectStatements getDirectStatements(ReadGraph graph, final Resource subject) {
ReadGraphImpl impl = (ReadGraphImpl)graph;
- impl.processor.forEachDirectStatement(impl, subject, procedure, false);
+ return impl.processor.getDirectStatements(impl, subject, false);
}
- @Override
+ /*@Override
public void forEachDirectStatement(AsyncReadGraph graph, Resource subject, SyncProcedure<DirectStatements> procedure) {
forEachDirectStatement(graph, subject, new SyncToAsyncProcedure<DirectStatements>(procedure));
}
public void forEachDirectStatement(AsyncReadGraph graph, Resource subject, Procedure<DirectStatements> procedure) {
ReadGraphImpl impl = (ReadGraphImpl)graph;
impl.processor.forEachDirectStatement(impl, subject, procedure);
- }
+ }*/
- @Override
+ /*@Override
public void forRelationInfo(AsyncReadGraph graph, Resource subject, AsyncProcedure<RelationInfo> procedure) {
ReadGraphImpl impl = (ReadGraphImpl)graph;
impl.processor.forRelationInfo(impl, subject, procedure);
@Override
public void forRelationInfo(AsyncReadGraph graph, Resource subject, Procedure<RelationInfo> procedure) {
forRelationInfo(graph, subject, new NoneToAsyncProcedure<RelationInfo>(procedure));
+ }*/
+
+ @Override
+ public RelationInfo getRelationInfo(ReadGraph graph, Resource subject) throws DatabaseException {
+ ReadGraphImpl impl = (ReadGraphImpl)graph;
+ return impl.processor.getRelationInfo(impl, subject);
}
@Override
- public AsyncMultiProcedure<Resource> compileForEachObject(ReadGraph graph, final Resource relation, AsyncMultiProcedure<Resource> user) {
+ public SyncMultiProcedure<Resource> compileForEachObject(ReadGraph graph, final Resource relation, SyncMultiProcedure<Resource> user) throws DatabaseException {
- try {
- RelationInfo info = graph.syncRequest(new AsyncRead<RelationInfo>() {
-
- @Override
- public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
- forRelationInfo(graph, relation, procedure);
- }
-
- @Override
- public int threadHash() {
- return hashCode();
- }
-
- @Override
- public int getFlags() {
- return 0;
- }
-
- });
- final int predicateKey = ((ResourceImpl)relation).id;
- return new ForEachObjectProcedure(predicateKey, info, session.queryProvider2, user);
- } catch (DatabaseException e) {
- return null;
- }
+ RelationInfo info = getRelationInfo(graph, relation);
+ final int predicateKey = ((ResourceImpl)relation).id;
+ return new ForEachObjectProcedure(predicateKey, info, session.queryProvider2, user);
}
@Override
- public <C> AsyncContextMultiProcedure<C, Resource> compileForEachObject(ReadGraph graph, final Resource relation, AsyncContextMultiProcedure<C, Resource> user) {
+ public <C> SyncContextMultiProcedure<C, Resource> compileForEachObject(ReadGraph graph, final Resource relation, SyncContextMultiProcedure<C, Resource> user) throws DatabaseException {
- try {
- RelationInfo info = graph.syncRequest(new AsyncRead<RelationInfo>() {
-
- @Override
- public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
- forRelationInfo(graph, relation, procedure);
- }
-
- @Override
- public int threadHash() {
- return hashCode();
- }
-
- @Override
- public int getFlags() {
- return 0;
- }
-
- });
- final int predicateKey = ((ResourceImpl)relation).id;
- return new ForEachObjectContextProcedure<C>(predicateKey, info, session.queryProvider2, user);
- } catch (DatabaseException e) {
- return null;
- }
+ RelationInfo info = getRelationInfo(graph, relation);
+ final int predicateKey = ((ResourceImpl)relation).id;
+ return new ForEachObjectContextProcedure<C>(predicateKey, info, session.queryProvider2, user);
}
@Override
- public <T> AsyncProcedure<T> compilePossibleRelatedValue(ReadGraph graph, final Resource relation, AsyncProcedure<T> user) {
+ public <T> SyncProcedure<T> compilePossibleRelatedValue(ReadGraph graph, final Resource relation, SyncProcedure<T> user) throws DatabaseException {
- try {
- RelationInfo info = graph.syncRequest(new AsyncRead<RelationInfo>() {
-
- @Override
- public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
- forRelationInfo(graph, relation, procedure);
- }
-
- @Override
- public int threadHash() {
- return hashCode();
- }
-
- @Override
- public int getFlags() {
- return 0;
- }
-
- });
- final int predicateKey = ((ResourceImpl)relation).id;
- return new ForPossibleRelatedValueProcedure<T>(predicateKey, info, user);
- } catch (DatabaseException e) {
- return null;
- }
+ RelationInfo info = getRelationInfo(graph, relation);
+ final int predicateKey = ((ResourceImpl)relation).id;
+ return new ForPossibleRelatedValueProcedure<T>(predicateKey, info, user);
}
@Override
- public <C, T> AsyncContextProcedure<C, T> compilePossibleRelatedValue(ReadGraph graph, final Resource relation, AsyncContextProcedure<C, T> user) {
+ public <C, T> SyncContextProcedure<C, T> compilePossibleRelatedValue(ReadGraph graph, final Resource relation, SyncContextProcedure<C, T> user) throws DatabaseException {
- try {
- RelationInfo info = graph.syncRequest(new AsyncRead<RelationInfo>() {
-
- @Override
- public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
- forRelationInfo(graph, relation, procedure);
- }
-
- @Override
- public int threadHash() {
- return hashCode();
- }
-
- @Override
- public int getFlags() {
- return 0;
- }
-
- });
- final int predicateKey = ((ResourceImpl)relation).id;
- return new ForPossibleRelatedValueContextProcedure<C, T>(predicateKey, info, user);
- } catch (DatabaseException e) {
- return null;
- }
+ RelationInfo info = getRelationInfo(graph, relation);
+ final int predicateKey = ((ResourceImpl)relation).id;
+ return new ForPossibleRelatedValueContextProcedure<C, T>(predicateKey, info, user);
}
@Override
- public void forEachObjectCompiled(AsyncReadGraph graph, Resource subject, final AsyncMultiProcedure<Resource> procedure) {
+ public void forEachObjectCompiled(ReadGraph graph, Resource subject, final SyncMultiProcedure<Resource> procedure) {
assert(subject != null);
}
@Override
- public <C> void forEachObjectCompiled(AsyncReadGraph graph, Resource subject, C context, final AsyncContextMultiProcedure<C, Resource> procedure) {
+ public <C> void forEachObjectCompiled(ReadGraph graph, Resource subject, C context, final SyncContextMultiProcedure<C, Resource> procedure) {
assert(subject != null);
}
@Override
- public <T> void forPossibleRelatedValueCompiled(AsyncReadGraph graph, Resource subject, final AsyncProcedure<T> procedure) {
+ public <T> void forPossibleRelatedValueCompiled(ReadGraph graph, Resource subject, final SyncProcedure<T> procedure) {
assert(subject != null);
// 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 {
//
}
@Override
- public <C, T> void forPossibleRelatedValueCompiled(AsyncReadGraph graph, Resource subject, C context, final AsyncContextProcedure<C, T> procedure) {
+ public <C, T> void forPossibleRelatedValueCompiled(ReadGraph graph, Resource subject, C context, final SyncContextProcedure<C, T> procedure) {
assert(subject != null);
// impl.inc();
- if(info.isFunctional) {
- getRelatedValue4(impl, subjectId, context, proc);
- } else {
- getRelatedValue4(impl, subjectId, context, proc);
- }
+// if(info.isFunctional) {
+// } else {
+// getRelatedValue4(impl, subjectId, context, proc);
+// }
+
+ try {
+ T result = getRelatedValue4(impl, subjectId, context, proc);
+ proc.execute(graph, context, result);
+ } catch (DatabaseException e) {
+ proc.exception(graph, e);
+ }
}
- @Override
+/* @Override
public <T> void forPossibleType(final AsyncReadGraph graph, Resource subject, final AsyncProcedure<Resource> procedure) {
assert(subject != null);
}
+
+ */
@Override
- public <C> void forPossibleDirectType(final AsyncReadGraph graph, Resource subject, final C context, final AsyncContextProcedure<C, Resource> procedure) {
+ public <C> void forPossibleDirectType(final ReadGraph graph, Resource subject, final C context, final SyncContextProcedure<C, Resource> procedure) {
assert(subject != null);
}
-
- private <C, T> void getRelatedValue4(final ReadGraphImpl graph, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
+ private <C, T> T getRelatedValue4(final ReadGraphImpl graph, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) throws DatabaseException {
int result = 0;
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;
}
}
if(result == 0) {
-
- procedure.exception(graph, new DatabaseException("No objects for " + subject ));
-// graph.dec();
- return;
-
+ throw new DatabaseException("No objects for " + subject );
} else {
-
- getValue4(graph, null, result, context, procedure);
- return;
-
+ return getValue4(graph, null, result, context, procedure);
}
}
final org.simantics.db.procore.cluster.ClusterImpl cluster = session.clusterTable.getClusterByResourceKey(subject);
if(!cluster.isLoaded()) {
- cluster.load(session.clusterTranslator, () -> getRelatedValue4(graph, subject, context, procedure));
- return;
+ cluster.load();
+ return getRelatedValue4(graph, subject, context, procedure);
}
if(cluster.hasVirtual() && session.virtualGraphServerSupport.virtuals.contains(subject)) {
if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject, predicate)) {
- SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate,
- g -> getRelatedValue4(g, subject, context, procedure)
- );
- return;
+ SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate, g -> {});
+ return getRelatedValue4(graph, subject, context, procedure);
}
for(TransientGraph g : session.virtualGraphServerSupport.providers) {
for (int id : g.getObjects(subject, predicate)) {
if(result != 0) {
- procedure.exception(graph, new DatabaseException("Multiple objects"));
-// graph.dec();
- return;
+ throw new DatabaseException("Multiple objects");
} else {
result = id;
}
}
}
- getRelatedDirectValue4(graph, cluster, subject, result, context, procedure);
+ return getRelatedDirectValue4(graph, cluster, subject, result, context, procedure);
} else {
- getRelatedDirectValue4(graph, cluster, subject, 0, context, procedure);
+ return getRelatedDirectValue4(graph, cluster, subject, 0, context, procedure);
}
}
- private <T> void getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) {
+ private <T> T getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) throws DatabaseException {
Object result = null;
if(subject < 0) {
if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject)) {
- SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject,
- g -> getValue4(g, containerCluster, subject, procedure)
- );
- return;
+ SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, g -> {});
+ return getValue4(graph, containerCluster, subject, procedure);
}
for(TransientGraph g : session.virtualGraphServerSupport.providers) {
Object value = g.getValue(subject);
if(value != null) {
if(result != null) {
- procedure.exception(graph, new DatabaseException("Multiple values"));
-// graph.dec();
- return;
+ throw new DatabaseException("Multiple values");
} else {
result = value;
}
}
}
-
- procedure.execute(graph, (T)"name");
-// graph.dec();
- return;
-
+
+ return (T)"name";
+
}
ClusterImpl cluster = containerCluster;
if(!containerCluster.contains(subject)) {
cluster = session.clusterTable.getClusterByResourceKey(subject);
if(!cluster.isLoaded()) {
- cluster.load(session.clusterTranslator, new Runnable() {
-
- @Override
- public void run() {
- getValue4(graph, containerCluster, subject, procedure);
- }
-
- });
- return;
+ cluster.load();
+ return getValue4(graph, containerCluster, subject, procedure);
}
}
if(cluster.hasVirtual() && session.virtualGraphServerSupport.virtuals.contains(subject)) {
if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject)) {
- SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject,
- g -> getValue4(g, containerCluster, subject, procedure)
- );
- return;
+ SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, g -> {});
+ return getValue4(graph, containerCluster, subject, procedure);
}
for(TransientGraph g : session.virtualGraphServerSupport.providers) {
Object value = g.getValue(subject);
if(value != null) {
if(result != null) {
- procedure.exception(graph, new DatabaseException("Multiple values"));
-// graph.dec();
- return;
+ throw new DatabaseException("Multiple values");
} else {
result = value;
}
}
if(result != null) {
-
- procedure.execute(graph, (T)result);
-// graph.state.barrier.dec();
-
+ return (T)result;
} else {
-
if(ClusterTypeEnum.SMALL == cluster.getType())
- getDirectValue4(graph, (ClusterSmall)cluster, subject, procedure);
+ return getDirectValue4(graph, (ClusterSmall)cluster, subject);
else
- getDirectValue4(graph, (ClusterBig)cluster, subject, procedure);
+ return getDirectValue4(graph, (ClusterBig)cluster, subject);
}
} else {
if(ClusterTypeEnum.SMALL == cluster.getType())
- getDirectValue4(graph, (ClusterSmall)cluster, subject, procedure);
+ return getDirectValue4(graph, (ClusterSmall)cluster, subject);
else
- getDirectValue4(graph, (ClusterBig)cluster, subject, procedure);
+ return getDirectValue4(graph, (ClusterBig)cluster, subject);
}
}
- private <C, T> void getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
+ private <C, T> T getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) throws DatabaseException {
Object result = null;
if(subject < 0) {
if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject)) {
- SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject,
- g -> getValue4(g, containerCluster, subject, context, procedure)
- );
- return;
+ SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, g -> {});
+ return getValue4(graph, containerCluster, subject, context, procedure);
}
for(TransientGraph g : session.virtualGraphServerSupport.providers) {
Object value = g.getValue(subject);
if(value != null) {
if(result != null) {
- procedure.exception(graph, new DatabaseException("Multiple values"));
-// graph.dec();
- return;
+ throw new DatabaseException("Multiple values");
} else {
result = value;
}
}
}
- procedure.execute(graph, context, (T)"name");
-// graph.dec();
- return;
-
+ return (T)"name";
+
}
ClusterImpl cluster = containerCluster;
if(!containerCluster.contains(subject)) {
cluster = session.clusterTable.getClusterByResourceKey(subject);
if(!cluster.isLoaded()) {
- cluster.load(session.clusterTranslator, new Runnable() {
-
- @Override
- public void run() {
- getValue4(graph, containerCluster, subject, context, procedure);
- }
-
- });
- return;
+ cluster.load();
+ return getValue4(graph, containerCluster, subject, context, procedure);
}
}
if(cluster.hasVirtual() && session.virtualGraphServerSupport.virtuals.contains(subject)) {
if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject)) {
- SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject,
- g -> getValue4(g, containerCluster, subject, context, procedure)
- );
- return;
+ SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, g -> {});
+ return getValue4(graph, containerCluster, subject, context, procedure);
}
for(TransientGraph g : session.virtualGraphServerSupport.providers) {
Object value = g.getValue(subject);
if(value != null) {
if(result != null) {
- procedure.exception(graph, new DatabaseException("Multiple values"));
-// graph.dec();
- return;
+ throw new DatabaseException("Multiple values");
} else {
result = value;
}
}
if(result != null) {
-
- procedure.execute(graph, context, (T)result);
-// graph.state.barrier.dec();
-
+ return (T)result;
} else {
-
if(ClusterTypeEnum.SMALL == cluster.getType())
- getDirectValue4(graph, (ClusterSmall)cluster, subject, context, procedure);
+ return getDirectValue4(graph, (ClusterSmall)cluster, subject);
else
- getDirectValue4(graph, (ClusterBig)cluster, subject, context, procedure);
+ return getDirectValue4(graph, (ClusterBig)cluster, subject);
}
} else {
if(ClusterTypeEnum.SMALL == cluster.getType())
- getDirectValue4(graph, (ClusterSmall)cluster, subject, context, procedure);
+ return getDirectValue4(graph, (ClusterSmall)cluster, subject);
else
- getDirectValue4(graph, (ClusterBig)cluster, subject, context, procedure);
+ return getDirectValue4(graph, (ClusterBig)cluster, subject);
}
}
- private <T> void getRelatedDirectValue4(final ReadGraphImpl graph, final ClusterImpl cluster, final int subject, final int result, final ForPossibleRelatedValueProcedure<T> procedure) {
+ private <T> T getRelatedDirectValue4(final ReadGraphImpl graph, final ClusterImpl cluster, final int subject, final int result, final ForPossibleRelatedValueProcedure<T> procedure) throws DatabaseException {
- try {
-
- int so = cluster.getSingleObject(subject, procedure, session.clusterTranslator);
- if(so == 0) {
- if(result == 0) {
- procedure.exception(graph, new DatabaseException("No objects " + subject + " " + procedure.predicateKey));
-// graph.dec();
- } else {
- getValue4(graph, cluster, result, procedure);
- }
+ int so = cluster.getSingleObject(subject, procedure, session.clusterTranslator);
+ if(so == 0) {
+ if(result == 0) {
+ throw new DatabaseException("No objects " + subject + " " + procedure.predicateKey);
} else {
- if(result == 0) {
- getValue4(graph, cluster, so, procedure);
- } else {
- procedure.exception(graph, new DatabaseException("Multiple objects"));
-// graph.dec();
- }
+ return getValue4(graph, cluster, result, procedure);
+ }
+ } else {
+ if(result == 0) {
+ return getValue4(graph, cluster, so, procedure);
+ } else {
+ throw new DatabaseException("Multiple objects");
}
-
- } catch (DatabaseException e) {
- e.printStackTrace();
}
-
- }
- private <C, T> void getRelatedDirectValue4(final ReadGraphImpl graph, final ClusterImpl cluster, final int subject, final int result, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
-
- try {
+ }
+
+ private <C, T> T getRelatedDirectValue4(final ReadGraphImpl graph, final ClusterImpl cluster, final int subject, final int result, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) throws DatabaseException {
- int so = cluster.getSingleObject(subject, procedure, session.clusterTranslator);
- if(so == 0) {
- if(result == 0) {
- procedure.exception(graph, new NoSingleResultException("No objects " + subject + " " + procedure.predicateKey, result));
-// graph.dec();
- } else {
- getValue4(graph, cluster, result, context, procedure);
- }
+ int so = cluster.getSingleObject(subject, procedure, session.clusterTranslator);
+ if(so == 0) {
+ if(result == 0) {
+ throw new NoSingleResultException("No objects " + subject + " " + procedure.predicateKey, result);
} else {
- if(result == 0) {
- getValue4(graph, cluster, so, context, procedure);
- } else {
- procedure.exception(graph, new NoSingleResultException("Multiple objects for " + subject + " " + procedure.predicateKey, result));
-// graph.dec();
- }
+ return getValue4(graph, cluster, result, context, procedure);
+ }
+ } else {
+ if(result == 0) {
+ return getValue4(graph, cluster, so, context, procedure);
+ } else {
+ throw new NoSingleResultException("Multiple objects for " + subject + " " + procedure.predicateKey, result);
}
-
- } catch (DatabaseException e) {
- LOGGER.error("Could not compute related value for subject {} with predicate {}", subject, procedure.predicateKey);
}
}
- public <T> void getRelatedValue4(final ReadGraphImpl graph, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) {
+ public <T> T getRelatedValue4(final ReadGraphImpl graph, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) throws DatabaseException {
int result = 0;
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;
}
}
if(result == 0) {
-
- procedure.exception(graph, new DatabaseException("No objects for " + subject ));
-// graph.dec();
- return;
-
+ throw new DatabaseException("No objects for " + subject );
} else {
-
- getValue4(graph, null, result, procedure);
- return;
-
+ return getValue4(graph, null, result, procedure);
}
}
final org.simantics.db.procore.cluster.ClusterImpl cluster = session.clusterTable.getClusterByResourceKey(subject);
if(!cluster.isLoaded()) {
- cluster.load(session.clusterTranslator, new Runnable() {
-
- @Override
- public void run() {
- getRelatedValue4(graph, subject, procedure);
- }
-
- });
- return;
+ cluster.load();
+ return getRelatedValue4(graph, subject, procedure);
}
if(cluster.hasVirtual() && session.virtualGraphServerSupport.virtuals.contains(subject)) {
if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject, predicate)) {
- SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate,
- g -> getRelatedValue4(graph, subject, procedure)
- );
- return;
+ SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate, g -> {});
+ return getRelatedValue4(graph, subject, procedure);
}
for(TransientGraph g : session.virtualGraphServerSupport.providers) {
for (int id : g.getObjects(subject, predicate)) {
if(result != 0) {
- procedure.exception(graph, new DatabaseException("Multiple objects"));
-// graph.dec();
- return;
+ throw new DatabaseException("Multiple objects");
} else {
result = id;
}
}
}
- getRelatedDirectValue4(graph, cluster, subject, result, procedure);
+ return getRelatedDirectValue4(graph, cluster, subject, result, procedure);
} else {
- getRelatedDirectValue4(graph, cluster, subject, 0, procedure);
+ return getRelatedDirectValue4(graph, cluster, subject, 0, procedure);
}
}
-
+
+ /*
private <C, T> void getDirectValue4(final ReadGraphImpl graph, final ClusterSmall cluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
try {
// graph.dec();
}
+ */
- private <T> void getDirectValue4(final ReadGraphImpl graph, final ClusterBig cluster, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) {
+ private <T> T getDirectValue4(final ReadGraphImpl graph, final ClusterBig cluster, final int subject) throws DatabaseException {
- try {
- byte[] bytes = cluster.getValue(subject, session.clusterTranslator);
- T value = (T)utf(bytes);
- procedure.execute(graph, value);
- } catch (DatabaseException e) {
- procedure.execute(graph, null);
- }
-
-// graph.dec();
+ byte[] bytes = cluster.getValue(subject, session.clusterTranslator);
+ return (T)utf(bytes);
}
- private <C, T> void getDirectValue4(final ReadGraphImpl graph, final ClusterBig cluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
-
- try {
- byte[] bytes = cluster.getValue(subject, session.clusterTranslator);
- if(bytes == null) {
- procedure.execute(graph, context, null);
- } else {
- T value = (T)utf(bytes);
- procedure.execute(graph, context, value);
- }
- } catch (DatabaseException e) {
- procedure.execute(graph, context, null);
- }
-
-// graph.dec();
-
- }
-
- private <T> void getDirectValue4(final ReadGraphImpl graph, final ClusterSmall cluster, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) {
+ private <T> T getDirectValue4(final ReadGraphImpl graph, final ClusterSmall cluster, final int subject) {
ResourceTableSmall rt = cluster.resourceTable;
ValueTableSmall vt = cluster.valueTable;
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;
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 {
}
@Override
- public boolean resume(AsyncReadGraph graph) {
+ public boolean resume(ReadGraph graph) {
ReadGraphImpl impl = (ReadGraphImpl)graph;
return impl.processor.querySupport.resume(impl);
}
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;
// 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) {
//
}
}
- procedure.finished(graph);
+ try {
+ procedure.finished(graph);
+ } catch (DatabaseException e) {
+ LOGGER.error("Unexpected exception while handling objects", e);
+ }
// graph.dec();
return;
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;
}
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) {
//
// 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) {
//
}
}
- procedure.finished(graph, context);
+
+ try {
+ procedure.finished(graph, context);
+ } catch (DatabaseException e) {
+ LOGGER.error("Unexpected exception while handling objects", e);
+ }
+
+
// graph.dec();
return;
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) {
//
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;
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;
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;
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;
}
+ public <T> void scheduleRequest(final MultiRead<T> request, final SyncMultiProcedure<T> procedure, final Semaphore notify) {
+
+ assert (request != null);
+ assert (procedure != null);
+
+ int thread = request.hashCode() & queryProvider2.THREAD_MASK;
+
+ int sync = notify != null ? thread : -1;
+
+ requestManager.scheduleRead(new SessionRead(null, notify) {
+
+ @Override
+ public void run(int thread) {
+
+ fireSessionVariableChange(SessionVariables.QUEUED_READS);
+
+ ListenerBase listener = getListenerBase(procedure);
+
+ final ReadGraphImpl newGraph = ReadGraphImpl.create(getQueryProvider2());
+
+ try {
+
+ if (listener != null) {
+
+ newGraph.processor.query(newGraph, request, null, procedure, listener);
+
+// newGraph.waitAsync(request);
+
+ } else {
+
+ final ResultCallWrappedSyncQueryProcedure<T> wrapper = new ResultCallWrappedSyncQueryProcedure<T>(procedure);
+
+ try {
+
+ request.perform(newGraph, wrapper);
+
+ } catch (Throwable t) {
+
+ t.printStackTrace();
+
+ }
+
+ }
+
+ } finally {
+
+ fireSessionVariableChange(SessionVariables.QUEUED_READS);
+
+ }
+
+ }
+
+ });
+
+ }
+
public <T> void scheduleRequest(final AsyncMultiRead<T> request, final AsyncMultiProcedure<T> procedure, final Semaphore notify) {
assert (request != null);
final ArrayList<T> result = new ArrayList<T>();
final DataContainer<Throwable> exception = new DataContainer<Throwable>();
- syncRequest(request, new AsyncMultiProcedure<T>() {
+ syncRequest(request, new SyncMultiProcedure<T>() {
@Override
- public void execute(AsyncReadGraph graph, T t) {
+ public void execute(ReadGraph graph, T t) {
synchronized(result) {
result.add(t);
}
}
@Override
- public void finished(AsyncReadGraph graph) {
+ public void finished(ReadGraph graph) {
}
@Override
- public void exception(AsyncReadGraph graph, Throwable t) {
+ public void exception(ReadGraph graph, Throwable t) {
exception.set(t);
}
}
@Override
- public <T> Collection<T> syncRequest(MultiRead<T> request, AsyncMultiListener<T> procedure) throws DatabaseException {
+ public <T> Collection<T> syncRequest(MultiRead<T> arg0, SyncMultiProcedure<T> arg1) throws DatabaseException {
assertNotSession();
- return syncRequest(request, (AsyncMultiProcedure<T>)procedure);
+ throw new Error("Not implemented!");
}
@Override
public <T> Collection<T> syncRequest(MultiRead<T> request, SyncMultiListener<T> procedure) throws DatabaseException {
assertNotSession();
- return syncRequest(request, new SyncToAsyncMultiListener<T>(procedure));
+ return syncRequest(request, (SyncMultiProcedure<T>)procedure);
}
@Override
public <T> Collection<T> syncRequest(MultiRead<T> request, MultiListener<T> procedure) throws DatabaseException {
assertNotSession();
- return syncRequest(request, new NoneToAsyncMultiListener<T>(procedure));
- }
-
- @Override
- public <T> Collection<T> syncRequest(MultiRead<T> request, SyncMultiProcedure<T> procedure) throws DatabaseException {
- assertNotSession();
- return syncRequest(request, new SyncToAsyncMultiProcedure<T>(procedure));
+ return syncRequest(request, new NoneToSyncMultiListener<T>(procedure));
}
@Override
public <T> Collection<T> syncRequest(MultiRead<T> request, MultiProcedure<T> procedure) throws DatabaseException {
assertNotSession();
- return syncRequest(request, new NoneToAsyncMultiProcedure<T>(procedure));
+ return syncRequest(request, new NoneToSyncMultiProcedure<T>(procedure));
}
@Override
assert(request != null);
- asyncRequest(request, new AsyncMultiProcedureAdapter<T>() {
+ asyncRequest(request, new SyncMultiProcedureAdapter<T>() {
@Override
- public void exception(AsyncReadGraph graph, Throwable t) {
+ public void exception(ReadGraph graph, Throwable t) {
t.printStackTrace();
}
});
}
- @Override
- public <T> void asyncRequest(MultiRead<T> request, AsyncMultiListener<T> procedure) {
- asyncRequest(request, (AsyncMultiProcedure<T>)procedure);
- }
-
@Override
public <T> void asyncRequest(MultiRead<T> request, SyncMultiListener<T> procedure) {
- asyncRequest(request, new SyncToAsyncMultiListener<T>(procedure));
+ asyncRequest(request, (SyncMultiProcedure<T>)procedure);
}
@Override
public <T> void asyncRequest(MultiRead<T> request, MultiListener<T> procedure) {
- asyncRequest(request, new NoneToAsyncMultiListener<T>(procedure));
+ asyncRequest(request, new NoneToSyncMultiListener<T>(procedure));
}
@Override
public <T> void asyncRequest(MultiRead<T> request, SyncMultiProcedure<T> procedure) {
- asyncRequest(request, new SyncToAsyncMultiProcedure<T>(procedure));
+ scheduleRequest(request, procedure, null);
}
@Override
public <T> void asyncRequest(MultiRead<T> request, MultiProcedure<T> procedure) {
- asyncRequest(request, new NoneToAsyncMultiProcedure<T>(procedure));
+ asyncRequest(request, new NoneToSyncMultiProcedure<T>(procedure));
}
@Override
asyncRequest(request, new NoneToAsyncMultiProcedure<T>(procedure));
}
- @Override
- public <T> Collection<T> syncRequest(MultiRead<T> arg0, AsyncMultiProcedure<T> arg1) throws DatabaseException {
- assertNotSession();
- throw new Error("Not implemented!");
- }
-
- @Override
- public <T> void asyncRequest(MultiRead<T> arg0, AsyncMultiProcedure<T> arg1) {
- throw new Error("Not implemented!");
- }
-
@Override
final public <T> void asyncRequest(final ExternalRead<T> request) {
public int getAmountOfQueryThreads() {
// This must be a power of two
- return 16;
+ return 1;
// return Integer.highestOneBit(Runtime.getRuntime().availableProcessors());
}
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;
return objectTable.getSingleObject(objectIndex, support, this);
}
- public void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, AsyncMultiProcedure<Resource> procedure,
+ public void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, SyncMultiProcedure<Resource> procedure,
ClusterSupport support) throws DatabaseException {
if (DEBUG)
System.out.println("Cluster.forObjects1: rk=" + resourceKey + " pk=" + predicateKey);
}
objectTable.foreachObject(graph, objectIndex, procedure, this);
}
- public <C> void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, C context, AsyncContextMultiProcedure<C, Resource> procedure,
+ public <C> void forObjects(int resourceKey, int predicateKey, int objectIndex, QueryProcessor processor, ReadGraphImpl graph, C context, SyncContextMultiProcedure<C, Resource> procedure,
ClusterSupport support) throws DatabaseException {
if (DEBUG)
System.out.println("Cluster.forObjects1: rk=" + resourceKey + " pk=" + predicateKey);
@Override
public void forObjects(ReadGraphImpl graph, int resourceKey,
- int predicateKey, AsyncMultiProcedure<Resource> procedure)
+ int predicateKey, SyncMultiProcedure<Resource> procedure)
throws DatabaseException {
SessionImplSocket session = (SessionImplSocket)graph.getSession();
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;
return objectTable.getSingleObject(objectIndex, support, this);
}
- public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, AsyncMultiProcedure<Resource> procedure,
+ public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, SyncMultiProcedure<Resource> procedure,
ClusterSupport support) throws DatabaseException {
if (deleted) return;
if (DEBUG)
objectTable.foreachObject(graph, objectIndex, procedure, this);
}
- public <C> void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, C context, AsyncContextMultiProcedure<C, Resource> procedure,
+ public <C> void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, int objectIndex, C context, SyncContextMultiProcedure<C, Resource> procedure,
ClusterSupport support) throws DatabaseException {
if (DEBUG)
System.out.println("ClusterSmall.forObjects1: rk=" + resourceKey + " pk=" + predicateKey);
@Override
public void forObjects(ReadGraphImpl graph, int resourceKey,
- int predicateKey, AsyncMultiProcedure<Resource> procedure) throws DatabaseException {
+ int predicateKey, SyncMultiProcedure<Resource> procedure) throws DatabaseException {
if (deleted) return;
SessionImplSocket session = (SessionImplSocket)graph.getSession();
ClusterSupport support = session.clusterTranslator;
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;
}
- static void foreachInt(final ReadGraphImpl graph, int[] table, int base, final AsyncMultiProcedure<Resource> procedure, Modifier modifier) throws DatabaseException {
+ static void foreachInt(final ReadGraphImpl graph, int[] table, int base, final SyncMultiProcedure<Resource> procedure, Modifier modifier) throws DatabaseException {
int capacity = getRealSize(table, base);
final int size = getUsedSize(table, base);
assert(size == count);
}
- static <C> void foreachInt(final ReadGraphImpl graph, int[] table, int base, C context, final AsyncContextMultiProcedure<C, Resource> procedure, Modifier modifier) throws DatabaseException {
+ static <C> void foreachInt(final ReadGraphImpl graph, int[] table, int base, C context, final SyncContextMultiProcedure<C, Resource> procedure, Modifier modifier) throws DatabaseException {
int capacity = getRealSize(table, base);
final int size = getUsedSize(table, base);
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;
}
final public void foreachObject( ReadGraphImpl graph, final int objectIndex,
- final AsyncMultiProcedure<Resource> procedure, Modifier modifier) throws DatabaseException {
+ final SyncMultiProcedure<Resource> procedure, Modifier modifier) throws DatabaseException {
if (ClusterTraits.statementIndexIsDirect(objectIndex)) {
int key = modifier.execute(objectIndex);
procedure.execute(graph, new ResourceImpl(graph.getResourceSupport(), key));
}
final public <C> void foreachObject( ReadGraphImpl graph, final int objectIndex, C context,
- final AsyncContextMultiProcedure<C, Resource> procedure, Modifier modifier) throws DatabaseException {
+ final SyncContextMultiProcedure<C, Resource> procedure, Modifier modifier) throws DatabaseException {
if (ClusterTraits.statementIndexIsDirect(objectIndex)) {
int key = modifier.execute(objectIndex);
procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), key));
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 {
}
public static void foreachObject(long[] table, int index,
- final ReadGraphImpl graph, final AsyncMultiProcedure<Resource> procedure,
+ final ReadGraphImpl graph, final SyncMultiProcedure<Resource> procedure,
ClusterSupport support, final int pRef, ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, final Modifier modifier)
throws DatabaseException {
if (DEBUG)
}
public static <C> void foreachObject(long[] table, int index,
- final ReadGraphImpl graph, final C context, final AsyncContextMultiProcedure<C, Resource> procedure,
+ final ReadGraphImpl graph, final C context, final SyncContextMultiProcedure<C, Resource> procedure,
ClusterSupport support, final int pRef, ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, final Modifier modifier)
throws DatabaseException {
if (DEBUG)
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;
}
public static void foreachObject(long[] table, int index,
- final ReadGraphImpl graph, final AsyncMultiProcedure<Resource> procedure,
+ final ReadGraphImpl graph, final SyncMultiProcedure<Resource> procedure,
final ClusterSupport support, final int pRef, final ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, final Modifier modifier)
throws DatabaseException {
if (DEBUG)
}
public static <C> void foreachObject(long[] table, int index,
- final ReadGraphImpl graph, final C context, final AsyncContextMultiProcedure<C, Resource> procedure,
+ final ReadGraphImpl graph, final C context, final SyncContextMultiProcedure<C, Resource> procedure,
final ClusterSupport support, final int pRef, final ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, final Modifier modifier)
throws DatabaseException {
if (DEBUG)
}
public void foreachObject(int resourceIndex, ReadGraphImpl graph,
- AsyncMultiProcedure<Resource> procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, Modifier modifier) throws DatabaseException {
+ SyncMultiProcedure<Resource> procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, Modifier modifier) throws DatabaseException {
int realIndex = checkIndexAndGetRealIndex(resourceIndex);
ResourceElement.foreachObject(table, realIndex, graph, procedure, support,
pRef, pCompleteType, ct, modifier);
}
public <C> void foreachObject(int resourceIndex, ReadGraphImpl graph, C context,
- AsyncContextMultiProcedure<C, Resource> procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, Modifier modifier) throws DatabaseException {
+ SyncContextMultiProcedure<C, Resource> procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum pCompleteType, CompleteTable ct, Modifier modifier) throws DatabaseException {
int realIndex = checkIndexAndGetRealIndex(resourceIndex);
ResourceElement.foreachObject(table, realIndex, graph, context, procedure, support,
pRef, pCompleteType, ct, modifier);
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;
}
public void foreachObject(int resourceIndex, ReadGraphImpl graph,
- AsyncMultiProcedure<Resource> procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum completeType, CompleteTable ct, Modifier modifier) throws DatabaseException {
+ SyncMultiProcedure<Resource> procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum completeType, CompleteTable ct, Modifier modifier) throws DatabaseException {
int realIndex = checkIndexAndGetRealIndex(resourceIndex);
ResourceElementSmall.foreachObject(table, realIndex, graph, procedure, support,
pRef, completeType, ct, modifier);
}
public <C> void foreachObject(int resourceIndex, ReadGraphImpl graph, C context,
- AsyncContextMultiProcedure<C, Resource> procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum completeType, CompleteTable ct, Modifier modifier) throws DatabaseException {
+ SyncContextMultiProcedure<C, Resource> procedure, ClusterSupport support, int pRef, ClusterI.CompleteTypeEnum completeType, CompleteTable ct, Modifier modifier) throws DatabaseException {
int realIndex = checkIndexAndGetRealIndex(resourceIndex);
ResourceElementSmall.foreachObject(table, realIndex, graph, context, procedure, support,
pRef, completeType, ct, modifier);
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;
return size + HeaderSize;
}
- static void foreachInt(final int[] table, final int base, ReadGraphImpl graph, AsyncMultiProcedure<Resource> procedure, Modifier modifier) throws DatabaseException {
+ static void foreachInt(final int[] table, final int base, ReadGraphImpl graph, SyncMultiProcedure<Resource> procedure, Modifier modifier) throws DatabaseException {
final int size = -table[base + SIZE_OFFSET];
assert(size>0);
}
- static <C> void foreachInt(final int[] table, final int base, ReadGraphImpl graph, C context, AsyncContextMultiProcedure<C, Resource> procedure, Modifier modifier) throws DatabaseException {
+ static <C> void foreachInt(final int[] table, final int base, ReadGraphImpl graph, C context, SyncContextMultiProcedure<C, Resource> procedure, Modifier modifier) throws DatabaseException {
final int size = -table[base + SIZE_OFFSET];
assert(size>0);
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;
return IntHash.getAllocatedSize(table, base);
}
- static void foreachInt(int[] table, int base, QueryProcessor processor, ReadGraphImpl graph, AsyncMultiProcedure<Resource> procedure, Modifier modifier) throws DatabaseException {
+ static void foreachInt(int[] table, int base, QueryProcessor processor, ReadGraphImpl graph, SyncMultiProcedure<Resource> procedure, Modifier modifier) throws DatabaseException {
IntHash.foreachInt(graph, table, base, procedure, modifier);
}
--- /dev/null
+eclipse.preferences.version=1\r
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\r
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8\r
+org.eclipse.jdt.core.compiler.compliance=1.8\r
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\r
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error\r
+org.eclipse.jdt.core.compiler.source=1.8\r
*******************************************************************************/
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;
import org.simantics.layer0.Layer0;
import org.simantics.utils.datastructures.Pair;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.procedure.TObjectObjectProcedure;
+import gnu.trove.set.hash.THashSet;
+
public class AdaptionService2 implements AdaptionService {
-
- int foobaz;
THashMap<Pair<Class<?>,Class<?>>, AdapterDeclaration<?>> adapters =
new THashMap<Pair<Class<?>,Class<?>>, AdapterDeclaration<?>>();
Adapter<T,C> adapter = getAdapter(g, r, context, contextClass, targetClass, possible);
if(adapter == null) return null;
- BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<T>(g, null, adapter);
-
-// SyncReadProcedure<T> procedure = new SyncReadProcedure<T>();
- adapter.adapt(g, r, context, ap);
-
- return ap.get();
-// procedure.checkAndThrow();
-// return procedure.result;
+ return g.syncRequest(new UniqueAsyncRead<T>() {
+
+ @Override
+ public void perform(AsyncReadGraph graph, AsyncProcedure<T> procedure) {
+ adapter.adapt(graph, r, context, procedure);
+ }
+
+ });
}
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));
}
}
Object[] args = new Object[parameters.length];
for(int i=0;i<parameters.length;++i)
args[i] = parameters[i].adapt(graph, r);
- construct(graph, procedure, args);
+ construct(g, procedure, args);
}
});
try {
for(int i=0;i<parameters.length;++i)
args[i] = parameters[i].adapt(graph, r);
- procedure.execute(graph, constructor.newInstance(args));
+ procedure.execute(g, constructor.newInstance(args));
} catch (IllegalArgumentException e) {
- procedure.exception(graph, e);
+ procedure.exception(g, e);
e.printStackTrace();
} catch (InstantiationException e) {
- procedure.exception(graph, e);
+ procedure.exception(g, e);
e.printStackTrace();
} catch (IllegalAccessException e) {
- procedure.exception(graph, e);
+ procedure.exception(g, e);
e.printStackTrace();
} catch (InvocationTargetException e) {
- procedure.exception(graph, e.getCause());
+ procedure.exception(g, e.getCause());
e.getCause().printStackTrace();
} catch (DatabaseException e) {
- procedure.exception(graph, e);
+ procedure.exception(g, e);
e.printStackTrace();
} catch (Throwable t) {
- procedure.exception(graph, t);
+ procedure.exception(g, t);
t.printStackTrace();
}
}
* @see Resource
* @see Statement
*/
-public interface AsyncReadGraph extends AsyncRequestProcessor {
+public interface AsyncReadGraph extends ReadGraph, AsyncRequestProcessor {
/**
* @see ReadGraph#getURI(Resource)
/**
* @see ReadGraph#getObjects(Resource, Resource)
*/
- void forEachDirectPredicate(Resource subject, AsyncMultiProcedure<Resource> procedure);
+ void forEachDirectPredicate(Resource subject, AsyncProcedure<Set<Resource>> procedure);
/**
* @see ReadGraph#getObjects(Resource, Resource)
*/
- void forEachDirectPredicate(Resource subject, SyncMultiProcedure<Resource> procedure);
+ void forEachDirectPredicate(Resource subject, SyncProcedure<Set<Resource>> procedure);
/**
* @see ReadGraph#getObjects(Resource, Resource)
*/
- void forEachDirectPredicate(Resource subject, MultiProcedure<Resource> procedure);
+ void forEachDirectPredicate(Resource subject, Procedure<Set<Resource>> procedure);
/**
* @see ReadGraph#getObjects(Resource, Resource)
*/
void forOrderedSet(Resource subject, MultiProcedure<Resource> procedure);
- int thread();
// void inc();
// void dec();
- boolean isImmutable(Resource resource) throws DatabaseException;
-
boolean performPending();
}
* @see MergingGraphRequestProcessor
* @see RequestProcessor
*/
-public interface AsyncRequestProcessor extends ServiceLocator, AsyncRequestProcessorSpecific {
-
- Resource getRootLibrary();
-
- /**
- * @return the {@link Session} for which this processor is based on.
- */
- Session getSession();
+public interface AsyncRequestProcessor extends RequestProcessor, AsyncRequestProcessorSpecific {
<T> void async(ReadInterface<T> r, Procedure<T> procedure);
<T> void async(ReadInterface<T> r, AsyncProcedure<T> procedure);
<T> void async(ReadInterface<T> r, AsyncListener<T> procedure);
<T> void async(ReadInterface<T> r, SyncListener<T> procedure);
- <T> void async(WriteInterface<T> r);
- <T> void async(WriteInterface<T> r, Procedure<T> procedure);
-
- Object getModificationCounter();
-
}
* @param request an instance of {@link MultiRead}.
* @param procedure an instance of {@link AsyncMultiListener}.
*/
- <T> void asyncRequest(MultiRead<T> request, AsyncMultiListener<T> procedure);
+ //<T> void asyncRequest(MultiRead<T> request, AsyncMultiListener<T> procedure);
/**
* Asynchronously registers the given {@link SyncMultiListener} (as
* @param request an instance of {@link MultiRead}.
* @param procedure an instance of {@link AsyncMultiProcedure}.
*/
- <T> void asyncRequest(MultiRead<T> request, AsyncMultiProcedure<T> procedure);
+ //<T> void asyncRequest(MultiRead<T> request, AsyncMultiProcedure<T> procedure);
/**
* Asynchronously supplies the result determined from the given
<T> void asyncRequest(ExternalRead<T> request, Listener<T> procedure);
<T> void asyncRequest(ExternalRead<T> request, Procedure<T> procedure);
- /**
- * Asynchronously performs the given {@link Write}. The outcome of the
- * request will be lost.
- *
- * @param request an instance of {@link Write}.
- */
- void asyncRequest(Write request);
-
- /**
- * Asynchronously performs the given {@link Write}. The outcome of the
- * request will be reported to given {@link Consumer} in the form of a
- * DatabaseException raised during request processing or null upon success.
- *
- * @param request an instance of {@link Write}.
- * @param request an instance of {@link Consumer}.
- */
- void asyncRequest(Write request, Consumer<DatabaseException> callback);
-
- <T> void asyncRequest(WriteResult<T> r, Procedure<T> procedure);
-
-
- /**
- * Asynchronously performs the given {@link WriteOnly}. The outcome of the
- * request will be lost.
- *
- * @param request an instance of {@link Write}.
- */
- void asyncRequest(DelayedWrite request);
-
- /**
- * Asynchronously performs the given {@link WriteOnly}. The outcome of the
- * request will be reported to given {@link Consumer} in the form of a
- * DatabaseException raised during request processing or null upon success.
- *
- * @param request an instance of {@link WriteOnly}.
- * @param request an instance of {@link Consumer}.
- */
- void asyncRequest(DelayedWrite request, Consumer<DatabaseException> callback);
-
- <T> void asyncRequest(DelayedWriteResult<T> r, Procedure<T> procedure);
-
- /**
- * Asynchronously performs the given {@link WriteOnly}. The outcome of the
- * request will be lost.
- *
- * @param request an instance of {@link Write}.
- */
- void asyncRequest(WriteOnly r);
-
- /**
- * Asynchronously performs the given {@link WriteOnly}. The outcome of the
- * request will be reported to given {@link Consumer} in the form of a
- * DatabaseException raised during request processing or null upon success.
- *
- * @param request an instance of {@link WriteOnly}.
- * @param request an instance of {@link Consumer}.
- */
- void asyncRequest(WriteOnly r, Consumer<DatabaseException> callback);
-
- <T> void asyncRequest(WriteOnlyResult<T> r, Procedure<T> procedure);
}
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;
* @see Statement
* @noimplement
*/
-public interface ReadGraph extends AsyncReadGraph, RequestProcessor {
+public interface ReadGraph extends RequestProcessor {
/**
*
boolean setSynchronous(boolean value);
boolean getSynchronous();
+
+ boolean isImmutable(Resource resource) throws DatabaseException;
+
+ int thread();
+
}
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;
* @see MergingGraphRequestProcessor
* @see AsyncRequestProcessor
*/
-public interface RequestProcessor extends AsyncRequestProcessor, RequestProcessorSpecific {
+public interface RequestProcessor extends RequestProcessorSpecific, ServiceLocator {
+
+ Resource getRootLibrary();
+
+ /**
+ * @return the {@link Session} for which this processor is based on.
+ */
+ Session getSession();
<T> T sync(ReadInterface<T> r) throws DatabaseException;
<T> T sync(WriteInterface<T> r) throws DatabaseException;
+ <T> void async(WriteInterface<T> r);
+ <T> void async(WriteInterface<T> r, Procedure<T> procedure);
+
+ Object getModificationCounter();
+
}
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;
* @see MergingGraphRequestProcessor
* @see AsyncRequestProcessor
*/
-public interface RequestProcessorSpecific extends AsyncRequestProcessor {
+public interface RequestProcessorSpecific {
/**
* Synchronously determines and returns the result of the given {@link Read}
* @param request an instance of {@link MultiRead}.
* @param procedure an instance of {@link AsyncMultiListener}.
*/
- <T> Collection<T> syncRequest(MultiRead<T> request, AsyncMultiListener<T> procedure) throws DatabaseException;
+ //<T> Collection<T> syncRequest(MultiRead<T> request, AsyncMultiListener<T> procedure) throws DatabaseException;
/**
* Synchronously registers the given {@link SyncMultiListener} (as
* @param request an instance of {@link MultiRead}.
* @param procedure an instance of {@link AsyncMultiProcedure}.
*/
- <T> Collection<T> syncRequest(MultiRead<T> request, AsyncMultiProcedure<T> procedure) throws DatabaseException;
+ //<T> Collection<T> syncRequest(MultiRead<T> request, AsyncMultiProcedure<T> procedure) throws DatabaseException;
/**
* Synchronously supplies the result determined from the given
*/
<T> T syncRequest(WriteOnlyResult<T> r) throws DatabaseException;
+ /**
+ * Asynchronously performs the given {@link Write}. The outcome of the
+ * request will be lost.
+ *
+ * @param request an instance of {@link Write}.
+ */
+ void asyncRequest(Write request);
+
+ /**
+ * Asynchronously performs the given {@link Write}. The outcome of the
+ * request will be reported to given {@link Consumer} in the form of a
+ * DatabaseException raised during request processing or null upon success.
+ *
+ * @param request an instance of {@link Write}.
+ * @param request an instance of {@link Consumer}.
+ */
+ void asyncRequest(Write request, Consumer<DatabaseException> callback);
+
+ <T> void asyncRequest(WriteResult<T> r, Procedure<T> procedure);
+
+
+ /**
+ * Asynchronously performs the given {@link WriteOnly}. The outcome of the
+ * request will be lost.
+ *
+ * @param request an instance of {@link Write}.
+ */
+ void asyncRequest(DelayedWrite request);
+
+ /**
+ * Asynchronously performs the given {@link WriteOnly}. The outcome of the
+ * request will be reported to given {@link Consumer} in the form of a
+ * DatabaseException raised during request processing or null upon success.
+ *
+ * @param request an instance of {@link WriteOnly}.
+ * @param request an instance of {@link Consumer}.
+ */
+ void asyncRequest(DelayedWrite request, Consumer<DatabaseException> callback);
+
+ <T> void asyncRequest(DelayedWriteResult<T> r, Procedure<T> procedure);
+
+ /**
+ * Asynchronously performs the given {@link WriteOnly}. The outcome of the
+ * request will be lost.
+ *
+ * @param request an instance of {@link Write}.
+ */
+ void asyncRequest(WriteOnly r);
+
+ /**
+ * Asynchronously performs the given {@link WriteOnly}. The outcome of the
+ * request will be reported to given {@link Consumer} in the form of a
+ * DatabaseException raised during request processing or null upon success.
+ *
+ * @param request an instance of {@link WriteOnly}.
+ * @param request an instance of {@link Consumer}.
+ */
+ void asyncRequest(WriteOnly r, Consumer<DatabaseException> callback);
+
+ <T> void asyncRequest(WriteOnlyResult<T> r, Procedure<T> procedure);
+
}
* @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
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.procedure;
+
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.exception.DatabaseException;
+
+/**
+ * @author Antti Villberg
+ *
+ * First execute is called k times. After this finished or exception is called exactly once.
+ *
+ * @param <Result> the result object type accepted by the procedure
+ */
+public interface SyncContextMultiProcedure<Context, Result> {
+
+ /**
+ * Invoked once for each separate result of the request with potentially
+ * multiple results. It shall be guaranteed that all <code>execute</code>
+ * invocations have been completed when either
+ * {@link #finished(AsyncReadGraph)} or
+ * {@link #exception(AsyncReadGraph, Throwable)} are called and that no
+ * <code>execute</code> invocations will follow afterwards.
+ *
+ * @param graph asynchronous graph access
+ * @param result a single result of the multiresult procedure
+ */
+ void execute(ReadGraph graph, Context context, Result result) throws DatabaseException;
+
+ /**
+ * Invoked after all {@link #execute(AsyncReadGraph, Object)} calls have
+ * been finished successfully. This method will not be invoked if case of
+ * errors in {@link #execute(AsyncReadGraph, Object)} or the performed
+ * request that provides the results to this procedure.
+ *
+ * @param graph asynchronous graph access
+ */
+ void finished(ReadGraph graph, Context context) throws DatabaseException;
+
+ /**
+ * If an error occurs in the processing of the database request that
+ * produces the results for this procedure.
+ *
+ * @param graph asynchronous graph access
+ * @param throwable the exception that occurred
+ */
+ void exception(ReadGraph graph, Throwable throwable) throws DatabaseException;
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.procedure;
+
+import org.simantics.db.ReadGraph;
+
+/*
+ *
+ * Execute or exception is called exactly once.
+ *
+ */
+public interface SyncContextProcedure<Context, Result> {
+
+ void execute(ReadGraph graph, Context context, Result result);
+ void exception(ReadGraph graph, Throwable throwable);
+
+}
import org.simantics.db.exception.CancelTransactionException;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
/**
* The <code>GraphRequest</code> interface is used to create transaction
* @throws CancelTransactionException to indicate that the request needs to
* be cancelled and any changes rolled back
*/
- void perform(ReadGraph graph, AsyncMultiProcedure<Result> callback) throws DatabaseException;
+ void perform(ReadGraph graph, SyncMultiProcedure<Result> callback) throws DatabaseException;
}
*******************************************************************************/
package org.simantics.db.service;
-import org.simantics.db.AsyncReadGraph;
import org.simantics.db.DirectStatements;
import org.simantics.db.ReadGraph;
import org.simantics.db.RelationInfo;
import org.simantics.db.Resource;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
-import org.simantics.db.procedure.AsyncContextProcedure;
-import org.simantics.db.procedure.AsyncMultiProcedure;
-import org.simantics.db.procedure.AsyncProcedure;
-import org.simantics.db.procedure.Procedure;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
+import org.simantics.db.procedure.SyncContextProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
import org.simantics.db.procedure.SyncProcedure;
public interface DirectQuerySupport {
- void forEachDirectPersistentStatement(AsyncReadGraph graph, Resource subject, AsyncProcedure<DirectStatements> procedure);
+ DirectStatements getDirectPersistentStatements(ReadGraph graph, Resource subject);
+ DirectStatements getDirectStatements(ReadGraph graph, Resource subject);
- void forEachDirectStatement(AsyncReadGraph graph, Resource subject, AsyncProcedure<DirectStatements> procedure);
- void forEachDirectStatement(AsyncReadGraph graph, Resource subject, SyncProcedure<DirectStatements> procedure);
- void forEachDirectStatement(AsyncReadGraph graph, Resource subject, Procedure<DirectStatements> procedure);
+// void forEachDirectPersistentStatement(ReadGraph graph, Resource subject, AsyncProcedure<DirectStatements> procedure);
+// void forEachDirectStatement(ReadGraph graph, Resource subject, AsyncProcedure<DirectStatements> procedure);
+// void forEachDirectStatement(ReadGraph graph, Resource subject, SyncProcedure<DirectStatements> procedure);
+// void forEachDirectStatement(ReadGraph graph, Resource subject, Procedure<DirectStatements> procedure);
- void forRelationInfo(AsyncReadGraph graph, Resource subject, AsyncProcedure<RelationInfo> procedure);
- void forRelationInfo(AsyncReadGraph graph, Resource subject, SyncProcedure<RelationInfo> procedure);
- void forRelationInfo(AsyncReadGraph graph, Resource subject, Procedure<RelationInfo> procedure);
+ RelationInfo getRelationInfo(ReadGraph graph, Resource subject) throws DatabaseException;
- <T> void forPossibleType(AsyncReadGraph graph, Resource subject, AsyncProcedure<Resource> procedure);
+// void forRelationInfo(AsyncReadGraph graph, Resource subject, AsyncProcedure<RelationInfo> procedure);
+// void forRelationInfo(AsyncReadGraph graph, Resource subject, SyncProcedure<RelationInfo> procedure);
+// void forRelationInfo(AsyncReadGraph graph, Resource subject, Procedure<RelationInfo> procedure);
- AsyncMultiProcedure<Resource> compileForEachObject(ReadGraph graph, Resource relation, AsyncMultiProcedure<Resource> user);
- <C> AsyncContextMultiProcedure<C, Resource> compileForEachObject(ReadGraph graph, Resource relation, AsyncContextMultiProcedure<C, Resource> user);
- <T> AsyncProcedure<T> compilePossibleRelatedValue(ReadGraph graph, Resource relation, AsyncProcedure<T> user);
- <C,T> AsyncContextProcedure<C,T> compilePossibleRelatedValue(ReadGraph graph, Resource relation, AsyncContextProcedure<C,T> user);
+ //<T> void forPossibleType(AsyncReadGraph graph, Resource subject, AsyncProcedure<Resource> procedure);
- void forEachObjectCompiled(AsyncReadGraph graph, Resource subject, AsyncMultiProcedure<Resource> procedure);
- <C> void forEachObjectCompiled(AsyncReadGraph graph, Resource subject, C context, AsyncContextMultiProcedure<C, Resource> procedure);
- <T> void forPossibleRelatedValueCompiled(AsyncReadGraph graph, Resource subject, AsyncProcedure<T> procedure);
- <C,T> void forPossibleRelatedValueCompiled(AsyncReadGraph graph, Resource subject, C context, AsyncContextProcedure<C,T> procedure);
- <C> void forPossibleDirectType(AsyncReadGraph graph, Resource subject, C context, AsyncContextProcedure<C,Resource> procedure);
+ SyncMultiProcedure<Resource> compileForEachObject(ReadGraph graph, Resource relation, SyncMultiProcedure<Resource> user) throws DatabaseException;
+ <C> SyncContextMultiProcedure<C, Resource> compileForEachObject(ReadGraph graph, Resource relation, SyncContextMultiProcedure<C, Resource> user) throws DatabaseException;
+ <T> SyncProcedure<T> compilePossibleRelatedValue(ReadGraph graph, Resource relation, SyncProcedure<T> user) throws DatabaseException;
+ <C,T> SyncContextProcedure<C,T> compilePossibleRelatedValue(ReadGraph graph, Resource relation, SyncContextProcedure<C,T> user) throws DatabaseException;
+
+ void forEachObjectCompiled(ReadGraph graph, Resource subject, SyncMultiProcedure<Resource> procedure);
+ <C> void forEachObjectCompiled(ReadGraph graph, Resource subject, C context, SyncContextMultiProcedure<C, Resource> procedure);
+ <T> void forPossibleRelatedValueCompiled(ReadGraph graph, Resource subject, SyncProcedure<T> procedure);
+ <C,T> void forPossibleRelatedValueCompiled(ReadGraph graph, Resource subject, C context, SyncContextProcedure<C,T> procedure);
+ <C> void forPossibleDirectType(ReadGraph graph, Resource subject, C context, SyncContextProcedure<C,Resource> procedure);
}
int getGraphThread(AsyncReadGraph graph);
- boolean resume(AsyncReadGraph graph);
+ boolean resume(ReadGraph graph);
void schedule(AsyncReadGraph graph, int targetThread, ControlProcedure procedure);
}
@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;
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;
public DiagramContents perform(ReadGraph g) throws DatabaseException {
final DiagramResource DIA = DiagramResource.getInstance(g);
- final DiagramContents result = new DiagramContents();
-
- result.elements = new ArrayList<Resource>(previousElementCount);
- result.nodeSet = new THashSet<Resource>();
- result.connectionSet = new THashSet<Resource>();
- result.connectionSegments = new THashSet<EdgeResource>();
- result.branchPoints = new THashSet<Resource>();
- result.routeGraphConnectionSet = new THashSet<Resource>();
- result.routeLinks = new THashSet<EdgeResource>();
- result.routeLines = new THashSet<Resource>();
- result.routePoints = new THashSet<Resource>();
-
- result.partToConnection = new THashMap<Object, Resource>();
// These help loading result.elements in the correct order.
final AtomicInteger index = new AtomicInteger();
Collection<Resource> components = OrderedSetUtils.toList(g, data);
- GraphSemaphore s = new GraphSemaphore(g, 0);
-
- for(Resource component : components) {
-
- // Must add the elements to the result set here in order to
- // keep their order the same as in the ordered set.
- final int elementIndex = index.getAndIncrement();
- result.elements.add(component);
-
- Set<Resource> types = g.getTypes(component);
-
- if (types.contains(DIA.Connection)) {
- if (types.contains(DIA.RouteGraphConnection)) {
- g.asyncRequest(new RouteGraphConnectionPartRequest(errorHandler, DIA, component),
- new ProcedureAdapter<RouteGraphConnectionPartData>() {
- @Override
- public void execute(RouteGraphConnectionPartData partData) {
- synchronized (result) {
- for (EdgeResource link : partData.links) {
- result.routeLinks.add(link);
- result.partToConnection.put(link, component);
- result.connectionToParts.add(component, link);
- }
- for (Resource line : partData.routeLines) {
- result.routeLines.add(line);
- result.connectionToParts.add(component, line);
- result.partToConnection.put(line, component);
- }
- for (Resource point : partData.routePoints) {
- result.routePoints.add(point);
- result.connectionToParts.add(component, point);
- result.partToConnection.put(point, component);
- }
- }
- s.release();
- }
- });
-
- synchronized (result.routeGraphConnectionSet) {
- result.routeGraphConnectionSet.add(component);
- }
- } else {
- g.asyncRequest(new ConnectionPartRequest(errorHandler, DIA, component),
- new ProcedureAdapter<ConnectionPartData>() {
- @Override
- public void execute(ConnectionPartData partData) {
- synchronized (result) {
- for (EdgeResource er : partData.edges) {
- result.connectionSegments.add(er);
- result.partToConnection.put(er, component);
- result.connectionToParts.add(component, er);
- }
- for (Resource bp : partData.branchPoints) {
- result.branchPoints.add(bp);
- result.connectionToParts.add(component, bp);
- result.partToConnection.put(bp, component);
- }
- }
- s.release();
- }
- });
-
- synchronized (result.connectionSet) {
- result.connectionSet.add(component);
- }
- }
- }
- else if (types.contains(DIA.Element)) {
- synchronized (result.nodeSet) {
- result.nodeSet.add(component);
- }
- s.release();
-
- }
- else {
- synchronized (unrecognizedElementIndices) {
- // Unrecognized element, mark it to be
- // removed after everything is processed.
- unrecognizedElementIndices.add(elementIndex);
- }
- s.release();
- }
-
- }
-
- try {
- s.waitFor(components.size());
- } catch (InterruptedException e) {
- LOGGER.error("An error occured while waiting for diagram to load", e);
- }
+ DiagramContents result = g.syncRequest(new UniqueAsyncRead<DiagramContents>() {
+
+ @Override
+ public void perform(AsyncReadGraph graph, AsyncProcedure<DiagramContents> procedure) {
+
+ DiagramContents result = new DiagramContents();
+ procedure.execute(graph, result);
+
+ result.elements = new ArrayList<Resource>(previousElementCount);
+ result.nodeSet = new THashSet<Resource>();
+ result.connectionSet = new THashSet<Resource>();
+ result.connectionSegments = new THashSet<EdgeResource>();
+ result.branchPoints = new THashSet<Resource>();
+ result.routeGraphConnectionSet = new THashSet<Resource>();
+ result.routeLinks = new THashSet<EdgeResource>();
+ result.routeLines = new THashSet<Resource>();
+ result.routePoints = new THashSet<Resource>();
+
+ result.partToConnection = new THashMap<Object, Resource>();
+
+ for(final Resource component : components) {
+
+ // Must add the elements to the result set here in order to
+ // keep their order the same as in the ordered set.
+ final int elementIndex = index.getAndIncrement();
+ result.elements.add(component);
+
+ graph.forTypes(component, new ProcedureAdapter<Set<Resource>>() {
+
+ @Override
+ public void execute(Set<Resource> types) {
+
+ if (types.contains(DIA.Connection)) {
+ if (types.contains(DIA.RouteGraphConnection)) {
+ graph.asyncRequest(new RouteGraphConnectionPartRequest(errorHandler, DIA, component),
+ new ProcedureAdapter<RouteGraphConnectionPartData>() {
+ @Override
+ public void execute(RouteGraphConnectionPartData partData) {
+ synchronized (result) {
+ for (EdgeResource link : partData.links) {
+ result.routeLinks.add(link);
+ result.partToConnection.put(link, component);
+ result.connectionToParts.add(component, link);
+ }
+ for (Resource line : partData.routeLines) {
+ result.routeLines.add(line);
+ result.connectionToParts.add(component, line);
+ result.partToConnection.put(line, component);
+ }
+ for (Resource point : partData.routePoints) {
+ result.routePoints.add(point);
+ result.connectionToParts.add(component, point);
+ result.partToConnection.put(point, component);
+ }
+ }
+ }
+ });
+
+ synchronized (result.routeGraphConnectionSet) {
+ result.routeGraphConnectionSet.add(component);
+ }
+ } else {
+ graph.asyncRequest(new ConnectionPartRequest(errorHandler, DIA, component),
+ new ProcedureAdapter<ConnectionPartData>() {
+ @Override
+ public void execute(ConnectionPartData partData) {
+ synchronized (result) {
+ for (EdgeResource er : partData.edges) {
+ result.connectionSegments.add(er);
+ result.partToConnection.put(er, component);
+ result.connectionToParts.add(component, er);
+ }
+ for (Resource bp : partData.branchPoints) {
+ result.branchPoints.add(bp);
+ result.connectionToParts.add(component, bp);
+ result.partToConnection.put(bp, component);
+ }
+ }
+ }
+ });
+
+ synchronized (result.connectionSet) {
+ result.connectionSet.add(component);
+ }
+ }
+ }
+ else if (types.contains(DIA.Element)) {
+ synchronized (result.nodeSet) {
+ result.nodeSet.add(component);
+ }
+ }
+ else {
+ synchronized (unrecognizedElementIndices) {
+ // Unrecognized element, mark it to be
+ // removed after everything is processed.
+ unrecognizedElementIndices.add(elementIndex);
+ }
+ }
+
+ }
+
+ });
+
+ }
+ }
+
+ });
// Remove elements that were not recognized in descending order.
unrecognizedElementIndices.sort();
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;
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;
return;
}
- // NOTICE: Layer information is loaded from the connection entity resource
- // that is shared by all segments of the same connection.
- ElementFactoryUtil.loadLayersForElement(graph, layerManager, diagram, edge, info.connection,
- new AsyncProcedureAdapter<IElement>() {
- @Override
- public void exception(AsyncReadGraph graph, Throwable t) {
- error("failed to load layers for connection segment", t);
- }
- });
+ graph.syncRequest(new AsyncReadRequest() {
+ @Override
+ public void run(AsyncReadGraph graph) {
+ // NOTICE: Layer information is loaded from the connection entity resource
+ // that is shared by all segments of the same connection.
+ ElementFactoryUtil.loadLayersForElement(graph, layerManager, diagram, edge, info.connection,
+ new AsyncProcedureAdapter<IElement>() {
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable t) {
+ error("failed to load layers for connection segment", t);
+ }
+ });
+ }
+ });
edge.setHintWithoutNotification(KEY_CONNECTION_BEGIN_PLACEHOLDER, new PlaceholderConnection(
EdgeEnd.Begin,
}
@Override
- public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener<Resource> listener) {
+ public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener<Resource> listener) throws DatabaseException {
if (types.isEmpty()) {
System.out.println("MappedTypeGroup has no types!");
return;
}
- processor.asyncRequest(new BinaryRead<Resource, Collection<Resource>, Collection<Resource>>(runtimeDiagram, types) {
+ processor.syncRequest(new BinaryRead<Resource, Collection<Resource>, Collection<Resource>>(runtimeDiagram, types) {
@Override
public Set<Resource> perform(ReadGraph graph) throws DatabaseException {
}
@Override
- public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener<Resource> listener) {
+ public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener<Resource> listener) throws DatabaseException {
if (types.isEmpty()) {
System.out.println("TypeGroup has no types!");
return;
}
- processor.asyncRequest(new BinaryRead<Resource, Collection<Resource>, Collection<Resource>>(runtimeDiagram, types) {
+ processor.syncRequest(new BinaryRead<Resource, Collection<Resource>, Collection<Resource>>(runtimeDiagram, types) {
@Override
public Set<Resource> perform(ReadGraph graph) throws DatabaseException {
}
@Override
- public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener<Resource> listener) {
- processor.asyncRequest(new BinaryRead<Class<?>, Resource, Collection<Resource>>(getClass(), runtimeDiagram) {
+ public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener<Resource> listener) throws DatabaseException {
+ processor.syncRequest(new BinaryRead<Class<?>, Resource, Collection<Resource>>(getClass(), runtimeDiagram) {
@Override
public Set<Resource> perform(ReadGraph graph) throws DatabaseException {
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
* @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);
return createRuntimeDiagram(graph, diagram, desc);
}
- private void listenRequest(RequestProcessor processor, final Resource diagram) {
- processor.asyncRequest(new RuntimeVariableForInput(getResourceInput()), new AsyncListener<RuntimeDiagramDesc>() {
+ private void listenRequest(RequestProcessor processor, final Resource diagram) throws DatabaseException {
+ processor.syncRequest(new RuntimeVariableForInput(getResourceInput()), new AsyncListener<RuntimeDiagramDesc>() {
@Override
public void exception(AsyncReadGraph graph, Throwable throwable) {
}
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));
public void add(ReadGraph graph, final Resource issue) throws DatabaseException {
IssueValidityListener listener = new IssueValidityListener(issue);
- graph.asyncRequest(new ResourceRead3<Boolean>(issue, model, source) {
+ graph.syncRequest(new ResourceRead3<Boolean>(issue, model, source) {
@Override
public Boolean perform(ReadGraph graph) throws DatabaseException {
sources.put(source, Pair.make(is, listener));
if (isListeningTracker) {
- graph.asyncRequest(
+ graph.syncRequest(
new Objects(source, ISSUE.IssueSource_Manages),
new IssueSourceManagedIssuesListener(disposed, source, model));
}
};
if(processor instanceof WriteGraph) processor.syncRequest(request, procedure);
- else processor.asyncRequest(request, procedure);
+ else processor.syncRequest(request, procedure);
}
}
if(monitorVariable != null)
- graph.asyncRequest(new MonitorVariableValueRequest(diagramRuntime, element), monitorListener);
+ graph.syncRequest(new MonitorVariableValueRequest(diagramRuntime, element), monitorListener);
}
}
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;
}
}
- private static class ComponentSyncListenerAdapter extends SyncListenerAdapter<Set<Resource>> implements Disposable {
+ private static class ComponentSyncListenerAdapter extends AsyncListenerAdapter<Set<Resource>> implements Disposable {
private ConcurrentHashMap<Resource, SCLValueDisposableSyncListener> currentlyListening = new ConcurrentHashMap<>();
private boolean disposed;
}
@Override
- public void execute(ReadGraph graph, Set<Resource> newComponents) {
+ public void execute(AsyncReadGraph graph, Set<Resource> newComponents) {
if (currentlyListening.isEmpty() && newComponents.isEmpty()) {
// we can stop here as nothing will change
return;
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();
}
import org.simantics.db.RequestProcessor;
import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
import org.simantics.db.procedure.SetListener;
* objects. Usually one just delegates normal database listener
* events to this listener.
*/
- void trackItems(RequestProcessor processor, Resource runtimeDiagram, SetListener<Resource> listener);
+ void trackItems(RequestProcessor processor, Resource runtimeDiagram, SetListener<Resource> listener) throws DatabaseException;
}
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
* @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
}
public static void subqueryL(ReadGraph graph, Function query, Function executeCallback, Function1<Throwable, Tuple> exceptionCallback, Function1<Tuple0, Boolean> isDisposedCallback) throws DatabaseException {
- graph.asyncRequest(new Subquery(query), new SyncListenerAdapter<Object>() {
+ graph.syncRequest(new Subquery(query), new SyncListenerAdapter<Object>() {
@Override
public void execute(ReadGraph graph, Object result) throws DatabaseException {
Simantics.applySCLRead(graph, executeCallback, result);
listener = propertyListener(client, childName);
listenerCache.put(child.first, listener);
}
- graph.asyncRequest(new FilteredVariableProperties(child.second), listener);
+ graph.syncRequest(new FilteredVariableProperties(child.second), listener);
}
}
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;
if(DEBUG)
System.out.println("GraphUI adds property " + property.second.getURI(graph));
- graph.asyncRequest(new CellValue(property.second), new SyncListener<Object>() {
+ graph.syncRequest(new CellValue(property.second), new SyncListener<Object>() {
@Override
public void execute(ReadGraph graph, final Object value) throws DatabaseException {
@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);
+ }
}
}
@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 {
// 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);
}
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;
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 {
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;
}
@Override
public Resource perform(ReadGraph graph) throws DatabaseException {
- SynchronizationProcedure<Resource> procedure = new SynchronizationProcedure<Resource>();
Resource relation = graph.getResource(relationURI);
- graph.forPossibleObject(subject, relation, procedure);
- return procedure.getResult();
+ return graph.getPossibleObject(subject, relation);
}
@Override
public int hashCode() {
}
@Override
public Resource perform(ReadGraph graph) throws DatabaseException {
- SynchronizationProcedure<Resource> procedure = new SynchronizationProcedure<Resource>();
Resource relation = graph.getResource(relationURI);
- graph.forSingleObject(subject, relation, procedure);
- return procedure.getResult();
+ return graph.getSingleObject(subject, relation);
}
@Override
public int hashCode() {