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=0cb5d9c4d9f5a78fedb3d8038bc1785bcbc6bb88;hb=a472ceaa29534d553e2af893e268b6a13bffa441;hp=26a6e68ae9f9378dd4b7a429c7ac2ccdbe317684;hpb=1ca7c5aad9e845ca9969ea37c7d4bef54e94b9e2;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 26a6e68ae..0cb5d9c4d 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 @@ -91,7 +91,7 @@ public class IndexUtils { public static Collection findByName(ReadGraph graph, Resource model, String name) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); HashSet results = new HashSet(); - + String search = IndexQueries.quoteTerm(Dependencies.FIELD_NAME, name); for(Resource resource : findResources(graph, model, search)) { @@ -101,49 +101,38 @@ public class IndexUtils { } public static Collection findByType(ReadGraph graph, Resource model, Resource type) throws DatabaseException { - - HashSet results = new HashSet(); - Layer0 L0 = Layer0.getInstance(graph); - String typeName = graph.getRelatedValue(type, L0.HasName, Bindings.STRING); - String search = IndexQueries.quoteTerm(Dependencies.FIELD_TYPES, typeName); + HashSet results = new HashSet<>(); + String search = IndexQueries.resourceIdTerm(Dependencies.FIELD_TYPE_RESOURCE, type); for(Resource resource : findResources(graph, model, search)) { - if(graph.isInstanceOf(resource, type)) results.add(resource); + if(graph.isInstanceOf(resource, type)) results.add(resource); } return results; } public static Collection findByTypeAndName(ReadGraph graph, Resource model, Resource type, String name) throws DatabaseException { - - Layer0 L0 = Layer0.getInstance(graph); - HashSet results = new HashSet(); - String typeName = graph.getRelatedValue(type, L0.HasName, Bindings.STRING); - - String search = IndexQueries.and(IndexQueries.quoteTerm(Dependencies.FIELD_TYPES, typeName), IndexQueries.quoteTerm(Dependencies.FIELD_NAME, name)); + String search = IndexQueries.and(IndexQueries.resourceIdTerm(Dependencies.FIELD_TYPE_RESOURCE, type), IndexQueries.quoteTerm(Dependencies.FIELD_NAME, name)); for(Resource resource : findResources(graph, model, search)) { - if(graph.isInstanceOf(resource, type)) results.add(resource); + if(graph.isInstanceOf(resource, type)) results.add(resource); } return results; } - - public static void flushIndexCaches(IProgressMonitor progress, Session session) throws Exception { - MemoryIndexing mem = MemoryIndexing.getInstance(session); - mem.flush(progress); - + public static void flushIndexCaches(IProgressMonitor monitor, Session session) throws Exception { + session.getService(IndexedRelations.class).flush(monitor, session); } - + public static List list(IProgressMonitor progress, Session session, Resource indexRoot) throws Exception { - + if(progress == null) progress = new NullProgressMonitor(); MemoryIndexing mem = MemoryIndexing.getInstance(session); Layer0X L0X = Layer0X.getInstance(session); - mem.flush(progress); - + session.getService(IndexedRelations.class).flush(progress, session); + IndexedRelationsSearcher searcher = mem.get(session, L0X.DependenciesRelation, indexRoot); List results; try {