@Override public Status read( final String table, final String key, final Set<String> fields, final HashMap<String, ByteIterator> result) { // logger.debug("read.enter; table: {}; startKey: {}; fields: {}", new Object[] {table, key, // fields}); XDMDocumentId xid = new XDMDocumentId(0, key); try { Map<String, Object> map = xRepo.getDocumentManagement().getDocumentAsMap(xid); if (map == null) { logger.info("read; not found document for key: {}; table: {}", key, table); return Status.NOT_FOUND; } if (fields == null) { for (Map.Entry<String, Object> entry : map.entrySet()) { result.put(entry.getKey(), new StringByteIterator(entry.getValue().toString())); } } else { for (String field : fields) { Object value = map.get(field); if (value != null) { result.put(field, new StringByteIterator(value.toString())); } } } return Status.OK; } catch (XDMException ex) { logger.error("read.error", ex); return Status.ERROR; } }
@Override public Status delete(final String table, final String key) { XDMDocumentId xid = new XDMDocumentId(0, key); try { xRepo.getDocumentManagement().removeDocument(xid); return Status.OK; } catch (XDMException ex) { logger.error("delete.error", ex); return Status.ERROR; } }
@Override @SuppressWarnings({"unchecked", "rawtypes"}) public Status insert( final String table, final String key, final HashMap<String, ByteIterator> values) { // logger.debug("insert.enter; table: {}; startKey: {}; values: {}", new Object[] {table, key, // values}); Properties props = new Properties(); props.setProperty(xdm_document_collections, table); // props.setProperty(xdm_document_data_format, "map"); XDMDocumentId xid = new XDMDocumentId(0, key); HashMap fields = StringByteIterator.getStringMap(values); try { xRepo.getDocumentManagement().storeDocumentFromMap(xid, fields, props); return Status.OK; } catch (XDMException ex) { logger.error("insert.error", ex); return Status.ERROR; } }
@Override public void cleanup() { logger.info("cleanup; xRepo: {}", xRepo); xRepo.close(); }