polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [1/3] polygene-java git commit: Unifying the clean up of SQL tests, as they caused a lot of problems. Removed a "throws Exception" in AbstractPolygeneBaseTest.tearDown(), which is effectively breaking test compatibility, but I think worth it in the long
Date Fri, 27 Oct 2017 07:37:26 GMT
Repository: polygene-java
Updated Branches:
  refs/heads/develop f6a5b3384 -> db90b19ca


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/SQLEntityStoreMixin.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/SQLEntityStoreMixin.java b/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/SQLEntityStoreMixin.java
index f3c4b93..bb6f4a9 100644
--- a/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/SQLEntityStoreMixin.java
+++ b/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/SQLEntityStoreMixin.java
@@ -22,16 +22,10 @@ import java.io.Reader;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.Writer;
-import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Stream;
 import javax.sql.DataSource;
-import liquibase.Contexts;
-import liquibase.Liquibase;
-import liquibase.database.Database;
-import liquibase.database.ObjectQuotingStrategy;
-import liquibase.exception.LiquibaseException;
 import org.apache.polygene.api.configuration.Configuration;
 import org.apache.polygene.api.entity.EntityDescriptor;
 import org.apache.polygene.api.entity.EntityReference;
@@ -40,25 +34,27 @@ import org.apache.polygene.api.injection.scope.This;
 import org.apache.polygene.api.injection.scope.Uses;
 import org.apache.polygene.api.service.ServiceActivation;
 import org.apache.polygene.api.service.ServiceDescriptor;
-import org.apache.polygene.library.sql.liquibase.LiquibaseService;
 import org.apache.polygene.serialization.javaxjson.JavaxJsonFactories;
 import org.apache.polygene.spi.entitystore.EntityNotFoundException;
 import org.apache.polygene.spi.entitystore.helpers.JSONKeys;
 import org.apache.polygene.spi.entitystore.helpers.MapEntityStore;
+import org.jooq.ConnectionProvider;
 import org.jooq.DSLContext;
 import org.jooq.Field;
 import org.jooq.Query;
 import org.jooq.Record;
 import org.jooq.SQLDialect;
-import org.jooq.Schema;
 import org.jooq.Table;
+import org.jooq.TransactionProvider;
 import org.jooq.conf.Settings;
 import org.jooq.impl.DSL;
+import org.jooq.impl.DataSourceConnectionProvider;
+import org.jooq.impl.DefaultConfiguration;
+import org.jooq.impl.ThreadLocalTransactionProvider;
 
 public class SQLEntityStoreMixin
     implements ServiceActivation, MapEntityStore
 {
-    private static final String TABLE_NAME_LIQUIBASE_PARAMETER = "es-sql.table";
     private static final String IDENTITY_COLUMN_NAME = "ENTITY_IDENTITY";
     private static final String VERSION_COLUMN_NAME = "ENTITY_VERSION";
     private static final String STATE_COLUMN_NAME = "ENTITY_STATE";
@@ -67,9 +63,6 @@ public class SQLEntityStoreMixin
     private DataSource dataSource;
 
     @Service
-    private LiquibaseService liquibaseService;
-
-    @Service
     private JavaxJsonFactories jsonFactories;
 
     @Uses
@@ -78,7 +71,6 @@ public class SQLEntityStoreMixin
     @This
     private Configuration<SQLEntityStoreConfiguration> configuration;
 
-    private Schema schema;
     private Table<Record> table;
     private Field<String> identityColumn;
     private Field<String> versionColumn;
@@ -86,7 +78,8 @@ public class SQLEntityStoreMixin
     private DSLContext dsl;
 
     @Override
-    public void activateService() throws Exception
+    public void activateService()
+        throws Exception
     {
         configuration.refresh();
         SQLEntityStoreConfiguration config = configuration.get();
@@ -94,66 +87,36 @@ public class SQLEntityStoreMixin
         // Prepare jooq DSL
         SQLDialect dialect = descriptor.metaInfo( SQLDialect.class );
         Settings settings = descriptor.metaInfo( Settings.class );
-        String schemaName = config.schemaName().get();
         String tableName = config.entityTableName().get();
-        schema = DSL.schema( DSL.name( schemaName ) );
-        table = DSL.table(
-            dialect.equals( SQLDialect.SQLITE )
-            ? DSL.name( tableName )
-            : DSL.name( schema.getName(), tableName )
-        );
+        ConnectionProvider connectionProvider = new DataSourceConnectionProvider( dataSource );
+        TransactionProvider transactionProvider = new ThreadLocalTransactionProvider( connectionProvider, false );
+        org.jooq.Configuration configuration = new DefaultConfiguration()
+            .set( dialect )
+            .set( connectionProvider )
+            .set( transactionProvider )
+            .set( settings );
+        dsl = DSL.using( configuration );
+        table = DSL.table( DSL.name( tableName ) );
         identityColumn = DSL.field( DSL.name( IDENTITY_COLUMN_NAME ), String.class );
         versionColumn = DSL.field( DSL.name( VERSION_COLUMN_NAME ), String.class );
         stateColumn = DSL.field( DSL.name( STATE_COLUMN_NAME ), String.class );
-        dsl = DSL.using( dataSource, dialect, settings );
 
-        // Eventually create schema and apply Liquibase changelog
         if( config.createIfMissing().get() )
         {
-            if( !dialect.equals( SQLDialect.SQLITE )
-                && dsl.meta().getSchemas().stream().noneMatch( s -> schema.getName().equalsIgnoreCase( s.getName() ) ) )
-            {
-                dsl.createSchema( schema ).execute();
-            }
-
-            applyLiquibaseChangelog( dialect );
-        }
-    }
-
-    private void applyLiquibaseChangelog( SQLDialect dialect ) throws SQLException, LiquibaseException
-    {
-        Liquibase liquibase = liquibaseService.newConnectedLiquibase();
-        Database db = liquibase.getDatabase();
-        db.setObjectQuotingStrategy( ObjectQuotingStrategy.QUOTE_ALL_OBJECTS );
-        try
-        {
-            if( !dialect.equals( SQLDialect.SQLITE ) )
-            {
-                if( db.supportsSchemas() )
-                {
-                    db.setDefaultSchemaName( schema.getName() );
-                    db.setLiquibaseSchemaName( schema.getName() );
-                }
-                if( db.supportsCatalogs() )
-                {
-                    db.setDefaultCatalogName( schema.getName() );
-                    db.setLiquibaseCatalogName( schema.getName() );
-                }
-            }
-            liquibase.getChangeLogParameters().set( TABLE_NAME_LIQUIBASE_PARAMETER, table.getName() );
-            liquibase.update( new Contexts() );
-        }
-        finally
-        {
-            db.close();
+            dsl.transaction( t -> dsl.createTableIfNotExists( table )
+                                     .column( identityColumn )
+                                     .column( versionColumn )
+                                     .column( stateColumn )
+                                     .constraint( DSL.primaryKey( identityColumn ) )
+                                     .execute() );
         }
     }
 
     @Override
-    public void passivateService() throws Exception
+    public void passivateService()
+        throws Exception
     {
         dsl = null;
-        schema = null;
         table = null;
         identityColumn = null;
         versionColumn = null;
@@ -182,7 +145,8 @@ public class SQLEntityStoreMixin
     }
 
     @Override
-    public void applyChanges( MapChanges changes ) throws Exception
+    public void applyChanges( MapChanges changes )
+        throws Exception
     {
         List<Query> operations = new ArrayList<>();
         changes.visitMap( new MapChanger()
@@ -193,7 +157,8 @@ public class SQLEntityStoreMixin
                 return new StringWriter( 1000 )
                 {
                     @Override
-                    public void close() throws IOException
+                    public void close()
+                        throws IOException
                     {
                         super.close();
                         String state = toString();
@@ -204,7 +169,7 @@ public class SQLEntityStoreMixin
                             dsl.insertInto( table )
                                .columns( identityColumn, versionColumn, stateColumn )
                                .values( ref.identity().toString(), version, state )
-                        );
+                                      );
                     }
                 };
             }
