use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class TestAsyncReplMode method dbClient2.
protected void dbClient2() {
synchronized (LOCK) {
OrientBaseGraph graph = new OrientGraph(getRemoteURL());
OrientVertex parentV1 = null;
OrientVertex parentV2 = null;
int countPropValue = 0;
try {
for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
pause();
if (exceptionInThread != null)
break;
// Let's give it some time for asynchronous replication.
// sleep(500);
countPropValue++;
if (parentV1 == null) {
parentV1 = graph.getVertex(parentV1Id);
}
for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
try {
parentV1.setProperty("cnt", countPropValue);
graph.commit();
} catch (OConcurrentModificationException c) {
graph.rollback();
parentV1.reload();
}
}
if (parentV2 == null) {
parentV2 = graph.getVertex(parentV2Id);
}
for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
try {
parentV2.setProperty("cnt", countPropValue);
graph.commit();
} catch (OConcurrentModificationException c) {
graph.rollback();
parentV2.reload();
}
}
}
} catch (Throwable e) {
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
System.out.println("Shutting down");
graph.shutdown();
LOCK.notifyAll();
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class TestAsyncReplMode2Servers method dbClient2.
protected void dbClient2() {
sleep(1000);
synchronized (LOCK) {
OrientBaseGraph graph = new OrientGraph(getLocalURL2());
try {
OrientVertex parentV1 = graph.getVertex(parentV1Id);
assertEquals(1, parentV1.getRecord().getVersion());
OrientVertex parentV2 = graph.getVertex(parentV2Id);
assertEquals(1, parentV2.getRecord().getVersion());
int countPropValue = 0;
for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
pause();
if (exceptionInThread != null)
break;
sleep(500);
parentV1.reload();
parentV2.reload();
assertEquals("parentV1 (" + parentV1.getRecord() + ")", ++countPropValue, parentV1.getProperty(CNT_PROP_NAME));
assertEquals("parentV2 (" + parentV2.getRecord() + ")", countPropValue, parentV2.getProperty(CNT_PROP_NAME));
}
} catch (Throwable e) {
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
System.out.println("Shutting down");
graph.shutdown();
LOCK.notifyAll();
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class TestAsyncReplMode2ServersAddEdge method dbClient2.
protected void dbClient2() {
sleep(500);
synchronized (LOCK) {
OrientBaseGraph graph = new OrientGraph(getLocalURL2());
try {
sleep(500);
OrientVertex parentV1 = graph.getVertex(parentV1Id);
assertEquals(NUM_OF_LOOP_ITERATIONS + 1, parentV1.getRecord().getVersion());
} catch (Throwable e) {
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
System.out.println("Shutting down");
graph.shutdown();
LOCK.notifyAll();
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class OCommandExecutorSQLMoveVertex method execute.
/**
* Executes the command and return the ODocument object created.
*/
public Object execute(final Map<Object, Object> iArgs) {
if (className == null && clusterName == null)
throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
OModifiableBoolean shutdownGraph = new OModifiableBoolean();
final boolean txAlreadyBegun = getDatabase().getTransaction().isActive();
final OrientGraph graph = OGraphCommandExecutorSQLFactory.getGraph(true, shutdownGraph);
try {
final Set<OIdentifiable> sourceRIDs = OSQLEngine.getInstance().parseRIDTarget(graph.getRawGraph(), source, context, iArgs);
// CREATE EDGES
final List<ODocument> result = new ArrayList<ODocument>(sourceRIDs.size());
for (OIdentifiable from : sourceRIDs) {
final OrientVertex fromVertex = graph.getVertex(from);
if (fromVertex == null)
continue;
final ORID oldVertex = fromVertex.getIdentity().copy();
final ORID newVertex = fromVertex.moveTo(className, clusterName);
final ODocument newVertexDoc = newVertex.getRecord();
if (fields != null) {
// EVALUATE FIELDS
for (final OPair<String, Object> f : fields) {
if (f.getValue() instanceof OSQLFunctionRuntime)
f.setValue(((OSQLFunctionRuntime) f.getValue()).getValue(newVertex.getRecord(), null, context));
}
OSQLHelper.bindParameters(newVertexDoc, fields, new OCommandParameters(iArgs), context);
}
if (merge != null)
newVertexDoc.merge(merge, true, false);
// SAVE CHANGES
newVertexDoc.save();
// PUT THE MOVE INTO THE RESULT
result.add(new ODocument().setTrackingChanges(false).field("old", oldVertex, OType.LINK).field("new", newVertex, OType.LINK));
if (batch > 0 && result.size() % batch == 0) {
graph.commit();
if (!graph.isAutoStartTx())
graph.begin();
}
}
graph.commit();
return result;
} finally {
if (!txAlreadyBegun)
graph.commit();
if (shutdownGraph.getValue())
graph.shutdown(false);
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class GraphShutdownTest method graphCommitAfterShutdown.
@Test(expected = ODatabaseException.class)
public void graphCommitAfterShutdown() {
OrientGraphFactory factory = new OrientGraphFactory("memory:graphCommitAfterShutdown");
OrientGraph graph1 = factory.getTx();
OrientGraph graph2 = factory.getTx();
// in 2.2 this will not close the database because graph1 is still active in the pool
graph2.shutdown(true);
// this should fail
graph2.commit();
factory.drop();
}
Aggregations