X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FQueryProcessor.java;h=7743907202eb8fbf54fd584330e3dc84fcdfac16;hp=b2951cb27e3c122322aeca97aabe124cac8b9702;hb=4d97b17c475cd2d73c427c33f01477249eedc73a;hpb=4c5ff8ec11947aae4d49106365819717cfa43209 diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java index b2951cb27..774390720 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java @@ -49,7 +49,6 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; import org.simantics.db.exception.NoInverseException; import org.simantics.db.exception.ResourceNotFoundException; -import org.simantics.db.impl.DebugPolicy; import org.simantics.db.impl.ResourceImpl; import org.simantics.db.impl.graph.BarrierTracing; import org.simantics.db.impl.graph.ReadGraphImpl; @@ -713,7 +712,11 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap } catch (DatabaseException e) { Logger.defaultLogError(e); } - if(DebugPolicy.DEPENDENCIES) System.out.println(child + " -> " + parent); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_DEPENDENCIES, Bindings.BOOLEAN)) { + System.out.println(child + " -> " + parent); + } + } } if (listener != null) { @@ -963,9 +966,11 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap list.add(result); } - if(DebugPolicy.LISTENER) { - new Exception().printStackTrace(); - System.out.println("addListener -> " + list.size() + " " + entry + " " + base + " " + procedure); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_LISTENERS, Bindings.BOOLEAN)) { + new Exception().printStackTrace(); + System.err.println("addListener -> " + list.size() + " " + entry + " " + base + " " + procedure); + } } return result; @@ -974,7 +979,11 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap private void scheduleListener(ListenerEntry entry) { assert (entry != null); - if(DebugPolicy.LISTENER) System.out.println("Scheduled " + entry.procedure); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_LISTENERS, Bindings.BOOLEAN)) { + System.err.println("Scheduled " + entry.procedure); + } + } scheduledListeners.add(entry); } @@ -1426,8 +1435,6 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap CacheEntry entry = e.entry; - //System.err.println("updateQuery " + entry); - /* * If the dependency graph forms a DAG, some entries are inserted in the * todo list many times. They only need to be processed once though. @@ -1435,10 +1442,10 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap if (entry.isDiscarded()) { if (Development.DEVELOPMENT) { if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) { - System.out.print("D"); + System.err.print("D"); for (int i = 0; i < e.indent; i++) - System.out.print(" "); - System.out.println(entry.getQuery()); + System.err.print(" "); + System.err.println(entry.getQuery()); } } // System.err.println(" => DISCARDED"); @@ -1448,10 +1455,10 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap if (entry.isRefuted()) { if (Development.DEVELOPMENT) { if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) { - System.out.print("R"); + System.err.print("R"); for (int i = 0; i < e.indent; i++) - System.out.print(" "); - System.out.println(entry.getQuery()); + System.err.print(" "); + System.err.println(entry.getQuery()); } } return false; @@ -1460,7 +1467,7 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap if (entry.isExcepted()) { if (Development.DEVELOPMENT) { if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) { - System.out.print("E"); + System.err.print("E"); } } } @@ -1468,7 +1475,7 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap if (entry.isPending()) { if (Development.DEVELOPMENT) { if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) { - System.out.print("P"); + System.err.print("P"); } } } @@ -1477,10 +1484,10 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap if (Development.DEVELOPMENT) { if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) { - System.out.print("U "); + System.err.print("U "); for (int i = 0; i < e.indent; i++) - System.out.print(" "); - System.out.print(entry.getQuery()); + System.err.print(" "); + System.err.print(entry.getQuery()); } } @@ -1492,9 +1499,9 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap if (Development.DEVELOPMENT) { if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) { if(hasListener(entry)) { - System.out.println(" (L)"); + System.err.println(" (L)"); } else { - System.out.println(""); + System.err.println(""); } } } @@ -1616,7 +1623,11 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap Query query = entry.getQuery(); - if(DebugPolicy.RECOMPUTE) System.out.println("R " + query); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_RECOMPUTE, Bindings.BOOLEAN)) { + System.err.println("R " + query); + } + } entry.prepareRecompute(querySupport); @@ -1629,10 +1640,12 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap Object newValue = entry.getResult(); if (ListenerEntry.NO_VALUE == oldValue) { - if(DebugPolicy.CHANGES) { - System.out.println("C " + query); - System.out.println("- " + oldValue); - System.out.println("- " + newValue); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_CHANGES, Bindings.BOOLEAN)) { + System.out.println("C " + query); + System.out.println("- " + oldValue); + System.out.println("- " + newValue); + } } return newValue; } @@ -1648,10 +1661,12 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap } else changed = (oldValue != null); - if(DebugPolicy.CHANGES && changed) { - System.out.println("C " + query); - System.out.println("- " + oldValue); - System.out.println("- " + newValue); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_CHANGES, Bindings.BOOLEAN)) { + System.err.println("C " + query); + System.err.println("- " + oldValue); + System.err.println("- " + newValue); + } } return changed ? newValue : ListenerEntry.NOT_CHANGED; @@ -1696,7 +1711,12 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap for (ListenerEntry listenerEntry : entries) { if (pruneListener(listenerEntry)) { - if(DebugPolicy.LISTENER) System.out.println("Pruned " + listenerEntry.procedure); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_LISTENERS, Bindings.BOOLEAN)) { + new Exception().printStackTrace(); + System.err.println("Pruned " + listenerEntry.procedure); + } + } continue; } @@ -1706,8 +1726,12 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap Object newValue = compareTo(graph, entry, listenerEntry.getLastKnown()); if (newValue != ListenerEntry.NOT_CHANGED) { - if(DebugPolicy.LISTENER) - System.out.println("Add to schedule " + listenerEntry.procedure + " with " + newValue); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_LISTENERS, Bindings.BOOLEAN)) { + new Exception().printStackTrace(); + System.err.println("Add to schedule " + listenerEntry.procedure + " with " + newValue); + } + } schedule.add(listenerEntry); listenerEntry.setLastKnown(entry.getResult()); } @@ -1716,11 +1740,17 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap for(ListenerEntry listenerEntry : schedule) { final CacheEntry entry = listenerEntry.entry; - if(DebugPolicy.LISTENER) - System.out.println("Firing " + listenerEntry.procedure); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_LISTENERS, Bindings.BOOLEAN)) { + System.err.println("Firing " + listenerEntry.procedure); + } + } try { - if(DebugPolicy.LISTENER) - System.out.println("Firing " + listenerEntry.procedure + " for " + listenerEntry.entry); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_LISTENERS, Bindings.BOOLEAN)) { + System.err.println("Firing " + listenerEntry.procedure + " for " + listenerEntry.entry); + } + } entry.performFromCache(graph, listenerEntry.procedure); } catch (Throwable t) { t.printStackTrace(); @@ -2296,67 +2326,16 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap @Override final public void forEachPredicate(final ReadGraphImpl impl, final Resource subject, final AsyncMultiProcedure procedure) { - throw new UnsupportedOperationException(); + try { -// assert(subject != null); -// assert(procedure != null); -// -// final ListenerBase listener = getListenerBase(procedure); -// -// IntProcedure ip = new IntProcedure() { -// -// AtomicBoolean first = new AtomicBoolean(true); -// -// @Override -// public void execute(ReadGraphImpl graph, int i) { -// try { -// if(first.get()) { -// procedure.execute(graph, querySupport.getResource(i)); -// } else { -// procedure.execute(impl.newRestart(graph), querySupport.getResource(i)); -// } -// } catch (Throwable t2) { -// Logger.defaultLogError(t2); -// } -// } -// -// @Override -// public void finished(ReadGraphImpl graph) { -// try { -// if(first.compareAndSet(true, false)) { -// procedure.finished(graph); -//// impl.state.barrier.dec(this); -// } else { -// procedure.finished(impl.newRestart(graph)); -// } -// -// } catch (Throwable t2) { -// Logger.defaultLogError(t2); -// } -// } -// -// @Override -// public void exception(ReadGraphImpl graph, Throwable t) { -// try { -// if(first.compareAndSet(true, false)) { -// procedure.exception(graph, t); -// } else { -// procedure.exception(impl.newRestart(graph), t); -// } -// } catch (Throwable t2) { -// Logger.defaultLogError(t2); -// } -// } -// -// }; -// -// int sId = querySupport.getId(subject); -// -// try { -// QueryCache.runnerPredicates(impl, sId, impl.parent, listener, ip); -// } catch (DatabaseException e) { -// Logger.defaultLogError(e); -// } + for(Resource predicate : getPredicates(impl, subject)) + procedure.execute(impl, predicate); + + procedure.finished(impl); + + } catch (Throwable e) { + procedure.exception(impl, e); + } }