/** * Read a record from the database. Each field/value pair from the result * will be stored in a HashMap. * * @param table * The name of the table * @param key * The record key of the record to read. * @param fields * The list of fields to read, or null for all of them * @param result * A HashMap of field/value pairs for the result * @return Zero on success, a non-zero error code on error or "not found". */ @Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try { VPackSlice document = arangoDB.db(databaseName).collection(table).getDocument(key, VPackSlice.class, null); if (!this.fillMap(result, document, fields)) { return Status.ERROR; } return Status.OK; } catch (ArangoDBException e) { logger.error("Exception while trying read {} {} with ex {}", table, key, e.toString()); } return Status.ERROR; }
@Override public <K> Iterable<Value> get(Iterable<K> keys) throws NullPointerException { return stream(keys.spliterator(), false) .map(Object::toString) .map(k -> arangoDB.db(bucketName).collection(namespace) .getDocument(k, BaseDocument.class)) .filter(Objects::nonNull) .map(TO_JSON) .map(ValueJSON::of) .collect(toList()); }
@Override public <K> Optional<Value> get(K key) throws NullPointerException { Objects.requireNonNull(key, "Key is required"); BaseDocument entity = arangoDB.db(bucketName).collection(namespace) .getDocument(key.toString(), BaseDocument.class); return ofNullable(entity) .map(TO_JSON) .map(ValueJSON::of); }
@Override public <T> T getDocument(final String id, final Class<T> type, final DocumentReadOptions options) throws ArangoDBException { DocumentUtil.validateDocumentId(id); final String[] split = id.split("/"); return collection(split[0]).getDocument(split[1], type, options); }
@Override public <T> T getDocument(final String id, final Class<T> type) throws ArangoDBException { DocumentUtil.validateDocumentId(id); final String[] split = id.split("/"); return collection(split[0]).getDocument(split[1], type); }
@Override public <T> Optional<T> find(final Object id, final Class<T> entityClass, final DocumentReadOptions options) throws DataAccessException { try { final VPackSlice doc = _collection(entityClass, id).getDocument(determineDocumentKeyFromId(id), VPackSlice.class, options); return Optional.ofNullable(fromVPack(entityClass, doc)); } catch (final ArangoDBException e) { throw translateExceptionIfPossible(e); } }
@Override public <T> Optional<T> find(final Object id, final Class<T> entityClass, final DocumentReadOptions options) throws DataAccessException { try { final VPackSlice doc = _collection(entityClass, id).getDocument(determineDocumentKeyFromId(id), VPackSlice.class, options); return Optional.ofNullable(fromVPack(entityClass, doc)); } catch (final ArangoDBException e) { throw translateExceptionIfPossible(e); } }