@@ -215,7 +180,8 @@ public class SQLEntityStoreMixin
                 return new StringWriter( 1000 )
                 {
                     @Override
-                    public void close() throws IOException
+                    public void close()
+                        throws IOException
                     {
                         super.close();
                         String state = toString();
@@ -225,7 +191,7 @@ public class SQLEntityStoreMixin
                                .set( stateColumn, state )
                                .where( identityColumn.equal( mapChange.reference().identity().toString() ) )
                                .and( versionColumn.equal( mapChange.previousVersion() ) )
-                        );
+                                      );
                     }
                 };
             }
@@ -236,9 +202,9 @@ public class SQLEntityStoreMixin
                 operations.add(
                     dsl.deleteFrom( table )
                        .where( identityColumn.equal( ref.identity().toString() ) )
-                );
+                              );
             }
         } );
-        dsl.batch( operations ).execute();
+        dsl.transaction( t -> dsl.batch( operations ).execute() );
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/assembly/AbstractSQLEntityStoreAssembler.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/assembly/AbstractSQLEntityStoreAssembler.java b/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/assembly/AbstractSQLEntityStoreAssembler.java
index c2f7eb2..0925d30 100644
--- a/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/assembly/AbstractSQLEntityStoreAssembler.java
+++ b/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/assembly/AbstractSQLEntityStoreAssembler.java
@@ -24,8 +24,6 @@ import org.apache.polygene.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.ModuleAssembly;
 import org.apache.polygene.entitystore.sqlkv.SQLEntityStoreConfiguration;
 import org.apache.polygene.entitystore.sqlkv.SQLEntityStoreService;
-import org.apache.polygene.library.sql.liquibase.LiquibaseAssembler;
-import org.apache.polygene.library.sql.liquibase.LiquibaseConfiguration;
 import org.jooq.SQLDialect;
 import org.jooq.conf.RenderNameStyle;
 import org.jooq.conf.Settings;
@@ -33,8 +31,7 @@ import org.jooq.conf.Settings;
 /**
  * Base SQL EntityStore assembly.
  */
-public abstract class AbstractSQLEntityStoreAssembler<AssemblerType>
-    extends Assemblers.VisibilityIdentityConfig<AssemblerType>
+public abstract class AbstractSQLEntityStoreAssembler<AssemblerType> extends Assemblers.VisibilityIdentityConfig<AssemblerType>
 {
     public static final Identity DEFAULT_ENTITYSTORE_IDENTITY = StringIdentity.identityOf( "entitystore-sqlkv" );
     private static final String DEFAULT_CHANGELOG_PATH = "org/apache/polygene/entitystore/sql/changelog.xml";
@@ -58,16 +55,6 @@ public abstract class AbstractSQLEntityStoreAssembler<AssemblerType>
 
         String identity = ( hasIdentity() ? identity() : DEFAULT_ENTITYSTORE_IDENTITY ).toString();
 
-        LiquibaseAssembler liquibase = new LiquibaseAssembler().identifiedBy( identity + "-liquibase" );
-        if( hasConfig() )
-        {
-            liquibase.withConfig( configModule(), configVisibility() );
-            LiquibaseConfiguration liquibaseconfig = configModule().forMixin( LiquibaseConfiguration.class )
-                                                                   .declareDefaults();
-            liquibaseconfig.changeLog().set( changelogPath );
-        }
-        liquibase.assemble( module );
-
         module.services( SQLEntityStoreService.class )
               .identifiedBy( identity )
               .visibleIn( visibility() )
@@ -80,12 +67,6 @@ public abstract class AbstractSQLEntityStoreAssembler<AssemblerType>
         }
     }
 
