private static Deque<String> getAllParentPaths(String baseDBPath) { Deque<String> params = new ArrayDeque<String>(); Pattern compile = Pattern.compile("/[^/]*$"); String current = trimSuffix(baseDBPath, "/"); while( true ) { current = compile.matcher(current).replaceFirst(""); if( current.isEmpty() ) { break; } params.add(current+"/"); } return params; }
private static Deque<String> getAllParentPaths(String baseDBPath) { Deque<String> params = new ArrayDeque<String>(); Pattern compile = Pattern.compile("/[^/]*$"); String current = trimSuffix(baseDBPath, "/"); while( true ) { current = compile.matcher(current).replaceFirst(""); if( current.isEmpty() ) { break; } params.add(current+"/"); } return params; }
@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(); } }
try { String path = record.getPath(); path = Strings.trimSuffix(path.substring(base.length()), "/");
try { String path = record.getPath(); path = Strings.trimSuffix(path.substring(base.length()), "/");
@Override public boolean delete(String path) { String baseDBPath = JsonRecordSupport.convertToDBPath(path); String like = baseDBPath+"%"; boolean rc[] = new boolean[]{false}; withTransaction(dbi -> { rc[0] = deleteJsonRecords(dbi, baseDBPath, like) > 0; }); if( bus!=null && rc[0] ) { bus.broadcast("jsondb-deleted", prefix(trimSuffix(path, "/"), "/")); } return rc[0]; }
@Override public boolean delete(String path) { String baseDBPath = JsonRecordSupport.convertToDBPath(path); String like = baseDBPath+"%"; boolean rc[] = new boolean[]{false}; withTransaction(dbi -> { rc[0] = deleteJsonRecords(dbi, baseDBPath, like) > 0; }); if( bus!=null && rc[0] ) { bus.broadcast("jsondb-deleted", prefix(trimSuffix(path, "/"), "/")); } return rc[0]; }
if( bus!=null ) { for (String updatePath : updatePaths) { bus.broadcast("jsondb-updated", prefix(trimSuffix(updatePath, "/"), "/"));
if( bus!=null ) { for (String updatePath : updatePaths) { bus.broadcast("jsondb-updated", prefix(trimSuffix(updatePath, "/"), "/"));
@Override public void set(String path, InputStream body) { withTransaction(dbi -> { BatchManager mb = new BatchManager(dbi); String baseDBPath = JsonRecordSupport.convertToDBPath(path); mb.deleteRecordsForSet(baseDBPath); try { JsonRecordSupport.jsonStreamToRecords(indexPaths, baseDBPath, body, mb.createSetConsumer()); } catch (IOException e) { throw new JsonDBException(e); } mb.flush(); }); if( bus!=null ) { bus.broadcast("jsondb-updated", prefix(trimSuffix(path, "/"), "/")); } }
@Override public void set(String path, InputStream body) { withTransaction(dbi -> { BatchManager mb = new BatchManager(dbi); String baseDBPath = JsonRecordSupport.convertToDBPath(path); mb.deleteRecordsForSet(baseDBPath); try { JsonRecordSupport.jsonStreamToRecords(indexes, baseDBPath, body, mb.createSetConsumer()); } catch (IOException e) { throw new JsonDBException(e); } mb.flush(); }); if( bus!=null ) { bus.broadcast("jsondb-updated", prefix(trimSuffix(path, "/"), "/")); } }