use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class ODatabaseFailDueCloseTest method createGraph.
private static void createGraph() {
OrientGraph g = new OrientGraph("memory:temp", "admin", "admin");
g.shutdown();
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class IndexTest method testPreservingIdentityInIndexTx.
public void testPreservingIdentityInIndexTx() {
OrientGraph graph = new OrientGraph((ODatabaseDocumentTx) database.getUnderlying(), true);
graph.setAutoScaleEdgeType(true);
OrientVertexType fieldClass = graph.getVertexType("PreservingIdentityInIndexTxChild");
if (fieldClass == null) {
fieldClass = graph.createVertexType("PreservingIdentityInIndexTxChild");
fieldClass.createProperty("name", OType.STRING);
fieldClass.createProperty("in_field", OType.LINK);
fieldClass.createIndex("nameParentIndex", OClass.INDEX_TYPE.NOTUNIQUE, "in_field", "name");
}
Vertex parent = graph.addVertex("class:PreservingIdentityInIndexTxParent");
Vertex child = graph.addVertex("class:PreservingIdentityInIndexTxChild");
parent.addEdge("preservingIdentityInIndexTxEdge", child);
child.setProperty("name", "pokus");
Vertex parent2 = graph.addVertex("class:PreservingIdentityInIndexTxParent");
Vertex child2 = graph.addVertex("class:PreservingIdentityInIndexTxChild");
parent2.addEdge("preservingIdentityInIndexTxEdge", child2);
child2.setProperty("name", "pokus2");
graph.commit();
{
fieldClass = graph.getVertexType("PreservingIdentityInIndexTxChild");
OIndex<?> index = fieldClass.getClassIndex("nameParentIndex");
OCompositeKey key = new OCompositeKey(parent.getId(), "pokus");
Set<ORecordId> h = (Set<ORecordId>) index.get(key);
for (ORecordId o : h) {
Assert.assertNotNull(graph.getVertex(o));
}
}
{
fieldClass = graph.getVertexType("PreservingIdentityInIndexTxChild");
OIndex<?> index = fieldClass.getClassIndex("nameParentIndex");
OCompositeKey key = new OCompositeKey(parent2.getId(), "pokus2");
Set<ORecordId> h = (Set<ORecordId>) index.get(key);
for (ORecordId o : h) {
Assert.assertNotNull(graph.getVertex(o));
}
}
parent.remove();
child.remove();
parent2.remove();
child2.remove();
graph.shutdown();
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class HAClusterStrategyTest method executeTest.
@Override
public void executeTest() throws Exception {
final OrientGraphFactory factory = new OrientGraphFactory(getDatabaseURL(serverInstance.get(0)));
final OrientGraphNoTx g = factory.getNoTx();
g.createVertexType("Test");
g.shutdown();
for (int i = 0; i < 10; ++i) {
// pressing 'return' 2 to 10 times should trigger the described behavior
Thread.sleep(100);
final OrientGraph graph = factory.getTx();
// should always be 'local', but eventually changes to 'round-robin'
System.out.println("StrategyClassName: " + graph.getVertexType("Test").getClusterSelection().getClass().getName());
System.out.println("ClusterSelectionStrategy for " + graph.getRawGraph().getURL() + ": " + graph.getVertexType("Test").getClusterSelection().getName());
Assert.assertEquals(graph.getVertexType("Test").getClusterSelection().getClass().getName(), OLocalClusterWrapperStrategy.class.getName());
Assert.assertEquals(graph.getVertexType("Test").getClusterSelection().getName(), "round-robin");
graph.addVertex("class:Test", "firstName", "Roger", "lastName", "Smith");
graph.getRawGraph().commit();
graph.shutdown();
}
factory.close();
factory.drop();
}
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);
}
}
Aggregations