Search in sources :

Example 26 with HugeEdge

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();
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Id(com.baidu.hugegraph.backend.id.Id)

Example 27 with HugeEdge

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();
}
Also used : HugeEdge(com.baidu.hugegraph.structure.HugeEdge) HugeException(com.baidu.hugegraph.HugeException) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 28 with HugeEdge

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;
}
Also used : HugeEdge(com.baidu.hugegraph.structure.HugeEdge) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 29 with HugeEdge

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;
}
Also used : EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeEdge(com.baidu.hugegraph.structure.HugeEdge)

Example 30 with HugeEdge

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);
    }
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId)

Aggregations

HugeEdge (com.baidu.hugegraph.structure.HugeEdge)54 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)29 Id (com.baidu.hugegraph.backend.id.Id)26 Edge (org.apache.tinkerpop.gremlin.structure.Edge)22 Test (org.junit.Test)20 HugeGraph (com.baidu.hugegraph.HugeGraph)17 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)12 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)11 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)9 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)9 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)8 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)8 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)6 EdgeStep (com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep)6 Iterator (java.util.Iterator)6 List (java.util.List)6 Set (java.util.Set)6 HugeException (com.baidu.hugegraph.HugeException)5 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)5 HugeConfig (com.baidu.hugegraph.config.HugeConfig)5