-    public AssemblerType withLiquibaseChangelog( String changelogPath )
-    {
-        this.changelogPath = changelogPath;
-        return (AssemblerType) this;
-    }
-
     protected Settings getSettings()
     {
         return new Settings().withRenderNameStyle( RenderNameStyle.QUOTED );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/assembly/DerbySQLEntityStoreAssembler.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/assembly/DerbySQLEntityStoreAssembler.java b/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/assembly/DerbySQLEntityStoreAssembler.java
index 9110b80..96bbbc4 100644
--- a/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/assembly/DerbySQLEntityStoreAssembler.java
+++ b/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/assembly/DerbySQLEntityStoreAssembler.java
@@ -24,8 +24,7 @@ import org.jooq.SQLDialect;
 /**
  * Derby EntityStore assembly.
  */
-public class DerbySQLEntityStoreAssembler
-    extends AbstractSQLEntityStoreAssembler<DerbySQLEntityStoreAssembler>
+public class DerbySQLEntityStoreAssembler extends AbstractSQLEntityStoreAssembler<DerbySQLEntityStoreAssembler>
 {
     @Override
     protected SQLDialect getSQLDialect()

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/assembly/MariaDbSQLEntityStoreAssembler.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/assembly/MariaDbSQLEntityStoreAssembler.java b/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/assembly/MariaDbSQLEntityStoreAssembler.java
new file mode 100644
index 0000000..6ae59f0
--- /dev/null
+++ b/extensions/entitystore-sqlkv/src/main/java/org/apache/polygene/entitystore/sqlkv/assembly/MariaDbSQLEntityStoreAssembler.java
@@ -0,0 +1,35 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *
+ */
+package org.apache.polygene.entitystore.sqlkv.assembly;
+
+import org.jooq.SQLDialect;
+
+/**
+ * MySQL EntityStore assembly.
+ */
+public class MariaDbSQLEntityStoreAssembler
+    extends AbstractSQLEntityStoreAssembler<MariaDbSQLEntityStoreAssembler>
+{
+    @Override
+    protected SQLDialect getSQLDialect()
+    {
+        return SQLDialect.MARIADB;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/main/resources/org/apache/polygene/entitystore/sql/changelog.xml
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/main/resources/org/apache/polygene/entitystore/sql/changelog.xml b/extensions/entitystore-sqlkv/src/main/resources/org/apache/polygene/entitystore/sql/changelog.xml
deleted file mode 100644
index 47ef554..0000000
--- a/extensions/entitystore-sqlkv/src/main/resources/org/apache/polygene/entitystore/sql/changelog.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  ~  Licensed to the Apache Software Foundation (ASF) under one
-  ~  or more contributor license agreements.  See the NOTICE file
-  ~  distributed with this work for additional information
-  ~  regarding copyright ownership.  The ASF licenses this file
-  ~  to you under the Apache License, Version 2.0 (the
-  ~  "License"); you may not use this file except in compliance
-  ~  with the License.  You may obtain a copy of the License at
-  ~
-  ~       http://www.apache.org/licenses/LICENSE-2.0
-  ~
-  ~  Unless required by applicable law or agreed to in writing, software
-  ~  distributed under the License is distributed on an "AS IS" BASIS,
-  ~  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  ~  See the License for the specific language governing permissions and
-  ~  limitations under the License.
-  -->
-<databaseChangeLog
-        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
-        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd"
-        objectQuotingStrategy="QUOTE_ALL_OBJECTS">
-    <changeSet id="0" author="paul">
-        <createTable tableName="${es-sql.table}">
-            <column name="ENTITY_IDENTITY" type="varchar(64)">
-                <constraints primaryKey="true" nullable="false"/>
-            </column>
-            <column name="ENTITY_VERSION" type="varchar(64)">
-                <constraints nullable="false"/>
-            </column>
-            <column name="ENTITY_STATE" type="varchar(10240)">
-                <constraints nullable="false"/>
-            </column>
-        </createTable>
-    </changeSet>
-</databaseChangeLog>

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/DerbySQLEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/DerbySQLEntityStoreTest.java b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/DerbySQLEntityStoreTest.java
index 627699f..161ee07 100644
--- a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/DerbySQLEntityStoreTest.java
+++ b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/DerbySQLEntityStoreTest.java
@@ -19,25 +19,18 @@
  */
 package org.apache.polygene.entitystore.sqlkv;
 
-import java.sql.Connection;
-import java.sql.Statement;
-import javax.sql.DataSource;
 import org.apache.polygene.api.common.Visibility;
-import org.apache.polygene.api.unitofwork.UnitOfWork;
-import org.apache.polygene.api.usecase.UsecaseBuilder;
 import org.apache.polygene.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.ModuleAssembly;
-import org.apache.polygene.entitystore.sqlkv.SQLEntityStoreConfiguration;
 import org.apache.polygene.entitystore.sqlkv.assembly.DerbySQLEntityStoreAssembler;
 import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
 import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
 import org.apache.polygene.test.EntityTestAssembler;
 import org.apache.polygene.test.entity.AbstractEntityStoreTest;
+import org.jooq.SQLDialect;
+import org.junit.After;
 
-import static org.apache.polygene.entitystore.sqlkv.assembly.DerbySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY;
-
-public class DerbySQLEntityStoreTest
-    extends AbstractEntityStoreTest
+public class DerbySQLEntityStoreTest extends AbstractEntityStoreTest
 {
     @Override
     // START SNIPPET: assembly
@@ -74,29 +67,9 @@ public class DerbySQLEntityStoreTest
     // END SNIPPET: assembly
 
     @Override
+    @After
     public void tearDown()
-        throws Exception
     {
-        UnitOfWork uow = this.unitOfWorkFactory.newUnitOfWork( UsecaseBuilder.newUsecase(
-            "Delete " + getClass().getSimpleName() + " test data" ) );
-        try
-        {
-            SQLEntityStoreConfiguration config = uow.get( SQLEntityStoreConfiguration.class,
-                                                          DEFAULT_ENTITYSTORE_IDENTITY );
-            Connection connection = serviceFinder.findService( DataSource.class ).get().getConnection();
-            connection.setAutoCommit( false );
-            try( Statement stmt = connection.createStatement() )
-            {
-                stmt.execute( String.format( "DELETE FROM %s.%s",
-                                             config.schemaName().get(),
-                                             config.entityTableName().get() ) );
-                connection.commit();
-            }
-        }
-        finally
-        {
-            uow.discard();
-            super.tearDown();
-        }
+        TearDown.dropTables( moduleInstance, SQLDialect.DERBY, super::tearDown );
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/DerbySQLEntityStoreTestSuite.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/DerbySQLEntityStoreTestSuite.java b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/DerbySQLEntityStoreTestSuite.java
index b5d3949..cc61b84 100644
--- a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/DerbySQLEntityStoreTestSuite.java
+++ b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/DerbySQLEntityStoreTestSuite.java
@@ -19,22 +19,16 @@
  */
 package org.apache.polygene.entitystore.sqlkv;
 
-import java.sql.Connection;
-import java.sql.Statement;
-import javax.sql.DataSource;
 import org.apache.polygene.api.common.Visibility;
 import org.apache.polygene.api.structure.Module;
-import org.apache.polygene.api.unitofwork.UnitOfWork;
 import org.apache.polygene.api.unitofwork.UnitOfWorkFactory;
-import org.apache.polygene.api.usecase.UsecaseBuilder;
 import org.apache.polygene.bootstrap.ModuleAssembly;
-import org.apache.polygene.entitystore.sqlkv.SQLEntityStoreConfiguration;
 import org.apache.polygene.entitystore.sqlkv.assembly.DerbySQLEntityStoreAssembler;
 import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
 import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
 import org.apache.polygene.test.entity.model.EntityStoreTestSuite;
-
-import static org.apache.polygene.entitystore.sqlkv.assembly.DerbySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY;
+import org.jooq.SQLDialect;
+import org.junit.After;
 
 public class DerbySQLEntityStoreTestSuite extends EntityStoreTestSuite
 {
@@ -65,31 +59,9 @@ public class DerbySQLEntityStoreTestSuite extends EntityStoreTestSuite
     }
 
     @Override
+    @After
     public void tearDown()
-        throws Exception
     {
-        Module storageModule = application.findModule( "Infrastructure Layer","Storage Module" );
-        UnitOfWorkFactory uowf = storageModule.unitOfWorkFactory();
-        UnitOfWork uow = uowf.newUnitOfWork( UsecaseBuilder.newUsecase(
-            "Delete " + getClass().getSimpleName() + " test data" ) );
-        try
-        {
-            SQLEntityStoreConfiguration config = uow.get( SQLEntityStoreConfiguration.class,
-                                                          DEFAULT_ENTITYSTORE_IDENTITY );
-            Connection connection = storageModule.serviceFinder().findService( DataSource.class ).get().getConnection();
-            connection.setAutoCommit( false );
-            try( Statement stmt = connection.createStatement() )
-            {
-                stmt.execute( String.format( "DELETE FROM %s.%s",
-                                             config.schemaName().get(),
-                                             config.entityTableName().get() ) );
-                connection.commit();
-            }
-        }
-        finally
-        {
-            uow.discard();
-            super.tearDown();
-        }
+        TearDown.dropTables( application.findModule( INFRASTRUCTURE_LAYER, STORAGE_MODULE ), SQLDialect.DERBY, super::tearDown );
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/H2SQLEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/H2SQLEntityStoreTest.java b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/H2SQLEntityStoreTest.java
index 1303106..8575cfb 100644
--- a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/H2SQLEntityStoreTest.java
+++ b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/H2SQLEntityStoreTest.java
@@ -27,9 +27,10 @@ import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
 import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
 import org.apache.polygene.test.EntityTestAssembler;
 import org.apache.polygene.test.entity.AbstractEntityStoreTest;
+import org.jooq.SQLDialect;
+import org.junit.After;
 
-public class H2SQLEntityStoreTest
-    extends AbstractEntityStoreTest
+public class H2SQLEntityStoreTest extends AbstractEntityStoreTest
 {
     @Override
     // START SNIPPET: assembly
@@ -64,4 +65,11 @@ public class H2SQLEntityStoreTest
             .assemble( module );
     }
     // END SNIPPET: assembly
+
+    @Override
+    @After
+    public void tearDown()
+    {
+        TearDown.dropTables( moduleInstance, SQLDialect.H2, super::tearDown );
+    }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/H2SQLEntityStoreTestSuite.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/H2SQLEntityStoreTestSuite.java b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/H2SQLEntityStoreTestSuite.java
index daa3030..b4b736e 100644
--- a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/H2SQLEntityStoreTestSuite.java
+++ b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/H2SQLEntityStoreTestSuite.java
@@ -25,6 +25,8 @@ import org.apache.polygene.entitystore.sqlkv.assembly.H2SQLEntityStoreAssembler;
 import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
 import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
 import org.apache.polygene.test.entity.model.EntityStoreTestSuite;
+import org.jooq.SQLDialect;
+import org.junit.After;
 
 public class H2SQLEntityStoreTestSuite extends EntityStoreTestSuite
 {
@@ -53,4 +55,11 @@ public class H2SQLEntityStoreTestSuite extends EntityStoreTestSuite
             .withConfig( configModule, Visibility.application )
             .assemble( module );
     }
+
+    @Override
+    @After
+    public void tearDown()
+    {
+        TearDown.dropTables( application.findModule( INFRASTRUCTURE_LAYER, STORAGE_MODULE ), SQLDialect.H2, super::tearDown );
+    }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MariaDbEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MariaDbEntityStoreTest.java b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MariaDbEntityStoreTest.java
new file mode 100644
index 0000000..fbc12f3
--- /dev/null
+++ b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MariaDbEntityStoreTest.java
@@ -0,0 +1,103 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *
+ */
+package org.apache.polygene.entitystore.sqlkv;
+
+import java.util.HashMap;
+import org.apache.polygene.api.common.Visibility;
+import org.apache.polygene.bootstrap.AssemblyException;
+import org.apache.polygene.bootstrap.ModuleAssembly;
+import org.apache.polygene.entitystore.sqlkv.assembly.MySQLEntityStoreAssembler;
+import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
+import org.apache.polygene.library.sql.datasource.DataSourceConfiguration;
+import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
+import org.apache.polygene.test.EntityTestAssembler;
+import org.apache.polygene.test.docker.DockerRule;
+import org.apache.polygene.test.entity.AbstractEntityStoreTest;
+import org.jooq.SQLDialect;
+import org.junit.After;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+
+@Ignore( "Waiting response from JOOQ to fix SQL generation. VARCHAR instead of CHAR")
+public class MariaDbEntityStoreTest extends AbstractEntityStoreTest
+{
+    @ClassRule
+    public static final DockerRule DOCKER = new DockerRule(
+        "mariadb",
+        new HashMap<String, String>()
+        {{
+            put( "MYSQL_ROOT_PASSWORD", "" );
+            put( "MYSQL_ALLOW_EMPTY_PASSWORD", "yes" );
+            put( "MYSQL_DATABASE", "jdbc_test_db" );
+            put( "MYSQL_ROOT_HOST", "172.17.0.1" );
+        }},
+        30000L
+//        , "mysqld: ready for connections"   TODO: add this after next release of tdomzal/junit-docker-rule
+    );
+
+    @Override
+    // START SNIPPET: assembly
+    public void assemble( ModuleAssembly module )
+        throws AssemblyException
+    {
+        // END SNIPPET: assembly
+        super.assemble( module );
+        ModuleAssembly config = module.layer().module( "config" );
+        new EntityTestAssembler().defaultServicesVisibleIn( Visibility.layer ).assemble( config );
+
+        // START SNIPPET: assembly
+        // DataSourceService
+        new DBCPDataSourceServiceAssembler()
+            .identifiedBy( "mysql-datasource-service" )
+            .visibleIn( Visibility.module )
+            .withConfig( config, Visibility.layer )
+            .assemble( module );
+
+        // DataSource
+        new DataSourceAssembler()
+            .withDataSourceServiceIdentity( "mysql-datasource-service" )
+            .identifiedBy( "mysql-datasource" )
+            .visibleIn( Visibility.module )
+            .withCircuitBreaker()
+            .assemble( module );
+
+        // SQL EntityStore
+        new MySQLEntityStoreAssembler()
+            .visibleIn( Visibility.application )
+            .withConfig( config, Visibility.layer )
+            .assemble( module );
+        // END SNIPPET: assembly
+        String mysqlHost = DOCKER.getDockerHost();
+        int mysqlPort = DOCKER.getExposedContainerPort( "3306/tcp" );
+        config.forMixin( DataSourceConfiguration.class ).declareDefaults()
+              .url().set( "jdbc:mysql://" + mysqlHost + ":" + mysqlPort
+                          + "/jdbc_test_db?profileSQL=false&useLegacyDatetimeCode=false&serverTimezone=UTC"
+                          + "&nullCatalogMeansCurrent=true&nullNamePatternMatchesAll=true" );
+        // START SNIPPET: assembly
+    }
+    // END SNIPPET: assembly
+
+    @Override
+    @After
+    public void tearDown()
+    {
+        TearDown.dropTables( moduleInstance, SQLDialect.MARIADB, super::tearDown );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MariaDbEntityStoreTestSuite.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MariaDbEntityStoreTestSuite.java b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MariaDbEntityStoreTestSuite.java
new file mode 100644
index 0000000..1c4502a
--- /dev/null
+++ b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MariaDbEntityStoreTestSuite.java
@@ -0,0 +1,92 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *
+ */
+package org.apache.polygene.entitystore.sqlkv;
+
+import java.util.HashMap;
+import org.apache.polygene.api.common.Visibility;
+import org.apache.polygene.bootstrap.ModuleAssembly;
+import org.apache.polygene.entitystore.sqlkv.assembly.MySQLEntityStoreAssembler;
+import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
+import org.apache.polygene.library.sql.datasource.DataSourceConfiguration;
+import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
+import org.apache.polygene.test.docker.DockerRule;
+import org.apache.polygene.test.entity.model.EntityStoreTestSuite;
+import org.jooq.SQLDialect;
+import org.junit.After;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+
+@Ignore( "Waiting response from JOOQ to fix SQL generation. VARCHAR instead of CHAR")
+public class MariaDbEntityStoreTestSuite extends EntityStoreTestSuite
+{
+    @ClassRule
+    public static final DockerRule DOCKER = new DockerRule(
+        "mariadb",
+        new HashMap<String, String>()
+        {{
+            put( "MYSQL_ROOT_PASSWORD", "" );
+            put( "MYSQL_ALLOW_EMPTY_PASSWORD", "yes" );
+            put( "MYSQL_DATABASE", "jdbc_test_db" );
+            put( "MYSQL_ROOT_HOST", "172.17.0.1" );
+        }},
+        30000L
+//        , "mysqld: ready for connections"   TODO: add this after next release of tdomzal/junit-docker-rule
+    );
+
+    @Override
+    protected void defineStorageModule( ModuleAssembly module )
+    {
+        module.defaultServices();
+        // DataSourceService
+        new DBCPDataSourceServiceAssembler()
+            .identifiedBy( "mysql-datasource-service" )
+            .visibleIn( Visibility.module )
+            .withConfig( configModule, Visibility.application )
+            .assemble( module );
+
+        // DataSource
+        new DataSourceAssembler()
+            .withDataSourceServiceIdentity( "mysql-datasource-service" )
+            .identifiedBy( "mysql-datasource" )
+            .visibleIn( Visibility.module )
+            .withCircuitBreaker()
+            .assemble( module );
+
+        // SQL EntityStore
+        new MySQLEntityStoreAssembler()
+            .visibleIn( Visibility.application )
+            .withConfig( configModule, Visibility.application )
+            .assemble( module );
+
+        String mysqlHost = DOCKER.getDockerHost();
+        int mysqlPort = DOCKER.getExposedContainerPort( "3306/tcp" );
+        configModule.forMixin( DataSourceConfiguration.class ).declareDefaults()
+                    .url().set( "jdbc:mysql://" + mysqlHost + ":" + mysqlPort
+                                + "/jdbc_test_db?profileSQL=false&useLegacyDatetimeCode=false&serverTimezone=UTC"
+                                + "&nullCatalogMeansCurrent=true&nullNamePatternMatchesAll=true" );
+    }
+
+    @Override
+    @After
+    public void tearDown()
+    {
+        TearDown.dropTables( application.findModule( INFRASTRUCTURE_LAYER, STORAGE_MODULE ), SQLDialect.MARIADB, super::tearDown );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MySQLEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MySQLEntityStoreTest.java b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MySQLEntityStoreTest.java
index 3c9f689..4e45ec8 100644
--- a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MySQLEntityStoreTest.java
+++ b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MySQLEntityStoreTest.java
@@ -19,16 +19,10 @@
  */
 package org.apache.polygene.entitystore.sqlkv;
 
-import java.sql.Connection;
-import java.sql.Statement;
 import java.util.HashMap;
-import javax.sql.DataSource;
 import org.apache.polygene.api.common.Visibility;
-import org.apache.polygene.api.unitofwork.UnitOfWork;
-import org.apache.polygene.api.usecase.UsecaseBuilder;
 import org.apache.polygene.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.ModuleAssembly;
-import org.apache.polygene.entitystore.sqlkv.SQLEntityStoreConfiguration;
 import org.apache.polygene.entitystore.sqlkv.assembly.MySQLEntityStoreAssembler;
 import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
 import org.apache.polygene.library.sql.datasource.DataSourceConfiguration;
@@ -36,12 +30,13 @@ import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
 import org.apache.polygene.test.EntityTestAssembler;
 import org.apache.polygene.test.docker.DockerRule;
 import org.apache.polygene.test.entity.AbstractEntityStoreTest;
+import org.jooq.SQLDialect;
+import org.junit.After;
 import org.junit.ClassRule;
+import org.junit.Ignore;
 
-import static org.apache.polygene.entitystore.sqlkv.assembly.MySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY;
-
-public class MySQLEntityStoreTest
-    extends AbstractEntityStoreTest
+@Ignore( "Waiting response from JOOQ to fix SQL generation. VARCHAR instead of CHAR")
+public class MySQLEntityStoreTest extends AbstractEntityStoreTest
 {
     @ClassRule
     public static final DockerRule DOCKER = new DockerRule(
@@ -100,29 +95,9 @@ public class MySQLEntityStoreTest
     // END SNIPPET: assembly
 
     @Override
-    public void tearDown() throws Exception
+    @After
+    public void tearDown()
     {
-        UnitOfWork uow = this.unitOfWorkFactory.newUnitOfWork(
-            UsecaseBuilder.newUsecase( "Delete " + getClass().getSimpleName() + " test data" )
-        );
-        try
-        {
-            Connection connection = serviceFinder.findService( DataSource.class ).get().getConnection();
-            SQLEntityStoreConfiguration configuration = uow.get( SQLEntityStoreConfiguration.class,
-                                                                 DEFAULT_ENTITYSTORE_IDENTITY );
-            connection.setAutoCommit( false );
-            try( Statement stmt = connection.createStatement() )
-            {
-                stmt.execute( String.format( "TRUNCATE %s.%s",
-                                             configuration.schemaName().get(),
-                                             configuration.entityTableName().get() ) );
-                connection.commit();
-            }
-        }
-        finally
-        {
-            uow.discard();
-            super.tearDown();
-        }
+        TearDown.dropTables( moduleInstance, SQLDialect.MYSQL, super::tearDown );
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MySQLEntityStoreTestSuite.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MySQLEntityStoreTestSuite.java b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MySQLEntityStoreTestSuite.java
index 65f6b72..349ad3f 100644
--- a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MySQLEntityStoreTestSuite.java
+++ b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/MySQLEntityStoreTestSuite.java
@@ -19,28 +19,21 @@
  */
 package org.apache.polygene.entitystore.sqlkv;
 
-import java.sql.Connection;
-import java.sql.Statement;
 import java.util.HashMap;
-import javax.sql.DataSource;
 import org.apache.polygene.api.common.Visibility;
-import org.apache.polygene.api.service.ServiceFinder;
-import org.apache.polygene.api.structure.Module;
-import org.apache.polygene.api.unitofwork.UnitOfWork;
-import org.apache.polygene.api.unitofwork.UnitOfWorkFactory;
-import org.apache.polygene.api.usecase.UsecaseBuilder;
 import org.apache.polygene.bootstrap.ModuleAssembly;
-import org.apache.polygene.entitystore.sqlkv.SQLEntityStoreConfiguration;
 import org.apache.polygene.entitystore.sqlkv.assembly.MySQLEntityStoreAssembler;
 import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
 import org.apache.polygene.library.sql.datasource.DataSourceConfiguration;
 import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
 import org.apache.polygene.test.docker.DockerRule;
 import org.apache.polygene.test.entity.model.EntityStoreTestSuite;
+import org.jooq.SQLDialect;
+import org.junit.After;
 import org.junit.ClassRule;
+import org.junit.Ignore;
 
-import static org.apache.polygene.entitystore.sqlkv.assembly.MySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY;
-
+@Ignore( "Waiting response from JOOQ to fix SQL generation. VARCHAR instead of CHAR")
 public class MySQLEntityStoreTestSuite extends EntityStoreTestSuite
 {
     @ClassRule
@@ -91,33 +84,9 @@ public class MySQLEntityStoreTestSuite extends EntityStoreTestSuite
     }
 
     @Override
+    @After
     public void tearDown()
-        throws Exception
     {
-        Module storageModule = application.findModule( "Infrastructure Layer", "Storage Module" );
-        UnitOfWorkFactory uowf = storageModule.unitOfWorkFactory();
-        ServiceFinder serviceFinder = storageModule.serviceFinder();
-        UnitOfWork uow = uowf.newUnitOfWork(
-            UsecaseBuilder.newUsecase( "Delete " + getClass().getSimpleName() + " test data" )
-                                                             );
-        try
-        {
-            Connection connection = serviceFinder.findService( DataSource.class ).get().getConnection();
-            SQLEntityStoreConfiguration configuration = uow.get( SQLEntityStoreConfiguration.class,
-                                                                 DEFAULT_ENTITYSTORE_IDENTITY );
-            connection.setAutoCommit( false );
-            try( Statement stmt = connection.createStatement() )
-            {
-                stmt.execute( String.format( "TRUNCATE %s.%s",
-                                             configuration.schemaName().get(),
-                                             configuration.entityTableName().get() ) );
-                connection.commit();
-            }
-        }
-        finally
-        {
-            uow.discard();
-            super.tearDown();
-        }
+        TearDown.dropTables( application.findModule( INFRASTRUCTURE_LAYER, STORAGE_MODULE ), SQLDialect.MYSQL, super::tearDown );
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/PostgreSQLEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/PostgreSQLEntityStoreTest.java b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/PostgreSQLEntityStoreTest.java
index 2525265..1abfa3f 100644
--- a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/PostgreSQLEntityStoreTest.java
+++ b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/PostgreSQLEntityStoreTest.java
@@ -19,28 +19,21 @@
  */
 package org.apache.polygene.entitystore.sqlkv;
 
-import java.sql.Connection;
-import java.sql.Statement;
-import javax.sql.DataSource;
 import org.apache.polygene.api.common.Visibility;
-import org.apache.polygene.api.unitofwork.UnitOfWork;
-import org.apache.polygene.api.usecase.UsecaseBuilder;
 import org.apache.polygene.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.ModuleAssembly;
 import org.apache.polygene.entitystore.sqlkv.assembly.PostgreSQLEntityStoreAssembler;
 import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
-import org.apache.polygene.library.sql.common.SQLConfiguration;
 import org.apache.polygene.library.sql.datasource.DataSourceConfiguration;
 import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
 import org.apache.polygene.test.EntityTestAssembler;
 import org.apache.polygene.test.docker.DockerRule;
 import org.apache.polygene.test.entity.AbstractEntityStoreTest;
+import org.jooq.SQLDialect;
+import org.junit.After;
 import org.junit.ClassRule;
 
-import static org.apache.polygene.entitystore.sqlkv.assembly.PostgreSQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY;
-
-public class PostgreSQLEntityStoreTest
-    extends AbstractEntityStoreTest
+public class PostgreSQLEntityStoreTest extends AbstractEntityStoreTest
 {
     @ClassRule
     public static final DockerRule DOCKER = new DockerRule( "postgres",
@@ -88,28 +81,9 @@ public class PostgreSQLEntityStoreTest
     // END SNIPPET: assembly
 
     @Override
+    @After
     public void tearDown()
-        throws Exception
     {
-        UnitOfWork uow = unitOfWorkFactory.newUnitOfWork(
-            UsecaseBuilder.newUsecase( "Delete " + getClass().getSimpleName() + " test data" )
-        );
-        try
-        {
-            SQLConfiguration config = uow.get( SQLConfiguration.class, DEFAULT_ENTITYSTORE_IDENTITY );
-            Connection connection = serviceFinder.findService( DataSource.class ).get().getConnection();
-            connection.setAutoCommit( false );
-            String schemaName = config.schemaName().get();
-            try( Statement stmt = connection.createStatement() )
-            {
-                stmt.execute( String.format( "DROP SCHEMA \"%s\" CASCADE", schemaName ) );
-                connection.commit();
-            }
-        }
-        finally
-        {
-            uow.discard();
-            super.tearDown();
-        }
+        TearDown.dropTables( moduleInstance, SQLDialect.POSTGRES, super::tearDown );
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/PostgreSQLEntityStoreTestSuite.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/PostgreSQLEntityStoreTestSuite.java b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/PostgreSQLEntityStoreTestSuite.java
index 93e73e8..5e975b7 100644
--- a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/PostgreSQLEntityStoreTestSuite.java
+++ b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/PostgreSQLEntityStoreTestSuite.java
@@ -19,27 +19,18 @@
  */
 package org.apache.polygene.entitystore.sqlkv;
 
-import java.sql.Connection;
-import java.sql.Statement;
-import javax.sql.DataSource;
 import org.apache.polygene.api.common.Visibility;
-import org.apache.polygene.api.service.ServiceFinder;
-import org.apache.polygene.api.structure.Module;
-import org.apache.polygene.api.unitofwork.UnitOfWork;
-import org.apache.polygene.api.unitofwork.UnitOfWorkFactory;
-import org.apache.polygene.api.usecase.UsecaseBuilder;
 import org.apache.polygene.bootstrap.ModuleAssembly;
 import org.apache.polygene.entitystore.sqlkv.assembly.PostgreSQLEntityStoreAssembler;
 import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
-import org.apache.polygene.library.sql.common.SQLConfiguration;
 import org.apache.polygene.library.sql.datasource.DataSourceConfiguration;
 import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
 import org.apache.polygene.test.docker.DockerRule;
 import org.apache.polygene.test.entity.model.EntityStoreTestSuite;
+import org.jooq.SQLDialect;
+import org.junit.After;
 import org.junit.ClassRule;
 
-import static org.apache.polygene.entitystore.sqlkv.assembly.PostgreSQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY;
-
 public class PostgreSQLEntityStoreTestSuite extends EntityStoreTestSuite
 {
     @ClassRule
@@ -81,31 +72,9 @@ public class PostgreSQLEntityStoreTestSuite extends EntityStoreTestSuite
     // END SNIPPET: assembly
 
     @Override
+    @After
     public void tearDown()
-        throws Exception
     {
-        Module storageModule = application.findModule( "Infrastructure Layer", "Storage Module" );
-        UnitOfWorkFactory uowf = storageModule.unitOfWorkFactory();
-        ServiceFinder serviceFinder = storageModule.serviceFinder();
-        UnitOfWork uow = uowf.newUnitOfWork(
-            UsecaseBuilder.newUsecase( "Delete " + getClass().getSimpleName() + " test data" )
-                                           );
-        try
-        {
-            SQLConfiguration config = uow.get( SQLConfiguration.class, DEFAULT_ENTITYSTORE_IDENTITY );
-            Connection connection = serviceFinder.findService( DataSource.class ).get().getConnection();
-            connection.setAutoCommit( false );
-            String schemaName = config.schemaName().get();
-            try( Statement stmt = connection.createStatement() )
-            {
-                stmt.execute( String.format( "DROP SCHEMA \"%s\" CASCADE", schemaName ) );
-                connection.commit();
-            }
-        }
-        finally
-        {
-            uow.discard();
-            super.tearDown();
-        }
+        TearDown.dropTables( application.findModule( INFRASTRUCTURE_LAYER, STORAGE_MODULE ), SQLDialect.POSTGRES, super::tearDown );
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/SQLiteEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/SQLiteEntityStoreTest.java b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/SQLiteEntityStoreTest.java
index d554cd6..a74e0c3 100644
--- a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/SQLiteEntityStoreTest.java
+++ b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/SQLiteEntityStoreTest.java
@@ -27,6 +27,8 @@ import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
 import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
 import org.apache.polygene.test.EntityTestAssembler;
 import org.apache.polygene.test.entity.AbstractEntityStoreTest;
+import org.jooq.SQLDialect;
+import org.junit.After;
 import org.junit.BeforeClass;
 
 import static org.apache.polygene.test.util.Assume.assumeNoIbmJdk;
@@ -72,4 +74,11 @@ public class SQLiteEntityStoreTest extends AbstractEntityStoreTest
             .assemble( module );
     }
     // END SNIPPET: assembly
+
+    @Override
+    @After
+    public void tearDown()
+    {
+        TearDown.dropTables( moduleInstance, SQLDialect.SQLITE, super::tearDown );
+    }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/SQLiteEntityStoreTestSuite.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/SQLiteEntityStoreTestSuite.java b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/SQLiteEntityStoreTestSuite.java
index 5ae254f..a73040c 100644
--- a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/SQLiteEntityStoreTestSuite.java
+++ b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/SQLiteEntityStoreTestSuite.java
@@ -25,6 +25,8 @@ import org.apache.polygene.entitystore.sqlkv.assembly.SQLiteEntityStoreAssembler
 import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
 import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
 import org.apache.polygene.test.entity.model.EntityStoreTestSuite;
+import org.jooq.SQLDialect;
+import org.junit.After;
 import org.junit.BeforeClass;
 
 import static org.apache.polygene.test.util.Assume.assumeNoIbmJdk;
@@ -62,4 +64,11 @@ public class SQLiteEntityStoreTestSuite extends EntityStoreTestSuite
             .withConfig( configModule, Visibility.application )
             .assemble( module );
     }
+
+    @Override
+    @After
+    public void tearDown()
+    {
+        TearDown.dropTables( application.findModule( INFRASTRUCTURE_LAYER, STORAGE_MODULE ), SQLDialect.SQLITE, super::tearDown );
+    }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/TearDown.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/TearDown.java b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/TearDown.java
new file mode 100644
index 0000000..6aaa6cb
--- /dev/null
+++ b/extensions/entitystore-sqlkv/src/test/java/org/apache/polygene/entitystore/sqlkv/TearDown.java
@@ -0,0 +1,81 @@
+package org.apache.polygene.entitystore.sqlkv;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import javax.sql.DataSource;
+import org.apache.polygene.api.service.ServiceFinder;
+import org.apache.polygene.api.structure.Module;
+import org.apache.polygene.api.unitofwork.UnitOfWork;
+import org.apache.polygene.api.unitofwork.UnitOfWorkFactory;
+import org.apache.polygene.api.usecase.UsecaseBuilder;
+import org.jooq.SQLDialect;
+
+class TearDown
+{
+    static void dropTables( Module module, SQLDialect dialect, Runnable after )
+    {
+        if( module == null ){
+            System.err.println( "WARNING: 'module' was null. Happens if there was a pre-activation error. Otherwise an InternalError" );
+        }
+        UnitOfWorkFactory unitOfWorkFactory = module.unitOfWorkFactory();
+        ServiceFinder serviceFinder = module.serviceFinder();
+        try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( UsecaseBuilder.newUsecase( "Cleaning up. Drop Tables" ) ) )
+        {
+            try( Connection connection = serviceFinder.findService( DataSource.class ).get().getConnection() )
+            {
+                connection.setAutoCommit( true );
+                try( Statement stmt = connection.createStatement() )
+                {
+                    dropTable( dialect, stmt, "POLYGENE_ENTITIES" );
+                }
+            }
+        }
+        catch( SQLException e )
+        {
+            throw new RuntimeException( "Unable to clean up tables.", e );
+        }
+        finally
+        {
+            after.run();
+        }
+    }
+
+    private static void dropTable( SQLDialect dialect, Statement stmt, String tableName )
+    {
+        try
+        {
+            if( dialect == SQLDialect.MYSQL || dialect == SQLDialect.MARIADB )
+            {
+                stmt.execute( String.format( "DROP TABLE `%s`", tableName ) );
+            }
+            else
+            {
+                stmt.execute( String.format( "DROP TABLE \"%s\"", tableName ) );
+            }
+        }
+        catch( SQLException e )
+        {
+            //  ignore. Not all tables will be present in all tests.
+        }
+    }
+
+    private static void dropIndex( SQLDialect dialect, Statement stmt, String tableName )
+    {
+        try
+        {
+            if( dialect == SQLDialect.MYSQL || dialect == SQLDialect.MARIADB )
+            {
+                stmt.execute( String.format( "DROP INDEX `IDX_%s`", tableName ) );
+            }
+            else
+            {
+                stmt.execute( String.format( "DROP INDEX \"IDX_%s\"", tableName ) );
+            }
+        }
+        catch( SQLException e )
+        {
+            //  ignore. Not all tables will be present in all tests.
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/AlarmHistoryImplTest.java
----------------------------------------------------------------------
diff --git a/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/AlarmHistoryImplTest.java b/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/AlarmHistoryImplTest.java
index 5bf2ac8..d5b861b 100644
--- a/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/AlarmHistoryImplTest.java
+++ b/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/AlarmHistoryImplTest.java
@@ -73,7 +73,6 @@ public class AlarmHistoryImplTest
 
     @Override
     public void tearDown()
-        throws Exception
     {
         if ( unitOfWorkFactory.isUnitOfWorkActive())
         {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/AlarmPointImplTest.java
----------------------------------------------------------------------
diff --git a/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/AlarmPointImplTest.java b/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/AlarmPointImplTest.java
index 2281e34..42109fa 100644
--- a/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/AlarmPointImplTest.java
+++ b/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/AlarmPointImplTest.java
@@ -71,7 +71,6 @@ public class AlarmPointImplTest extends AbstractPolygeneTest
 
     @Override
     public void tearDown()
-        throws Exception
     {
         if( unitOfWorkFactory.isUnitOfWorkActive() )
         {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/AlarmServiceTest.java
----------------------------------------------------------------------
diff --git a/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/AlarmServiceTest.java b/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/AlarmServiceTest.java
index 43af0b6..0c39afe 100644
--- a/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/AlarmServiceTest.java
+++ b/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/AlarmServiceTest.java
@@ -74,7 +74,6 @@ public class AlarmServiceTest
 
     @Override
     public void tearDown()
-        throws Exception
     {
         if ( unitOfWorkFactory.isUnitOfWorkActive())
         {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/ExtendedAlarmModelTest.java
----------------------------------------------------------------------
diff --git a/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/ExtendedAlarmModelTest.java b/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/ExtendedAlarmModelTest.java
index 69fb835..56f122a 100644
--- a/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/ExtendedAlarmModelTest.java
+++ b/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/ExtendedAlarmModelTest.java
@@ -75,7 +75,6 @@ public class ExtendedAlarmModelTest
 
     @Override
     public void tearDown()
-        throws Exception
     {
         UnitOfWork uow = unitOfWorkFactory.currentUnitOfWork();
         if( uow != null )

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/SimpleAlarmModelTest.java
----------------------------------------------------------------------
diff --git a/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/SimpleAlarmModelTest.java b/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/SimpleAlarmModelTest.java
index a4c402f..1c93d2f 100644
--- a/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/SimpleAlarmModelTest.java
+++ b/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/SimpleAlarmModelTest.java
@@ -75,7 +75,6 @@ public class SimpleAlarmModelTest
 
     @Override
     public void tearDown()
-        throws Exception
     {
         UnitOfWork uow = unitOfWorkFactory.currentUnitOfWork();
         if( uow != null )

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/StandardAlarmModelTest.java
----------------------------------------------------------------------
diff --git a/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/StandardAlarmModelTest.java b/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/StandardAlarmModelTest.java
index deaa8fe..20f6440 100644
--- a/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/StandardAlarmModelTest.java
+++ b/libraries/alarm/src/test/java/org/apache/polygene/library/alarm/StandardAlarmModelTest.java
@@ -77,7 +77,6 @@ public class StandardAlarmModelTest
 
     @Override
     public void tearDown()
-        throws Exception
     {
         UnitOfWork uow = unitOfWorkFactory.currentUnitOfWork();
         if( uow != null )

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/27dc60c4/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/DerbySQLEntityStorePerformanceTest.java
----------------------------------------------------------------------
diff --git a/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/DerbySQLEntityStorePerformanceTest.java b/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/DerbySQLEntityStorePerformanceTest.java
index e034c38..291f19f 100644
--- a/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/DerbySQLEntityStorePerformanceTest.java
+++ b/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/DerbySQLEntityStorePerformanceTest.java
@@ -92,8 +92,7 @@ public class DerbySQLEntityStorePerformanceTest
             connection.setAutoCommit( false );
             try( Statement stmt = connection.createStatement() )
             {
-                stmt.execute( String.format( "DELETE FROM %s.%s",
-                                             config.schemaName().get(),
+                stmt.execute( String.format( "DELETE FROM \"%s\"",
                                              config.entityTableName().get() ) );
                 connection.commit();
             }


Mime
View raw message