use of com.tinkerpop.blueprints.impls.orient.OrientGraph 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.OrientGraph in project orientdb by orientechnologies.
the class OrientdbEdgeTest method verifyDatabaseExists.
private static void verifyDatabaseExists(Map<String, Object> conf) {
final String url = (String) conf.get("storage.url");
if (!url.startsWith("remote:"))
return;
try {
final OServerAdmin admin = new OServerAdmin(url);
admin.connect((String) conf.get("storage.user"), (String) conf.get("storage.password"));
if (!admin.existsDatabase()) {
System.err.println("creating database " + url);
admin.createDatabase("graph", "plocal");
}
OrientGraph t = new OrientGraph(url, (String) conf.get("storage.user"), (String) conf.get("storage.password"));
try {
t.command(new OCommandSQL("alter database custom useLightweightEdges=false")).execute();
t.commit();
t.command(new OCommandSQL("ALTER CLASS V CLUSTERSELECTION balanced")).execute();
t.commit();
t.command(new OCommandSQL("ALTER CLASS E CLUSTERSELECTION balanced")).execute();
t.commit();
} finally {
t.shutdown();
}
admin.close();
} catch (IOException ex1) {
throw new RuntimeException(ex1);
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class ServerClusterSchemaTest method executeTest.
@Override
protected void executeTest() throws Exception {
for (int s = 0; s < SERVERS; ++s) {
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
System.out.println("Creating vertex class Client" + s + " against server " + g + "...");
OrientVertexType t = g.createVertexType("Client" + s);
t.createProperty("name", OType.STRING).setMandatory(true);
System.out.println("Creating vertex class Knows" + s + " against server " + g + "...");
g.createEdgeType("Knows" + s);
} finally {
g.shutdown();
}
}
for (int s = 0; s < SERVERS; ++s) {
System.out.println("Checking vertices classes on server " + s + "...");
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
for (int i = 0; i < SERVERS; ++i) {
Assert.assertNotNull(g.getVertexType("Client" + i));
Assert.assertNotNull(g.getEdgeType("Knows" + i));
}
} finally {
g.shutdown();
}
}
for (int s = 0; s < SERVERS; ++s) {
System.out.println("Add vertices on server " + s + "...");
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
for (int i = 0; i < SERVERS; ++i) {
try {
final OrientVertex v = g.addVertex("class:" + "Client" + i);
Assert.assertTrue(false);
} catch (OValidationException e) {
// EXPECTED
}
}
} finally {
g.shutdown();
}
}
for (int s = 0; s < SERVERS; ++s) {
System.out.println("Add vertices in TX on server " + s + "...");
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraph g = factory.getTx();
try {
for (int i = 0; i < SERVERS; ++i) {
try {
final OrientVertex v = g.addVertex("class:" + "Client" + i);
g.commit();
Assert.assertTrue(false);
} catch (ONeedRetryException e) {
// EXPECTED
} catch (OValidationException e) {
// EXPECTED
}
}
} finally {
g.shutdown();
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class VertexIndexTest method testFullTextIndexOnvertex.
@Test
public void testFullTextIndexOnvertex() {
OrientGraph graph = new OrientGraph("memory:TestDB", "admin", "admin");
OrientVertexType vType = graph.getVertexType("V");
vType.createProperty("title", OType.STRING);
vType.createProperty("text", OType.STRING);
vType.createIndex("V.", "FULLTEXT", null, null, "LUCENE", new String[] { "title", "text" });
graph.drop();
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class DbListenerTest method testEmbeddedDbListenersGraph.
@Test
public void testEmbeddedDbListenersGraph() throws IOException {
if (database.getURL().startsWith("remote:"))
return;
if (database.exists())
ODatabaseHelper.deleteDatabase(database, getStorageType());
ODatabaseHelper.createDatabase(database, url, getStorageType());
database.open("admin", "admin");
OrientGraph g = new OrientGraph(database);
OrientVertex v = g.addVertex(null);
v.setProperty("name", "Jay");
g.commit();
final DocumentChangeListener cl = new DocumentChangeListener(g);
v.setProperty("surname", "Miner");
g.shutdown();
Assert.assertEquals(cl.getChanges().size(), 1);
ODatabaseHelper.deleteDatabase(database, getStorageType());
ODatabaseHelper.createDatabase(database, url, getStorageType());
}
Aggregations