X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fgraph%2FReadGraphImpl.java;h=cc15c1eac9111e063369cadd9c7167b3c843b4a9;hb=refs%2Fchanges%2F48%2F4248%2F1;hp=dfde4ec12973663737cb3e53244d32a0190e410a;hpb=a88c02c2d0f4250caf887a130b9f4314c6564722;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 dfde4ec12..cc15c1eac 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,8 +188,6 @@ 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; @@ -1351,7 +1349,10 @@ public class ReadGraphImpl implements AsyncReadGraph { Statement stm = getSingleStatement(resource, relation); - return adaptContextual(stm.getObject(), new RelationContextImpl(resource, stm), RelationContext.class, clazz); + Object o = adaptContextual(stm.getObject(), new RelationContextImpl(resource, stm), RelationContext.class, clazz); + if (clazz.isInstance(o)) + return (T)o; + throw new AdaptionException("Returned value is not expected class , got " + o.getClass().getName()+ " , expected " + clazz.getName()); } @@ -1513,15 +1514,15 @@ public class ReadGraphImpl implements AsyncReadGraph { try { - int result = processor.getSingleObject(this, subject, relation); - if(result == 0) return null; - - return processor.querySupport.getResource(result); + int result = processor.getSingleObject(this, subject, relation); + if(result == 0) return null; + + return processor.querySupport.getResource(result); - } catch (ManyObjectsForFunctionalRelationException e) { + } catch (ManyObjectsForFunctionalRelationException e) { + + throw new ManyObjectsForFunctionalRelationException("Many objects in " + subject + " for functional relation " + relation); - throw new ManyObjectsForFunctionalRelationException("subject=" + subject + ", relation=" + relation, e); - } catch (DatabaseException e) { throw new ServiceException(e); @@ -1922,14 +1923,11 @@ public class ReadGraphImpl implements AsyncReadGraph { * Implementation of the interface RequestProcessor */ - @Override - public T syncRequest(final Read request) throws DatabaseException { - assert (request != null); - - T result = (T)QueryCache.runnerReadEntry(this, request, parent, null, null, true); - return result; - - } + @Override + public T syncRequest(final Read request) throws DatabaseException { + assert (request != null); + return (T)QueryCache.runnerReadEntry(this, request, parent, null, null, true); + } @Override public T syncRequest(Read request, SyncListener procedure) @@ -1943,16 +1941,12 @@ public class ReadGraphImpl implements AsyncReadGraph { return syncRequest(request, new NoneToAsyncListener(procedure)); } - @Override - public T syncRequest(final Read request, final AsyncProcedure procedure) throws DatabaseException { - - assert (request != null); - - ListenerBase listener = procedure != null ? getListenerBase(procedure) : null; - T result = (T)QueryCache.runnerReadEntry(this, request, parent, listener, procedure, true); - return result; - - } + @Override + public T syncRequest(final Read request, final AsyncProcedure procedure) throws DatabaseException { + assert (request != null); + ListenerBase listener = procedure != null ? getListenerBase(procedure) : null; + return (T)QueryCache.runnerReadEntry(this, request, parent, listener, procedure, true); + } @Override public T syncRequest(final Read request, @@ -2028,17 +2022,13 @@ public class ReadGraphImpl implements AsyncReadGraph { return syncRequest(request, new NoneToAsyncListener(procedure)); } - @Override - final public T syncRequest(final AsyncRead request, - final AsyncProcedure procedure) throws DatabaseException { - - assert (request != null); - - ListenerBase listener = getListenerBase(procedure); - T result = (T)QueryCache.runnerAsyncReadEntry(this, request, parent, listener, procedure, true); - return result; - - } + @Override + final public T syncRequest(final AsyncRead request, + final AsyncProcedure procedure) throws DatabaseException { + assert (request != null); + ListenerBase listener = getListenerBase(procedure); + return (T)QueryCache.runnerAsyncReadEntry(this, request, parent, listener, procedure, true); + } @Override public T syncRequest(AsyncRead request, @@ -5235,54 +5225,55 @@ public class ReadGraphImpl implements AsyncReadGraph { asyncRequest(request, new NoneToAsyncListener(procedure)); } - @Override - final public void asyncRequest(final AsyncRead request, - final AsyncProcedure procedure) { + @Override + final public void asyncRequest(final AsyncRead request, + final AsyncProcedure procedure) { - assert (request != null); - assert (procedure != null); + assert (request != null); + assert (procedure != null); AsyncBarrierImpl barrier = asyncBarrier; if(barrier != null) barrier.inc(); - processor.scheduleNow(new SessionTask(this) { + processor.scheduleNow(new SessionTask(this) { - @Override - public void run0(int thread) { + @Override + public void run0(int thread) { - if(barrier != null) - barrier.inc(); + if(barrier != null) + barrier.inc(); - try { - final ListenerBase listener = getListenerBase(procedure); - QueryCache.runnerAsyncReadEntry(ReadGraphImpl.this, request, parent, listener, new AsyncProcedure() { + try { + final ListenerBase listener = getListenerBase(procedure); + QueryCache.runnerAsyncReadEntry(ReadGraphImpl.this, request, parent, listener, new AsyncProcedure() { - @Override - public void execute(AsyncReadGraph graph, T result) { - procedure.execute(graph, result); - if(barrier != null) - barrier.dec(); - } + @Override + public void execute(AsyncReadGraph graph, T result) { + procedure.execute(graph, result); + if(barrier != null) + barrier.dec(); + } - @Override - public void exception(AsyncReadGraph graph, Throwable throwable) { - procedure.exception(graph, throwable); + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + procedure.exception(graph, throwable); if(barrier != null) barrier.dec(); - } - - }, false); - if(barrier != null) - barrier.dec(); - } catch (DatabaseException e) { - Logger.defaultLogError(e); - } - } - - }); + } + + }, false); + } catch (DatabaseException e) { + LOGGER.error("Error while executing async request", e); + } finally { + if(barrier != null) + barrier.dec(); + } + } - } + }); + + } @Override public void asyncRequest(AsyncRead request, @@ -5692,22 +5683,14 @@ public class ReadGraphImpl implements AsyncReadGraph { return new ReadGraphImpl(this, parent, callback, needsToBlock); } -// public ReadGraphImpl withParent(CacheEntry parent) { -// return withParent(parent, null); -// } - - public ReadGraphImpl syncWithParent(CacheEntry parent) { - return new ReadGraphImpl(this, parent, processor, null); - } - public ReadGraphImpl forRecompute(CacheEntry parent) { return new ReadGraphImpl(null, parent, processor); } - public static ReadGraphImpl create(QueryProcessor support) { - ReadGraphImpl result = new ReadGraphImpl(null, null, support); - return result; - } + public static ReadGraphImpl create(QueryProcessor support) { + ReadGraphImpl result = new ReadGraphImpl(null, null, support); + return result; + } public ReadGraphImpl newRestart(ReadGraphImpl impl) { @@ -6407,4 +6390,10 @@ public class ReadGraphImpl implements AsyncReadGraph { else return getTopLevelGraphStatic(impl.parentGraph); } + @SuppressWarnings("unchecked") + @Override + public T l0() { + return (T) processor.getL0(); + } + }