@Override public Set<String> fetchIdsByPropertyValue(final String collectionPath, final String property, final String value) { String path = prefix(trimSuffix(collectionPath, "/"), "/"); String idx = path+"/#"+property; if( !indexPaths.contains(idx) ) { String message = "Index not defined for: collectionPath: " + path + ", property: " + property; LOG.warn("fetchIdsByPropertyValue not optimzed !!!: {}", message); return fetchIdsByPropertyValueFullTableScan(collectionPath, property, value); } else { final AtomicReference<Set<String>> ret = new AtomicReference<>(); withTransaction(dbi -> { final String query = "SELECT path FROM jsondb WHERE idx = ? AND value = ?"; final List<String> paths = dbi.createQuery(query) .bind(0, idx) .bind(1, STRING_VALUE_PREFIX+value) .map(StringColumnMapper.INSTANCE).list(); String suffix = "/" + property + "/"; ret.set(paths.stream() .map(x -> trimSuffix(x, suffix)) .collect(Collectors.toCollection(HashSet::new))); }); return ret.get(); } }
@Override public Set<String> fetchIdsByPropertyValue(final String collectionPath, final String property, final String value) { String path = prefix(trimSuffix(collectionPath, "/"), "/"); String idx = path+"/"+property; if( !indexes.contains(idx) ) { String message = "Index not defined for: collectionPath: " + path + ", property: " + property; LOG.warn("fetchIdsByPropertyValue not optimzed !!!: {}", message); return fetchIdsByPropertyValueFullTableScan(collectionPath, property, value); } else { final AtomicReference<Set<String>> ret = new AtomicReference<>(); withTransaction(dbi -> { final String query = "SELECT path FROM jsondb WHERE idx = ? AND value = ?"; final List<String> paths = dbi.createQuery(query) .bind(0, idx) .bind(1, value) .map(StringColumnMapper.INSTANCE).list(); String suffix = "/" + property + "/"; ret.set(paths.stream() .map(x -> trimSuffix(x, suffix)) .collect(Collectors.toCollection(HashSet::new))); }); return ret.get(); } }