com.arangodb.model.DocumentCreateOptions Java Examples

The following examples show how to use com.arangodb.model.DocumentCreateOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomSerdeTest.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Test
public void insertDocument() throws ExecutionException, InterruptedException {
    String key = "test-" + UUID.randomUUID().toString();

    BaseDocument doc = new BaseDocument(key);
    doc.addAttribute("arr", Collections.singletonList("hello"));
    doc.addAttribute("int", 10);

    BaseDocument result = collection.insertDocument(
            doc,
            new DocumentCreateOptions().returnNew(true)
    ).get().getNew();

    assertThat(result.getAttribute("arr"), instanceOf(String.class));
    assertThat(result.getAttribute("arr"), is("hello"));
    assertThat(result.getAttribute("int"), instanceOf(BigInteger.class));
    assertThat(result.getAttribute("int"), is(BigInteger.valueOf(10)));
}
 
Example #2
Source File: ArangoTemplate.java    From spring-data with Apache License 2.0 6 votes vote down vote up
@Override
public DocumentEntity insert(final String collectionName, final Object value, final DocumentCreateOptions options)
		throws DataAccessException {
	potentiallyEmitEvent(new BeforeSaveEvent<>(value));

	final DocumentEntity result;
	try {
		result = _collection(collectionName).insertDocument(toVPack(value), options);
	} catch (final ArangoDBException e) {
		throw exceptionTranslator.translateExceptionIfPossible(e);
	}

	updateDBFields(value, result);
	potentiallyEmitEvent(new AfterSaveEvent<>(value));
	return result;
}
 
Example #3
Source File: CustomSerdeTest.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Test
public void insertDocument() {
    String key = "test-" + UUID.randomUUID().toString();

    BaseDocument doc = new BaseDocument(key);
    doc.addAttribute("arr", Collections.singletonList("hello"));
    doc.addAttribute("int", 10);

    BaseDocument result = collection.insertDocument(
            doc,
            new DocumentCreateOptions().returnNew(true)
    ).getNew();

    assertThat(result.getAttribute("arr"), instanceOf(String.class));
    assertThat(result.getAttribute("arr"), is("hello"));
    assertThat(result.getAttribute("int"), instanceOf(BigInteger.class));
    assertThat(result.getAttribute("int"), is(BigInteger.valueOf(10)));
}
 
Example #4
Source File: CustomSerdeTest.java    From arangodb-java-driver-async with Apache License 2.0 6 votes vote down vote up
@Test
public void insertDocument() throws ExecutionException, InterruptedException {
    String key = "test-" + UUID.randomUUID().toString();

    BaseDocument doc = new BaseDocument(key);
    doc.addAttribute("arr", Collections.singletonList("hello"));
    doc.addAttribute("int", 10);

    BaseDocument result = collection.insertDocument(
            doc,
            new DocumentCreateOptions().returnNew(true)
    ).get().getNew();

    assertThat(result.getAttribute("arr"), instanceOf(String.class));
    assertThat(result.getAttribute("arr"), is("hello"));
    assertThat(result.getAttribute("int"), instanceOf(BigInteger.class));
    assertThat(result.getAttribute("int"), is(BigInteger.valueOf(10)));
}
 
Example #5
Source File: ArangoTemplate.java    From spring-data with Apache License 2.0 6 votes vote down vote up
@Override
public <T> MultiDocumentEntity<? extends DocumentEntity> insert(
	final Iterable<T> values,
	final Class<T> entityClass,
	final DocumentCreateOptions options) throws DataAccessException {

	potentiallyEmitBeforeSaveEvent(values);

	final MultiDocumentEntity<? extends DocumentEntity> result;
	try {
		result = _collection(entityClass).insertDocuments(toVPackCollection(values), options);
	} catch (final ArangoDBException e) {
		throw translateExceptionIfPossible(e);
	}

	updateDBFields(values, result);
	potentiallyEmitAfterSaveEvent(values, result);
	return result;
}
 
Example #6
Source File: ConcurrentStreamTransactionsTest.java    From arangodb-java-driver-async with Apache License 2.0 5 votes vote down vote up
@Test
 public void conflictOnInsertDocumentWithNotYetCommittedTx() throws ExecutionException, InterruptedException {
     assumeTrue(isSingleServer());
     assumeTrue(isAtLeastVersion(3, 5));
     assumeTrue(isStorageEngine(ArangoDBEngine.StorageEngineName.rocksdb));

     StreamTransactionEntity tx1 = db.beginStreamTransaction(
             new StreamTransactionOptions().readCollections(COLLECTION_NAME).writeCollections(COLLECTION_NAME)).get();

     StreamTransactionEntity tx2 = db.beginStreamTransaction(
             new StreamTransactionOptions().readCollections(COLLECTION_NAME).writeCollections(COLLECTION_NAME)).get();

     String key = UUID.randomUUID().toString();

     // insert a document from within tx1
     db.collection(COLLECTION_NAME)
             .insertDocument(new BaseDocument(key), new DocumentCreateOptions().streamTransactionId(tx1.getId())).get();

     try {
         // insert conflicting document from within tx2
         db.collection(COLLECTION_NAME).insertDocument(new BaseDocument(key),
                 new DocumentCreateOptions().streamTransactionId(tx2.getId())).get();
fail();
     } catch (ExecutionException e) {
         assertThat(e.getCause(), Matchers.instanceOf(ArangoDBException.class));
e.getCause().printStackTrace();
     }

     db.abortStreamTransaction(tx1.getId()).get();
     db.abortStreamTransaction(tx2.getId()).get();
 }
 
