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=25438ef1ef3f0d57878c32c3c03def4111c8ca0c;hb=1fb7e00de0895266e08097371c6f84e4322d6530;hp=614a96df3c47d29ea45e249dfb10df9653aaedf4;hpb=bc5e6cb19f6af5f67bc5cfaad7d602841b8fdd0b;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 614a96df3..25438ef1e 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 @@ -137,6 +137,7 @@ import org.simantics.db.impl.procedure.CallWrappedSingleQueryProcedure4; import org.simantics.db.impl.procedure.ResultCallWrappedQueryProcedure4; import org.simantics.db.impl.procedure.ResultCallWrappedSingleQueryProcedure4; import org.simantics.db.impl.query.CacheEntry; +import org.simantics.db.impl.query.QueryCache; import org.simantics.db.impl.query.QueryProcessor; import org.simantics.db.impl.query.QuerySupport; import org.simantics.db.impl.query.TripleIntProcedure; @@ -1896,35 +1897,38 @@ public class ReadGraphImpl implements ReadGraph { assert (request != null); - if (parent != null) { - - try { - return processor.queryRead(this, request, parent, null, null); - } catch (Throwable e) { - if(e instanceof DatabaseException) throw (DatabaseException)e; - else throw new DatabaseException(e); - } - - } else { - - try { - - return processor.tryQuery(this, request); - - } catch (Throwable throwable) { - - //Logger.defaultLogError("Internal read request failure", throwable); - - if (throwable instanceof DatabaseException) - throw (DatabaseException) throwable; - else - throw new DatabaseException( - "Unexpected exception in ReadGraph.syncRequest(Read,Procedure)", - throwable); - - } + return QueryCache.resultReadEntry(this, request, parent, null, null); + + //return processor.query(this, request, parent, null, null); - } +// if (parent != null) { +// +// try { +// } catch (Throwable e) { +// if(e instanceof DatabaseException) throw (DatabaseException)e; +// else throw new DatabaseException(e); +// } +// +// } else { +// +// try { +// +// return processor.tryQuery(this, request); +// +// } catch (Throwable throwable) { +// +// //Logger.defaultLogError("Internal read request failure", throwable); +// +// if (throwable instanceof DatabaseException) +// throw (DatabaseException) throwable; +// else +// throw new DatabaseException( +// "Unexpected exception in ReadGraph.syncRequest(Read,Procedure)", +// throwable); +// +// } +// +// } } @@ -1947,42 +1951,46 @@ public class ReadGraphImpl implements ReadGraph { ListenerBase listener = procedure != null ? getListenerBase(procedure) : null; - if (parent != null || listener != null) { - - try { - return processor.queryRead(this, request, parent, procedure, listener); - } catch (Throwable e) { - if(e instanceof DatabaseException) throw (DatabaseException)e; - else throw new DatabaseException(e); - } - - } else { - - try { - - T t = processor.tryQuery(this, request); - if(procedure != null) - procedure.execute(this, t); - - return t; - - } catch (Throwable throwable) { - - Logger.defaultLogError("Internal read request failure", throwable); - - if(procedure != null) - procedure.exception(this, throwable); - - if (throwable instanceof DatabaseException) - throw (DatabaseException) throwable; - else - throw new DatabaseException( - "Unexpected exception in ReadGraph.syncRequest(Read,Procedure)", - throwable); - - } + return QueryCache.resultReadEntry(this, request, parent, listener, procedure); + +// return processor.query(this, request, parent, procedure, listener); + - } +// if (parent != null || listener != null) { +// +// try { +// } catch (Throwable e) { +// if(e instanceof DatabaseException) throw (DatabaseException)e; +// else throw new DatabaseException(e); +// } +// +// } else { +// +// try { +// +// T t = processor.tryQuery(this, request); +// if(procedure != null) +// procedure.execute(this, t); +// +// return t; +// +// } catch (Throwable throwable) { +// +// Logger.defaultLogError("Internal read request failure", throwable); +// +// if(procedure != null) +// procedure.exception(this, throwable); +// +// if (throwable instanceof DatabaseException) +// throw (DatabaseException) throwable; +// else +// throw new DatabaseException( +// "Unexpected exception in ReadGraph.syncRequest(Read,Procedure)", +// throwable); +// +// } +// +// } } @@ -2071,71 +2079,73 @@ public class ReadGraphImpl implements ReadGraph { assert (request != null); - // System.out.println("syncRequest " + request + " syncParent=" + - // syncParent); - ListenerBase listener = getListenerBase(procedure); - if (parent != null || listener != null || ((request.getFlags() & RequestFlags.SCHEDULE) > 0)) { - -// Object syncParent = request; - -// final ReadGraphImpl newGraph = newSync(); - - final ResultCallWrappedSingleQueryProcedure4 wrapper = new ResultCallWrappedSingleQueryProcedure4( - procedure, request); - - processor.query(this, request, parent, wrapper, listener); - -// newGraph.waitAsync(syncParent); - - Throwable e = wrapper.getException(); - if (e != null) { - // The request was async - produce meaningful stack trace by - // wrapping - if (e instanceof DatabaseException) - throw (DatabaseException) e; - else - throw new DatabaseException(e); - } - - return wrapper.getResult(); - - } else { - - // System.out.println("direct call " + request ); - - // Do not set the sync state.parent for external threads -// Object syncParent = request; - -// final ReadGraphImpl newGraph = newSync(); - - final ResultCallWrappedSingleQueryProcedure4 wrapper = new ResultCallWrappedSingleQueryProcedure4( - procedure, request); - - try { - - processor.tryQuery(this, request, wrapper); - - } catch (Throwable t) { - - wrapper.exception(this, t); - - } - - Throwable e = wrapper.getException(); - if (e != null) { - // The request was async - produce meaningful stack trace by - // wrapping - if (e instanceof DatabaseException) - throw (DatabaseException) e; - else - throw new DatabaseException(e); - } - - return wrapper.getResult(); + final ResultCallWrappedSingleQueryProcedure4 wrapper = new ResultCallWrappedSingleQueryProcedure4( + procedure, request); + + QueryCache.runnerAsyncReadEntry(this, request, parent, listener, wrapper); + + //processor.query(this, request, parent, wrapper, listener); + + return wrapper.getResult(); - } +// if (parent != null || listener != null || ((request.getFlags() & RequestFlags.SCHEDULE) > 0)) { +// +//// Object syncParent = request; +// +//// final ReadGraphImpl newGraph = newSync(); +// +// +//// newGraph.waitAsync(syncParent); +// +// Throwable e = wrapper.getException(); +// if (e != null) { +// // The request was async - produce meaningful stack trace by +// // wrapping +// if (e instanceof DatabaseException) +// throw (DatabaseException) e; +// else +// throw new DatabaseException(e); +// } +// +// return wrapper.getResult(); +// +// } else { +// +// // System.out.println("direct call " + request ); +// +// // Do not set the sync state.parent for external threads +//// Object syncParent = request; +// +//// final ReadGraphImpl newGraph = newSync(); +// +// final ResultCallWrappedSingleQueryProcedure4 wrapper = new ResultCallWrappedSingleQueryProcedure4( +// procedure, request); +// +// try { +// +// processor.tryQuery(this, request, wrapper); +// +// } catch (Throwable t) { +// +// wrapper.exception(this, t); +// +// } +// +// Throwable e = wrapper.getException(); +// if (e != null) { +// // The request was async - produce meaningful stack trace by +// // wrapping +// if (e instanceof DatabaseException) +// throw (DatabaseException) e; +// else +// throw new DatabaseException(e); +// } +// +// return wrapper.getResult(); +// +// } } @@ -2143,40 +2153,13 @@ public class ReadGraphImpl implements ReadGraph { assert (request != null); - // System.out.println("syncRequest " + request + " syncParent=" + - // syncParent); - ListenerBase listener = getListenerBase(procedure); + assert(listener == null); - if (parent != null || listener != null || ((request.getFlags() & RequestFlags.SCHEDULE) > 0)) { - -// final ReadGraphImpl newGraph = newSync(); - - final ResultCallWrappedSingleQueryProcedure4 wrapper = new ResultCallWrappedSingleQueryProcedure4( - procedure, request); - - processor.query(this, request, parent, wrapper, listener); - - } else { - - try { - -// final ReadGraphImpl newGraph = newSync(); - processor.tryQuery(this, request, procedure); -// newGraph.waitAsync(null); - waitAsyncProcedure(procedure); - - } catch (Throwable t) { - if(Development.DEVELOPMENT) { - if(Development.getProperty(DevelopmentKeys.WRITEGRAPH_EXCEPTION_STACKTRACES, Bindings.BOOLEAN)) { - t.printStackTrace(); - } - } - procedure.exception(this, t); - waitAsyncProcedure(procedure); - } +// final ResultCallWrappedSingleQueryProcedure4 wrapper = new ResultCallWrappedSingleQueryProcedure4( +// procedure, request); - } + QueryCache.runnerAsyncReadEntry(this, request, parent, listener, procedure); } @@ -2545,55 +2528,58 @@ public class ReadGraphImpl implements ReadGraph { assert (request != null); ListenerBase listener = getListenerBase(procedure); - + final DataContainer exception = new DataContainer(); final DataContainer result = new DataContainer(); - if (parent != null || listener != null) { - -// final ReadGraphImpl newGraph = newSync(); - - processor.query(this, request, parent, new Procedure() { - - @Override - public void exception(Throwable throwable) { - exception.set(throwable); - procedure.exception(throwable); - } - - @Override - public void execute(T t) { - result.set(t); - procedure.execute(t); - } - - }, listener); - -// newGraph.waitAsync(request); + processor.query(this, request, parent, new Procedure() { - } else { - - try { + @Override + public void exception(Throwable throwable) { + exception.set(throwable); + procedure.exception(throwable); + } - T t = processor.tryQuery(this, request); + @Override + public void execute(T t) { result.set(t); procedure.execute(t); + } - } catch (Throwable t) { + }, listener); + - if (t instanceof DatabaseException) { - exception.set((DatabaseException)t); - procedure.exception(exception.get()); - } else { - exception.set(new DatabaseException( - "Unexpected exception in ReadGraph.syncRequest(Read)", - t)); - procedure.exception(exception.get()); - } - } - - } +// if (parent != null || listener != null) { +// +//// final ReadGraphImpl newGraph = newSync(); +// +// +//// newGraph.waitAsync(request); +// +// } else { +// +// try { +// +// T t = processor.tryQuery(this, request); +// result.set(t); +// procedure.execute(t); +// +// } catch (Throwable t) { +// +// if (t instanceof DatabaseException) { +// exception.set((DatabaseException)t); +// procedure.exception(exception.get()); +// } else { +// exception.set(new DatabaseException( +// "Unexpected exception in ReadGraph.syncRequest(Read)", +// t)); +// procedure.exception(exception.get()); +// } +// +// } +// +// } Throwable t = exception.get(); if (t != null) { @@ -5406,11 +5392,12 @@ public class ReadGraphImpl implements ReadGraph { if (parent != null || listener != null) { try { - processor.queryRead(this, request, parent, procedure, - listener); - } catch (Throwable e) { + QueryCache.runnerReadEntry(this, request, parent, listener, procedure); + //processor.query(this, request, parent, procedure,listener); + } catch (DatabaseException e) { + Logger.defaultLogError(e); // This throwable has already been transferred to procedure at this point - do nothing about it - //Logger.defaultLogError("Internal error ", e); + // } } else { @@ -5515,7 +5502,12 @@ public class ReadGraphImpl implements ReadGraph { if (parent != null || listener != null) { - processor.query(this, request, parent, procedure, listener); + try { + QueryCache.runnerAsyncReadEntry(this, request, parent, listener, procedure); + //processor.query(this, request, parent, procedure, listener); + } catch (DatabaseException e) { + Logger.defaultLogError(e); + } } else {