]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java
Use Logger in DependencyChanges & related mechanisms
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / genericrelation / DependenciesRelation.java
index fc32222084c0f7e08509c152a882b893e7bd5b61..033efc9cc007d859a4ceb458f88284082cc9d302 100644 (file)
@@ -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;
@@ -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;
@@ -95,9 +94,9 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic
        class Process {
 
                final ArrayList<Entry> result = new ArrayList<Entry>();
-               final AsyncContextMultiProcedure<Resource, Resource> structure;
-               final AsyncContextProcedure<Entry, String> names;
-               final AsyncContextProcedure<Entry, Resource> type;
+               final SyncContextMultiProcedure<Resource, Resource> structure;
+               final SyncContextProcedure<Entry, String> names;
+               final SyncContextProcedure<Entry, Resource> type;
 
                Process(ReadGraph graph, final Resource resource) throws DatabaseException {
 
@@ -105,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<Entry, String>() {
+                       names = dqs.compilePossibleRelatedValue(graph, L0.HasName, new SyncContextProcedure<Entry, String>() {
 
                                @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<Entry, Resource>() {
+                       type = new SyncContextProcedure<Entry, Resource>() {
 
                                @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<Resource, Resource>() {
+                       structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new SyncContextMultiProcedure<Resource, Resource>() {
 
                                @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, "", "", "");
@@ -147,11 +146,11 @@ 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) {
+                               public void exception(ReadGraph graph, Throwable throwable) {
                                    if (throwable instanceof NoSingleResultException) {
                                        // Ignore
                                        if (LOGGER.isDebugEnabled())
@@ -229,10 +228,11 @@ 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<Object[]> result = new ArrayList<Object[]>();
                                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;
@@ -290,7 +290,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()) {
@@ -299,7 +302,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();
@@ -312,7 +316,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);
                                } 
                        }
@@ -368,7 +373,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())
@@ -392,9 +397,9 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic
                            Collection<Object[]> _replacementObjects = Collections.emptyList();
                            Collection<Pair<String, String>> _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<Object[]>();
                                _removals = new ArrayList<Object>();
@@ -414,10 +419,10 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic
                                            if (parent != null) {
                                                _additions.add(new Object[] { ss.getRandomAccessId(parent), ss.getRandomAccessId(entry.component), name, types, id != null ? id.indexString() : "" });
                                            } 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;
@@ -448,7 +453,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()) {
 
@@ -472,7 +477,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);
@@ -482,22 +487,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;
                                                }
@@ -557,7 +562,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic
 
                for (Pair<String, String> nr : typeChanges) {
                        String query = Dependencies.FIELD_RESOURCE + ":[" + nr.second + " TO " + nr.second + "]";
-                       //System.out.println("query: " + query);
+                       //LOGGER.info("query: " + query);
                        List<Map<String, Object>> results = indexer.query(null, query, graph, resource, model, Integer.MAX_VALUE);
                        if (results.size() != 1) {
                                return true;
@@ -567,7 +572,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;
        }
@@ -593,7 +598,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);