Search in sources :

Example 46 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class EdgeLabelTest method testLinkedVertexLabel.

@Test
public void testLinkedVertexLabel() {
    SchemaManager schema = schema();
    EdgeLabel father = schema.edgeLabel("father").link("person", "person").properties("weight").userdata("multiplicity", "one-to-many").create();
    EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("multiplicity", "many-to-many").create();
    Assert.assertTrue(father.linkedVertexLabel("person"));
    Assert.assertFalse(father.linkedVertexLabel("book"));
    Assert.assertTrue(write.linkedVertexLabel("person"));
    Assert.assertTrue(write.linkedVertexLabel("book"));
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Test(org.junit.Test)

Example 47 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class EdgeLabelTest method testSetCheckExist.

@Test
public void testSetCheckExist() {
    SchemaManager schema = schema();
    EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("icon", "picture2").create();
    Assert.assertTrue(write.checkExist());
    write.checkExist(false);
    Assert.assertFalse(write.checkExist());
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Test(org.junit.Test)

Example 48 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class EdgeLabelTest method testAppendEdgeLabelWithUserData.

@Test
public void testAppendEdgeLabelWithUserData() {
    SchemaManager schema = schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").nullableKeys("city").ifNotExist().create();
    EdgeLabel father = schema.edgeLabel("father").link("person", "person").properties("weight").create();
    Assert.assertEquals(1, father.userdata().size());
    String time = (String) father.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
    father = schema.edgeLabel("father").userdata("multiplicity", "one-to-many").append();
    Assert.assertEquals(2, father.userdata().size());
    Assert.assertEquals("one-to-many", father.userdata().get("multiplicity"));
    time = (String) father.userdata().get("~create_time");
    Assert.assertEquals(createTime, DateUtil.parse(time));
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Date(java.util.Date) Test(org.junit.Test)

Example 49 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class EdgeApiTest method testAddEdgeWithTtlAndTtlStartTime.

@Test
public void testAddEdgeWithTtlAndTtlStartTime() {
    SchemaManager schema = schema();
    schema.propertyKey("place").asText().ifNotExist().create();
    schema.edgeLabel("borrow").link("person", "book").properties("place", "date").ttl(3000L).ttlStartTime("date").enableLabelIndex(true).ifNotExist().create();
    Vertex baby = graph().addVertex(T.label, "person", "name", "Baby", "age", 3, "city", "Beijing");
    Vertex java = graph().addVertex(T.label, "book", T.id, "java", "name", "Java in action");
    long date = DateUtil.now().getTime() - 1000L;
    String dateString = Utils.formatDate(new Date(date));
    Edge edge = baby.addEdge("borrow", java, "place", "library of school", "date", date);
    Edge result = graph().getEdge(edge.id());
    Assert.assertEquals("borrow", result.label());
    Assert.assertEquals("person", edge.sourceLabel());
    Assert.assertEquals("book", edge.targetLabel());
    Assert.assertEquals(baby.id(), edge.sourceId());
    Assert.assertEquals(java.id(), edge.targetId());
    Map<String, Object> props = ImmutableMap.of("place", "library of school", "date", dateString);
    Assert.assertEquals(props, result.properties());
    try {
        Thread.sleep(1100L);
    } catch (InterruptedException e) {
    // Ignore
    }
    result = graph().getEdge(edge.id());
    Assert.assertEquals("borrow", result.label());
    Assert.assertEquals("person", edge.sourceLabel());
    Assert.assertEquals("book", edge.targetLabel());
    Assert.assertEquals(baby.id(), edge.sourceId());
    Assert.assertEquals(java.id(), edge.targetId());
    Assert.assertEquals(props, result.properties());
    try {
        Thread.sleep(1100L);
    } catch (InterruptedException e) {
    // Ignore
    }
    Assert.assertThrows(ServerException.class, () -> {
        graph().getEdge(edge.id());
    }, e -> {
        Assert.assertContains("does not exist", e.getMessage());
    });
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Edge(com.baidu.hugegraph.structure.graph.Edge) Date(java.util.Date) Test(org.junit.Test)

Example 50 with SchemaManager

use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.

the class GraphsApiTest method initEdgeLabel.

protected static void initEdgeLabel(HugeClient client) {
    SchemaManager schema = client.schema();
    schema.edgeLabel("knows").sourceLabel("person").targetLabel("person").multiTimes().properties("date", "city").sortKeys("date").nullableKeys("city").ifNotExist().create();
    schema.edgeLabel("created").sourceLabel("person").targetLabel("software").properties("date", "city").nullableKeys("city").ifNotExist().create();
}
Also used : SchemaManager(com.baidu.hugegraph.driver.SchemaManager)

Aggregations

SchemaManager (com.baidu.hugegraph.driver.SchemaManager)61 Test (org.junit.Test)39 Vertex (com.baidu.hugegraph.structure.graph.Vertex)18 Date (java.util.Date)14 GraphManager (com.baidu.hugegraph.driver.GraphManager)11 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)11 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)9 HugeClient (com.baidu.hugegraph.driver.HugeClient)8 BeforeClass (org.junit.BeforeClass)8 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)7 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)6 Edge (com.baidu.hugegraph.structure.graph.Edge)4 ArrayList (java.util.ArrayList)3 PropertyIndex (com.baidu.hugegraph.entity.schema.PropertyIndex)2 Task (com.baidu.hugegraph.structure.Task)2 Result (com.baidu.hugegraph.structure.gremlin.Result)2 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)2 BaseClientTest (com.baidu.hugegraph.BaseClientTest)1 GremlinManager (com.baidu.hugegraph.driver.GremlinManager)1 LoadOptions (com.baidu.hugegraph.loader.executor.LoadOptions)1