Example #7
Source File: StreamTransactionTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void insertDocumentWithNonExistingTransactionIdShouldThrow() throws ExecutionException, InterruptedException {
    assumeTrue(isSingleServer());
    assumeTrue(isAtLeastVersion(3, 5));
    assumeTrue(isStorageEngine(ArangoDBEngine.StorageEngineName.rocksdb));

    try {
        db.collection(COLLECTION_NAME)
                .insertDocument(new BaseDocument(), new DocumentCreateOptions().streamTransactionId("123456")).get();
        fail();
    } catch (ExecutionException e) {
        assertThat(e.getCause(), instanceOf(ArangoDBException.class));
    }
}
 
Example #8
Source File: StreamTransactionConflictsTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void conflictOnInsertDocumentWithAlreadyCommittedTx() throws ExecutionException, InterruptedException {
    assumeTrue(isSingleServer());
    assumeTrue(isAtLeastVersion(3, 5));
    assumeTrue(isStorageEngine(ArangoDBEngine.StorageEngineName.rocksdb));

    StreamTransactionEntity tx1 = db.beginStreamTransaction(
            new StreamTransactionOptions().readCollections(COLLECTION_NAME).writeCollections(COLLECTION_NAME)).get();

    StreamTransactionEntity tx2 = db.beginStreamTransaction(
            new StreamTransactionOptions().readCollections(COLLECTION_NAME).writeCollections(COLLECTION_NAME)).get();

    String key = UUID.randomUUID().toString();

    // insert a document from within tx1
    db.collection(COLLECTION_NAME)
            .insertDocument(new BaseDocument(key), new DocumentCreateOptions().streamTransactionId(tx1.getId())).get();

    // commit tx1
    db.commitStreamTransaction(tx1.getId()).get();

    try {
        // insert conflicting document from within tx2
        db.collection(COLLECTION_NAME).insertDocument(new BaseDocument(key),
                new DocumentCreateOptions().streamTransactionId(tx2.getId())).get();
        fail();
    } catch (ExecutionException e) {
        assertThat(e.getCause(), Matchers.instanceOf(ArangoDBException.class));
        e.getCause().printStackTrace();
    }

    db.abortStreamTransaction(tx2.getId()).get();
}
 
Example #9
Source File: StreamTransactionConflictsTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void conflictOnInsertDocumentWithNotYetCommittedTx() throws ExecutionException, InterruptedException {
    assumeTrue(isSingleServer());
    assumeTrue(isAtLeastVersion(3, 5));
    assumeTrue(isStorageEngine(ArangoDBEngine.StorageEngineName.rocksdb));

    StreamTransactionEntity tx1 = db.beginStreamTransaction(
            new StreamTransactionOptions().readCollections(COLLECTION_NAME).writeCollections(COLLECTION_NAME)).get();

    StreamTransactionEntity tx2 = db.beginStreamTransaction(
            new StreamTransactionOptions().readCollections(COLLECTION_NAME).writeCollections(COLLECTION_NAME)).get();

    String key = UUID.randomUUID().toString();

    // insert a document from within tx1
    db.collection(COLLECTION_NAME)
            .insertDocument(new BaseDocument(key), new DocumentCreateOptions().streamTransactionId(tx1.getId())).get();

    try {
        // insert conflicting document from within tx2
        db.collection(COLLECTION_NAME).insertDocument(new BaseDocument(key),
                new DocumentCreateOptions().streamTransactionId(tx2.getId())).get();
        fail();
    } catch (ExecutionException e) {
        assertThat(e.getCause(), Matchers.instanceOf(ArangoDBException.class));
        e.getCause().printStackTrace();
    }

    db.abortStreamTransaction(tx1.getId()).get();
    db.abortStreamTransaction(tx2.getId()).get();
}
 
