use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.
the class BinarySerializer method parseEdge.
protected void parseEdge(BackendColumn col, HugeVertex vertex, HugeGraph graph) {
// owner-vertex + dir + edge-label + sort-values + other-vertex
BytesBuffer buffer = BytesBuffer.wrap(col.name);
if (this.keyWithIdPrefix) {
// Consume owner-vertex id
buffer.readId();
}
byte type = buffer.read();
Id labelId = buffer.readId();
String sortValues = buffer.readStringWithEnding();
Id otherVertexId = buffer.readId();
boolean direction = EdgeId.isOutDirectionFromCode(type);
EdgeLabel edgeLabel = graph.edgeLabelOrNone(labelId);
// Construct edge
HugeEdge edge = HugeEdge.constructEdge(vertex, direction, edgeLabel, sortValues, otherVertexId);
// Parse edge-id + edge-properties
buffer = BytesBuffer.wrap(col.value);
// Id id = buffer.readId();
// Parse edge properties
this.parseProperties(buffer, edge);
// Parse edge expired time if needed
if (edge.hasTtl()) {
this.parseExpiredTime(buffer, edge);
}
}
use of com.baidu.hugegraph.structure.HugeEdge 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.structure.HugeEdge in project incubator-hugegraph by apache.
the class GraphTransaction method prepareDeletions.
protected void prepareDeletions(Map<Id, HugeEdge> removedEdges) {
// Remove edges
for (HugeEdge e : removedEdges.values()) {
this.checkAggregateProperty(e);
// Update edge index
this.indexTx.updateEdgeIndex(e, true);
this.indexTx.updateLabelIndex(e, true);
// Remove edge of OUT and IN
e = e.prepareRemoved();
this.doRemove(this.serializer.writeEdge(e));
this.doRemove(this.serializer.writeEdge(e.switchOwner()));
}
}
use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.
the class GraphTransaction method prepareAdditions.
protected void prepareAdditions(Map<Id, HugeVertex> addedVertices, Map<Id, HugeEdge> addedEdges) {
if (this.checkCustomVertexExist) {
this.checkVertexExistIfCustomizedId(addedVertices);
}
if (this.removeLeftIndexOnOverwrite) {
this.removeLeftIndexIfNeeded(addedVertices);
}
// Do vertex update
for (HugeVertex v : addedVertices.values()) {
assert !v.removed();
v.committed();
this.checkAggregateProperty(v);
// Check whether passed all non-null properties
if (!this.graphMode().loading()) {
this.checkNonnullProperty(v);
}
// Add vertex entry
this.doInsert(this.serializer.writeVertex(v));
// Update index of vertex(only include props)
this.indexTx.updateVertexIndex(v, false);
this.indexTx.updateLabelIndex(v, false);
}
// Do edge update
for (HugeEdge e : addedEdges.values()) {
assert !e.removed();
e.committed();
// Skip edge if its owner has been removed
if (this.removingEdgeOwner(e)) {
continue;
}
this.checkAggregateProperty(e);
// Add edge entry of OUT and IN
this.doInsert(this.serializer.writeEdge(e));
this.doInsert(this.serializer.writeEdge(e.switchOwner()));
// Update index of edge
this.indexTx.updateEdgeIndex(e, false);
this.indexTx.updateLabelIndex(e, false);
}
}
use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.
the class GraphTransaction method addEdgeProperty.
@Watched(prefix = "graph")
public <V> void addEdgeProperty(HugeEdgeProperty<V> prop) {
// NOTE: this method can also be used to update property
HugeEdge edge = prop.element();
E.checkState(edge != null, "No owner for updating property '%s'", prop.key());
// Add property in memory for new created edge
if (edge.fresh()) {
// The owner will do property update
edge.setProperty(prop);
return;
}
// Check is updating property of added/removed edge
E.checkArgument(!this.addedEdges.containsKey(edge.id()) || this.updatedEdges.containsKey(edge.id()), "Can't update property '%s' for adding-state edge", prop.key());
E.checkArgument(!edge.removed() && !this.removedEdges.containsKey(edge.id()), "Can't update property '%s' for removing-state edge", prop.key());
// Check is updating sort key
List<Id> sortKeys = edge.schemaLabel().sortKeys();
E.checkArgument(!sortKeys.contains(prop.propertyKey().id()), "Can't update sort key '%s'", prop.key());
// Do property update
this.lockForUpdateProperty(edge.schemaLabel(), prop, () -> {
// Update old edge to remove index (without new property)
this.indexTx.updateEdgeIndex(edge, true);
// Update(add) edge property
this.propertyUpdated(edge, prop, edge.setProperty(prop));
});
}
Aggregations