Search in sources :

Example 26 with EdgeLabel

use of com.baidu.hugegraph.structure.schema.EdgeLabel in project incubator-hugegraph-toolchain by apache.

the class PropertyKeyService method checkUsing.

/**
 * Check the property key is being used, used means that there is
 * any vertex label or edge label contains the property(name)
 */
public boolean checkUsing(String name, int connId) {
    HugeClient client = this.client(connId);
    List<VertexLabel> vertexLabels = client.schema().getVertexLabels();
    for (VertexLabel vertexLabel : vertexLabels) {
        if (vertexLabel.properties().contains(name)) {
            return true;
        }
    }
    List<EdgeLabel> edgeLabels = client.schema().getEdgeLabels();
    for (EdgeLabel edgeLabel : edgeLabels) {
        if (edgeLabel.properties().contains(name)) {
            return true;
        }
    }
    return false;
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel)

Example 27 with EdgeLabel

use of com.baidu.hugegraph.structure.schema.EdgeLabel in project incubator-hugegraph-toolchain by apache.

the class VertexLabelService method checkUsing.

public boolean checkUsing(String name, int connId) {
    HugeClient client = this.client(connId);
    List<EdgeLabel> edgeLabels = client.schema().getEdgeLabels();
    for (EdgeLabel edgeLabel : edgeLabels) {
        if (edgeLabel.linkedVertexLabel(name)) {
            return true;
        }
    }
    return false;
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel)

Example 28 with EdgeLabel

use of com.baidu.hugegraph.structure.schema.EdgeLabel in project incubator-hugegraph-toolchain by apache.

the class EdgeLabelTest method testAddEdgeLabelWithUserData.

@Test
public void testAddEdgeLabelWithUserData() {
    SchemaManager schema = schema();
    EdgeLabel father = schema.edgeLabel("father").link("person", "person").properties("weight").userdata("multiplicity", "one-to-many").create();
    Assert.assertEquals(2, father.userdata().size());
    Assert.assertEquals("one-to-many", father.userdata().get("multiplicity"));
    String time = (String) father.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
    EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("multiplicity", "many-to-many").create();
    // The same key user data will be overwritten
    Assert.assertEquals(2, write.userdata().size());
    Assert.assertEquals("many-to-many", write.userdata().get("multiplicity"));
    time = (String) write.userdata().get("~create_time");
    createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Date(java.util.Date) Test(org.junit.Test)

Example 29 with EdgeLabel

use of com.baidu.hugegraph.structure.schema.EdgeLabel in project incubator-hugegraph-toolchain by apache.

the class EdgeLabelTest method testRemoveEdgeLabelSync.

@Test
public void testRemoveEdgeLabelSync() {
    SchemaManager schema = schema();
    EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("icon", "picture2").create();
    Assert.assertNotNull(write);
    // Remove edge label sync
    schema.removeEdgeLabel("write");
    write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("icon", "picture2").create();
    Assert.assertNotNull(write);
    // Remove edge label sync with timeout
    schema.removeEdgeLabel("write", 10);
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Test(org.junit.Test)

Example 30 with EdgeLabel

use of com.baidu.hugegraph.structure.schema.EdgeLabel 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)

Aggregations

EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)44 Test (org.junit.Test)31 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)9 HugeClient (com.baidu.hugegraph.driver.HugeClient)8 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)6 ExternalException (com.baidu.hugegraph.exception.ExternalException)4 ServerException (com.baidu.hugegraph.exception.ServerException)4 Date (java.util.Date)4 RestResult (com.baidu.hugegraph.rest.RestResult)3 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)3 ArrayList (java.util.ArrayList)3 Task (com.baidu.hugegraph.structure.Task)2 BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)1 EdgeLabelEntity (com.baidu.hugegraph.entity.schema.EdgeLabelEntity)1 EdgeLabelStyle (com.baidu.hugegraph.entity.schema.EdgeLabelStyle)1 Edge (com.baidu.hugegraph.structure.graph.Edge)1 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)1 HashSet (java.util.HashSet)1