use of com.orientechnologies.orient.console.OConsoleDatabaseApp in project orientdb by orientechnologies.
the class OInternalGraphImporter method runImport.
public void runImport(String inputFile, String dbURL) throws IOException, FileNotFoundException {
if (inputFile == null)
throw new OSystemException("needed an input file as first argument");
if (dbURL == null)
throw new OSystemException("needed an database location as second argument");
ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbURL);
ODatabaseHelper.deleteDatabase(db, db.getStorage().getType());
OrientBaseGraph g = OrientGraphFactory.getNoTxGraphImplFactory().getGraph(dbURL);
System.out.println("Importing graph from file '" + inputFile + "' into database: " + g + "...");
final long startTime = System.currentTimeMillis();
OConsoleDatabaseApp console = new OGremlinConsole(new String[] { "import database " + inputFile }).setCurrentDatabase(g.getRawGraph());
console.run();
System.out.println("Imported in " + (System.currentTimeMillis() - startTime) + "ms. Vertexes: " + g.countVertices());
g.command(new OCommandSQL("alter database TIMEZONE 'GMT'")).execute();
g.command(new OCommandSQL("alter database LOCALECOUNTRY 'UK'")).execute();
g.command(new OCommandSQL("alter database LOCALELANGUAGE 'EN'")).execute();
g.shutdown();
}
use of com.orientechnologies.orient.console.OConsoleDatabaseApp in project orientdb by orientechnologies.
the class OConsoleDatatabaseAppTest method testSelectBinaryDoc.
@Test
public void testSelectBinaryDoc() throws IOException {
final StringBuilder builder = new StringBuilder();
OConsoleDatabaseApp app = new OConsoleDatabaseApp(new String[] {}) {
@Override
public void message(String iMessage, Object... iArgs) {
builder.append(String.format(iMessage, iArgs)).append("\n");
}
};
app.createDatabase("memory:test", null, null, "memory", null, null);
ODatabaseDocument db = app.getCurrentDatabase();
db.addBlobCluster("blobTest");
ORecord record = db.save(new ORecordBytes("blobContent".getBytes()), "blobTest");
builder.setLength(0);
app.select(" from " + record.getIdentity() + " limit -1 ");
assertTrue(builder.toString().contains("<binary>"));
}
use of com.orientechnologies.orient.console.OConsoleDatabaseApp in project orientdb by orientechnologies.
the class OConsoleDatabaseAppTest method testDisplayRawRecord.
@Test
public void testDisplayRawRecord() {
String dbUrl = "memory:OConsoleDatabaseAppTestDisplayRawRecord";
// builder.append("display raw record " + rid);
// OConsoleDatabaseApp console = new OConsoleDatabaseApp(new String[] { builder.toString() });
OConsoleDatabaseApp console = new OConsoleDatabaseApp(null);
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream stream = new PrintStream(out);
console.setOutput(stream);
try {
console.createDatabase(dbUrl, null, null, null, null, null);
console.createClass("class foo");
console.insert("into foo set name = 'barbar'");
byte[] result = out.toByteArray();
out.close();
stream.close();
out = new ByteArrayOutputStream();
stream = new PrintStream(out);
console.setOutput(stream);
String resultString = new String(result);
String rid = resultString.substring(resultString.indexOf("#"), resultString.indexOf("#") + 5).trim();
console.set("maxBinaryDisplay", "10000");
console.displayRawRecord(rid);
result = out.toByteArray();
resultString = new String(result);
Assert.assertTrue(resultString.contains("Raw record content."));
if ("ORecordSerializerBinary".equals(((ODatabaseDocumentTx) console.getCurrentDatabase()).getSerializer().toString())) {
Assert.assertTrue(resultString.contains("class name: foo"));
Assert.assertTrue(resultString.contains("property value: barbar"));
}
} catch (IOException e) {
Assert.fail();
} finally {
try {
out.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
console.close();
}
}
use of com.orientechnologies.orient.console.OConsoleDatabaseApp in project orientdb by orientechnologies.
the class OGremlinConsoleTest method testGremlin.
@Test
public void testGremlin() {
final String INPUT_FILE = "src/test/resources/graph-example-2.xml";
String dbUrl = "memory:testGremlin";
StringBuilder builder = new StringBuilder();
builder.append("create database " + dbUrl + ";\n");
builder.append("import database " + INPUT_FILE + " batchSize=10;\n");
builder.append("gremlin g.V;\n");
OConsoleDatabaseApp console = new TestOGremlinConsole(new String[] { builder.toString() });
try {
console.run();
ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
db.open("admin", "admin");
try {
long totalVertices = db.countClass("V");
Assert.assertTrue(totalVertices > 0);
long totalEdges = db.countClass("E");
Assert.assertTrue(totalEdges > 0);
} finally {
db.close();
}
} finally {
console.close();
}
}
use of com.orientechnologies.orient.console.OConsoleDatabaseApp in project orientdb by orientechnologies.
the class OGremlinConsoleTest method testGraphMLExport.
@Test
public void testGraphMLExport() {
final String INPUT_FILE = "src/test/resources/graph-example-2.xml";
final String OUTPUT_FILE = "target/test/resources/graph-example-2.xml";
String dbUrl = "memory:testGraphMLExport";
StringBuilder builder = new StringBuilder();
builder.append("create database " + dbUrl + ";\n");
builder.append("import database " + INPUT_FILE + ";\n");
builder.append("export database " + OUTPUT_FILE + ";\n");
OConsoleDatabaseApp console = new TestOGremlinConsole(new String[] { builder.toString() });
try {
console.run();
final File f = new File(OUTPUT_FILE);
Assert.assertTrue(f.exists());
Assert.assertTrue(f.length() > 0);
} finally {
console.close();
}
}
Aggregations