use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class ConcurrentDistributedUpdateTest method createWriter.
protected Callable<Void> createWriter(final int serverId, final int threadId, final String databaseURL) {
return new Callable<Void>() {
@Override
public Void call() throws Exception {
final String id = serverId + "." + threadId;
boolean isRunning = true;
final OrientBaseGraph graph = new OrientGraph(databaseURL);
try {
String query = "select from Test where prop2='v2-1'";
for (int i = 0; i < 100 && isRunning; i++) {
if ((i % 25) == 0) {
log("[" + id + "] Records Processed: [" + i + "]");
}
Iterable<Vertex> vtxs = graph.command(new OCommandSQL(query)).execute();
boolean update = true;
for (Vertex vtx : vtxs) {
if (update) {
update = true;
for (int k = 0; k < 10 && update; k++) {
OrientVertex vtx1 = (OrientVertex) vtx;
try {
vtx1.setProperty("prop5", "prop55");
graph.commit();
// log("[" + id + "/" + i + "/" + k + "] OK!\n");
break;
} catch (OConcurrentModificationException ex) {
vtx1.reload();
} catch (ODistributedRecordLockedException ex) {
log("[" + id + "/" + i + "/" + k + "] Distributed lock Exception " + ex + " for vertex " + vtx1 + " \n");
// ex.printStackTrace();
update = false;
// isRunning = false;
break;
} catch (Exception ex) {
log("[" + id + "/" + i + "/" + k + "] Exception " + ex + " for vertex " + vtx1 + "\n\n");
ex.printStackTrace();
isRunning = false;
break;
}
}
if (!isRunning)
break;
}
}
}
} catch (Exception ex) {
System.out.println("ID: [" + id + "]********** Exception " + ex + " \n\n");
ex.printStackTrace();
} finally {
log("[" + id + "] Done................>>>>>>>>>>>>>>>>>>");
graph.shutdown();
runningWriters.countDown();
}
Assert.assertTrue(isRunning);
return null;
}
};
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class MultipleDBAlignmentOnNodesJoining method prepare.
/**
* Creates the databases as follows:
* - server1: db A, db B
* - server2: db B, db C
*
* @throws IOException
*/
@Override
protected void prepare(final boolean iCopyDatabaseToNodes, final boolean iCreateDatabase, final OCallable<Object, OrientGraphFactory> iCfgCallback) throws IOException {
serverInstance.remove(2);
// creating databases on server1
ServerRun master = serverInstance.get(0);
if (iCreateDatabase) {
final OrientBaseGraph graph1 = master.createDatabase(dbA, iCfgCallback);
final OrientBaseGraph graph2 = master.createDatabase(dbB, iCfgCallback);
try {
onAfterDatabaseCreation(graph1, "plocal:" + serverInstance.get(0).getDatabasePath(dbA));
onAfterDatabaseCreation(graph2, "plocal:" + serverInstance.get(0).getDatabasePath(dbB));
} finally {
if (!graph1.isClosed()) {
graph1.shutdown();
}
if (!graph1.isClosed()) {
graph2.shutdown();
}
}
}
// copying db-B on server2
if (iCopyDatabaseToNodes)
master.copyDatabase(dbB, serverInstance.get(1).getDatabasePath(dbB));
// creating db-C on server2
master = serverInstance.get(1);
if (iCreateDatabase) {
final OrientBaseGraph graph1 = master.createDatabase(dbC, iCfgCallback);
try {
onAfterDatabaseCreation(graph1, "plocal:" + serverInstance.get(1).getDatabasePath(dbC));
} finally {
if (!graph1.isClosed()) {
graph1.shutdown();
}
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class OGremlinEngineThreadLocal method get.
public ScriptEngine get(final OrientBaseGraph iGraph) {
ScriptEngine engine = super.get();
if (engine != null) {
final OrientBaseGraph currGraph = (OrientBaseGraph) engine.getBindings(ScriptContext.ENGINE_SCOPE).get("g");
if (currGraph == iGraph || (currGraph != null && currGraph.getRawGraph().getURL().equals(iGraph.getRawGraph().getURL()))) {
// REUSE IT
engine.getBindings(ScriptContext.ENGINE_SCOPE).put("g", iGraph);
return engine;
}
}
// CREATE A NEW ONE
engine = new GremlinGroovyScriptEngine();
engine.getBindings(ScriptContext.ENGINE_SCOPE).put("g", iGraph);
set(engine);
return engine;
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class OCommandExecutorSQLCreateVertex method execute.
/**
* Execute the command and return the ODocument object created.
*/
public Object execute(final Map<Object, Object> iArgs) {
if (clazz == null)
throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
// CREATE VERTEX DOES NOT HAVE TO BE IN TX
return OGraphCommandExecutorSQLFactory.runWithAnyGraph(new OGraphCommandExecutorSQLFactory.GraphCallBack<Object>() {
@Override
public Object call(final OrientBaseGraph graph) {
final OrientVertex vertex = graph.addTemporaryVertex(clazz.getName());
if (fields != null)
// EVALUATE FIELDS
for (final OPair<String, Object> f : fields) {
if (f.getValue() instanceof OSQLFunctionRuntime)
f.setValue(((OSQLFunctionRuntime) f.getValue()).getValue(vertex.getRecord(), null, context));
}
OSQLHelper.bindParameters(vertex.getRecord(), fields, new OCommandParameters(iArgs), context);
if (content != null)
vertex.getRecord().merge(content, true, false);
if (clusterName != null)
vertex.save(clusterName);
else
vertex.save();
return vertex.getRecord();
}
});
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph 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;
}
Aggregations