Search in sources :

Example 1 with DatabaseProcessorAdapter

use of org.qi4j.index.sql.support.common.GenericDatabaseExplorer.DatabaseProcessorAdapter 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)

Aggregations

Connection (java.sql.Connection)1 Test (org.junit.Test)1 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)1 DatabaseProcessorAdapter (org.qi4j.index.sql.support.common.GenericDatabaseExplorer.DatabaseProcessorAdapter)1 SQLConfiguration (org.qi4j.library.sql.common.SQLConfiguration)1 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)1 PostgreSQLVendor (org.sql.generation.api.vendor.PostgreSQLVendor)1