Example #10
Source File: CustomTypeHintTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void insertDocument() {
    Gorilla gorilla = new Gorilla();
    gorilla.setName("kingKong");

    Zoo doc = new Zoo();
    doc.setAnimal(gorilla);

    Zoo insertedDoc = collection.insertDocument(
            doc,
            new DocumentCreateOptions().returnNew(true)
    ).getNew();

    assertThat((insertedDoc.getAnimal().getName()), is("kingKong"));

    String key = insertedDoc.getKey();

    // in the db a document like this is created:
    //        {
    //            "animal": {
    //                  "type": "com.arangodb.serde.CustomTypeHintTest$Gorilla",
    //                      "name": "kingKong"
    //            }
    //        }

    final Zoo readDoc = collection.getDocument(
            key,
            Zoo.class,
            null);

    assertThat((readDoc.getAnimal().getName()), is("kingKong"));
}
 
Example #11
Source File: StreamTransactionConflictsTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void conflictOnInsertDocumentWithAlreadyCommittedTx() {
    assumeTrue(isSingleServer());
    assumeTrue(isAtLeastVersion(3, 5));
    assumeTrue(isStorageEngine(ArangoDBEngine.StorageEngineName.rocksdb));

    StreamTransactionEntity tx1 = db.beginStreamTransaction(
            new StreamTransactionOptions().readCollections(COLLECTION_NAME).writeCollections(COLLECTION_NAME));

    StreamTransactionEntity tx2 = db.beginStreamTransaction(
            new StreamTransactionOptions().readCollections(COLLECTION_NAME).writeCollections(COLLECTION_NAME));

    String key = UUID.randomUUID().toString();

    // insert a document from within tx1
    db.collection(COLLECTION_NAME)
            .insertDocument(new BaseDocument(key), new DocumentCreateOptions().streamTransactionId(tx1.getId()));

    // commit tx1
    db.commitStreamTransaction(tx1.getId());

    try {
        // insert conflicting document from within tx2
        db.collection(COLLECTION_NAME).insertDocument(new BaseDocument(key),
                new DocumentCreateOptions().streamTransactionId(tx2.getId()));

        fail();
    } catch (ArangoDBException e) {
        e.printStackTrace();
    }

    db.abortStreamTransaction(tx2.getId());
}
 
Example #12
Source File: StreamTransactionConflictsTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore
public void conflictOnInsertDocumentWithNotYetCommittedTx() {
    assumeTrue(isSingleServer());
    assumeTrue(isAtLeastVersion(3, 5));
    assumeTrue(isStorageEngine(ArangoDBEngine.StorageEngineName.rocksdb));

    StreamTransactionEntity tx1 = db.beginStreamTransaction(
            new StreamTransactionOptions().readCollections(COLLECTION_NAME).writeCollections(COLLECTION_NAME));

    StreamTransactionEntity tx2 = db.beginStreamTransaction(
            new StreamTransactionOptions().readCollections(COLLECTION_NAME).writeCollections(COLLECTION_NAME));

    String key = UUID.randomUUID().toString();

    // insert a document from within tx1
    db.collection(COLLECTION_NAME)
            .insertDocument(new BaseDocument(key), new DocumentCreateOptions().streamTransactionId(tx1.getId()));

    try {
        // insert conflicting document from within tx2
        db.collection(COLLECTION_NAME).insertDocument(new BaseDocument(key),
                new DocumentCreateOptions().streamTransactionId(tx2.getId()));

        fail();
    } catch (ArangoDBException e) {
        e.printStackTrace();
    }

    db.abortStreamTransaction(tx1.getId());
    db.abortStreamTransaction(tx2.getId());
}
 
Example #13
Source File: StreamTransactionTest.java    From arangodb-java-driver-async with Apache License 2.0 5 votes vote down vote up
@Test
public void insertDocumentWithNonExistingTransactionIdShouldThrow() throws ExecutionException, InterruptedException {
    assumeTrue(isSingleServer());
    assumeTrue(isAtLeastVersion(3, 5));
    assumeTrue(isStorageEngine(ArangoDBEngine.StorageEngineName.rocksdb));

    try {
        db.collection(COLLECTION_NAME)
                .insertDocument(new BaseDocument(), new DocumentCreateOptions().streamTransactionId("123456")).get();
        fail();
    } catch (ExecutionException e) {
        assertThat(e.getCause(), instanceOf(ArangoDBException.class));
    }
}
 
