X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=inline;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fgraph%2FReadGraphImpl.java;h=a693b29228e026c1e1f6a5c7f3652c8d4320eb4c;hb=f002990cb02c4842cdc992395117958f75fff68c;hp=79fe974642d2a71e66054fe6de5d00a60424b7bf;hpb=a548be86e2719d5a01bcaf55e34185d624d5fbef;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java index 79fe97464..a693b2922 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java @@ -188,6 +188,8 @@ 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.simantics.utils.threads.logger.ITask; +import org.simantics.utils.threads.logger.ThreadLogger; import org.slf4j.LoggerFactory; import gnu.trove.map.hash.TObjectIntHashMap; @@ -1923,7 +1925,12 @@ public class ReadGraphImpl implements AsyncReadGraph { @Override public T syncRequest(final Read request) throws DatabaseException { assert (request != null); - return (T)QueryCache.runnerReadEntry(this, request, parent, null, null, true); + + ITask task = ThreadLogger.task(request); + T result = (T)QueryCache.runnerReadEntry(this, request, parent, null, null, true); + task.finish(); + return result; + } @Override @@ -1943,9 +1950,11 @@ public class ReadGraphImpl implements AsyncReadGraph { assert (request != null); + ITask task = ThreadLogger.task(request); ListenerBase listener = procedure != null ? getListenerBase(procedure) : null; - - return QueryCache.resultReadEntry(this, request, parent, listener, procedure); + T result = QueryCache.resultReadEntry(this, request, parent, listener, procedure); + task.finish(); + return result; } @@ -2029,11 +2038,11 @@ public class ReadGraphImpl implements AsyncReadGraph { assert (request != null); + ITask task = ThreadLogger.task(request); ListenerBase listener = getListenerBase(procedure); - -// BlockingAsyncProcedure ap = new BlockingAsyncProcedure<>(this, procedure, request); - return (T)QueryCache.runnerAsyncReadEntry(this, request, parent, listener, procedure, true); -// return ap.get(); + T result = (T)QueryCache.runnerAsyncReadEntry(this, request, parent, listener, procedure, true); + task.finish(); + return result; } @@ -5152,7 +5161,7 @@ public class ReadGraphImpl implements AsyncReadGraph { assert (request != null); assert (procedure != null); - processor.schedule(new SessionTask(this) { + processor.scheduleNow(new SessionTask(this) { @Override public void run0(int thread) { @@ -5232,13 +5241,29 @@ public class ReadGraphImpl implements AsyncReadGraph { assert (request != null); assert (procedure != null); - processor.schedule(new SessionTask(this) { + ITask task = ThreadLogger.task(request); + + processor.scheduleNow(new SessionTask(this) { @Override public void run0(int thread) { try { final ListenerBase listener = getListenerBase(procedure); - QueryCache.runnerAsyncReadEntry(ReadGraphImpl.this, request, parent, listener, procedure, false); + QueryCache.runnerAsyncReadEntry(ReadGraphImpl.this, request, parent, listener, new AsyncProcedure() { + + @Override + public void execute(AsyncReadGraph graph, T result) { + task.finish(); + procedure.execute(graph, result); + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + task.finish(); + procedure.exception(graph, throwable); + } + + }, false); } catch (DatabaseException e) { Logger.defaultLogError(e); } @@ -6181,11 +6206,12 @@ public class ReadGraphImpl implements AsyncReadGraph { @Override public T getRelatedValue2(Resource subject, Resource relation, Object context) throws DatabaseException { if(Development.DEVELOPMENT) { - String error = L0Validations.checkValueType(this, subject, relation); - if(error != null) { - Logger.defaultLogError(new ValidationException(error)); - //throw new ValidationException(error); - new ValidationException(error).printStackTrace(); + if(Development.getProperty(DevelopmentKeys.L0_VALIDATION, Bindings.BOOLEAN)) { + String error = L0Validations.checkValueType(this, subject, relation); + if(error != null) { + Logger.defaultLogError(new ValidationException(error)); + throw new ValidationException(error); + } } } return getValue2(getSingleObject(subject, relation), context); @@ -6194,12 +6220,13 @@ public class ReadGraphImpl implements AsyncReadGraph { @Override public Variant getRelatedVariantValue2(Resource subject, Resource relation, Object context) throws DatabaseException { if(Development.DEVELOPMENT) { - String error = L0Validations.checkValueType(this, subject, relation); - if(error != null) { - Logger.defaultLogError(new ValidationException(error)); - //throw new ValidationException(error); - new ValidationException(error).printStackTrace(); - } + if(Development.getProperty(DevelopmentKeys.L0_VALIDATION, Bindings.BOOLEAN)) { + String error = L0Validations.checkValueType(this, subject, relation); + if(error != null) { + Logger.defaultLogError(new ValidationException(error)); + throw new ValidationException(error); + } + } } return getVariantValue2(getSingleObject(subject, relation), context); } @@ -6310,7 +6337,7 @@ public class ReadGraphImpl implements AsyncReadGraph { public boolean performPending() { return processor.performPending(this); } - + public Set ancestorSet() { HashSet result = new HashSet<>(); ReadGraphImpl g = this; @@ -6320,5 +6347,23 @@ public class ReadGraphImpl implements AsyncReadGraph { } return result; } + + public int getLevel() { + return getLevelStatic(this); + } + + private static int getLevelStatic(ReadGraphImpl impl) { + if(impl == null) return 0; + else return 1 + getLevelStatic(impl.parentGraph); + } + + public ReadGraphImpl getTopLevelGraph() { + return getTopLevelGraphStatic(this); + } + + private static ReadGraphImpl getTopLevelGraphStatic(ReadGraphImpl impl) { + if(impl.parentGraph == null) return impl; + else return getTopLevelGraphStatic(impl.parentGraph); + } }