Search in sources :

Example 61 with VertexLabel

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

the class HugeVertexProperty method remove.

@Override
public void remove() {
    assert this.owner instanceof HugeVertex;
    VertexLabel vertexLabel = ((HugeVertex) this.owner).schemaLabel();
    E.checkArgument(vertexLabel.nullableKeys().contains(this.propertyKey().id()), "Can't remove non-null vertex property '%s'", this);
    this.owner.graph().removeVertexProperty(this);
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel)

Example 62 with VertexLabel

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

the class HugeEdge method constructEdge.

@Watched
public static HugeEdge constructEdge(HugeVertex ownerVertex, boolean isOutEdge, EdgeLabel edgeLabel, String sortValues, Id otherVertexId) {
    HugeGraph graph = ownerVertex.graph();
    VertexLabel srcLabel = graph.vertexLabelOrNone(edgeLabel.sourceLabel());
    VertexLabel tgtLabel = graph.vertexLabelOrNone(edgeLabel.targetLabel());
    VertexLabel otherVertexLabel;
    if (isOutEdge) {
        ownerVertex.correctVertexLabel(srcLabel);
        otherVertexLabel = tgtLabel;
    } else {
        ownerVertex.correctVertexLabel(tgtLabel);
        otherVertexLabel = srcLabel;
    }
    HugeVertex otherVertex = new HugeVertex(graph, otherVertexId, otherVertexLabel);
    ownerVertex.propNotLoaded();
    otherVertex.propNotLoaded();
    HugeEdge edge = new HugeEdge(graph, null, edgeLabel);
    edge.name(sortValues);
    edge.vertices(isOutEdge, ownerVertex, otherVertex);
    edge.assignId();
    if (isOutEdge) {
        ownerVertex.addOutEdge(edge);
        otherVertex.addInEdge(edge.switchOwner());
    } else {
        ownerVertex.addInEdge(edge);
        otherVertex.addOutEdge(edge.switchOwner());
    }
    return edge;
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 63 with VertexLabel

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

the class VertexLabelBuilder method append.

@Override
public VertexLabel append() {
    VertexLabel vertexLabel = this.vertexLabelOrNull(this.name);
    if (vertexLabel == null) {
        throw new NotFoundException("Can't update vertex label '%s' " + "since it doesn't exist", this.name);
    }
    this.checkStableVars();
    this.checkProperties(Action.APPEND);
    this.checkNullableKeys(Action.APPEND);
    Userdata.check(this.userdata, Action.APPEND);
    for (String key : this.properties) {
        PropertyKey propertyKey = this.graph().propertyKey(key);
        vertexLabel.property(propertyKey.id());
    }
    for (String key : this.nullableKeys) {
        PropertyKey propertyKey = this.graph().propertyKey(key);
        vertexLabel.nullableKey(propertyKey.id());
    }
    vertexLabel.userdata(this.userdata);
    this.graph().addVertexLabel(vertexLabel);
    return vertexLabel;
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 64 with VertexLabel

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

the class VertexLabelBuilder method create.

@Override
public VertexLabel create() {
    HugeType type = HugeType.VERTEX_LABEL;
    this.checkSchemaName(this.name);
    return this.lockCheckAndCreateSchema(type, this.name, name -> {
        VertexLabel vertexLabel = this.vertexLabelOrNull(name);
        if (vertexLabel != null) {
            if (this.checkExist || !hasSameProperties(vertexLabel)) {
                throw new ExistedException(type, name);
            }
            return vertexLabel;
        }
        this.checkSchemaIdIfRestoringMode(type, this.id);
        this.checkProperties(Action.INSERT);
        this.checkIdStrategy();
        this.checkNullableKeys(Action.INSERT);
        Userdata.check(this.userdata, Action.INSERT);
        this.checkTtl();
        this.checkUserdata(Action.INSERT);
        vertexLabel = this.build();
        assert vertexLabel.name().equals(name);
        this.graph().addVertexLabel(vertexLabel);
        return vertexLabel;
    });
}
Also used : ExistedException(com.baidu.hugegraph.exception.ExistedException) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) HugeType(com.baidu.hugegraph.type.HugeType)

Example 65 with VertexLabel

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

the class VertexLabelBuilder method eliminate.

@Override
public VertexLabel eliminate() {
    VertexLabel vertexLabel = this.vertexLabelOrNull(this.name);
    if (vertexLabel == null) {
        throw new NotFoundException("Can't update vertex label '%s' " + "since it doesn't exist", this.name);
    }
    // Only allowed to eliminate user data
    this.checkStableVars();
    this.checkProperties(Action.ELIMINATE);
    this.checkNullableKeys(Action.ELIMINATE);
    Userdata.check(this.userdata, Action.ELIMINATE);
    vertexLabel.removeUserdata(this.userdata);
    this.graph().addVertexLabel(vertexLabel);
    return vertexLabel;
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) NotFoundException(com.baidu.hugegraph.exception.NotFoundException)

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