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