Search in sources :

Example 11 with GraphTransaction

use of com.baidu.hugegraph.backend.tx.GraphTransaction in project incubator-hugegraph by apache.

the class HugeVariables method createVariableVertex.

private void createVariableVertex(String key, Object value) {
    VertexLabel vl = this.variableVertexLabel();
    GraphTransaction tx = this.params.graphTransaction();
    HugeVertex vertex = HugeVertex.create(tx, null, vl);
    try {
        this.setProperty(vertex, key, value);
    } catch (IllegalArgumentException e) {
        throw Graph.Variables.Exceptions.dataTypeOfVariableValueNotSupported(value, e);
    }
    // PrimaryKey id
    vertex.assignId(null);
    tx.addVertex(vertex);
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 12 with GraphTransaction

use of com.baidu.hugegraph.backend.tx.GraphTransaction in project incubator-hugegraph by apache.

the class Example1 method thread.

private static void thread(HugeGraph graph) throws InterruptedException {
    Thread t = new Thread(() -> {
        // Default tx
        graph.addVertex(T.label, "book", "name", "java-11");
        graph.addVertex(T.label, "book", "name", "java-12");
        graph.tx().commit();
        // New tx
        GraphTransaction tx = Whitebox.invoke(graph.getClass(), "openGraphTransaction", graph);
        tx.addVertex(T.label, "book", "name", "java-21");
        tx.addVertex(T.label, "book", "name", "java-22");
        tx.commit();
        tx.close();
        // This will close the schema tx
        Whitebox.invoke(graph.getClass(), "closeTx", graph);
    });
    t.start();
    t.join();
}
Also used : GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction)

Example 13 with GraphTransaction

use of com.baidu.hugegraph.backend.tx.GraphTransaction in project incubator-hugegraph by apache.

the class HugeEdge method remove.

@Watched(prefix = "edge")
@Override
public void remove() {
    this.removed(true);
    this.sourceVertex.removeEdge(this);
    this.targetVertex.removeEdge(this);
    GraphTransaction tx = this.tx();
    if (tx != null) {
        assert this.fresh();
        tx.removeEdge(this);
    } else {
        this.graph().removeEdge(this);
    }
}
Also used : GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 14 with GraphTransaction

use of com.baidu.hugegraph.backend.tx.GraphTransaction in project incubator-hugegraph by apache.

the class ServerInfoManager method save.

private int save(Collection<HugeServerInfo> serverInfos) {
    return this.call(() -> {
        if (serverInfos.isEmpty()) {
            return serverInfos.size();
        }
        HugeServerInfo.Schema schema = HugeServerInfo.schema(this.graph);
        if (!schema.existVertexLabel(HugeServerInfo.P.SERVER)) {
            throw new HugeException("Schema is missing for %s", HugeServerInfo.P.SERVER);
        }
        // Save server info in batch
        GraphTransaction tx = this.tx();
        int updated = 0;
        for (HugeServerInfo server : serverInfos) {
            if (!server.updated()) {
                continue;
            }
            HugeVertex vertex = tx.constructVertex(false, server.asArray());
            tx.addVertex(vertex);
            updated++;
        }
        // NOTE: actually it is auto-commit, to be improved
        tx.commitOrRollback();
        return updated;
    });
}
Also used : GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) HugeException(com.baidu.hugegraph.HugeException) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 15 with GraphTransaction

use of com.baidu.hugegraph.backend.tx.GraphTransaction in project incubator-hugegraph by apache.

the class DeleteExpiredElementJob method execute.

@Override
public V execute() throws Exception {
    LOG.debug("Delete expired elements: {}", this.elements);
    HugeGraphParams graph = this.params();
    GraphTransaction tx = graph.graphTransaction();
    try {
        for (HugeElement element : this.elements) {
            element.remove();
        }
        tx.commit();
    } catch (Exception e) {
        tx.rollback();
        LOG.warn("Failed to delete expired elements: {}", this.elements);
        throw e;
    } finally {
        JOB_COUNTERS.jobCounter(graph.graph()).decrement();
    }
    return null;
}
Also used : HugeGraphParams(com.baidu.hugegraph.HugeGraphParams) GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) HugeElement(com.baidu.hugegraph.structure.HugeElement)

Aggregations

GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)22 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)7 SchemaTransaction (com.baidu.hugegraph.backend.tx.SchemaTransaction)6 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)6 LockUtil (com.baidu.hugegraph.util.LockUtil)6 Id (com.baidu.hugegraph.backend.id.Id)5 HugeGraph (com.baidu.hugegraph.HugeGraph)4 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)4 Test (org.junit.Test)4 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)3 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)3 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)3 HugeElement (com.baidu.hugegraph.structure.HugeElement)3 Edge (org.apache.tinkerpop.gremlin.structure.Edge)3 HugeException (com.baidu.hugegraph.HugeException)2 HugeGraphParams (com.baidu.hugegraph.HugeGraphParams)2 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)2 Query (com.baidu.hugegraph.backend.query.Query)2 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)2 FakeEdge (com.baidu.hugegraph.testutil.FakeObjects.FakeEdge)2