]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java
Index tokenized lowercase versions of name and types for UI searches
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / genericrelation / DependenciesRelation.java
index a3e19f1fc7d94c2af38e01f003e368df7965335d..989639ef846b17b8a78c794e650b3fdd0503e399 100644 (file)
@@ -40,10 +40,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;
@@ -62,9 +62,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;
@@ -76,7 +78,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;
@@ -112,7 +116,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic
 
                                @Override
                                public void exception(AsyncReadGraph graph, Throwable throwable) {
-                                       Logger.defaultLogError(throwable);
+                                       LOGGER.error("Could not compile possible related value for resource {}", resource, throwable);
                                }
 
                        });
@@ -126,7 +130,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic
 
                                @Override
                                public void exception(AsyncReadGraph graph, Throwable throwable) {
-                                       Logger.defaultLogError(throwable);
+                                       LOGGER.error("Could not find type for resource {}", resource, throwable);
                                }
 
                        };
@@ -150,7 +154,13 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic
 
                                @Override
                                public void exception(AsyncReadGraph graph, Throwable throwable) {
-                                       Logger.defaultLogError(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 +181,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,7 +235,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic
 
                                ArrayList<Object[]> result = new ArrayList<Object[]>();
                                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 });
                                }
                                return result;
 
@@ -241,21 +251,21 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic
 
        @Override
        public List<Map<String, Object>> 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<Resource> 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<Map<String, Object>> 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);
        }
@@ -404,7 +414,7 @@ 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);
                                            }
@@ -425,7 +435,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});
                                                }
                                            }
                                        }
@@ -507,9 +517,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.
@@ -610,7 +619,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic
 
                ArrayList<Object[]> result = new ArrayList<Object[]>(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);