/** * Insert a record in the database. Any field/value pairs in the specified * values HashMap will be written into the record with the specified record * key. * * @param table * The name of the table * @param key * The record key of the record to insert. * @param values * A HashMap of field/value pairs to insert in the record * @return Zero on success, a non-zero error code on error. See the * {@link DB} class's description for a discussion of error codes. */ @Override public Status insert(String table, String key, Map<String, ByteIterator> values) { try { BaseDocument toInsert = new BaseDocument(key); for (Map.Entry<String, ByteIterator> entry : values.entrySet()) { toInsert.addAttribute(entry.getKey(), byteIteratorToString(entry.getValue())); } DocumentCreateOptions options = new DocumentCreateOptions().waitForSync(waitForSync); arangoDB.db(databaseName).collection(table).insertDocument(toInsert, options); return Status.OK; } catch (ArangoDBException e) { logger.error("Exception while trying insert {} {} with ex {}", table, key, e.toString()); } return Status.ERROR; }
@Override public <T> MultiDocumentEntity<? extends DocumentEntity> insert( final Iterable<T> values, final Class<T> entityClass) throws DataAccessException { return insert(values, entityClass, new DocumentCreateOptions()); }
@Override public <T> MultiDocumentEntity<DocumentCreateEntity<T>> insertDocuments(final Collection<T> values) throws ArangoDBException { return insertDocuments(values, new DocumentCreateOptions()); }
@Override public <T> MultiDocumentEntity<? extends DocumentEntity> insert( final Iterable<T> values, final Class<T> entityClass) throws DataAccessException { return insert(values, entityClass, new DocumentCreateOptions()); }
@Override public DocumentEntity insert(final Object value) throws DataAccessException { return insert(value, new DocumentCreateOptions()); }
@Override public DocumentEntity insert(final String collectionName, final Object value) throws DataAccessException { return insert(collectionName, value, new DocumentCreateOptions()); }
@Override public <T> DocumentCreateEntity<T> insertDocument(final T value) throws ArangoDBException { return insertDocument(value, new DocumentCreateOptions()); }
@Override public DocumentEntity insert(final Object value) throws DataAccessException { return insert(value, new DocumentCreateOptions()); }
@Override public <T> void repsert(final Iterable<T> value, final Class<T> entityClass) throws DataAccessException { insert(value, entityClass, new DocumentCreateOptions().overwrite(true)); }
@Override public <T> void repsert(final T value) throws DataAccessException { insert(value, new DocumentCreateOptions().overwrite(true)); }
@Override public <T> void repsert(final T value) throws DataAccessException { insert(value, new DocumentCreateOptions().overwrite(true)); }
@Override public <T> void repsert(final Iterable<T> value, final Class<T> entityClass) throws DataAccessException { insert(value, entityClass, new DocumentCreateOptions().overwrite(true)); }
@Override public <T> CompletableFuture<MultiDocumentEntity<DocumentCreateEntity<T>>> insertDocuments( final Collection<T> values, final DocumentCreateOptions options) { final DocumentCreateOptions params = (options != null ? options : new DocumentCreateOptions()); return executor.execute(insertDocumentsRequest(values, params), insertDocumentsResponseDeserializer(values, params)); }
@Override public <T> CompletableFuture<MultiDocumentEntity<DocumentCreateEntity<T>>> insertDocuments( final Collection<T> values) { final DocumentCreateOptions params = new DocumentCreateOptions(); return executor.execute(insertDocumentsRequest(values, params), insertDocumentsResponseDeserializer(values, params)); }
@Override public <T> CompletableFuture<DocumentCreateEntity<T>> insertDocument(final T value) { final DocumentCreateOptions options = new DocumentCreateOptions(); return executor.execute(insertDocumentRequest(value, options), insertDocumentResponseDeserializer(value, options)); }
@Override public <T> CompletableFuture<MultiDocumentEntity<DocumentCreateEntity<T>>> insertDocuments( final Collection<T> values) { final DocumentCreateOptions params = new DocumentCreateOptions(); return executor.execute(insertDocumentsRequest(values, params), insertDocumentsResponseDeserializer(values, params)); }
@Override public <T> MultiDocumentEntity<DocumentCreateEntity<T>> insertDocuments( final Collection<T> values, final DocumentCreateOptions options) throws ArangoDBException { final DocumentCreateOptions params = (options != null ? options : new DocumentCreateOptions()); return executor.execute(insertDocumentsRequest(values, params), insertDocumentsResponseDeserializer(values, params)); }
@Override public <T> CompletableFuture<DocumentCreateEntity<T>> insertDocument(final T value) { final DocumentCreateOptions options = new DocumentCreateOptions(); return executor.execute(insertDocumentRequest(value, options), insertDocumentResponseDeserializer(value, options)); }
@Override public <T> CompletableFuture<MultiDocumentEntity<DocumentCreateEntity<T>>> insertDocuments( final Collection<T> values, final DocumentCreateOptions options) { final DocumentCreateOptions params = (options != null ? options : new DocumentCreateOptions()); return executor.execute(insertDocumentsRequest(values, params), insertDocumentsResponseDeserializer(values, params)); }
protected <T> Request insertDocumentRequest(final T value, final DocumentCreateOptions options) { final Request request = request(db.name(), RequestType.POST, PATH_API_DOCUMENT, name); final DocumentCreateOptions params = (options != null ? options : new DocumentCreateOptions()); request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync()); request.putQueryParam(RETURN_NEW, params.getReturnNew()); request.putQueryParam(RETURN_OLD, params.getReturnOld()); request.putQueryParam(SILENT, params.getSilent()); request.putQueryParam(OVERWRITE, params.getOverwrite()); request.setBody(util(Serializer.CUSTOM).serialize(value)); return request; }