Search in sources :

Example 1 with HugeClient

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

the class GraphService method updateVertex.

public Vertex updateVertex(int connId, VertexEntity entity) {
    HugeClient client = this.client(connId);
    GraphManager graph = client.graph();
    Vertex vertex = this.buildVertex(connId, entity);
    // TODO: client should add updateVertex() method
    return graph.addVertex(vertex);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) HugeClient(com.baidu.hugegraph.driver.HugeClient) GraphManager(com.baidu.hugegraph.driver.GraphManager)

Example 2 with HugeClient

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

the class GraphService method fillProperties.

private void fillProperties(int connId, SchemaLabelEntity schema, GraphElement element, Map<String, Object> properties) {
    HugeClient client = this.client(connId);
    for (Map.Entry<String, Object> entry : properties.entrySet()) {
        String key = entry.getKey();
        Object rawValue = entry.getValue();
        // Skip nullable property
        if (schema.getNullableProps().contains(key)) {
            if (rawValue instanceof String && StringUtils.isEmpty((String) rawValue)) {
                continue;
            }
        }
        PropertyKeyEntity pkEntity = this.pkService.get(key, connId);
        PropertyKey propertyKey = PropertyKeyService.convert(pkEntity, client);
        assert propertyKey != null;
        Object value;
        try {
            // DataTypeUtil.convert in loader need param InputSource
            FileSource source = new FileSource();
            ListFormat listFormat = new ListFormat("", "", ",");
            source.listFormat(listFormat);
            value = DataTypeUtil.convert(rawValue, propertyKey, source);
        } catch (IllegalArgumentException e) {
            throw new ExternalException("graph.property.convert.failed", e, key, rawValue);
        }
        element.property(key, value);
    }
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) FileSource(com.baidu.hugegraph.loader.source.file.FileSource) ListFormat(com.baidu.hugegraph.loader.source.file.ListFormat) ExternalException(com.baidu.hugegraph.exception.ExternalException) Map(java.util.Map) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey) PropertyKeyEntity(com.baidu.hugegraph.entity.schema.PropertyKeyEntity)

Example 3 with HugeClient

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

the class GraphService method updateEdge.

public Edge updateEdge(int connId, EdgeEntity entity) {
    HugeClient client = this.client(connId);
    GraphManager graph = client.graph();
    EdgeHolder edgeHolder = this.buildEdge(connId, entity);
    // TODO: client should add updateEdge()
    return graph.addEdge(edgeHolder.edge);
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) GraphManager(com.baidu.hugegraph.driver.GraphManager)

Example 4 with HugeClient

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

the class GraphService method addEdge.

public GraphView addEdge(int connId, EdgeEntity entity) {
    HugeClient client = this.client(connId);
    GraphManager graph = client.graph();
    EdgeHolder edgeHolder = this.buildEdge(connId, entity);
    Edge edge = graph.addEdge(edgeHolder.edge);
    Vertex source = edgeHolder.source;
    Vertex target = edgeHolder.target;
    return GraphView.builder().vertices(ImmutableSet.of(source, target)).edges(ImmutableSet.of(edge)).build();
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) HugeClient(com.baidu.hugegraph.driver.HugeClient) GraphManager(com.baidu.hugegraph.driver.GraphManager) Edge(com.baidu.hugegraph.structure.graph.Edge)

Example 5 with HugeClient

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

the class EdgeLabelService method list.

public List<EdgeLabelEntity> list(Collection<String> names, int connId, boolean emptyAsAll) {
    HugeClient client = this.client(connId);
    List<EdgeLabel> edgeLabels;
    if (CollectionUtils.isEmpty(names)) {
        if (emptyAsAll) {
            edgeLabels = client.schema().getEdgeLabels();
        } else {
            edgeLabels = new ArrayList<>();
        }
    } else {
        edgeLabels = client.schema().getEdgeLabels(new ArrayList<>(names));
    }
    List<IndexLabel> indexLabels = client.schema().getIndexLabels();
    List<EdgeLabelEntity> results = new ArrayList<>(edgeLabels.size());
    edgeLabels.forEach(edgeLabel -> {
        results.add(convert(edgeLabel, indexLabels));
    });
    return results;
}
Also used : EdgeLabelEntity(com.baidu.hugegraph.entity.schema.EdgeLabelEntity) HugeClient(com.baidu.hugegraph.driver.HugeClient) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) ArrayList(java.util.ArrayList)

Aggregations

HugeClient (com.baidu.hugegraph.driver.HugeClient)66 Vertex (com.baidu.hugegraph.structure.graph.Vertex)21 ArrayList (java.util.ArrayList)16 ExternalException (com.baidu.hugegraph.exception.ExternalException)15 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)14 ServerException (com.baidu.hugegraph.exception.ServerException)12 GraphManager (com.baidu.hugegraph.driver.GraphManager)11 Edge (com.baidu.hugegraph.structure.graph.Edge)10 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)9 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)8 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)8 Test (org.junit.Test)8 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)7 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)6 ExecuteHistory (com.baidu.hugegraph.entity.query.ExecuteHistory)4 GraphView (com.baidu.hugegraph.entity.query.GraphView)4 LoadOptions (com.baidu.hugegraph.loader.executor.LoadOptions)4 ClientException (com.baidu.hugegraph.rest.ClientException)4 BeforeClass (org.junit.BeforeClass)4 GraphConnection (com.baidu.hugegraph.entity.GraphConnection)3