use of com.orientechnologies.orient.core.db.tool.ODatabaseExport in project serverless by bluenimble.
the class OrientDatabase method exp.
@Override
public void exp(Set<String> entities, OutputStream out, Map<ExchangeOption, Boolean> options, final ExchangeListener listener) throws DatabaseException {
OCommandOutputListener olistener = new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
if (listener != null) {
listener.onMessage(iText);
}
}
};
ODatabaseExport export = null;
try {
export = new ODatabaseExport(db, out, olistener);
} catch (IOException e) {
throw new DatabaseException(e.getMessage(), e);
}
export.setIncludeInfo(option(options, ExchangeOption.info, false));
export.setIncludeClusterDefinitions(option(options, ExchangeOption.entities, false));
export.setIncludeSchema(option(options, ExchangeOption.schema, false));
export.setIncludeIndexDefinitions(option(options, ExchangeOption.indexes, false));
export.setIncludeManualIndexes(option(options, ExchangeOption.indexes, false));
export.setPreserveRids(option(options, ExchangeOption.ids, false));
export.setOptions("-compressionLevel=9");
if (entities != null && !entities.isEmpty()) {
export.setIncludeClasses(entities);
}
export.exportDatabase();
export.close();
}
use of com.orientechnologies.orient.core.db.tool.ODatabaseExport in project orientdb by orientechnologies.
the class LuceneExportImportTest method testExportImport.
@Test
public void testExportImport() {
String file = "./target/exportTest.json";
List<?> query = db.query(new OSQLSynchQuery<Object>("select from City where name lucene 'Rome'"));
assertThat(query).hasSize(1);
try {
// export the DB
new ODatabaseExport(db, file, new OCommandOutputListener() {
@Override
public void onMessage(String s) {
}
}).exportDatabase();
db.drop();
db.create();
GZIPInputStream stream = new GZIPInputStream(new FileInputStream(file + ".gz"));
// import
new ODatabaseImport(db, stream, new OCommandOutputListener() {
@Override
public void onMessage(String s) {
System.out.println(s);
}
}).importDatabase();
} catch (IOException e) {
Assert.fail(e.getMessage());
}
db.commit();
long city = db.countClass("City");
Assert.assertEquals(city, 1);
OIndex<?> index = db.getMetadata().getIndexManager().getIndex("City.name");
Assert.assertNotNull(index);
assertThat(index.getSize()).isEqualTo(1L);
Assert.assertEquals(index.getType(), "FULLTEXT");
Assert.assertEquals(index.getAlgorithm(), "LUCENE");
query = db.query(new OSQLSynchQuery<Object>("select from City "));
assertThat(query.size()).isEqualTo(1);
query = db.query(new OSQLSynchQuery<Object>("select from City where name lucene 'rome'"));
assertThat(query).hasSize(1);
}
use of com.orientechnologies.orient.core.db.tool.ODatabaseExport in project orientdb by orientechnologies.
the class OAutomaticBackup method exportDatabase.
protected void exportDatabase(final String dbURL, final String iPath, final ODatabaseDocumentInternal db) throws IOException {
OLogManager.instance().info(this, "AutomaticBackup: executing export of database '%s' to %s", dbURL, iPath);
final ODatabaseExport exp = new ODatabaseExport(db, iPath, new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
OLogManager.instance().info(this, iText);
}
});
if (exportOptions != null && !exportOptions.trim().isEmpty())
exp.setOptions(exportOptions.trim());
exp.exportDatabase().close();
}
use of com.orientechnologies.orient.core.db.tool.ODatabaseExport in project orientdb by orientechnologies.
the class CRUDObjectInheritanceTestSchemaFull method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
super.beforeClass();
database.close();
database = new OObjectDatabaseTx(url + "_objectschema");
ODatabaseHelper.dropDatabase(database, getStorageType());
ODatabaseHelper.createDatabase(database, url + "_objectschema", getStorageType());
try {
ODatabaseDocumentTx exportDatabase = new ODatabaseDocumentTx(url);
exportDatabase.open("admin", "admin");
OCommandOutputListener listener = new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
}
};
ODatabaseExport export = new ODatabaseExport(exportDatabase, EXPORT_DIR, listener);
export.exportDatabase();
export.close();
exportDatabase.close();
ODatabaseDocumentTx importDatabase = new ODatabaseDocumentTx(url + "_objectschema");
if (url.startsWith("remote")) {
importDatabase.open("root", ODatabaseHelper.getServerRootPassword());
} else {
importDatabase.open("admin", "admin");
}
ODatabaseImport impor = new ODatabaseImport(importDatabase, EXPORT_DIR, listener);
// UNREGISTER ALL THE HOOKS
for (ORecordHook hook : new ArrayList<ORecordHook>(importDatabase.getHooks().keySet())) {
importDatabase.unregisterHook(hook);
}
impor.setDeleteRIDMapping(true);
impor.importDatabase();
impor.close();
importDatabase.close();
final File importDir = new File(EXPORT_DIR);
importDir.delete();
} catch (IOException e) {
Assert.fail("Export import didn't go as expected", e);
}
database.open("admin", "admin");
if (database.getMetadata().getSchema().existsClass("Company"))
database.command(new OCommandSQL("delete from Company")).execute();
if (database.getMetadata().getSchema().existsClass("Account"))
database.command(new OCommandSQL("delete from Account")).execute();
if (database.getMetadata().getSchema().existsClass("JavaComplexTestClass"))
database.command(new OCommandSQL("delete from JavaComplexTestClass")).execute();
if (database.getMetadata().getSchema().existsClass("Profile"))
database.command(new OCommandSQL("delete from Profile")).execute();
if (database.getMetadata().getSchema().existsClass("IdentityChild"))
database.command(new OCommandSQL("delete from IdentityChild")).execute();
database.close();
}
use of com.orientechnologies.orient.core.db.tool.ODatabaseExport in project orientdb by orientechnologies.
the class ObjectExportImportTest method testExportImport.
@Test
public void testExportImport() throws IOException {
OObjectDatabaseTx db = new OObjectDatabaseTx("memory:test");
db.create();
db.setAutomaticSchemaGeneration(true);
db.getMetadata().getSchema().synchronizeSchema();
assertNotNull(db.getMetadata().getSchema().getClass("ODocumentWrapper"));
byte[] bytes;
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
new ODatabaseExport(db.getUnderlying(), byteOutputStream, new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
}
}).exportDatabase().close();
bytes = byteOutputStream.toByteArray();
OObjectDatabaseTx db1 = new OObjectDatabaseTx("memory:test1");
db1.create();
db1.setAutomaticSchemaGeneration(true);
db1.getMetadata().getSchema().synchronizeSchema();
InputStream input = new ByteArrayInputStream(bytes);
new ODatabaseImport(db1.getUnderlying(), input, new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
}
}).importDatabase().close();
assertNotNull(db1.getMetadata().getSchema().getClass("ODocumentWrapper"));
}
Aggregations