Search in sources :

Example 16 with VertexLabel

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

the class EdgeLabelService method reuse.

public void reuse(ConflictDetail detail, int connId) {
    Ex.check(!detail.hasConflict(), "schema.cannot-reuse-conflict");
    HugeClient client = this.client(connId);
    List<PropertyKey> propertyKeys = this.pkService.filter(detail, client);
    if (!propertyKeys.isEmpty()) {
        try {
            this.pkService.addBatch(propertyKeys, client);
        } catch (Exception e) {
            throw new ExternalException("schema.propertykey.reuse.failed", e);
        }
    }
    List<VertexLabel> vertexLabels = this.vlService.filter(detail, client);
    if (!vertexLabels.isEmpty()) {
        try {
            this.vlService.addBatch(vertexLabels, client);
        } catch (Exception e) {
            this.pkService.removeBatch(propertyKeys, client);
            throw new ExternalException("schema.vertexlabel.reuse.failed", e);
        }
    }
    List<EdgeLabel> edgeLabels = this.filter(detail, client);
    if (!edgeLabels.isEmpty()) {
        try {
            this.addBatch(edgeLabels, client);
        } catch (Exception e) {
            this.vlService.removeBatch(vertexLabels, client);
            this.pkService.removeBatch(propertyKeys, client);
            throw new ExternalException("schema.edgelabel.reuse.failed", e);
        }
    }
    List<IndexLabel> indexLabels = this.piService.filter(detail, client);
    if (!indexLabels.isEmpty()) {
        try {
            this.piService.addBatch(indexLabels, client);
        } catch (Exception e) {
            this.removeBatch(edgeLabels, client);
            this.vlService.removeBatch(vertexLabels, client);
            this.pkService.removeBatch(propertyKeys, client);
            throw new ExternalException("schema.propertyindex.reuse.failed", e);
        }
    }
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) ExternalException(com.baidu.hugegraph.exception.ExternalException) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey) ServerException(com.baidu.hugegraph.exception.ServerException) ExternalException(com.baidu.hugegraph.exception.ExternalException)

Example 17 with VertexLabel

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

the class VertexLabelService method update.

public void update(VertexLabelUpdateEntity entity, int connId) {
    HugeClient client = this.client(connId);
    VertexLabel vertexLabel = convert(entity, client);
    // All existed indexlabels
    List<IndexLabel> existedIndexLabels = client.schema().getIndexLabels();
    List<String> existedIndexLabelNames = collectNames(existedIndexLabels);
    List<String> addedIndexLabelNames = entity.getAppendPropertyIndexNames();
    List<IndexLabel> addedIndexLabels = convertIndexLabels(entity.getAppendPropertyIndexes(), client, true, entity.getName());
    List<String> removedIndexLabelNames = entity.getRemovePropertyIndexes();
    if (addedIndexLabelNames != null) {
        for (String name : addedIndexLabelNames) {
            if (existedIndexLabelNames.contains(name)) {
                throw new ExternalException("schema.vertexlabel.update.append-index-existed", entity.getName(), name);
            }
        }
    }
    if (removedIndexLabelNames != null) {
        for (String name : removedIndexLabelNames) {
            if (!existedIndexLabelNames.contains(name)) {
                throw new ExternalException("schema.vertexlabel.update.remove-index-unexisted", entity.getName(), name);
            }
        }
    }
    try {
        // NOTE: property can append but doesn't support eliminate now
        client.schema().appendVertexLabel(vertexLabel);
    } catch (Exception e) {
        throw new ExternalException("schema.vertexlabel.update.failed", e, entity.getName());
    }
    this.piService.addBatch(addedIndexLabels, client);
    this.piService.removeBatch(removedIndexLabelNames, client);
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ExternalException(com.baidu.hugegraph.exception.ExternalException) ServerException(com.baidu.hugegraph.exception.ServerException) ExternalException(com.baidu.hugegraph.exception.ExternalException)

Example 18 with VertexLabel

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

the class VertexLabelService method list.

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

Example 19 with VertexLabel

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

the class VertexLabelService method get.

public VertexLabelEntity get(String name, int connId) {
    HugeClient client = this.client(connId);
    try {
        VertexLabel vertexLabel = client.schema().getVertexLabel(name);
        List<IndexLabel> indexLabels = client.schema().getIndexLabels();
        return join(vertexLabel, indexLabels);
    } catch (ServerException e) {
        if (e.status() == Constant.STATUS_NOT_FOUND) {
            throw new ExternalException("schema.vertexlabel.not-exist", e, name);
        }
        throw new ExternalException("schema.vertexlabel.get.failed", e, name);
    }
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) ServerException(com.baidu.hugegraph.exception.ServerException) VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ExternalException(com.baidu.hugegraph.exception.ExternalException)

Example 20 with VertexLabel

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

the class VertexLabelService method add.

public void add(VertexLabelEntity entity, int connId) {
    HugeClient client = this.client(connId);
    VertexLabel vertexLabel = convert(entity, client);
    try {
        client.schema().addVertexLabel(vertexLabel);
    } catch (Exception e) {
        throw new ExternalException("schema.vertexlabel.create.failed", e, entity.getName());
    }
    List<IndexLabel> indexLabels = collectIndexLabels(entity, client);
    this.piService.addBatch(indexLabels, client);
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ExternalException(com.baidu.hugegraph.exception.ExternalException) ServerException(com.baidu.hugegraph.exception.ServerException) ExternalException(com.baidu.hugegraph.exception.ExternalException)

Aggregations

VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)46 Test (org.junit.Test)31 HugeClient (com.baidu.hugegraph.driver.HugeClient)7 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)7 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)6 ExternalException (com.baidu.hugegraph.exception.ExternalException)5 ServerException (com.baidu.hugegraph.exception.ServerException)5 Edge (com.baidu.hugegraph.structure.graph.Edge)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 RestResult (com.baidu.hugegraph.rest.RestResult)3 Vertex (com.baidu.hugegraph.structure.graph.Vertex)3 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)3 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)2 VertexLabelEntity (com.baidu.hugegraph.entity.schema.VertexLabelEntity)1 VertexLabelStyle (com.baidu.hugegraph.entity.schema.VertexLabelStyle)1 Record (com.baidu.hugegraph.loader.builder.Record)1 VertexBuilder (com.baidu.hugegraph.loader.builder.VertexBuilder)1 ParseException (com.baidu.hugegraph.loader.exception.ParseException)1 ElementMapping (com.baidu.hugegraph.loader.mapping.ElementMapping)1