Search in sources :

Example 11 with TypeDB

use of com.vaticle.typedb.core.TypeDB in project grakn by graknlabs.

the class DataExporter method run.

public void run() {
    LOG.info("Exporting {} from TypeDB {}", database, version);
    try (OutputStream outputStream = new BufferedOutputStream(Files.newOutputStream(filename))) {
        export(outputStream, header());
        try (TypeDB.Session session = databaseMgr.session(database, Arguments.Session.Type.DATA);
            TypeDB.Transaction tx = session.transaction(Arguments.Transaction.Type.READ)) {
            totalEntityCount = tx.concepts().getRootEntityType().getInstancesCount();
            totalAttributeCount = tx.concepts().getRootAttributeType().getInstancesCount();
            totalRelationCount = tx.concepts().getRootRelationType().getInstancesCount();
            List<Runnable> exporters = Arrays.asList(() -> exportEntities(tx, outputStream), () -> exportRelations(tx, outputStream), () -> exportAttributes(tx, outputStream));
            exporters.parallelStream().forEach(Runnable::run);
            export(outputStream, checksums());
        }
    } catch (IOException e) {
        throw TypeDBException.of(FILE_NOT_WRITABLE, filename.toString());
    }
    LOG.info("Exported " + status.toString());
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) TypeDB(com.vaticle.typedb.core.TypeDB) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

TypeDB (com.vaticle.typedb.core.TypeDB)11 Test (org.junit.Test)10 EntityType (com.vaticle.typedb.core.concept.type.EntityType)8 RelationType (com.vaticle.typedb.core.concept.type.RelationType)8 AttributeType (com.vaticle.typedb.core.concept.type.AttributeType)7 RoleType (com.vaticle.typedb.core.concept.type.RoleType)7 Attribute (com.vaticle.typedb.core.concept.thing.Attribute)6 IOException (java.io.IOException)6 MB (com.vaticle.typedb.core.common.collection.Bytes.MB)5 Arguments (com.vaticle.typedb.core.common.parameters.Arguments)5 ConceptManager (com.vaticle.typedb.core.concept.ConceptManager)5 CoreDatabaseManager (com.vaticle.typedb.core.database.CoreDatabaseManager)5 LogicManager (com.vaticle.typedb.core.logic.LogicManager)5 Rule (com.vaticle.typedb.core.logic.Rule)5 Util (com.vaticle.typedb.core.test.integration.util.Util)5 Util.assertNotNulls (com.vaticle.typedb.core.test.integration.util.Util.assertNotNulls)5 TypeQL (com.vaticle.typeql.lang.TypeQL)5 Pattern (com.vaticle.typeql.lang.pattern.Pattern)5 Path (java.nio.file.Path)5 Paths (java.nio.file.Paths)5