X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.indexing%2Fsrc%2Forg%2Fsimantics%2Fdb%2Findexing%2FIndexUtils.java;h=343623bcfd137f960667e0985cf2f304befc753b;hb=e23dba36;hp=5262d99a2d85690715f4264a9a01cfaf664bcf95;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexUtils.java b/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexUtils.java index 5262d99a2..343623bcf 100644 --- a/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexUtils.java +++ b/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexUtils.java @@ -17,8 +17,9 @@ import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.request.ObjectsWithType; -import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.genericrelation.Dependencies; +import org.simantics.db.layer0.genericrelation.IndexQueries; import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.service.CollectionSupport; import org.simantics.layer0.Layer0; @@ -84,10 +85,9 @@ public class IndexUtils { Layer0 L0 = Layer0.getInstance(graph); HashSet results = new HashSet(); - String search = "Name:" + name; + String search = IndexQueries.quoteTerm(Dependencies.FIELD_NAME, name); - for(Map entry : find(graph, model, search)) { - Resource resource = (Resource)entry.get("Resource"); + for(Resource resource : findResources(graph, model, search)) { if(name.equals(graph.getPossibleRelatedValue(resource, L0.HasName, Bindings.STRING))) results.add(resource); } return results; @@ -96,11 +96,11 @@ public class IndexUtils { public static Collection findByType(ReadGraph graph, Resource model, Resource type) throws DatabaseException { HashSet results = new HashSet(); - - String search = "Types:*" + NameUtils.getSafeName(graph, type); + Layer0 L0 = Layer0.getInstance(graph); + String typeName = graph.getRelatedValue(type, L0.HasName, Bindings.STRING); + String search = IndexQueries.quoteTerm(Dependencies.FIELD_TYPES, typeName); - for(Map entry : find(graph, model, search)) { - Resource resource = (Resource)entry.get("Resource"); + for(Resource resource : findResources(graph, model, search)) { if(graph.isInstanceOf(resource, type)) results.add(resource); } return results; @@ -111,12 +111,12 @@ public class IndexUtils { Layer0 L0 = Layer0.getInstance(graph); HashSet results = new HashSet(); + String typeName = graph.getRelatedValue(type, L0.HasName, Bindings.STRING); - String search = "Types:*" + type + " AND Name:" + name; + String search = IndexQueries.and(IndexQueries.quoteTerm(Dependencies.FIELD_TYPES, typeName), IndexQueries.quoteTerm(Dependencies.FIELD_NAME, name)); - for(Map entry : find(graph, model, search)) { - Resource resource = (Resource)entry.get("Resource"); - if(graph.isInstanceOf(resource, type) && name.equals(graph.getPossibleRelatedValue(resource, L0.HasName, Bindings.STRING))) results.add(resource); + for(Resource resource : findResources(graph, model, search)) { + if(graph.isInstanceOf(resource, type)) results.add(resource); } return results; }