Search in sources :

Example 41 with VertexLabel

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

the class GraphTransaction method checkVertexExistIfCustomizedId.

private void checkVertexExistIfCustomizedId(Map<Id, HugeVertex> vertices) {
    Set<Id> ids = new HashSet<>();
    for (HugeVertex vertex : vertices.values()) {
        VertexLabel vl = vertex.schemaLabel();
        if (!vl.hidden() && vl.idStrategy().isCustomized()) {
            ids.add(vertex.id());
        }
    }
    if (ids.isEmpty()) {
        return;
    }
    IdQuery idQuery = new IdQuery(HugeType.VERTEX, ids);
    Iterator<HugeVertex> results = this.queryVerticesFromBackend(idQuery);
    try {
        if (!results.hasNext()) {
            return;
        }
        HugeVertex existedVertex = results.next();
        HugeVertex newVertex = vertices.get(existedVertex.id());
        if (!existedVertex.label().equals(newVertex.label())) {
            throw new HugeException("The newly added vertex with id:'%s' label:'%s' " + "is not allowed to insert, because already exist " + "a vertex with same id and different label:'%s'", newVertex.id(), newVertex.label(), existedVertex.label());
        }
    } finally {
        CloseableIterator.closeIterator(results);
    }
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) IdQuery(com.baidu.hugegraph.backend.query.IdQuery) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) HugeException(com.baidu.hugegraph.HugeException) HashSet(java.util.HashSet)

Example 42 with VertexLabel

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

the class SchemaTransaction method removePropertyKey.

@Watched(prefix = "schema")
public Id removePropertyKey(Id id) {
    LOG.debug("SchemaTransaction remove property key '{}'", id);
    PropertyKey propertyKey = this.getPropertyKey(id);
    // If the property key does not exist, return directly
    if (propertyKey == null) {
        return null;
    }
    List<VertexLabel> vertexLabels = this.getVertexLabels();
    for (VertexLabel vertexLabel : vertexLabels) {
        if (vertexLabel.properties().contains(id)) {
            throw new NotAllowException("Not allowed to remove property key: '%s' " + "because the vertex label '%s' is still using it.", propertyKey, vertexLabel.name());
        }
    }
    List<EdgeLabel> edgeLabels = this.getEdgeLabels();
    for (EdgeLabel edgeLabel : edgeLabels) {
        if (edgeLabel.properties().contains(id)) {
            throw new NotAllowException("Not allowed to remove property key: '%s' " + "because the edge label '%s' is still using it.", propertyKey, edgeLabel.name());
        }
    }
    if (propertyKey.oltp()) {
        this.removeSchema(propertyKey);
        return IdGenerator.ZERO;
    } else {
        return this.removeOlapPk(propertyKey);
    }
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) NotAllowException(com.baidu.hugegraph.exception.NotAllowException) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 43 with VertexLabel

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

the class SchemaTransaction method removeVertexLabel.

@Watched(prefix = "schema")
public Id removeVertexLabel(Id id) {
    LOG.debug("SchemaTransaction remove vertex label '{}'", id);
    SchemaJob callable = new VertexLabelRemoveJob();
    VertexLabel schema = this.getVertexLabel(id);
    return asyncRun(this.graph(), schema, callable);
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) VertexLabelRemoveJob(com.baidu.hugegraph.job.schema.VertexLabelRemoveJob) SchemaJob(com.baidu.hugegraph.job.schema.SchemaJob) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 44 with VertexLabel

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

the class EdgeAPI method newVertex.

private static Vertex newVertex(HugeGraph g, Object id, String label) {
    VertexLabel vl = vertexLabel(g, label, "Invalid vertex label '%s'");
    Id idValue = HugeVertex.getIdValue(id);
    return new HugeVertex(g, idValue, vl);
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 45 with VertexLabel

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

the class VertexAPI method getVertexId.

private static Id getVertexId(HugeGraph g, JsonVertex vertex) {
    VertexLabel vertexLabel = g.vertexLabel(vertex.label);
    String labelId = vertexLabel.id().asString();
    IdStrategy idStrategy = vertexLabel.idStrategy();
    E.checkArgument(idStrategy != IdStrategy.AUTOMATIC, "Automatic Id strategy is not supported now");
    if (idStrategy == IdStrategy.PRIMARY_KEY) {
        List<Id> pkIds = vertexLabel.primaryKeys();
        List<Object> pkValues = new ArrayList<>(pkIds.size());
        for (Id pkId : pkIds) {
            String propertyKey = g.propertyKey(pkId).name();
            Object propertyValue = vertex.properties.get(propertyKey);
            E.checkArgument(propertyValue != null, "The value of primary key '%s' can't be null", propertyKey);
            pkValues.add(propertyValue);
        }
        String value = ConditionQuery.concatValues(pkValues);
        return SplicingIdGenerator.splicing(labelId, value);
    } else if (idStrategy == IdStrategy.CUSTOMIZE_UUID) {
        return Text.uuid(String.valueOf(vertex.id));
    } else {
        assert idStrategy == IdStrategy.CUSTOMIZE_NUMBER || idStrategy == IdStrategy.CUSTOMIZE_STRING;
        return HugeVertex.getIdValue(vertex.id);
    }
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) IdStrategy(com.baidu.hugegraph.type.define.IdStrategy) ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id)

Aggregations

VertexLabel (com.baidu.hugegraph.schema.VertexLabel)86 Test (org.junit.Test)35 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)27 Id (com.baidu.hugegraph.backend.id.Id)23 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)20 HugeGraph (com.baidu.hugegraph.HugeGraph)19 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)19 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)12 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)12 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)11 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)7 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)6 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)5 Timed (com.codahale.metrics.annotation.Timed)5 RolesAllowed (jakarta.annotation.security.RolesAllowed)5 Produces (jakarta.ws.rs.Produces)5 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)4 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)4 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)4 Date (java.util.Date)4