use of com.baidu.hugegraph.backend.id.Id 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;
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class HugeElement method getPropertyKeys.
public Set<Id> getPropertyKeys() {
Set<Id> propKeys = InsertionOrderUtil.newSet();
IntIterator keys = this.properties.keysView().intIterator();
while (keys.hasNext()) {
propKeys.add(IdGenerator.of(keys.next()));
}
return propKeys;
}
use of com.baidu.hugegraph.backend.id.Id 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;
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class HugeIndex method parseIndexId.
public static HugeIndex parseIndexId(HugeGraph graph, HugeType type, byte[] id) {
Object values;
IndexLabel indexLabel;
if (type.isStringIndex()) {
Id idObject = IdGenerator.of(id, IdType.STRING);
String[] parts = SplicingIdGenerator.parse(idObject);
E.checkState(parts.length == 2, "Invalid secondary index id");
Id label = IdGenerator.ofStoredString(parts[0], IdType.LONG);
indexLabel = IndexLabel.label(graph, label);
values = parts[1];
} else {
assert type.isRange4Index() || type.isRange8Index();
final int labelLength = 4;
E.checkState(id.length > labelLength, "Invalid range index id");
BytesBuffer buffer = BytesBuffer.wrap(id);
Id label = IdGenerator.of(buffer.readInt());
indexLabel = IndexLabel.label(graph, label);
List<Id> fields = indexLabel.indexFields();
E.checkState(fields.size() == 1, "Invalid range index fields");
DataType dataType = graph.propertyKey(fields.get(0)).dataType();
E.checkState(dataType.isNumber() || dataType.isDate(), "Invalid range index field type");
Class<?> clazz = dataType.isNumber() ? dataType.clazz() : DataType.LONG.clazz();
values = bytes2number(buffer.read(id.length - labelLength), clazz);
}
HugeIndex index = new HugeIndex(graph, indexLabel);
index.fieldValues(values);
return index;
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class HugeVertex method edges.
@Watched(prefix = "vertex")
@Override
public Iterator<Edge> edges(Direction tinkerpopDir, String... edgeLabels) {
Directions direction = Directions.convert(tinkerpopDir);
// NOTE: get edges from memory if load all edges when loading vertex.
if (this.existsEdges()) {
return this.getEdges(direction, edgeLabels);
}
Id[] edgeLabelIds = this.graph().mapElName2Id(edgeLabels);
Query query = GraphTransaction.constructEdgesQuery(this.id(), direction, edgeLabelIds);
return this.graph().edges(query);
}
Aggregations