Search in sources :

Example 11 with PropertyKey

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

the class PropertyKeyBuilder method eliminate.

@Override
public PropertyKey eliminate() {
    PropertyKey propertyKey = this.propertyKeyOrNull(this.name);
    if (propertyKey == null) {
        throw new NotFoundException("Can't update property key '%s' " + "since it doesn't exist", this.name);
    }
    this.checkStableVars();
    Userdata.check(this.userdata, Action.ELIMINATE);
    propertyKey.removeUserdata(this.userdata);
    this.graph().addPropertyKey(propertyKey);
    return propertyKey;
}
Also used : NotFoundException(com.baidu.hugegraph.exception.NotFoundException) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 12 with PropertyKey

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

the class VertexLabelBuilder method checkTtl.

private void checkTtl() {
    E.checkArgument(this.ttl >= 0, "The ttl must be >= 0, but got: %s", this.ttl);
    if (this.ttl == 0L) {
        E.checkArgument(this.ttlStartTime == null, "Can't set ttl start time if ttl is not set");
        return;
    }
    if (this.ttlStartTime == null) {
        return;
    }
    // Check whether the properties contains the specified keys
    E.checkArgument(!this.properties.isEmpty(), "The properties can't be empty when exist " + "ttl start time for edge label '%s'", this.name);
    E.checkArgument(this.properties.contains(this.ttlStartTime), "The ttl start time '%s' must be contained in " + "properties '%s' for vertex label '%s'", this.ttlStartTime, this.name, this.properties);
    PropertyKey pkey = this.graph().propertyKey(this.ttlStartTime);
    E.checkArgument(pkey.dataType().isDate(), "The ttl start time property must be date type," + "but got '%s(%s)'", this.ttlStartTime, pkey.dataType());
}
Also used : PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 13 with PropertyKey

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

the class VertexLabelBuilder method build.

@Override
public VertexLabel build() {
    Id id = this.validOrGenerateId(HugeType.VERTEX_LABEL, this.id, this.name);
    VertexLabel vertexLabel = new VertexLabel(this.graph(), id, this.name);
    vertexLabel.idStrategy(this.idStrategy);
    vertexLabel.enableLabelIndex(this.enableLabelIndex == null || this.enableLabelIndex);
    vertexLabel.ttl(this.ttl);
    if (this.ttlStartTime != null) {
        vertexLabel.ttlStartTime(this.graph().propertyKey(this.ttlStartTime).id());
    }
    // Assign properties
    for (String key : this.properties) {
        PropertyKey propertyKey = this.graph().propertyKey(key);
        vertexLabel.property(propertyKey.id());
    }
    for (String key : this.primaryKeys) {
        PropertyKey propertyKey = this.graph().propertyKey(key);
        vertexLabel.primaryKey(propertyKey.id());
    }
    for (String key : this.nullableKeys) {
        PropertyKey propertyKey = this.graph().propertyKey(key);
        vertexLabel.nullableKey(propertyKey.id());
    }
    vertexLabel.userdata(this.userdata);
    return vertexLabel;
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) Id(com.baidu.hugegraph.backend.id.Id) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 14 with PropertyKey

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

the class HugeElement method setProperty.

@Watched(prefix = "element")
public <V> HugeProperty<?> setProperty(HugeProperty<V> prop) {
    if (this.properties == EMPTY_MAP) {
        this.properties = CollectionFactory.newIntObjectMap();
    }
    PropertyKey pkey = prop.propertyKey();
    E.checkArgument(this.properties.containsKey(intFromId(pkey.id())) || this.properties.size() < MAX_PROPERTIES, "Exceeded the maximum number of properties");
    return this.properties.put(intFromId(pkey.id()), prop);
}
Also used : PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 15 with PropertyKey

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

the class HugeElement method updateToDefaultValueIfNone.

protected void updateToDefaultValueIfNone() {
    if (this.fresh() || this.defaultValueUpdated) {
        return;
    }
    this.defaultValueUpdated = true;
    // Set default value if needed
    for (Id pkeyId : this.schemaLabel().properties()) {
        if (this.properties.containsKey(intFromId(pkeyId))) {
            continue;
        }
        PropertyKey pkey = this.graph().propertyKey(pkeyId);
        Object value = pkey.defaultValue();
        if (value != null) {
            this.setProperty(this.newProperty(pkey, value));
        }
    }
    this.defaultValueUpdated = true;
}
Also used : EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

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