use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class OCommandExecutorSQLDeleteVertex method result.
/**
* Delete the current vertex.
*/
public boolean result(final Object iRecord) {
final OIdentifiable id = (OIdentifiable) iRecord;
if (id.getIdentity().isValid()) {
final ODocument record = id.getRecord();
final OrientBaseGraph g = currentGraph.get();
final OrientVertex v = g.getVertex(record);
if (v != null) {
v.remove();
if (!txAlreadyBegun && batch > 0 && removed % batch == 0) {
if (g instanceof OrientGraph) {
g.commit();
((OrientGraph) g).begin();
}
}
if (returning.equalsIgnoreCase("BEFORE"))
allDeletedRecords.add(record);
removed++;
}
}
return true;
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class OGraphCommandExecutorSQLFactory method runInTx.
public static <T> T runInTx(final GraphCallBack<T> callBack) {
final OModifiableBoolean shutdownFlag = new OModifiableBoolean();
final ODatabaseDocumentInternal curDb = ODatabaseRecordThreadLocal.INSTANCE.get();
final boolean txAlreadyBegun = curDb.getTransaction().isActive();
final OrientGraph graph = OGraphCommandExecutorSQLFactory.getGraph(true, shutdownFlag);
try {
return runInTx(graph, callBack);
} finally {
if (!txAlreadyBegun) {
graph.commit();
if (shutdownFlag.getValue())
graph.shutdown(false, false);
}
ODatabaseRecordThreadLocal.INSTANCE.set(curDb);
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class OGraphCommandExecutorSQLFactory method getGraph.
/**
* Returns a Transactional OrientGraph implementation from the current database in thread local.
*
* @param autoStartTx
* Whether returned graph will start transaction before each operation till commit automatically or user should do it
* explicitly be calling {@link OrientGraph#getRawGraph()} method {@link ODatabaseDocumentTx#begin()}.
*
* @return Transactional OrientGraph implementation from the current database in thread local.
*/
public static OrientGraph getGraph(final boolean autoStartTx, OModifiableBoolean shouldBeShutDown) {
final ODatabaseDocument database = ODatabaseRecordThreadLocal.INSTANCE.get();
final OrientBaseGraph result = OrientBaseGraph.getActiveGraph();
if (result != null && (result instanceof OrientGraph)) {
final ODatabaseDocumentTx graphDb = result.getRawGraph();
// CHECK IF THE DATABASE + USER IN TL IS THE SAME IN ORDER TO USE IT
if (canReuseActiveGraph(graphDb, database)) {
if (!graphDb.isClosed()) {
ODatabaseRecordThreadLocal.INSTANCE.set(graphDb);
if (autoStartTx && autoTxStartRequired(graphDb))
((OrientGraph) result).begin();
shouldBeShutDown.setValue(false);
return (OrientGraph) result;
}
}
}
// Set it again on ThreadLocal because the getRawGraph() may have set a closed db in the thread-local
ODatabaseRecordThreadLocal.INSTANCE.set((ODatabaseDocumentInternal) database);
shouldBeShutDown.setValue(true);
final OrientGraph g = (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph((ODatabaseDocumentTx) database, false);
if (autoStartTx && autoTxStartRequired(database))
g.begin();
return g;
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class OSQLFunctionHeuristicPathFinderAbstract method getCustomHeuristicCost.
protected double getCustomHeuristicCost(final String functionName, final String[] vertextAxisNames, final OrientVertex start, final OrientVertex goal, final OrientVertex current, final OrientVertex parent, final long depth, double dFactor) {
double heuristic = 0.0;
OrientGraph ff;
OFunction func = OrientGraph.getActiveGraph().getRawGraph().getMetadata().getFunctionLibrary().getFunction(functionName);
Object fValue = func.executeInContext(context, vertextAxisNames, start, goal, current, parent, depth, dFactor);
if (fValue != null && fValue instanceof Number) {
heuristic = doubleOrDefault(fValue, heuristic);
}
return heuristic;
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class IndexTest method testIndexEdgeComposite.
public void testIndexEdgeComposite() {
OrientGraph graphNoTx = new OrientGraph((ODatabaseDocumentTx) database.getUnderlying());
OrientVertexType vertexType = null;
if (!graphNoTx.getRawGraph().existsCluster("CustomVertex")) {
vertexType = graphNoTx.createVertexType("CustomVertex");
} else {
vertexType = graphNoTx.getVertexType("CustomVertex");
}
if (!graphNoTx.getRawGraph().existsCluster("CustomEdge")) {
OrientEdgeType edgeType = graphNoTx.createEdgeType("CustomEdge");
edgeType.createProperty("out", OType.LINK, vertexType);
edgeType.createProperty("in", OType.LINK, vertexType);
edgeType.createIndex("CustomEdge.in", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "in" });
edgeType.createIndex("CustomEdge.out", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "out" });
edgeType.createIndex("CustomEdge.compositeInOut", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "out", "in" });
}
// graphNoTx.shutdown();
OrientGraph graph = new OrientGraph((ODatabaseDocumentTx) database.getUnderlying());
Vertex inVert = null;
for (int i = 0; i < 5; ++i) {
Vertex currentVert = graph.addVertex("class:CustomVertex");
if (inVert != null) {
graph.addEdge("class:CustomEdge", currentVert, inVert, "CustomEdge");
}
inVert = currentVert;
}
graph.commit();
Iterable<Vertex> verts = graph.getVertices();
StringBuilder vertIds = new StringBuilder();
for (Vertex vert : verts) {
vertIds.append(vert.getId().toString()).append(" ");
}
System.out.println("Vertices: " + vertIds);
System.out.println();
checkIndexKeys(graph, "CustomEdge.in");
checkIndexKeys(graph, "CustomEdge.out");
checkIndexKeys(graph, "CustomEdge.compositeInOut");
}
Aggregations