use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class OSQLFunctionGremlin method execute.
public Object execute(Object iThis, final OIdentifiable iCurrentRecord, Object iCurrentResult, final Object[] iParams, final OCommandContext iContext) {
final ODatabaseDocumentTx db = OGremlinHelper.getGraphDatabase(ODatabaseRecordThreadLocal.INSTANCE.get());
result = new ArrayList<Object>();
OGremlinHelper.execute(db, (String) iParams[0], null, (Map) iContext.getVariables(), result, new OGremlinHelper.OGremlinCallback() {
@Override
public boolean call(final ScriptEngine iEngine, final OrientBaseGraph iGraph) {
if (iCurrentRecord == null)
// IGNORE PRE-PROCESSING
return true;
final ODocument document = (ODocument) iCurrentRecord;
OClass clazz = ODocumentInternal.getImmutableSchemaClass(document);
if (clazz != null && clazz.isSubClassOf(OrientEdgeType.CLASS_NAME)) {
// EDGE TYPE, CREATE THE BLUEPRINTS'S WRAPPER
OrientEdge graphElement = (OrientEdge) new OrientElementIterable<OrientEdge>(iGraph, Arrays.asList(new ODocument[] { document })).iterator().next();
iEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("current", graphElement);
// FRAMES LIKE SYNTAX
iEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("it", graphElement);
} else {
// VERTEX TYPE, CREATE THE BLUEPRINTS'S WRAPPER
OrientVertex graphElement = (OrientVertex) new OrientElementIterable<OrientVertex>(iGraph, Arrays.asList(new ODocument[] { document })).iterator().next();
iEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("current", graphElement);
// FRAMES LIKE SYNTAX
iEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("it", graphElement);
}
return true;
}
}, null);
return result;
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class OrientdbEdgeTest method testEdges.
@Test
public void testEdges() throws Exception {
OrientGraphFactory factory = getGraphFactory();
OrientBaseGraph g = factory.getNoTx();
try {
try {
g.createEdgeType("some-label");
} catch (OSchemaException ex) {
if (!ex.getMessage().contains("exists"))
throw (ex);
g.command(new OCommandSQL("delete edge some-label")).execute();
}
try {
g.createVertexType("some-v-label");
} catch (OSchemaException ex) {
if (!ex.getMessage().contains("exists"))
throw (ex);
g.command(new OCommandSQL("delete vertex some-v-label")).execute();
}
} finally {
g.shutdown();
}
OrientGraph t = factory.getTx();
try {
Vertex v1 = t.addVertex("class:some-v-label");
Vertex v2 = t.addVertex("class:some-v-label");
v1.setProperty("_id", "v1");
v2.setProperty("_id", "v2");
OrientEdge edge = t.addEdge(null, v1, v2, "some-label");
edge.setProperty("some", "thing");
t.commit();
t.shutdown();
t = factory.getTx();
assertEquals(2, t.countVertices("some-v-label"));
assertEquals(1, t.countEdges());
assertNotNull(t.getVertices("_id", "v1").iterator().next());
assertNotNull(t.getVertices("_id", "v2").iterator().next());
t.commit();
t.shutdown();
t = factory.getTx();
// works
assertEquals(1, t.getVertices("_id", "v1").iterator().next().query().labels("some-label").count());
// NoSuchElementException
assertNotNull(t.getVertices("_id", "v1").iterator().next().query().labels("some-label").edges().iterator().next());
t.commit();
} finally {
t.shutdown();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class AbstractServerClusterTest method prepare.
/**
* Create the database on first node only
*
* @throws IOException
*/
protected void prepare(final boolean iCopyDatabaseToNodes, final boolean iCreateDatabase, final OCallable<Object, OrientGraphFactory> iCfgCallback) throws IOException {
// CREATE THE DATABASE
final Iterator<ServerRun> it = serverInstance.iterator();
final ServerRun master = it.next();
if (iCreateDatabase) {
final OrientBaseGraph graph = master.createDatabase(getDatabaseName(), iCfgCallback);
try {
onAfterDatabaseCreation(graph);
} finally {
graph.shutdown();
Orient.instance().closeAllStorages();
}
}
// COPY DATABASE TO OTHER SERVERS
while (it.hasNext()) {
final ServerRun replicaSrv = it.next();
replicaSrv.deleteNode();
if (iCopyDatabaseToNodes)
master.copyDatabase(getDatabaseName(), replicaSrv.getDatabasePath(getDatabaseName()));
}
}
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();
}
}
}
}
Aggregations