use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.
the class StandardHugeGraph method removeEdge.
@Override
public void removeEdge(String label, Object id) {
if (label != null) {
EdgeLabel el = this.edgeLabel(label);
if (!el.existsIndexLabel()) {
// Improve perf by removeEdge(id)
Id idValue = HugeEdge.getIdValue(id, false);
HugeEdge edge = new HugeEdge(this, idValue, el);
this.removeEdge(edge);
return;
}
}
this.edge(id).remove();
}
use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.
the class RelationshipManager method save.
private Id save(T relationship, boolean expectExists) {
if (!this.graph().existsEdgeLabel(relationship.label())) {
throw new HugeException("Schema is missing for %s '%s'", relationship.label(), relationship.source());
}
HugeVertex source = this.newVertex(relationship.source(), relationship.sourceLabel());
HugeVertex target = this.newVertex(relationship.target(), relationship.targetLabel());
HugeEdge edge = source.constructEdge(relationship.label(), target, relationship.asArray());
E.checkArgument(this.exists(edge.id()) == expectExists, "Can't save %s '%s' that %s exists", this.unhideLabel(), edge.id(), expectExists ? "not" : "already");
this.tx().addEdge(edge);
this.commitOrRollback();
return edge.id();
}
use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.
the class RelationshipManager method delete.
public T delete(Id id) {
T relationship = null;
Iterator<Edge> edges = this.tx().queryEdges(id);
if (edges.hasNext()) {
HugeEdge edge = (HugeEdge) edges.next();
relationship = this.deser.apply(edge);
this.tx().removeEdge(edge);
this.commitOrRollback();
assert !edges.hasNext();
}
return relationship;
}
use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.
the class TableSerializer method writeEdgeProperty.
@Override
public BackendEntry writeEdgeProperty(HugeEdgeProperty<?> prop) {
HugeEdge edge = prop.element();
EdgeId id = edge.idWithDirection();
TableBackendEntry.Row row = new TableBackendEntry.Row(edge.type(), id);
if (edge.hasTtl()) {
row.ttl(edge.ttl());
row.column(HugeKeys.EXPIRED_TIME, edge.expiredTime());
}
// Id: ownerVertex + direction + edge-label + sortValues + otherVertex
row.column(HugeKeys.OWNER_VERTEX, this.writeId(id.ownerVertexId()));
row.column(HugeKeys.DIRECTION, id.directionCode());
row.column(HugeKeys.LABEL, id.edgeLabelId().asLong());
row.column(HugeKeys.SORT_VALUES, id.sortValues());
row.column(HugeKeys.OTHER_VERTEX, this.writeId(id.otherVertexId()));
// Format edge property
this.formatProperty(prop, row);
TableBackendEntry entry = newBackendEntry(row);
entry.subId(IdGenerator.of(prop.key()));
return entry;
}
use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.
the class TextSerializer method parseEdge.
/**
* Parse an edge from a column item
*/
private void parseEdge(String colName, String colValue, HugeVertex vertex) {
String[] colParts = EdgeId.split(colName);
HugeGraph graph = vertex.graph();
boolean direction = colParts[0].equals(EDGE_OUT_TYPE);
String sortValues = readEdgeName(colParts[2]);
EdgeLabel edgeLabel = graph.edgeLabelOrNone(readId(colParts[1]));
Id otherVertexId = readEntryId(colParts[3]);
// Construct edge
HugeEdge edge = HugeEdge.constructEdge(vertex, direction, edgeLabel, sortValues, otherVertexId);
String[] valParts = colValue.split(VALUE_SPLITOR);
// Parse edge expired time
String name = this.formatSyspropName(HugeKeys.EXPIRED_TIME);
E.checkState(valParts[1].equals(name), "Invalid system property name '%s'", valParts[1]);
edge.expiredTime(JsonUtil.fromJson(valParts[2], Long.class));
// Edge properties
for (int i = 3; i < valParts.length; i += 2) {
this.parseProperty(valParts[i], valParts[i + 1], edge);
}
}
Aggregations