X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fgenericrelation%2FDependenciesRelation.java;h=4f98af7b4ab33fe4349e7bae9845fe703e728e98;hp=a3e19f1fc7d94c2af38e01f003e368df7965335d;hb=9f0fd59be54719b1fe9322d8fd37e4950857308c;hpb=88ef829f11351683821ba3dc735e28307c3819c0 diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java index a3e19f1fc..4f98af7b4 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java @@ -23,7 +23,6 @@ import java.util.UUID; import org.simantics.databoard.Bindings; import org.simantics.databoard.util.ObjectUtils; import org.simantics.datatypes.literal.GUID; -import org.simantics.db.AsyncReadGraph; import org.simantics.db.ChangeSet; import org.simantics.db.ChangeSet.StatementChange; import org.simantics.db.MetadataI; @@ -40,10 +39,10 @@ import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.request.SuperTypeString; import org.simantics.db.common.request.TypeString; import org.simantics.db.common.request.UnaryRead; -import org.simantics.db.common.utils.Logger; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.event.ChangeListener; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; import org.simantics.db.layer0.adapter.GenericRelation; import org.simantics.db.layer0.adapter.GenericRelationIndex; import org.simantics.db.layer0.genericrelation.DependencyChanges.Change; @@ -51,8 +50,8 @@ import org.simantics.db.layer0.genericrelation.DependencyChanges.ComponentAdditi import org.simantics.db.layer0.genericrelation.DependencyChanges.ComponentModification; import org.simantics.db.layer0.genericrelation.DependencyChanges.ComponentRemoval; import org.simantics.db.layer0.genericrelation.DependencyChanges.LinkChange; -import org.simantics.db.procedure.AsyncContextMultiProcedure; -import org.simantics.db.procedure.AsyncContextProcedure; +import org.simantics.db.procedure.SyncContextMultiProcedure; +import org.simantics.db.procedure.SyncContextProcedure; import org.simantics.db.service.CollectionSupport; import org.simantics.db.service.DirectQuerySupport; import org.simantics.db.service.GraphChangeListenerSupport; @@ -62,9 +61,11 @@ import org.simantics.layer0.Layer0; import org.simantics.operation.Layer0X; import org.simantics.utils.datastructures.Pair; import org.simantics.utils.logging.TimeLogger; +import org.slf4j.LoggerFactory; public class DependenciesRelation extends UnsupportedRelation implements GenericRelationIndex { + private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DependenciesRelation.class); private static final boolean DEBUG = false; static final boolean DEBUG_LISTENERS = false; private static final boolean PROFILE = false; @@ -93,9 +94,9 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic class Process { final ArrayList result = new ArrayList(); - final AsyncContextMultiProcedure structure; - final AsyncContextProcedure names; - final AsyncContextProcedure type; + final SyncContextMultiProcedure structure; + final SyncContextProcedure names; + final SyncContextProcedure type; Process(ReadGraph graph, final Resource resource) throws DatabaseException { @@ -103,38 +104,38 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class); final CollectionSupport cs = graph.getService(CollectionSupport.class); - names = dqs.compilePossibleRelatedValue(graph, L0.HasName, new AsyncContextProcedure() { + names = dqs.compilePossibleRelatedValue(graph, L0.HasName, new SyncContextProcedure() { @Override - public void execute(AsyncReadGraph graph, Entry entry, String name) { + public void execute(ReadGraph graph, Entry entry, String name) { entry.name = name; } @Override - public void exception(AsyncReadGraph graph, Throwable throwable) { - Logger.defaultLogError(throwable); + public void exception(ReadGraph graph, Throwable throwable) { + LOGGER.error("Could not compile possible related value for resource {}", resource, throwable); } }); - type = new AsyncContextProcedure() { + type = new SyncContextProcedure() { @Override - public void execute(AsyncReadGraph graph, Entry entry, Resource type) { + public void execute(ReadGraph graph, Entry entry, Resource type) { entry.principalType = type; } @Override - public void exception(AsyncReadGraph graph, Throwable throwable) { - Logger.defaultLogError(throwable); + public void exception(ReadGraph graph, Throwable throwable) { + LOGGER.error("Could not find type for resource {}", resource, throwable); } }; - structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new AsyncContextMultiProcedure() { + structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new SyncContextMultiProcedure() { @Override - public void execute(AsyncReadGraph graph, Resource parent, Resource child) { + public void execute(ReadGraph graph, Resource parent, Resource child) { // WORKAROUND: don't browse virtual child resources if(!child.isPersistent()) return; Entry entry = new Entry(parent, child, "", "", ""); @@ -145,12 +146,18 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic } @Override - public void finished(AsyncReadGraph graph, Resource parent) { + public void finished(ReadGraph graph, Resource parent) { } @Override - public void exception(AsyncReadGraph graph, Throwable throwable) { - Logger.defaultLogError(throwable); + public void exception(ReadGraph graph, Throwable throwable) { + if (throwable instanceof NoSingleResultException) { + // Ignore + if (LOGGER.isDebugEnabled()) + LOGGER.debug("Could not compile for resource {}", resource, throwable); + } else { + LOGGER.error("Could not compile for resource {}", resource, throwable); + } } }); @@ -171,7 +178,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic if(typeString == null) { typeString = graph.syncRequest(new SuperTypeString(e.principalType)); if (typeString.isEmpty()) { - Logger.defaultLogError(new DatabaseException("No name for type " + NameUtils.getURIOrSafeNameInternal(graph, e.resource) + " (" + e.resource + ")")); + LOGGER.error("No name for type", new DatabaseException("No name for type " + NameUtils.getURIOrSafeNameInternal(graph, e.resource) + " (" + e.resource + ")")); } typeStrings.put(e.principalType, typeString); } @@ -225,6 +232,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic ArrayList result = new ArrayList(); for (Entry entry : entries) { + if(entry.name == null) continue; result.add(new Object[] { ss.getRandomAccessId(entry.parent), ss.getRandomAccessId(entry.resource), entry.name, entry.types, entry.id }); } return result; @@ -507,9 +515,8 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic } catch (Throwable t) { // Just to know if something unexpected happens here. - Logger.defaultLogError("Dependencies index update failed for model " - + model + " and relation " + resource + ".", t); - t.printStackTrace(); + LOGGER.error("Dependencies index update failed for model " + + model + " and relation " + resource + ".", t); // NOTE: Last resort: failure to update index // properly results in removal of the whole index.