Java Code Examples for com.arangodb.entity.BaseEdgeDocument#updateAttribute()

The following examples show how to use com.arangodb.entity.BaseEdgeDocument#updateAttribute() . 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: ArangoEdgeCollectionTest.java    From arangodb-java-driver-async with Apache License 2.0 6 votes vote down vote up
@Test
public void updateEdgeIfMatchFail() throws InterruptedException, ExecutionException {
    final BaseEdgeDocument doc = createEdgeValue();
    doc.addAttribute("a", "test");
    doc.addAttribute("c", "test");
    final EdgeEntity createResult = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).insertEdge(doc, null)
            .get();
    doc.updateAttribute("a", "test1");
    doc.addAttribute("b", "test");
    doc.updateAttribute("c", null);
    try {
        final EdgeUpdateOptions options = new EdgeUpdateOptions().ifMatch("no");
        db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).updateEdge(createResult.getKey(), doc, options)
                .get();
        fail();
    } catch (final ExecutionException e) {
        assertThat(e.getCause(), instanceOf(ArangoDBException.class));
    }
}
 
Example 2
Source File: ArangoEdgeCollectionTest.java    From arangodb-java-driver-async with Apache License 2.0 6 votes vote down vote up
@Test
public void updateEdgeKeepNullTrue() throws InterruptedException, ExecutionException {
    final BaseEdgeDocument doc = createEdgeValue();
    doc.addAttribute("a", "test");
    final EdgeEntity createResult = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).insertEdge(doc, null)
            .get();
    doc.updateAttribute("a", null);
    final EdgeUpdateOptions options = new EdgeUpdateOptions().keepNull(true);
    final EdgeUpdateEntity updateResult = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME)
            .updateEdge(createResult.getKey(), doc, options).get();
    assertThat(updateResult, is(notNullValue()));
    assertThat(updateResult.getId(), is(createResult.getId()));
    assertThat(updateResult.getRev(), is(not(updateResult.getOldRev())));
    assertThat(updateResult.getOldRev(), is(createResult.getRev()));

    final BaseEdgeDocument readResult = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME)
            .getEdge(createResult.getKey(), BaseEdgeDocument.class, null).get();
    assertThat(readResult.getKey(), is(createResult.getKey()));
    assertThat(readResult.getProperties().keySet().size(), is(1));
    assertThat(readResult.getProperties().keySet(), hasItem("a"));
}
 
Example 3
Source File: ArangoEdgeCollectionTest.java    From arangodb-java-driver-async with Apache License 2.0 6 votes vote down vote up
@Test
public void updateEdgeKeepNullFalse() throws InterruptedException, ExecutionException {
    final BaseEdgeDocument doc = createEdgeValue();
    doc.addAttribute("a", "test");
    final EdgeEntity createResult = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).insertEdge(doc, null)
            .get();
    doc.updateAttribute("a", null);
    final EdgeUpdateOptions options = new EdgeUpdateOptions().keepNull(false);
    final EdgeUpdateEntity updateResult = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME)
            .updateEdge(createResult.getKey(), doc, options).get();
    assertThat(updateResult, is(notNullValue()));
    assertThat(updateResult.getId(), is(createResult.getId()));
    assertThat(updateResult.getRev(), is(not(updateResult.getOldRev())));
    assertThat(updateResult.getOldRev(), is(createResult.getRev()));

    final BaseEdgeDocument readResult = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME)
            .getEdge(createResult.getKey(), BaseEdgeDocument.class, null).get();
    assertThat(readResult.getKey(), is(createResult.getKey()));
    assertThat(readResult.getId(), is(createResult.getId()));
    assertThat(readResult.getRevision(), is(notNullValue()));
    assertThat(readResult.getProperties().keySet(), not(hasItem("a")));
}
 
Example 4
Source File: ArangoEdgeCollectionTest.java    From arangodb-java-driver-async with Apache License 2.0 5 votes vote down vote up
@Test
public void updateEdge() throws InterruptedException, ExecutionException {
    final BaseEdgeDocument doc = createEdgeValue();
    doc.addAttribute("a", "test");
    doc.addAttribute("c", "test");
    final EdgeEntity createResult = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).insertEdge(doc, null)
            .get();
    doc.updateAttribute("a", "test1");
    doc.addAttribute("b", "test");
    doc.updateAttribute("c", null);
    final EdgeUpdateEntity updateResult = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME)
            .updateEdge(createResult.getKey(), doc, null).get();
    assertThat(updateResult, is(notNullValue()));
    assertThat(updateResult.getId(), is(createResult.getId()));
    assertThat(updateResult.getRev(), is(not(updateResult.getOldRev())));
    assertThat(updateResult.getOldRev(), is(createResult.getRev()));

    final BaseEdgeDocument readResult = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME)
            .getEdge(createResult.getKey(), BaseEdgeDocument.class, null).get();
    assertThat(readResult.getKey(), is(createResult.getKey()));
    assertThat(readResult.getAttribute("a"), is(notNullValue()));
    assertThat(String.valueOf(readResult.getAttribute("a")), is("test1"));
    assertThat(readResult.getAttribute("b"), is(notNullValue()));
    assertThat(String.valueOf(readResult.getAttribute("b")), is("test"));
    assertThat(readResult.getRevision(), is(updateResult.getRev()));
    assertThat(readResult.getProperties().keySet(), hasItem("c"));
}
 
Example 5
Source File: ArangoEdgeCollectionTest.java    From arangodb-java-driver-async with Apache License 2.0 5 votes vote down vote up
@Test
public void updateEdgeIfMatch() throws InterruptedException, ExecutionException {
    final BaseEdgeDocument doc = createEdgeValue();
    doc.addAttribute("a", "test");
    doc.addAttribute("c", "test");
    final EdgeEntity createResult = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).insertEdge(doc, null)
            .get();
    doc.updateAttribute("a", "test1");
    doc.addAttribute("b", "test");
    doc.updateAttribute("c", null);
    final EdgeUpdateOptions options = new EdgeUpdateOptions().ifMatch(createResult.getRev());
    final EdgeUpdateEntity updateResult = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME)
            .updateEdge(createResult.getKey(), doc, options).get();
    assertThat(updateResult, is(notNullValue()));
    assertThat(updateResult.getId(), is(createResult.getId()));
    assertThat(updateResult.getRev(), is(not(updateResult.getOldRev())));
    assertThat(updateResult.getOldRev(), is(createResult.getRev()));

    final BaseEdgeDocument readResult = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME)
            .getEdge(createResult.getKey(), BaseEdgeDocument.class, null).get();
    assertThat(readResult.getKey(), is(createResult.getKey()));
    assertThat(readResult.getAttribute("a"), is(notNullValue()));
    assertThat(String.valueOf(readResult.getAttribute("a")), is("test1"));
    assertThat(readResult.getAttribute("b"), is(notNullValue()));
    assertThat(String.valueOf(readResult.getAttribute("b")), is("test"));
    assertThat(readResult.getRevision(), is(updateResult.getRev()));
    assertThat(readResult.getProperties().keySet(), hasItem("c"));
}