This class provides access to main-memory key/value stores. @author BaseX Team, BSD License @author Christian Gruen
| 24 | * @author Christian Gruen |
| 25 | */ |
| 26 | public final class Stores implements Closeable { |
| 27 | /** Name of store files. */ |
| 28 | private static final String NAME = "store"; |
| 29 | |
| 30 | /** Stores. */ |
| 31 | private final HashMap<String, Store> stores = new HashMap<>(); |
| 32 | /** Database context. */ |
| 33 | private final Context context; |
| 34 | |
| 35 | /** |
| 36 | * Constructor. |
| 37 | * @param context database context |
| 38 | */ |
| 39 | public Stores(final Context context) { |
| 40 | this.context = context; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Returns all keys. |
| 45 | * @param name name of store |
| 46 | * @param info input info |
| 47 | * @param qc query context |
| 48 | * @return keys |
| 49 | * @throws QueryException query exception |
| 50 | */ |
| 51 | public synchronized Value keys(final String name, final InputInfo info, final QueryContext qc) |
| 52 | throws QueryException { |
| 53 | final Store store = get(name, false, info, qc); |
| 54 | if(store != null) { |
| 55 | final TokenList list = new TokenList(store.map.size()); |
| 56 | for(final String key : store.map.keySet()) list.add(key); |
| 57 | return StrSeq.get(list); |
| 58 | } |
| 59 | return Empty.VALUE; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Returns a value. |
| 64 | * @param key key |
| 65 | * @param name name of store |
| 66 | * @param info input info |
| 67 | * @param qc query context |
| 68 | * @return value or empty sequence |
| 69 | * @throws QueryException query exception |
| 70 | */ |
| 71 | public synchronized Value get(final String key, final String name, final InputInfo info, |
| 72 | final QueryContext qc) throws QueryException { |
| 73 | final Store store = get(name, false, info, qc); |
| 74 | if(store != null) { |
| 75 | final Value value = store.map.get(key); |
| 76 | if(value != null) return value; |
| 77 | } |
| 78 | return Empty.VALUE; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Stores a value. |
| 83 | * @param key key |
nothing calls this directly
no test coverage detected