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

The following examples show how to use com.arangodb.entity.BaseEdgeDocument#addAttribute() . 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 replaceEdge() 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.getProperties().clear();
    doc.addAttribute("b", "test");
    final EdgeUpdateEntity replaceResult = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME)
            .replaceEdge(createResult.getKey(), doc, null).get();
    assertThat(replaceResult, is(notNullValue()));
    assertThat(replaceResult.getId(), is(createResult.getId()));
    assertThat(replaceResult.getRev(), is(not(replaceResult.getOldRev())));
    assertThat(replaceResult.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.getRevision(), is(replaceResult.getRev()));
    assertThat(readResult.getProperties().keySet(), not(hasItem("a")));
    assertThat(readResult.getAttribute("b"), is(notNullValue()));
    assertThat(String.valueOf(readResult.getAttribute("b")), is("test"));
}
 
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 replaceEdgeIfMatch() 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.getProperties().clear();
    doc.addAttribute("b", "test");
    final EdgeReplaceOptions options = new EdgeReplaceOptions().ifMatch(createResult.getRev());
    final EdgeUpdateEntity replaceResult = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME)
            .replaceEdge(createResult.getKey(), doc, options).get();
    assertThat(replaceResult, is(notNullValue()));
    assertThat(replaceResult.getId(), is(createResult.getId()));
    assertThat(replaceResult.getRev(), is(not(replaceResult.getOldRev())));
    assertThat(replaceResult.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.getRevision(), is(replaceResult.getRev()));
    assertThat(readResult.getProperties().keySet(), not(hasItem("a")));
    assertThat(readResult.getAttribute("b"), is(notNullValue()));
    assertThat(String.valueOf(readResult.getAttribute("b")), is("test"));
}
 
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 replaceEdgeIfMatchFail() 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.getProperties().clear();
    doc.addAttribute("b", "test");
    try {
        final EdgeReplaceOptions options = new EdgeReplaceOptions().ifMatch("no");
        db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).replaceEdge(createResult.getKey(), doc, options)
                .get();
        fail();
    } catch (final ExecutionException e) {
        assertThat(e.getCause(), instanceOf(ArangoDBException.class));
    }
}
 
Example 4
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 5
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 6
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 7
Source File: AQLActorsAndMoviesExample.java    From arangodb-java-driver-async with Apache License 2.0 5 votes vote down vote up
private static void saveActsIn(
        final ArangoCollectionAsync actsIn,
        final String actor,
        final String movie,
        final String[] roles,
        final int year) throws InterruptedException, ExecutionException {
    final BaseEdgeDocument value = new BaseEdgeDocument();
    value.setFrom(actor);
    value.setTo(movie);
    value.addAttribute("roles", roles);
    value.addAttribute("year", year);
    actsIn.insertDocument(value).get();
}
 
Example 8
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 9
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"));
}
 
Example 10
Source File: AQLActorsAndMoviesExample.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
private static void saveActsIn(
        final ArangoCollection actsIn,
        final String actor,
        final String movie,
        final String[] roles,
        final int year) {
    final BaseEdgeDocument value = new BaseEdgeDocument();
    value.setFrom(actor);
    value.setTo(movie);
    value.addAttribute("roles", roles);
    value.addAttribute("year", year);
    actsIn.insertDocument(value);
}
 
Example 11
Source File: AQLActorsAndMoviesExample.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
private static void saveActsIn(
        final ArangoCollectionAsync actsIn,
        final String actor,
        final String movie,
        final String[] roles,
        final int year) throws InterruptedException, ExecutionException {
    final BaseEdgeDocument value = new BaseEdgeDocument();
    value.setFrom(actor);
    value.setTo(movie);
    value.addAttribute("roles", roles);
    value.addAttribute("year", year);
    actsIn.insertDocument(value).get();
}