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);
}
}
}
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());
}
}
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);
}
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()));
});
}
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);
});
}
Aggregations