Search in sources :

Example 6 with SQLConfiguration

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

the class PostgreSQLEntityStorePerformanceTest method cleanUp.

@Override
protected void cleanUp() throws Exception {
    try {
        super.cleanUp();
    } finally {
        Energy4Java qi4j = new Energy4Java();
        Assembler[][][] assemblers = new Assembler[][][] { { { createAssembler() } } };
        Application application = qi4j.newApplication(new ApplicationAssemblerAdapter(assemblers) {
        });
        application.activate();
        Module moduleInstance = application.findModule("Layer 1", "config");
        UnitOfWorkFactory uowf = moduleInstance;
        UnitOfWork uow = uowf.newUnitOfWork();
        try {
            SQLConfiguration config = uow.get(SQLConfiguration.class, PostgreSQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY);
            // TODO fix AbstractEntityStorePerformanceTest to extend from AbstractQi4jTest
            // SQLUtil.getConnection( this.serviceLocator );
            Connection connection = null;
            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();
        }
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Statement(java.sql.Statement) Connection(java.sql.Connection) Energy4Java(org.qi4j.bootstrap.Energy4Java) UnitOfWorkFactory(org.qi4j.api.unitofwork.UnitOfWorkFactory) SQLConfiguration(org.qi4j.library.sql.common.SQLConfiguration) DBCPDataSourceServiceAssembler(org.qi4j.library.sql.dbcp.DBCPDataSourceServiceAssembler) PostgreSQLEntityStoreAssembler(org.qi4j.entitystore.sql.assembly.PostgreSQLEntityStoreAssembler) Assembler(org.qi4j.bootstrap.Assembler) DataSourceAssembler(org.qi4j.library.sql.assembly.DataSourceAssembler) Module(org.qi4j.api.structure.Module) Application(org.qi4j.api.structure.Application) ApplicationAssemblerAdapter(org.qi4j.bootstrap.ApplicationAssemblerAdapter)

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