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=6f310120bc6f5c5cc6eb9bbf0469199091a471ac;hp=333f3771c843c636e2838b51b0d32488edf6e7fa;hb=2ebe792aa45ea728815c82dc54e08d83b7de0cd5;hpb=8b8630b93f8e4ec88a8a4eb53b55031407deedc0 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 333f3771c..6f310120b 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; @@ -43,6 +42,7 @@ import org.simantics.db.common.request.UnaryRead; 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; @@ -50,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; @@ -77,7 +77,9 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic Pair.make(Dependencies.FIELD_RESOURCE, "Long"), Pair.make(Dependencies.FIELD_NAME, "String"), Pair.make(Dependencies.FIELD_TYPES, "Text"), - Pair.make(Dependencies.FIELD_GUID, "Text") + Pair.make(Dependencies.FIELD_GUID, "Text"), + Pair.make(Dependencies.FIELD_NAME_SEARCH, "Text"), + Pair.make(Dependencies.FIELD_TYPES_SEARCH, "Text") }; final Resource resource; @@ -94,9 +96,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 { @@ -104,38 +106,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) { + 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) { + 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, "", "", ""); @@ -146,16 +148,24 @@ 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.error("Could not compile for resource {}", resource, 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); + } } }); + result.add(new Entry(graph, resource)); + graph.syncRequest(new ReadRequest() { @Override @@ -222,11 +232,12 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic long time2 = System.nanoTime(); if (PROFILE) - System.out.println("Found " + entries.size() + " dependencies in " + 1e-6 * (time2 - time) + "ms for " + graph.getPossibleURI(subject) + "."); + LOGGER.info("Found " + entries.size() + " dependencies in " + 1e-6 * (time2 - time) + "ms for " + graph.getPossibleURI(subject) + "."); ArrayList result = new ArrayList(); for (Entry entry : entries) { - result.add(new Object[] { ss.getRandomAccessId(entry.parent), ss.getRandomAccessId(entry.resource), entry.name, entry.types, entry.id }); + if(entry.name == null) continue; + result.add(new Object[] { ss.getRandomAccessId(entry.parent), ss.getRandomAccessId(entry.resource), entry.name, entry.types, entry.id, entry.name, entry.types }); } return result; @@ -242,21 +253,21 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic @Override public List> query(RequestProcessor session, String search, String bindingPattern, Object[] constants, int maxResultCount) { - if(!Dependencies.getBindingPattern().equals(bindingPattern)) throw new IllegalArgumentException("DependenciesRelation supports indexing only with 'bfffff'"); + if(!Dependencies.getBindingPattern().equals(bindingPattern)) throw new IllegalArgumentException("DependenciesRelation supports indexing only with 'bfffffff'"); IndexedRelations indexer = session.getService(IndexedRelations.class); return indexer.query(null, search, session, resource, (Resource)constants[0], maxResultCount); } @Override public List queryResources(RequestProcessor session, String search, String bindingPattern, Object[] constants, int maxResultCount) { - if(!Dependencies.getBindingPattern().equals(bindingPattern)) throw new IllegalArgumentException("DependenciesRelation supports indexing only with 'bfffff'"); + if(!Dependencies.getBindingPattern().equals(bindingPattern)) throw new IllegalArgumentException("DependenciesRelation supports indexing only with 'bfffffff'"); IndexedRelations indexer = session.getService(IndexedRelations.class); return indexer.queryResources(null, search, session, resource, (Resource)constants[0], maxResultCount); } @Override public List> list(RequestProcessor session, String bindingPattern, Object[] constants, int maxResultCount) { - if(!Dependencies.getBindingPattern().equals(bindingPattern)) throw new IllegalArgumentException("DependenciesRelation supports indexing only with 'bfffff'"); + if(!Dependencies.getBindingPattern().equals(bindingPattern)) throw new IllegalArgumentException("DependenciesRelation supports indexing only with 'bfffffff'"); IndexedRelations indexer = session.getService(IndexedRelations.class); return indexer.query(null, null, session, resource, (Resource)constants[0], maxResultCount); } @@ -283,7 +294,10 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic if (modifiedComponent == null || modifiedComponent.getPredicate().equals(changeInformation)) continue; - //System.err.println("+comp modi " + NameUtils.getSafeName(graph, renamedComponent, true)); + if (DEBUG) { + LOGGER.info("+comp modi " + NameUtils.getSafeName(graph, modifiedComponent.getObject(), true)); + LOGGER.info(" +value " + NameUtils.getSafeName(graph, value, true)); + } w.addComponentModification(modifiedComponent.getObject()); } for (Resource value : parameter.changedResources()) { @@ -292,7 +306,8 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic w.addComponentModification(value); } for (StatementChange change : parameter.changedStatements()) { - //System.err.println("-stm " + NameUtils.getSafeName(graph, change.getSubject(), true) + " " + NameUtils.getSafeName(graph, change.getPredicate(), true) + " " + NameUtils.getSafeName(graph, change.getObject(), true)); + if (DEBUG) + LOGGER.info("-stm " + NameUtils.getSafeName(graph, change.getSubject(), true) + " " + NameUtils.getSafeName(graph, change.getPredicate(), true) + " " + NameUtils.getSafeName(graph, change.getObject(), true)); Resource subject = change.getSubject(); Resource predicate = change.getPredicate(); Resource object = change.getObject(); @@ -305,7 +320,8 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic } else if (predicate.equals(l0.IsLinkedTo)) { w.addLinkChange(subject); } else /*if (graph.isSubrelationOf(predicate, l0.DependsOn))*/ { - //System.err.println("-modi " + NameUtils.getSafeName(graph, subject, true)); + if (DEBUG) + LOGGER.info("-modi " + NameUtils.getSafeName(graph, subject, true)); w.addComponentModification(subject); } } @@ -361,7 +377,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic TimeLogger.log(DependenciesRelation.class, "trackAndIndex.onEvent: starting index update processing"); if(DEBUG) - System.err.println("Adding metadata " + event + " in revision " + graph.getService(ManagementSupport.class).getHeadRevisionId()); + LOGGER.info("Adding metadata " + event + " in revision " + graph.getService(ManagementSupport.class).getHeadRevisionId()); WriteGraph w = (WriteGraph)graph; if(!event.isEmpty()) @@ -385,9 +401,9 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic Collection _replacementObjects = Collections.emptyList(); Collection> _typeChanges = Collections.emptyList(); - if(DEBUG) System.out.println("MODEL: " + NameUtils.getSafeLabel(graph, model)); + if(DEBUG) LOGGER.info("MODEL: " + NameUtils.getSafeLabel(graph, model)); // final Change[] changes = event.get(model); - if(DEBUG) System.out.println(" CHANGES: " + Arrays.toString(changes)); + if(DEBUG) LOGGER.info(" CHANGES: " + Arrays.toString(changes)); if (changes != null) { _additions = new ArrayList(); _removals = new ArrayList(); @@ -405,12 +421,12 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic if(!entry.isValid(graph)) continue; Resource parent = graph.getPossibleObject(entry.component, L0.PartOf); if (parent != null) { - _additions.add(new Object[] { ss.getRandomAccessId(parent), ss.getRandomAccessId(entry.component), name, types, id != null ? id.indexString() : "" }); + _additions.add(new Object[] { ss.getRandomAccessId(parent), ss.getRandomAccessId(entry.component), name, types, id != null ? id.indexString() : "", name, types}); } else { - //System.err.println("resource " + entry.component + ": no parent for entry " + name + " " + types); + //LOGGER.info("resource " + entry.component + ": no parent for entry " + name + " " + types); } } else { - //System.err.println("resource " + entry.component + ": " + name + " " + types); + //LOGGER.info("resource " + entry.component + ": " + name + " " + types); } } else if(_entry instanceof ComponentModification) { ComponentModification entry = (ComponentModification)_entry; @@ -426,7 +442,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic if(part != null) { _replacementKeys.add(ss.getRandomAccessId(entry.component)); _replacementObjects.add(new Object[] { ss.getRandomAccessId(part), - ss.getRandomAccessId(entry.component), name, types, id != null ? id.indexString() : "" }); + ss.getRandomAccessId(entry.component), name, types, id != null ? id.indexString() : "", name, types}); } } } @@ -441,7 +457,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic } final boolean reset = linkChange || event.hasUnresolved; - //System.err.println("dependencies(" + NameUtils.getSafeLabel(graph, model) + "): reset=" + reset + " linkChange=" + linkChange + " unresolved=" + event.hasUnresolved ); + //LOGGER.info("dependencies(" + NameUtils.getSafeLabel(graph, model) + "): reset=" + reset + " linkChange=" + linkChange + " unresolved=" + event.hasUnresolved ); if (reset || !_additions.isEmpty() || !_removals.isEmpty() || !_replacementKeys.isEmpty() || !_typeChanges.isEmpty()) { @@ -465,7 +481,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic if (doReset) { if(DEBUG) { - System.err.println("resetIndex " + reset + " " + typeNameChanges); + LOGGER.info("resetIndex " + reset + " " + typeNameChanges); } indexer.removeAll(null, graph, DependenciesRelation.this, resource, model); @@ -475,22 +491,22 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic if (!replacementKeys.isEmpty() && (replacementKeys.size() == replacementObjects.size())) { if(DEBUG) { - System.out.println(replacementKeys.size() + " index replacements: " + replacementKeys); + LOGGER.info(replacementKeys.size() + " index replacements: " + replacementKeys); } didChange |= indexer.replace(null, graph, DependenciesRelation.this, resource, model, Dependencies.FIELD_RESOURCE, replacementKeys, replacementObjects); } if (!removals.isEmpty()) { if(DEBUG) { - System.out.println(removals.size() + " index removals: " + removals); + LOGGER.info(removals.size() + " index removals: " + removals); } indexer.remove(null, graph, DependenciesRelation.this, resource, model, Dependencies.FIELD_RESOURCE, removals); didChange = true; } if (!additions.isEmpty()) { if(DEBUG) { - for(Object[] os : additions) System.err.println("Adding to index " + model + ": " + Arrays.toString(os)); + for(Object[] os : additions) LOGGER.info("Adding to index " + model + ": " + Arrays.toString(os)); } - //System.out.println(additions.size() + " index insertions"); + //LOGGER.info(additions.size() + " index insertions"); indexer.insert(null, graph, DependenciesRelation.this, resource, model, additions); didChange = true; } @@ -550,7 +566,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic for (Pair nr : typeChanges) { String query = Dependencies.FIELD_RESOURCE + ":[" + nr.second + " TO " + nr.second + "]"; - //System.out.println("query: " + query); + //LOGGER.info("query: " + query); List> results = indexer.query(null, query, graph, resource, model, Integer.MAX_VALUE); if (results.size() != 1) { return true; @@ -560,7 +576,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic return true; } } -// System.err.println("Type " + nr.first + " was unchanged."); +// LOGGER.info("Type " + nr.first + " was unchanged."); } return false; } @@ -586,7 +602,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic @Override public void reset(RequestProcessor processor, Resource input) { if (DEBUG) { - System.out.println("DependenciesRelation.reset: " + input); + LOGGER.info("DependenciesRelation.reset: " + input); new Exception("DependenciesRelation.reset(" + listener + ")").printStackTrace(System.out); } DependenciesListenerStore store = processor.getSession().getService(DependenciesListenerStore.class); @@ -610,7 +626,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic ArrayList result = new ArrayList(entries.size()); for (Entry entry : entries) { - result.add(new Object[] { ss.getRandomAccessId(entry.parent), ss.getRandomAccessId(entry.resource), entry.name, entry.types, entry.id }); + result.add(new Object[] { ss.getRandomAccessId(entry.parent), ss.getRandomAccessId(entry.resource), entry.name, entry.types, entry.id, entry.name, entry.types }); } Layer0X L0X = Layer0X.getInstance(graph);