Search in sources :

Example 1 with SQLConfiguration

use of org.qi4j.library.sql.common.SQLConfiguration in project qi4j-sdk by Qi4j.

the class DerbySQLEntityStoreTest method tearDown.

// END SNIPPET: assembly
@Override
public void tearDown() throws Exception {
    UnitOfWork uow = this.module.newUnitOfWork(UsecaseBuilder.newUsecase("Delete " + getClass().getSimpleName() + " test data"));
    try {
        SQLConfiguration config = uow.get(SQLConfiguration.class, DerbySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY);
        Connection connection = module.findService(DataSource.class).get().getConnection();
        connection.setAutoCommit(false);
        String schemaName = config.schemaName().get();
        if (schemaName == null) {
            schemaName = SQLs.DEFAULT_SCHEMA_NAME;
        }
        try (Statement stmt = connection.createStatement()) {
            stmt.execute(String.format("DELETE FROM %s." + SQLs.TABLE_NAME, schemaName));
            connection.commit();
        }
        FileUtil.removeDirectory("target/qi4j-data");
    } finally {
        uow.discard();
        super.tearDown();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Statement(java.sql.Statement) Connection(java.sql.Connection) SQLConfiguration(org.qi4j.library.sql.common.SQLConfiguration)

Example 2 with SQLConfiguration

use of org.qi4j.library.sql.common.SQLConfiguration in project qi4j-sdk by Qi4j.

the class MySQLEntityStoreTest method tearDown.

// END SNIPPET: assembly
@Override
public void tearDown() throws Exception {
    if (true) {
        return;
    }
    UnitOfWork uow = this.module.newUnitOfWork(UsecaseBuilder.newUsecase("Delete " + getClass().getSimpleName() + " test data"));
    try {
        SQLConfiguration config = uow.get(SQLConfiguration.class, MySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY);
        Connection connection = module.findService(DataSource.class).get().getConnection();
        connection.setAutoCommit(false);
        String schemaName = config.schemaName().get();
        if (schemaName == null) {
            schemaName = SQLs.DEFAULT_SCHEMA_NAME;
        }
        try (Statement stmt = connection.createStatement()) {
            stmt.execute(String.format("DELETE FROM %s." + SQLs.TABLE_NAME, schemaName));
            connection.commit();
        }
    } finally {
        uow.discard();
        super.tearDown();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Statement(java.sql.Statement) Connection(java.sql.Connection) SQLConfiguration(org.qi4j.library.sql.common.SQLConfiguration)

Example 3 with SQLConfiguration

use of org.qi4j.library.sql.common.SQLConfiguration in project qi4j-sdk by Qi4j.

the class PostgreSQLDBIntegrityTest method createAndRemoveEntityAndVerifyNoExtraDataLeftInDB.

@Test
public void createAndRemoveEntityAndVerifyNoExtraDataLeftInDB() throws Exception {
    UnitOfWork uow = this.module.newUnitOfWork();
    TestEntity entity = uow.newEntity(TestEntity.class);
    uow.complete();
    uow = this.module.newUnitOfWork();
    entity = uow.get(entity);
    SQLConfiguration config = uow.get(SQLConfiguration.class, PostgreSQLIndexQueryAssembler.DEFAULT_IDENTITY);
    String schemaName = config.schemaName().get();
    if (schemaName == null) {
        schemaName = PostgreSQLAppStartup.DEFAULT_SCHEMA_NAME;
    }
    uow.remove(entity);
    uow.complete();
    Connection connection = this.module.findService(DataSource.class).get().getConnection();
    try {
        GenericDatabaseExplorer.visitDatabaseTables(connection, null, schemaName, null, new DatabaseProcessorAdapter() {

            @Override
            public void beginProcessRowInfo(String schemaNamee, String tableName, Object[] rowContents) {
                if ((tableName.startsWith(DBNames.QNAME_TABLE_NAME_PREFIX) && (tableName.equals(DBNames.QNAME_TABLE_NAME_PREFIX + 0) || tableName.equals(DBNames.QNAME_TABLE_NAME_PREFIX + 1))) || tableName.equals(DBNames.ALL_QNAMES_TABLE_NAME) || tableName.equals(DBNames.ENTITY_TABLE_NAME)) {
                    throw new RuntimeException("Table: " + schemaNamee + "." + tableName);
                }
            }
        }, SQLVendorProvider.createVendor(PostgreSQLVendor.class));
    } finally {
        SQLUtil.closeQuietly(connection);
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) DatabaseProcessorAdapter(org.qi4j.index.sql.support.common.GenericDatabaseExplorer.DatabaseProcessorAdapter) Connection(java.sql.Connection) SQLConfiguration(org.qi4j.library.sql.common.SQLConfiguration) PostgreSQLVendor(org.sql.generation.api.vendor.PostgreSQLVendor) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 4 with SQLConfiguration

use of org.qi4j.library.sql.common.SQLConfiguration in project qi4j-sdk by Qi4j.

the class PostgreSQLEntityStoreTest method tearDown.

// END SNIPPET: assembly
@Override
public void tearDown() throws Exception {
    UnitOfWork uow = module.newUnitOfWork(UsecaseBuilder.newUsecase("Delete " + getClass().getSimpleName() + " test data"));
    try {
        SQLConfiguration config = uow.get(SQLConfiguration.class, PostgreSQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY);
        Connection connection = module.findService(DataSource.class).get().getConnection();
        connection.setAutoCommit(false);
        String schemaName = config.schemaName().get();
        if (schemaName == null) {
            schemaName = SQLs.DEFAULT_SCHEMA_NAME;
        }
        try (Statement stmt = connection.createStatement()) {
            stmt.execute(String.format("DELETE FROM %s." + SQLs.TABLE_NAME, schemaName));
            connection.commit();
        }
    } finally {
        uow.discard();
        super.tearDown();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Statement(java.sql.Statement) Connection(java.sql.Connection) SQLConfiguration(org.qi4j.library.sql.common.SQLConfiguration)

Example 5 with SQLConfiguration

use of org.qi4j.library.sql.common.SQLConfiguration in project qi4j-sdk by Qi4j.

the class DerbySQLEntityStorePerformanceTest method cleanUp.

@Override
protected void cleanUp() throws Exception {
    if (module == null) {
        return;
    }
    UnitOfWork uow = this.module.newUnitOfWork(UsecaseBuilder.newUsecase("Delete " + getClass().getSimpleName() + " test data"));
    try {
        SQLConfiguration config = uow.get(SQLConfiguration.class, DerbySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY);
        Connection connection = module.findService(DataSource.class).get().getConnection();
        String schemaName = config.schemaName().get();
        if (schemaName == null) {
            schemaName = SQLs.DEFAULT_SCHEMA_NAME;
        }
        Statement stmt = null;
        try {
            stmt = connection.createStatement();
            stmt.execute(String.format("DELETE FROM %s." + SQLs.TABLE_NAME, schemaName));
            connection.commit();
        } finally {
            SQLUtil.closeQuietly(stmt);
        }
    } finally {
        uow.discard();
        super.cleanUp();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Statement(java.sql.Statement) Connection(java.sql.Connection) SQLConfiguration(org.qi4j.library.sql.common.SQLConfiguration)

Aggregations

Connection (java.sql.Connection)6 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)6 SQLConfiguration (org.qi4j.library.sql.common.SQLConfiguration)6 Statement (java.sql.Statement)5 Test (org.junit.Test)1 Application (org.qi4j.api.structure.Application)1 Module (org.qi4j.api.structure.Module)1 UnitOfWorkFactory (org.qi4j.api.unitofwork.UnitOfWorkFactory)1 ApplicationAssemblerAdapter (org.qi4j.bootstrap.ApplicationAssemblerAdapter)1 Assembler (org.qi4j.bootstrap.Assembler)1 Energy4Java (org.qi4j.bootstrap.Energy4Java)1 PostgreSQLEntityStoreAssembler (org.qi4j.entitystore.sql.assembly.PostgreSQLEntityStoreAssembler)1 DatabaseProcessorAdapter (org.qi4j.index.sql.support.common.GenericDatabaseExplorer.DatabaseProcessorAdapter)1 DataSourceAssembler (org.qi4j.library.sql.assembly.DataSourceAssembler)1 DBCPDataSourceServiceAssembler (org.qi4j.library.sql.dbcp.DBCPDataSourceServiceAssembler)1 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)1 PostgreSQLVendor (org.sql.generation.api.vendor.PostgreSQLVendor)1