Example #14
Source File: ConcurrentStreamTransactionsTest.java    From arangodb-java-driver-async with Apache License 2.0 5 votes vote down vote up
@Test
public void conflictOnInsertDocumentWithAlreadyCommittedTx() throws ExecutionException, InterruptedException {
    assumeTrue(isSingleServer());
    assumeTrue(isAtLeastVersion(3, 5));
    assumeTrue(isStorageEngine(ArangoDBEngine.StorageEngineName.rocksdb));

    StreamTransactionEntity tx1 = db.beginStreamTransaction(
            new StreamTransactionOptions().readCollections(COLLECTION_NAME).writeCollections(COLLECTION_NAME)).get();

    StreamTransactionEntity tx2 = db.beginStreamTransaction(
            new StreamTransactionOptions().readCollections(COLLECTION_NAME).writeCollections(COLLECTION_NAME)).get();

    String key = UUID.randomUUID().toString();

    // insert a document from within tx1
    db.collection(COLLECTION_NAME)
            .insertDocument(new BaseDocument(key), new DocumentCreateOptions().streamTransactionId(tx1.getId())).get();

    // commit tx1
    db.commitStreamTransaction(tx1.getId()).get();

    try {
        // insert conflicting document from within tx2
        db.collection(COLLECTION_NAME).insertDocument(new BaseDocument(key),
                new DocumentCreateOptions().streamTransactionId(tx2.getId())).get();
        fail();
    } catch (ExecutionException e) {
        assertThat(e.getCause(), Matchers.instanceOf(ArangoDBException.class));
        e.getCause().printStackTrace();
    }

    db.abortStreamTransaction(tx2.getId()).get();
}
 
Example #15
Source File: ArangoTemplate.java    From spring-data with Apache License 2.0 5 votes vote down vote up
@Override
public DocumentEntity insert(final Object value, final DocumentCreateOptions options) throws DataAccessException {
	potentiallyEmitEvent(new BeforeSaveEvent<>(value));

	final DocumentEntity result;
	try {
		result = _collection(value.getClass()).insertDocument(toVPack(value), options);
	} catch (final ArangoDBException e) {
		throw exceptionTranslator.translateExceptionIfPossible(e);
	}

	updateDBFields(value, result);
	potentiallyEmitEvent(new AfterSaveEvent<>(value));
	return result;
}
 
Example #16
Source File: ArangoTemplate.java    From spring-data with Apache License 2.0 4 votes vote down vote up
@Override
public <T> void repsert(final Iterable<T> value, final Class<T> entityClass) throws DataAccessException {
	insert(value, entityClass, new DocumentCreateOptions().overwrite(true));
}
 
Example #17
Source File: ArangoTemplate.java    From spring-data with Apache License 2.0 4 votes vote down vote up
@Override
public <T> void repsert(final T value) throws DataAccessException {
	insert(value, new DocumentCreateOptions().overwrite(true));
}
 
Example #18
Source File: ArangoTemplate.java    From spring-data with Apache License 2.0 4 votes vote down vote up
@Override
public DocumentEntity insert(final String collectionName, final Object value) throws DataAccessException {
	return insert(collectionName, value, new DocumentCreateOptions());
}
 
Example #19
Source File: ArangoTemplate.java    From spring-data with Apache License 2.0 4 votes vote down vote up
@Override
public DocumentEntity insert(final Object value) throws DataAccessException {
	return insert(value, new DocumentCreateOptions());
}
 
Example #20
Source File: ArangoTemplate.java    From spring-data with Apache License 2.0 4 votes vote down vote up
@Override
public <T> MultiDocumentEntity<? extends DocumentEntity> insert(
	final Iterable<T> values,
	final Class<T> entityClass) throws DataAccessException {
	return insert(values, entityClass, new DocumentCreateOptions());
}
 
Example #21
Source File: ArangoOperations.java    From spring-data with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new document from the given document, unless there is already a document with the _key given. If no
 * _key is given, a new unique _key is generated automatically.
 *
 * @param collectionName
 *            Name of the collection in which the new document should be inserted
 * @param value
 *            A representation of a single document
 * @param options
 *            Additional options, can be null
 * @return information about the document
 * @throws DataAccessException
 */
DocumentEntity insert(String collectionName, Object value, DocumentCreateOptions options)
		throws DataAccessException;
 
Example #22
Source File: ArangoOperations.java    From spring-data with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new document from the given document, unless there is already a document with the _key given. If no
 * _key is given, a new unique _key is generated automatically.
 *
 * @param value
 *            A representation of a single document
 * @param options
 *            Additional options, can be null
 * @return information about the document
 */
<T> DocumentEntity insert(T value, DocumentCreateOptions options) throws DataAccessException;
 
Example #23
Source File: ArangoOperations.java    From spring-data with Apache License 2.0 2 votes vote down vote up
/**
 * Creates new documents from the given documents, unless there is already a document with the _key given. If no
 * _key is given, a new unique _key is generated automatically.
 *
 * @param <T>
 *
 * @param values
 *            A List of documents
 * @param entityClass
 *            The entity class which represents the collection
 * @param options
 *            Additional options, can be null
 * @return information about the documents
 * @throws DataAccessException
 */
<T> MultiDocumentEntity<? extends DocumentEntity> insert(
	Iterable<T> values,
	Class<T> entityClass,
	DocumentCreateOptions options) throws DataAccessException;