use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class OConsoleDatabaseAppTest method testWrongCommand.
@Test
public void testWrongCommand() {
String dbUrl = "memory:OConsoleDatabaseAppTest2";
StringBuilder builder = new StringBuilder();
builder.append("create database " + dbUrl + ";\n");
builder.append("create class foo;\n");
builder.append("insert into foo set name = 'foo';\n");
builder.append("insert into foo set name = 'bla';\n");
// <- wrong command, this should break the console
builder.append("blabla;\n");
builder.append("update foo set surname = 'bar' where name = 'foo';\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.assertNull(doc.field("surname"));
} finally {
db.close();
}
} finally {
console.close();
}
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx 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.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class OGremlinConsoleTest method testGraphMLImportWithSmallBatch.
@Test
public void testGraphMLImportWithSmallBatch() {
final String INPUT_FILE = "src/test/resources/graph-example-2.xml";
String dbUrl = "memory:testGraphMLImportWithSmallBatch";
StringBuilder builder = new StringBuilder();
builder.append("create database " + dbUrl + ";\n");
builder.append("import database " + INPUT_FILE + " batchSize=10;\n");
OConsoleDatabaseApp console = new TestOGremlinConsole(new String[] { builder.toString() });
try {
console.run();
ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
db.open("admin", "admin");
try {
List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from V"));
Assert.assertFalse(result.isEmpty());
} finally {
db.close();
}
} finally {
console.close();
}
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class OGremlinConsoleTest method testMoveVertexCommand.
@Test
public void testMoveVertexCommand() {
final String INPUT_FILE = "src/test/resources/graph-example-2.xml";
String dbUrl = "memory:testMoveVertexCommand";
StringBuilder builder = new StringBuilder();
builder.append("create database " + dbUrl + ";\n");
builder.append("import database " + INPUT_FILE + " batchSize=10;\n");
builder.append("create class newposition extends V;\n");
builder.append("move vertex (select from V) to class:newposition;\n");
OConsoleDatabaseApp console = new TestOGremlinConsole(new String[] { builder.toString() });
try {
console.run();
ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
db.open("admin", "admin");
try {
List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from newposition"));
Assert.assertFalse(result.isEmpty());
} finally {
db.close();
}
} finally {
console.close();
}
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class OGremlinConsoleTest method testGraphMLImportDirect.
@Test
public void testGraphMLImportDirect() throws IOException {
final String INPUT_FILE = "src/test/resources/graph-example-fromexport.xml";
String dbUrl = "memory:testGraphMLImportDirect";
new OGraphMLReader(new OrientGraphNoTx(dbUrl)).inputGraph(INPUT_FILE);
ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
db.open("admin", "admin");
try {
boolean foundTypeVAttr = false;
boolean foundFriendEAttr = false;
List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from V"));
Assert.assertFalse(result.isEmpty());
for (ODocument d : result) {
if (d.containsField("__type__"))
foundTypeVAttr = true;
}
Assert.assertTrue(foundTypeVAttr);
result = db.query(new OSQLSynchQuery<ODocument>("select from E"));
Assert.assertFalse(result.isEmpty());
for (ODocument d : result) {
if (d.containsField("friend"))
foundFriendEAttr = true;
}
Assert.assertTrue(foundFriendEAttr);
} finally {
db.close();
}
}
Aggregations