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%2FMultiReadEntry.java;h=6b7415c9780f7a45c715068c83c4f02f1fe1fb29;hp=d0bb436d74e88e994a66fa9e27474f5a31139bfd;hb=0d9b90834ce56b292c00b1a39850ed842c3e4d42;hpb=e5db6157fd8722c946613d4e46d7aaf6bfa92609 diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/MultiReadEntry.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/MultiReadEntry.java index d0bb436d7..6b7415c97 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/MultiReadEntry.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/MultiReadEntry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * Copyright (c) 2007, 2018 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 @@ -14,21 +14,24 @@ package org.simantics.db.impl.query; 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; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -final public class MultiReadEntry extends CacheEntryBase { +public final class MultiReadEntry extends CacheEntryBase> { -// public ArrayList, AsyncBarrier>> procs; + private static final Logger LOGGER = LoggerFactory.getLogger(MultiReadEntry.class); protected MultiRead request; - public MultiReadEntry(MultiRead request) { + MultiReadEntry(MultiRead request) { this.request = request; } @@ -49,34 +52,14 @@ final public class MultiReadEntry extends CacheEntryBase { setResult(null); } - synchronized public void finish(AsyncReadGraph graph) { + synchronized public void finish(ReadGraph graph) { assert(isPending()); - ArrayList, AsyncBarrier>> p = null; - - synchronized(this) { - + synchronized(this) { setReady(); - -// p = procs; -// procs = null; - } -// if(p != null) { -// ArrayList v = (ArrayList)getResult(); -// if(v != null) { -// for(Pair, AsyncBarrier> pair : p) { -// for(T t : v) pair.first.execute(graph, t); -// } -// } -// for(Pair, AsyncBarrier> pair : p) { -// pair.first.finished(graph); -// pair.second.dec(); -// } -// } - } @Override @@ -99,41 +82,30 @@ final public class MultiReadEntry extends CacheEntryBase { return new Query() { @Override - public void recompute(ReadGraphImpl graph, Object provider, CacheEntry entry) { + public void recompute(ReadGraphImpl graph) { - QueryProcessor qp = (QueryProcessor)provider; - - final ReadGraphImpl parentGraph = ReadGraphImpl.forRecompute(entry, qp); -// parentGraph.state.barrier.inc(); - try { - request.perform(parentGraph , new AsyncMultiProcedure() { + request.perform(graph , new SyncMultiProcedure() { @Override - public void execute(AsyncReadGraph graph, T result) { + public void execute(ReadGraph graph, T result) { addOrSet(result); -// parentGraph.state.barrier.dec(); } - public void finished(AsyncReadGraph graph) { + public void finished(ReadGraph graph) { finish(graph); -// parentGraph.state.barrier.dec(); }; @Override - public void exception(AsyncReadGraph graph, Throwable t) { + public void exception(ReadGraph graph, Throwable t) { except(t); -// parentGraph.state.barrier.dec(); } }); -// parentGraph.waitAsync(request); - } catch (Throwable t) { except(t); -// parentGraph.state.barrier.dec(); if(DebugException.DEBUG) new DebugException(t).printStackTrace(); } @@ -141,7 +113,7 @@ final public class MultiReadEntry extends CacheEntryBase { @Override public void removeEntry(QueryProcessor processor) { - processor.multiReadMap.remove(request); + processor.cache.remove(MultiReadEntry.this); } @Override @@ -168,7 +140,7 @@ final public class MultiReadEntry extends CacheEntryBase { try { proc.exception(graph, (Throwable)getResult()); } catch (Throwable t) { - t.printStackTrace(); + LOGGER.error("performFromCache proc.exception failed", t); } // parentBarrier.dec(); @@ -179,33 +151,30 @@ final public class MultiReadEntry extends CacheEntryBase { try { proc.execute(graph, value); } catch (Throwable t) { - t.printStackTrace(); + LOGGER.error("performFromCache proc.execute failed", t); } } try { proc.finished(graph); } catch (Throwable t) { - t.printStackTrace(); + LOGGER.error("performFromCache proc.finished failed", t); } // parentBarrier.dec(); } } - - @Override - public void performFromCache(ReadGraphImpl graph, Object provider, - Object procedure) { - - final AsyncMultiProcedure proc = (AsyncMultiProcedure)procedure; + + @Override + public Object performFromCache(ReadGraphImpl graph, SyncMultiProcedure proc) { if(isExcepted()) { try { proc.exception(graph, (Throwable)getResult()); } catch (Throwable t) { - t.printStackTrace(); + LOGGER.error("performFromCache(Sync) proc.exception failed", t); } } else { @@ -215,26 +184,30 @@ final public class MultiReadEntry extends CacheEntryBase { try { proc.execute(graph, value); } catch (Throwable t) { - t.printStackTrace(); + LOGGER.error("performFromCache(Sync) proc.execute failed", t); } } try { proc.finished(graph); } catch (Throwable t) { - t.printStackTrace(); + LOGGER.error("performFromCache(Sync) proc.finished failed", t); } } - - - + + return null; + } - + @Override public String toString() { if(request == null) return "DISCARDED"; else return request.toString() + statusOrException; } + public Object compute(ReadGraphImpl graph, SyncMultiProcedure procedure) throws DatabaseException { + return graph.processor.cache.performQuery(graph, request, this, procedure); + } + }