Search in sources :

Example 36 with EdgeLabel

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

the class TextSerializer method readEdgeLabel.

@Override
public EdgeLabel readEdgeLabel(HugeGraph graph, BackendEntry backendEntry) {
    if (backendEntry == null) {
        return null;
    }
    TextBackendEntry entry = this.convertEntry(backendEntry);
    Id id = readId(entry.id());
    String name = JsonUtil.fromJson(entry.column(HugeKeys.NAME), String.class);
    String sourceLabel = entry.column(HugeKeys.SOURCE_LABEL);
    String targetLabel = entry.column(HugeKeys.TARGET_LABEL);
    String frequency = entry.column(HugeKeys.FREQUENCY);
    String sortKeys = entry.column(HugeKeys.SORT_KEYS);
    String nullablekeys = entry.column(HugeKeys.NULLABLE_KEYS);
    String properties = entry.column(HugeKeys.PROPERTIES);
    String indexLabels = entry.column(HugeKeys.INDEX_LABELS);
    String enableLabelIndex = entry.column(HugeKeys.ENABLE_LABEL_INDEX);
    String status = entry.column(HugeKeys.STATUS);
    String ttl = entry.column(HugeKeys.TTL);
    String ttlStartTime = entry.column(HugeKeys.TTL_START_TIME);
    EdgeLabel edgeLabel = new EdgeLabel(graph, id, name);
    edgeLabel.sourceLabel(readId(sourceLabel));
    edgeLabel.targetLabel(readId(targetLabel));
    edgeLabel.frequency(JsonUtil.fromJson(frequency, Frequency.class));
    edgeLabel.properties(readIds(properties));
    edgeLabel.sortKeys(readIds(sortKeys));
    edgeLabel.nullableKeys(readIds(nullablekeys));
    edgeLabel.addIndexLabels(readIds(indexLabels));
    edgeLabel.enableLabelIndex(JsonUtil.fromJson(enableLabelIndex, Boolean.class));
    readUserdata(edgeLabel, entry);
    edgeLabel.status(JsonUtil.fromJson(status, SchemaStatus.class));
    edgeLabel.ttl(JsonUtil.fromJson(ttl, Long.class));
    edgeLabel.ttlStartTime(readId(ttlStartTime));
    return edgeLabel;
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) Frequency(com.baidu.hugegraph.type.define.Frequency) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) SchemaStatus(com.baidu.hugegraph.type.define.SchemaStatus)

Example 37 with EdgeLabel

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

the class SchemaTransaction method removeEdgeLabel.

@Watched(prefix = "schema")
public Id removeEdgeLabel(Id id) {
    LOG.debug("SchemaTransaction remove edge label '{}'", id);
    SchemaJob callable = new EdgeLabelRemoveJob();
    EdgeLabel schema = this.getEdgeLabel(id);
    return asyncRun(this.graph(), schema, callable);
}
Also used : EdgeLabelRemoveJob(com.baidu.hugegraph.job.schema.EdgeLabelRemoveJob) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaJob(com.baidu.hugegraph.job.schema.SchemaJob) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 38 with EdgeLabel

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

the class EdgeLabelBuilder method create.

@Override
public EdgeLabel create() {
    HugeType type = HugeType.EDGE_LABEL;
    this.checkSchemaName(this.name);
    return this.lockCheckAndCreateSchema(type, this.name, name -> {
        EdgeLabel edgeLabel = this.edgeLabelOrNull(this.name);
        if (edgeLabel != null) {
            if (this.checkExist || !hasSameProperties(edgeLabel)) {
                throw new ExistedException(type, this.name);
            }
            return edgeLabel;
        }
        this.checkSchemaIdIfRestoringMode(type, this.id);
        // These methods will check params and fill to member variables
        this.checkRelation();
        this.checkProperties(Action.INSERT);
        this.checkSortKeys();
        this.checkNullableKeys(Action.INSERT);
        Userdata.check(this.userdata, Action.INSERT);
        this.checkTtl();
        this.checkUserdata(Action.INSERT);
        edgeLabel = this.build();
        assert edgeLabel.name().equals(name);
        this.graph().addEdgeLabel(edgeLabel);
        return edgeLabel;
    });
}
Also used : ExistedException(com.baidu.hugegraph.exception.ExistedException) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeType(com.baidu.hugegraph.type.HugeType)

Example 39 with EdgeLabel

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

the class EdgeLabelBuilder method eliminate.

@Override
public EdgeLabel eliminate() {
    EdgeLabel edgeLabel = this.edgeLabelOrNull(this.name);
    if (edgeLabel == null) {
        throw new NotFoundException("Can't update edge 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);
    edgeLabel.removeUserdata(this.userdata);
    this.graph().addEdgeLabel(edgeLabel);
    return edgeLabel;
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) NotFoundException(com.baidu.hugegraph.exception.NotFoundException)

Example 40 with EdgeLabel

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

the class EdgeLabelBuilder method build.

@Override
public EdgeLabel build() {
    Id id = this.validOrGenerateId(HugeType.EDGE_LABEL, this.id, this.name);
    HugeGraph graph = this.graph();
    EdgeLabel edgeLabel = new EdgeLabel(graph, id, this.name);
    edgeLabel.sourceLabel(graph.vertexLabel(this.sourceLabel).id());
    edgeLabel.targetLabel(graph.vertexLabel(this.targetLabel).id());
    edgeLabel.frequency(this.frequency == Frequency.DEFAULT ? Frequency.SINGLE : this.frequency);
    edgeLabel.ttl(this.ttl);
    if (this.ttlStartTime != null) {
        edgeLabel.ttlStartTime(this.graph().propertyKey(this.ttlStartTime).id());
    }
    edgeLabel.enableLabelIndex(this.enableLabelIndex == null || this.enableLabelIndex);
    for (String key : this.properties) {
        PropertyKey propertyKey = graph.propertyKey(key);
        edgeLabel.property(propertyKey.id());
    }
    for (String key : this.sortKeys) {
        PropertyKey propertyKey = graph.propertyKey(key);
        edgeLabel.sortKey(propertyKey.id());
    }
    for (String key : this.nullableKeys) {
        PropertyKey propertyKey = graph.propertyKey(key);
        edgeLabel.nullableKey(propertyKey.id());
    }
    edgeLabel.userdata(this.userdata);
    return edgeLabel;
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) Id(com.baidu.hugegraph.backend.id.Id) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Aggregations

EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)58 Test (org.junit.Test)22 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)19 Id (com.baidu.hugegraph.backend.id.Id)16 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)12 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)11 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)11 HugeGraph (com.baidu.hugegraph.HugeGraph)10 Edge (org.apache.tinkerpop.gremlin.structure.Edge)10 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)8 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)7 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)6 Timed (com.codahale.metrics.annotation.Timed)5 RolesAllowed (jakarta.annotation.security.RolesAllowed)5 Produces (jakarta.ws.rs.Produces)5 Date (java.util.Date)4 GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)3 SchemaTransaction (com.baidu.hugegraph.backend.tx.SchemaTransaction)3 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)3 SchemaStatus (com.baidu.hugegraph.type.define.SchemaStatus)3