Search in sources :

Example 61 with PropertyKey

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

the class TextSerializer method parseProperty.

private void parseProperty(String colName, String colValue, HugeElement owner) {
    String[] colParts = SplicingIdGenerator.split(colName);
    assert colParts.length == 2 : colName;
    // Get PropertyKey by PropertyKey id
    PropertyKey pkey = owner.graph().propertyKey(readId(colParts[1]));
    // Parse value
    Object value = JsonUtil.fromJson(colValue, pkey.implementClazz());
    // Set properties of vertex/edge
    if (pkey.cardinality() == Cardinality.SINGLE) {
        owner.addProperty(pkey, value);
    } else {
        if (!(value instanceof Collection)) {
            throw new BackendException("Invalid value of non-single property: %s", colValue);
        }
        for (Object v : (Collection<?>) value) {
            v = JsonUtil.castNumber(v, pkey.dataType().clazz());
            owner.addProperty(pkey, v);
        }
    }
}
Also used : Collection(java.util.Collection) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 62 with PropertyKey

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

the class BinarySerializer method formatProperties.

protected void formatProperties(Collection<HugeProperty<?>> props, BytesBuffer buffer) {
    // Write properties size
    buffer.writeVInt(props.size());
    // Write properties data
    for (HugeProperty<?> property : props) {
        PropertyKey pkey = property.propertyKey();
        buffer.writeVInt(SchemaElement.schemaId(pkey.id()));
        buffer.writeProperty(pkey, property.value());
    }
}
Also used : PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 63 with PropertyKey

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

the class BackendStoreSystemInfo method init.

public synchronized void init() {
    if (this.exists()) {
        return;
    }
    // Set schema counter to reserve primitive system id
    this.schemaTx.setNextIdLowest(HugeType.SYS_SCHEMA, SchemaElement.MAX_PRIMITIVE_SYS_ID);
    HugeGraph graph = this.schemaTx.graph();
    E.checkState(this.info() == null, "Already exists backend info of graph '%s' in backend " + "'%s'", graph.name(), graph.backend());
    // Use property key to store backend version
    String backendVersion = graph.backendVersion();
    PropertyKey backendInfo = graph.schema().propertyKey(PK_BACKEND_INFO).userdata("version", backendVersion).build();
    this.schemaTx.addPropertyKey(backendInfo);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 64 with PropertyKey

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

the class GraphTransaction method removeEdgeProperty.

@Watched(prefix = "graph")
public <V> void removeEdgeProperty(HugeEdgeProperty<V> prop) {
    HugeEdge edge = prop.element();
    PropertyKey propKey = prop.propertyKey();
    E.checkState(edge != null, "No owner for removing property '%s'", prop.key());
    // Maybe have ever been removed
    if (!edge.hasProperty(propKey.id())) {
        return;
    }
    // Check is removing sort key
    List<Id> sortKeyIds = edge.schemaLabel().sortKeys();
    E.checkArgument(!sortKeyIds.contains(prop.propertyKey().id()), "Can't remove sort key '%s'", prop.key());
    // Remove property in memory for new created edge
    if (edge.fresh()) {
        // The owner will do property update
        edge.removeProperty(propKey.id());
        return;
    }
    // Check is updating property of added/removed edge
    E.checkArgument(!this.addedEdges.containsKey(edge.id()) || this.updatedEdges.containsKey(edge.id()), "Can't remove property '%s' for adding-state edge", prop.key());
    E.checkArgument(!this.removedEdges.containsKey(edge.id()), "Can't remove property '%s' for removing-state edge", prop.key());
    // Do property update
    this.lockForUpdateProperty(edge.schemaLabel(), prop, () -> {
        // Update old edge to remove index (with the property)
        this.indexTx.updateEdgeIndex(edge, true);
        // Update(remove) edge property
        this.propertyUpdated(edge, null, edge.removeProperty(propKey.id()));
    });
}
Also used : HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 65 with PropertyKey

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

the class GraphTransaction method removeVertexProperty.

@Watched(prefix = "graph")
public <V> void removeVertexProperty(HugeVertexProperty<V> prop) {
    HugeVertex vertex = prop.element();
    PropertyKey propKey = prop.propertyKey();
    E.checkState(vertex != null, "No owner for removing property '%s'", prop.key());
    // Maybe have ever been removed (compatible with tinkerpop)
    if (!vertex.hasProperty(propKey.id())) {
        // PropertyTest shouldAllowRemovalFromVertexWhenAlreadyRemoved()
        return;
    }
    // Check is removing primary key
    List<Id> primaryKeyIds = vertex.schemaLabel().primaryKeys();
    E.checkArgument(!primaryKeyIds.contains(propKey.id()), "Can't remove primary key '%s'", prop.key());
    // Remove property in memory for new created vertex
    if (vertex.fresh()) {
        // The owner will do property update
        vertex.removeProperty(propKey.id());
        return;
    }
    // Check is updating property of added/removed vertex
    E.checkArgument(!this.addedVertices.containsKey(vertex.id()) || this.updatedVertices.containsKey(vertex.id()), "Can't remove property '%s' for adding-state vertex", prop.key());
    E.checkArgument(!this.removedVertices.containsKey(vertex.id()), "Can't remove property '%s' for removing-state vertex", prop.key());
    // Do property update
    this.lockForUpdateProperty(vertex.schemaLabel(), prop, () -> {
        // Update old vertex to remove index (with the property)
        this.indexTx.updateVertexIndex(vertex, true);
        // Update(remove) vertex property
        HugeProperty<?> removed = vertex.removeProperty(propKey.id());
        this.propertyUpdated(vertex, null, removed);
    });
}
Also used : Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Aggregations

PropertyKey (com.baidu.hugegraph.schema.PropertyKey)94 Id (com.baidu.hugegraph.backend.id.Id)31 Test (org.junit.Test)24 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)20 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)15 HugeGraph (com.baidu.hugegraph.HugeGraph)13 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)11 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)9 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)9 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)9 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)7 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)7 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)6 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)6 DataType (com.baidu.hugegraph.type.define.DataType)6 Map (java.util.Map)6 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)5 Timed (com.codahale.metrics.annotation.Timed)5 RolesAllowed (jakarta.annotation.security.RolesAllowed)5 Collection (java.util.Collection)5