Search in sources :

Example 1 with ODatabaseExport

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();
}
Also used : IOException(java.io.IOException) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) DatabaseException(com.bluenimble.platform.db.DatabaseException) ODatabaseExport(com.orientechnologies.orient.core.db.tool.ODatabaseExport)

Example 2 with ODatabaseExport

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);
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ODatabaseImport(com.orientechnologies.orient.core.db.tool.ODatabaseImport) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) ODatabaseExport(com.orientechnologies.orient.core.db.tool.ODatabaseExport) Test(org.junit.Test)

Example 3 with ODatabaseExport

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();
}
Also used : OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) ODatabaseExport(com.orientechnologies.orient.core.db.tool.ODatabaseExport)

Example 4 with ODatabaseExport

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();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseImport(com.orientechnologies.orient.core.db.tool.ODatabaseImport) OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) ArrayList(java.util.ArrayList) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) IOException(java.io.IOException) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) File(java.io.File) ORecordHook(com.orientechnologies.orient.core.hook.ORecordHook) ODatabaseExport(com.orientechnologies.orient.core.db.tool.ODatabaseExport) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with ODatabaseExport

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"));
}
Also used : ODatabaseImport(com.orientechnologies.orient.core.db.tool.ODatabaseImport) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) ODatabaseExport(com.orientechnologies.orient.core.db.tool.ODatabaseExport) Test(org.testng.annotations.Test)

Aggregations

ODatabaseExport (com.orientechnologies.orient.core.db.tool.ODatabaseExport)7 OCommandOutputListener (com.orientechnologies.orient.core.command.OCommandOutputListener)5 ODatabaseImport (com.orientechnologies.orient.core.db.tool.ODatabaseImport)3 IOException (java.io.IOException)3 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)2 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)2 Test (org.testng.annotations.Test)2 DatabaseException (com.bluenimble.platform.db.DatabaseException)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 ORecordHook (com.orientechnologies.orient.core.hook.ORecordHook)1 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)1 OObjectDatabaseTx (com.orientechnologies.orient.object.db.OObjectDatabaseTx)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 SocketException (java.net.SocketException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 Test (org.junit.Test)1