use of com.tinkerpop.blueprints.Vertex in project orientdb by orientechnologies.
the class OOrientDBLoaderTest method shouldSaveDocumentsOnGivenCluster.
@Test
public void shouldSaveDocumentsOnGivenCluster() {
process("{source: { content: { value: 'name,surname\nJay,Miner' } }, extractor : { csv: {} }, loader: { orientdb: {\n" + " dbURL: \"memory:OETLBaseTest\",\n" + " dbUser: \"admin\",\n" + " dbPassword: \"admin\",\n" + " dbAutoCreate: true,\n" + " cluster : \"myCluster\",\n" + " tx: false,\n" + " batchCommit: 1000,\n" + " wal : true,\n" + " dbType: \"graph\",\n" + " classes: [\n" + " {name:\"Person\", extends: \"V\" },\n" + " ],\n" + " indexes: [{class:\"V\" , fields:[\"surname:String\"], \"type\":\"NOTUNIQUE\", \"metadata\": { \"ignoreNullValues\" : \"false\"}} ] } } }");
graph.makeActive();
int idByName = graph.getRawGraph().getClusterIdByName("myCluster");
Iterable<Vertex> vertices = graph.getVertices();
for (Vertex vertex : vertices) {
assertThat(((ORID) vertex.getId()).getClusterId()).isEqualTo(idByName);
}
}
use of com.tinkerpop.blueprints.Vertex in project orientdb by orientechnologies.
the class OGraphBatchInsertTest method testTraverse.
@Test
public void testTraverse() {
String dbUrl = "memory:batchinsert_testTraverse";
OGraphBatchInsert batch = new OGraphBatchInsert(dbUrl, "admin", "admin");
batch.begin();
batch.createEdge(0L, 1L, null);
batch.createEdge(1L, 2L, null);
batch.createEdge(2L, 3L, null);
Map<String, Object> vertexProps = new HashMap<String, Object>();
vertexProps.put("foo", "bar");
batch.setVertexProperties(3L, vertexProps);
batch.end();
OrientGraph g = new OrientGraph(dbUrl, "admin", "admin");
Iterable<Vertex> result = g.command(new OSQLSynchQuery<Vertex>("select expand(out().in().out().out().in().out()) from V where uid = ?")).execute(1L);
for (Vertex v : result) {
assertEquals("bar", v.getProperty("foo"));
}
g.shutdown();
}
use of com.tinkerpop.blueprints.Vertex in project orientdb by orientechnologies.
the class OConsoleDatabaseAppTest method testSimple.
@Test
public void testSimple() {
String dbUrl = "memory:OConsoleDatabaseAppTest";
StringBuilder builder = new StringBuilder();
builder.append("create database " + dbUrl + ";\n");
builder.append("profile storage on;\n");
builder.append("create class foo;\n");
builder.append("config;\n");
builder.append("list classes;\n");
builder.append("list properties;\n");
builder.append("list clusters;\n");
builder.append("list indexes;\n");
builder.append("info class OUser;\n");
builder.append("info property OUser.name;\n");
builder.append("begin;\n");
builder.append("insert into foo set name = 'foo';\n");
builder.append("insert into foo set name = 'bla';\n");
builder.append("update foo set surname = 'bar' where name = 'foo';\n");
builder.append("commit;\n");
builder.append("select from foo;\n");
builder.append("create class bar;\n");
builder.append("create property bar.name STRING;\n");
builder.append("create index bar_name on bar (name) NOTUNIQUE;\n");
builder.append("insert into bar set name = 'foo';\n");
builder.append("delete from bar;\n");
builder.append("begin;\n");
builder.append("insert into bar set name = 'foo';\n");
builder.append("rollback;\n");
builder.append("create vertex V set name = 'foo';\n");
builder.append("create vertex V set name = 'bar';\n");
builder.append("traverse out() from V;\n");
builder.append("create edge from (select from V where name = 'foo') to (select from V where name = 'bar');\n");
builder.append("traverse out() from V;\n");
// builder.append("create user TestUser identified by password ROLE ['reader','writer'];\n");
builder.append("drop user TestUser;\n");
builder.append("profile storage off;\n");
builder.append("repair database -v;\n");
ConsoleTest c = new ConsoleTest(new String[] { builder.toString() });
OConsoleDatabaseApp console = c.console();
try {
console.run();
ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
db.open("admin", "admin");
try {
List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from foo where name = 'foo'"));
Assert.assertEquals(1, result.size());
ODocument doc = result.get(0);
Assert.assertEquals("bar", doc.field("surname"));
result = db.query(new OSQLSynchQuery<ODocument>("select from bar"));
Assert.assertEquals(0, result.size());
} finally {
db.close();
}
OrientGraph graph = new OrientGraph(dbUrl);
try {
Iterable<Vertex> result = graph.command(new OSQLSynchQuery<Vertex>("select expand(out()) from (select from V where name = 'foo')")).execute();
Iterator<Vertex> iterator = result.iterator();
Assert.assertTrue(iterator.hasNext());
Vertex next = iterator.next();
Assert.assertEquals("bar", next.getProperty("name"));
Assert.assertFalse(iterator.hasNext());
} finally {
graph.shutdown();
}
} finally {
console.close();
}
}
use of com.tinkerpop.blueprints.Vertex in project orientdb by orientechnologies.
the class GraphCommands method testParams.
@Test
public void testParams() {
String sql = "SELECT FROM V WHERE tags IN :tags";
Map<String, Object> queryParams = new HashMap<String, Object>();
queryParams.put("tags", new HashSet<String>() {
{
add("Genius");
}
});
Iterable<Vertex> results = ((Iterable<Vertex>) graph.command(new OSQLSynchQuery(sql)).execute(queryParams));
Assert.assertTrue(results.iterator().hasNext());
sql = "SELECT FROM V WHERE tags NOT IN :tags";
queryParams = new HashMap<String, Object>();
queryParams.put("tags", new HashSet<String>() {
{
add("Genius");
}
});
results = ((Iterable<Vertex>) graph.command(new OSQLSynchQuery(sql)).execute(queryParams));
Assert.assertFalse(results.iterator().hasNext());
}
use of com.tinkerpop.blueprints.Vertex in project orientdb by orientechnologies.
the class GraphCommands method testAddValueSQL.
@Test
public void testAddValueSQL() {
graph.command(new OCommandSQL("update V add testprop = 'first' return after @this limit 1")).execute();
Iterable<Vertex> results = ((Iterable<Vertex>) graph.command(new OSQLSynchQuery("select from V where 'first' in testprop")).execute());
Assert.assertTrue(results.iterator().hasNext());
graph.command(new OCommandSQL("update V add testprop = 'second' return after @this limit 1")).execute();
results = ((Iterable<Vertex>) graph.command(new OSQLSynchQuery("select from V where 'first' in testprop")).execute());
Assert.assertTrue(results.iterator().hasNext());
results = ((Iterable<Vertex>) graph.command(new OSQLSynchQuery("select from V where 'second' in testprop")).execute());
Assert.assertTrue(results.iterator().hasNext());
}
Aggregations