use of com.baidu.hugegraph.schema.PropertyKey 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;
}
use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.
the class EdgeLabelBuilder 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;
}
VertexLabel source = this.graph().vertexLabel(this.sourceLabel);
VertexLabel target = this.graph().vertexLabel(this.targetLabel);
E.checkArgument((source.ttl() == 0L || this.ttl <= source.ttl()) && (target.ttl() == 0L || this.ttl <= target.ttl()), "The ttl(%s) of edge label '%s' should less than " + "ttl(%s) of source label '%s' and ttl(%s) of target " + "label '%s'", this.ttl, this.name, source.ttl(), this.sourceLabel, target.ttl(), this.targetLabel);
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 edge 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());
}
use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.
the class HugeVertex method property.
@Watched(prefix = "vertex")
@Override
public <V> VertexProperty<V> property(VertexProperty.Cardinality cardinality, String key, V value, Object... objects) {
if (objects.length != 0 && objects[0].equals(T.id)) {
throw VertexProperty.Exceptions.userSuppliedIdsNotSupported();
}
// TODO: extra props: objects
if (objects.length != 0) {
throw VertexProperty.Exceptions.metaPropertiesNotSupported();
}
PropertyKey propertyKey = this.graph().propertyKey(key);
/*
* g.AddV("xxx").property("key1", val1).property("key2", val2)
* g.AddV("xxx").property(single, "key1", val1)
* .property(list, "key2", val2)
*
* The cardinality single may be user supplied single, it may also be
* that user doesn't supplied cardinality, when it is latter situation,
* we shouldn't check it. Because of this reason, we are forced to
* give up the check of user supplied cardinality single.
* The cardinality not single must be user supplied, so should check it
*/
if (cardinality != VertexProperty.Cardinality.single) {
E.checkArgument(propertyKey.cardinality() == Cardinality.convert(cardinality), "Invalid cardinality '%s' for property key '%s', " + "expect '%s'", cardinality, key, propertyKey.cardinality().string());
}
// Check key in vertex label
E.checkArgument(VertexLabel.OLAP_VL.equals(this.label) || this.label.properties().contains(propertyKey.id()), "Invalid property '%s' for vertex label '%s'", key, this.label);
// Primary-Keys can only be set once
if (this.schemaLabel().primaryKeys().contains(propertyKey.id())) {
E.checkArgument(!this.hasProperty(propertyKey.id()), "Can't update primary key: '%s'", key);
}
@SuppressWarnings("unchecked") VertexProperty<V> prop = (VertexProperty<V>) this.addProperty(propertyKey, value, !this.fresh());
return prop;
}
use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.
the class PropertyKeyBuilder method createWithTask.
@Override
public SchemaElement.TaskWithSchema createWithTask() {
HugeType type = HugeType.PROPERTY_KEY;
this.checkSchemaName(this.name);
return this.lockCheckAndCreateSchema(type, this.name, name -> {
PropertyKey propertyKey = this.propertyKeyOrNull(name);
if (propertyKey != null) {
if (this.checkExist || !hasSameProperties(propertyKey)) {
throw new ExistedException(type, name);
}
return new SchemaElement.TaskWithSchema(propertyKey, IdGenerator.ZERO);
}
this.checkSchemaIdIfRestoringMode(type, this.id);
Userdata.check(this.userdata, Action.INSERT);
this.checkAggregateType();
this.checkOlap();
propertyKey = this.build();
assert propertyKey.name().equals(name);
Id id = this.graph().addPropertyKey(propertyKey);
return new SchemaElement.TaskWithSchema(propertyKey, id);
});
}
use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.
the class PropertyKeyBuilder method append.
@Override
public PropertyKey append() {
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.APPEND);
propertyKey.userdata(this.userdata);
this.graph().addPropertyKey(propertyKey);
return propertyKey;
}
Aggregations