You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by pa...@apache.org on 2017/03/13 15:28:52 UTC

[29/48] polygene-java git commit: Finish jooq & liquibase powered SQL ES

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/DerbySQLEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/DerbySQLEntityStoreTest.java b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/DerbySQLEntityStoreTest.java
index 6d849cc..f66ca9c 100644
--- a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/DerbySQLEntityStoreTest.java
+++ b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/DerbySQLEntityStoreTest.java
@@ -28,13 +28,13 @@ import org.apache.polygene.api.usecase.UsecaseBuilder;
 import org.apache.polygene.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.ModuleAssembly;
 import org.apache.polygene.entitystore.sql.assembly.DerbySQLEntityStoreAssembler;
-import org.apache.polygene.entitystore.sql.internal.SQLs;
 import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
-import org.apache.polygene.library.sql.common.SQLConfiguration;
 import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
 import org.apache.polygene.test.EntityTestAssembler;
 import org.apache.polygene.test.entity.AbstractEntityStoreTest;
 
+import static org.apache.polygene.entitystore.sql.assembly.DerbySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY;
+
 public class DerbySQLEntityStoreTest
     extends AbstractEntityStoreTest
 {
@@ -80,18 +80,15 @@ public class DerbySQLEntityStoreTest
             "Delete " + getClass().getSimpleName() + " test data" ) );
         try
         {
-            SQLConfiguration config = uow.get( SQLConfiguration.class,
-                                               DerbySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY );
+            SQLMapEntityStoreConfiguration config = uow.get( SQLMapEntityStoreConfiguration.class,
+                                                             DEFAULT_ENTITYSTORE_IDENTITY );
             Connection connection = serviceFinder.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.%s", schemaName, SQLs.TABLE_NAME ) );
+                stmt.execute( String.format( "DELETE FROM %s.%s",
+                                             config.schemaName().get(),
+                                             config.entityTableName().get() ) );
                 connection.commit();
             }
         }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/MySQLEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/MySQLEntityStoreTest.java b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/MySQLEntityStoreTest.java
index 059301c..402782e 100644
--- a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/MySQLEntityStoreTest.java
+++ b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/MySQLEntityStoreTest.java
@@ -29,15 +29,16 @@ import org.apache.polygene.api.usecase.UsecaseBuilder;
 import org.apache.polygene.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.ModuleAssembly;
 import org.apache.polygene.entitystore.sql.assembly.MySQLEntityStoreAssembler;
-import org.apache.polygene.entitystore.sql.internal.SQLs;
-import org.apache.polygene.test.internal.DockerRule;
 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.entity.AbstractEntityStoreTest;
+import org.apache.polygene.test.internal.DockerRule;
 import org.junit.ClassRule;
 
+import static org.apache.polygene.entitystore.sql.assembly.MySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY;
+
 public class MySQLEntityStoreTest
     extends AbstractEntityStoreTest
 {
@@ -90,7 +91,8 @@ public class MySQLEntityStoreTest
         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" );
+                          + "/jdbc_test_db?profileSQL=false&useLegacyDatetimeCode=false&serverTimezone=UTC"
+                          + "&nullCatalogMeansCurrent=true&nullNamePatternMatchesAll=true" );
         // START SNIPPET: assembly
     }
     // END SNIPPET: assembly
@@ -104,10 +106,14 @@ public class MySQLEntityStoreTest
         try
         {
             Connection connection = serviceFinder.findService( DataSource.class ).get().getConnection();
+            SQLMapEntityStoreConfiguration configuration = uow.get( SQLMapEntityStoreConfiguration.class,
+                                                                    DEFAULT_ENTITYSTORE_IDENTITY );
             connection.setAutoCommit( false );
             try( Statement stmt = connection.createStatement() )
             {
-                stmt.execute( String.format( "TRUNCATE %s", SQLs.TABLE_NAME ) );
+                stmt.execute( String.format( "TRUNCATE %s.%s",
+                                             configuration.schemaName().get(),
+                                             configuration.entityTableName().get() ) );
                 connection.commit();
             }
         }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/PostgreSQLEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/PostgreSQLEntityStoreTest.java b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/PostgreSQLEntityStoreTest.java
index c6dd48c..d1f06f3 100644
--- a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/PostgreSQLEntityStoreTest.java
+++ b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/PostgreSQLEntityStoreTest.java
@@ -28,16 +28,17 @@ import org.apache.polygene.api.usecase.UsecaseBuilder;
 import org.apache.polygene.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.ModuleAssembly;
 import org.apache.polygene.entitystore.sql.assembly.PostgreSQLEntityStoreAssembler;
-import org.apache.polygene.entitystore.sql.internal.SQLs;
-import org.apache.polygene.test.internal.DockerRule;
 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.entity.AbstractEntityStoreTest;
+import org.apache.polygene.test.internal.DockerRule;
 import org.junit.ClassRule;
 
+import static org.apache.polygene.entitystore.sql.assembly.PostgreSQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY;
+
 /**
  * WARN This test run only if localhost:5432 is listening.
  *
@@ -127,15 +128,10 @@ public class PostgreSQLEntityStoreTest
         );
         try
         {
-            SQLConfiguration config = uow.get( SQLConfiguration.class,
-                                               PostgreSQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY );
+            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();
-            if( schemaName == null )
-            {
-                schemaName = SQLs.DEFAULT_SCHEMA_NAME;
-            }
             try( Statement stmt = connection.createStatement() )
             {
                 stmt.execute( String.format( "DROP SCHEMA \"%s\" CASCADE", schemaName ) );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/SQLiteEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/SQLiteEntityStoreTest.java b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/SQLiteEntityStoreTest.java
index 24dd298..07402b5 100644
--- a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/SQLiteEntityStoreTest.java
+++ b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/SQLiteEntityStoreTest.java
@@ -31,8 +31,7 @@ import org.junit.BeforeClass;
 
 import static org.apache.polygene.test.util.Assume.assumeNoIbmJdk;
 
-public class SQLiteEntityStoreTest
-    extends AbstractEntityStoreTest
+public class SQLiteEntityStoreTest extends AbstractEntityStoreTest
 {
     @BeforeClass
     public static void beforeClass_IBMJDK()

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/extensions/entitystore-sql/src/test/resources/mysql-datasource.properties
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/test/resources/mysql-datasource.properties b/extensions/entitystore-sql/src/test/resources/mysql-datasource.properties
index 964c7d6..a2f4175 100644
--- a/extensions/entitystore-sql/src/test/resources/mysql-datasource.properties
+++ b/extensions/entitystore-sql/src/test/resources/mysql-datasource.properties
@@ -19,7 +19,7 @@
 #
 
 enabled=true
-#url=jdbc:mysql://localhost:3306/jdbc_test_db?profileSQL=false&useLegacyDatetimeCode=false&serverTimezone=UTC
+#url=jdbc:mysql://localhost:3306/jdbc_test_db?profileSQL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&nullCatalogMeansCurrent=true&nullNamePatternMatchesAll=true
 driver=com.mysql.cj.jdbc.Driver
 username=root
 password=

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/SQLIndexingEngineConfiguration.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/SQLIndexingEngineConfiguration.java b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/SQLIndexingEngineConfiguration.java
new file mode 100644
index 0000000..5920ed6
--- /dev/null
+++ b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/SQLIndexingEngineConfiguration.java
@@ -0,0 +1,31 @@
+/*
+ *  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.index.sql;
+
+import org.apache.polygene.api.common.UseDefaults;
+import org.apache.polygene.api.property.Property;
+import org.apache.polygene.library.sql.common.SQLConfiguration;
+
+public interface SQLIndexingEngineConfiguration extends SQLConfiguration
+{
+    @UseDefaults( "POLYGENE_INDEX" )
+    @Override
+    Property<String> schemaName();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/assembly/AbstractSQLIndexQueryAssembler.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/assembly/AbstractSQLIndexQueryAssembler.java b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/assembly/AbstractSQLIndexQueryAssembler.java
index 11f257e..a9dcd0c 100644
--- a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/assembly/AbstractSQLIndexQueryAssembler.java
+++ b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/assembly/AbstractSQLIndexQueryAssembler.java
@@ -28,8 +28,8 @@ import org.apache.polygene.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.ModuleAssembly;
 import org.apache.polygene.index.reindexer.ReindexerConfiguration;
 import org.apache.polygene.index.reindexer.ReindexerService;
+import org.apache.polygene.index.sql.SQLIndexingEngineConfiguration;
 import org.apache.polygene.index.sql.support.common.ReindexingStrategy;
-import org.apache.polygene.library.sql.common.SQLConfiguration;
 import org.sql.generation.api.vendor.SQLVendor;
 import org.sql.generation.api.vendor.SQLVendorProvider;
 
@@ -91,7 +91,7 @@ public abstract class AbstractSQLIndexQueryAssembler<AssemblerType>
 
         if( hasConfig() )
         {
-            configModule().entities( SQLConfiguration.class,
+            configModule().entities( SQLIndexingEngineConfiguration.class,
                                      ReindexerConfiguration.class ).
                               visibleIn( configVisibility() );
         }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLStartup.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLStartup.java b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLStartup.java
index e74572f..b41c41a 100644
--- a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLStartup.java
+++ b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLStartup.java
@@ -136,8 +136,6 @@ public abstract class AbstractSQLStartup
         SQLDataType customizeType( Type propertyType, SQLTypeInfo sqlTypeInfo );
     }
 
-    public static final String DEFAULT_SCHEMA_NAME = "polygene";
-
     private static final Class<?> ENTITY_PK_TYPE = Long.class;
     private static final Class<?> ENTITY_TYPE_PK_TYPE = Integer.class;
 
@@ -195,15 +193,8 @@ public abstract class AbstractSQLStartup
         this.initTypes();
         this.modifyPrimitiveTypes( this._primitiveTypes, this._state.javaTypes2SQLTypes().get() );
 
-        String schemaName = this._configuration.get().schemaName().get();
-        if( schemaName == null )
-        {
-            schemaName = DEFAULT_SCHEMA_NAME;
-        }
-        else
-        {
-            this.checkSchemaName( schemaName );
-        }
+        String schemaName = this._configuration.get().schemaName().get().toLowerCase();
+        this.checkSchemaName( schemaName );
         LOGGER.debug( "Will use '{}' as schema name", schemaName );
 
         this._state.schemaName().set( schemaName );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/extensions/indexing-sql/src/test/java/org/apache/polygene/index/sql/postgresql/PostgreSQLDBIntegrityTest.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-sql/src/test/java/org/apache/polygene/index/sql/postgresql/PostgreSQLDBIntegrityTest.java b/extensions/indexing-sql/src/test/java/org/apache/polygene/index/sql/postgresql/PostgreSQLDBIntegrityTest.java
index 627c8df..62c245e 100644
--- a/extensions/indexing-sql/src/test/java/org/apache/polygene/index/sql/postgresql/PostgreSQLDBIntegrityTest.java
+++ b/extensions/indexing-sql/src/test/java/org/apache/polygene/index/sql/postgresql/PostgreSQLDBIntegrityTest.java
@@ -90,11 +90,7 @@ public class PostgreSQLDBIntegrityTest
         uow = this.unitOfWorkFactory.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;
-        }
+        String schemaName = config.schemaName().get().toLowerCase();
         uow.remove( entity );
         uow.complete();
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/libraries/sql-liquibase/build.gradle
----------------------------------------------------------------------
diff --git a/libraries/sql-liquibase/build.gradle b/libraries/sql-liquibase/build.gradle
index 4d94e30..e6a43ef 100644
--- a/libraries/sql-liquibase/build.gradle
+++ b/libraries/sql-liquibase/build.gradle
@@ -26,9 +26,7 @@ jar { manifest { name = "Apache Polygene\u2122 Library - SQL Liquibase" } }
 
 dependencies {
   api polygene.library( 'sql' )
-
-  implementation libraries.liquibase
-  implementation libraries.slf4j_api
+  api libraries.liquibase
 
   runtimeOnly polygene.core.runtime
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/libraries/sql-liquibase/src/main/java/org/apache/polygene/library/sql/liquibase/LiquibaseAssembler.java
----------------------------------------------------------------------
diff --git a/libraries/sql-liquibase/src/main/java/org/apache/polygene/library/sql/liquibase/LiquibaseAssembler.java b/libraries/sql-liquibase/src/main/java/org/apache/polygene/library/sql/liquibase/LiquibaseAssembler.java
index 15124f8..e462c0b 100644
--- a/libraries/sql-liquibase/src/main/java/org/apache/polygene/library/sql/liquibase/LiquibaseAssembler.java
+++ b/libraries/sql-liquibase/src/main/java/org/apache/polygene/library/sql/liquibase/LiquibaseAssembler.java
@@ -27,13 +27,17 @@ import org.apache.polygene.bootstrap.ServiceDeclaration;
 public class LiquibaseAssembler
     extends Assemblers.VisibilityIdentityConfig<LiquibaseAssembler>
 {
+    private boolean applyChangelogOnStartup;
+
     @Override
     public void assemble( ModuleAssembly module )
         throws AssemblyException
     {
-        ServiceDeclaration service = module.services( LiquibaseService.class ).
-            visibleIn( visibility() ).
-            instantiateOnStartup();
+        ServiceDeclaration service = module.services( LiquibaseService.class ).visibleIn( visibility() );
+        if( applyChangelogOnStartup )
+        {
+            service.withActivators( LiquibaseService.ApplyChangelogActivator.class ).instantiateOnStartup();
+        }
         if( hasIdentity() )
         {
             service.identifiedBy( identity() );
@@ -43,4 +47,10 @@ public class LiquibaseAssembler
             configModule().entities( LiquibaseConfiguration.class ).visibleIn( configVisibility() );
         }
     }
+
+    public LiquibaseAssembler applyChangelogOnStartup()
+    {
+        applyChangelogOnStartup = true;
+        return this;
+    }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/libraries/sql-liquibase/src/main/java/org/apache/polygene/library/sql/liquibase/LiquibaseConfiguration.java
----------------------------------------------------------------------
diff --git a/libraries/sql-liquibase/src/main/java/org/apache/polygene/library/sql/liquibase/LiquibaseConfiguration.java b/libraries/sql-liquibase/src/main/java/org/apache/polygene/library/sql/liquibase/LiquibaseConfiguration.java
index bb5c00b..99ffa3a 100644
--- a/libraries/sql-liquibase/src/main/java/org/apache/polygene/library/sql/liquibase/LiquibaseConfiguration.java
+++ b/libraries/sql-liquibase/src/main/java/org/apache/polygene/library/sql/liquibase/LiquibaseConfiguration.java
@@ -20,18 +20,18 @@
 package org.apache.polygene.library.sql.liquibase;
 
 import org.apache.polygene.api.common.UseDefaults;
-import org.apache.polygene.api.configuration.ConfigurationComposite;
-import org.apache.polygene.api.configuration.Enabled;
 import org.apache.polygene.api.property.Property;
 
 /**
- * Configuration for Liquibase
+ * Configuration for Liquibase.
  */
 // START SNIPPET: config
 public interface LiquibaseConfiguration
-        extends ConfigurationComposite, Enabled
 {
-    @UseDefaults Property<String> contexts();
-    @UseDefaults Property<String> changeLog();
+    @UseDefaults
+    Property<String> changeLog();
+
+    @UseDefaults
+    Property<String> contexts();
 }
 // END SNIPPET: config

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/libraries/sql-liquibase/src/main/java/org/apache/polygene/library/sql/liquibase/LiquibaseService.java
----------------------------------------------------------------------
diff --git a/libraries/sql-liquibase/src/main/java/org/apache/polygene/library/sql/liquibase/LiquibaseService.java b/libraries/sql-liquibase/src/main/java/org/apache/polygene/library/sql/liquibase/LiquibaseService.java
index e909999..4be23a5 100644
--- a/libraries/sql-liquibase/src/main/java/org/apache/polygene/library/sql/liquibase/LiquibaseService.java
+++ b/libraries/sql-liquibase/src/main/java/org/apache/polygene/library/sql/liquibase/LiquibaseService.java
@@ -19,58 +19,76 @@
  */
 package org.apache.polygene.library.sql.liquibase;
 
-import java.net.ConnectException;
-import java.sql.Connection;
 import java.sql.SQLException;
+import java.util.Collections;
+import java.util.Map;
 import javax.sql.DataSource;
 import liquibase.Liquibase;
 import liquibase.database.DatabaseConnection;
 import liquibase.database.jvm.JdbcConnection;
+import liquibase.exception.LiquibaseException;
 import liquibase.resource.ClassLoaderResourceAccessor;
 import org.apache.polygene.api.activation.ActivatorAdapter;
-import org.apache.polygene.api.activation.Activators;
 import org.apache.polygene.api.configuration.Configuration;
 import org.apache.polygene.api.injection.scope.Service;
 import org.apache.polygene.api.injection.scope.This;
 import org.apache.polygene.api.mixin.Mixins;
-import org.apache.polygene.api.service.ServiceComposite;
-import org.apache.polygene.api.service.ServiceImporterException;
 import org.apache.polygene.api.service.ServiceReference;
-import org.apache.polygene.library.sql.common.SQLUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Wrapper service for Liquibase.
  */
 @Mixins( LiquibaseService.Mixin.class )
-@Activators( LiquibaseService.Activator.class )
 public interface LiquibaseService
-        extends ServiceComposite
 {
-
-    void activateLiquibase()
-            throws Exception;
-
-    public static class Activator
-            extends ActivatorAdapter<ServiceReference<LiquibaseService>>
+    /**
+     * Creates a new Liquibase instance connected to a visible DataSource.
+     *
+     * <strong>WARNING</strong> remember to {@literal liquibase.getDatabase().close()}
+     *
+     * @return a new Liquibase instance connected to a visible DataSource.
+     * @throws SQLException if something goes wrong
+     * @throws LiquibaseException  if something goes wrong
+     */
+    Liquibase newConnectedLiquibase() throws SQLException, LiquibaseException;
+
+    /**
+     * Apply the configured database changelog.
+     *
+     * @throws SQLException if something goes wrong
+     * @throws LiquibaseException  if something goes wrong
+     */
+    void applyChangelog() throws SQLException, LiquibaseException;
+
+    /**
+     * Apply the configured database changelog.
+     *
+     * @param parameters changelog parameters, see {@link Liquibase#getChangeLogParameters()}
+     * @throws SQLException if something goes wrong
+     * @throws LiquibaseException  if something goes wrong
+     */
+    void applyChangelog( Map<String, Object> parameters )
+        throws SQLException, LiquibaseException;
+
+    /**
+     * Apply database changelog on application startup.
+     *
+     * Assembled by {@link LiquibaseAssembler#applyChangelogOnStartup()}.
+     *
+     * @see LiquibaseService#applyChangelog()
+     */
+    class ApplyChangelogActivator extends ActivatorAdapter<ServiceReference<LiquibaseService>>
     {
-
         @Override
         public void afterActivation( ServiceReference<LiquibaseService> activated )
-                throws Exception
+            throws Exception
         {
-            activated.get().activateLiquibase();
+            activated.get().applyChangelog();
         }
-
     }
 
-    public static abstract class Mixin
-            implements LiquibaseService
+    class Mixin implements LiquibaseService
     {
-
-        private static final Logger LOGGER = LoggerFactory.getLogger( "org.apache.polygene.library.sql" );
-
         @This
         Configuration<LiquibaseConfiguration> config;
 
@@ -78,49 +96,42 @@ public interface LiquibaseService
         ServiceReference<DataSource> dataSource;
 
         @Override
-        public void activateLiquibase()
-                throws Exception
+        public Liquibase newConnectedLiquibase() throws SQLException, LiquibaseException
         {
             config.refresh();
-            boolean enabled = config.get().enabled().get();
-            if ( !enabled ) {
-                return;
-            }
-
-            Connection connection = null;
-            try {
-
-                connection = dataSource.get().getConnection();
-                DatabaseConnection dc = new JdbcConnection( connection );
-                Liquibase liquibase = new Liquibase( config.get().changeLog().get(), new ClassLoaderResourceAccessor(), dc );
-                liquibase.update( config.get().contexts().get() );
+            DatabaseConnection dbConnection = new JdbcConnection( dataSource.get().getConnection() );
+            return new Liquibase( config.get().changeLog().get(),
+                                  new ClassLoaderResourceAccessor(),
+                                  dbConnection );
+        }
 
-            } catch ( SQLException e ) {
+        @Override
+        public void applyChangelog() throws SQLException, LiquibaseException
+        {
+            applyChangelog( Collections.emptyMap() );
+        }
 
-                Throwable ex = e;
-                while ( ex.getCause() != null ) {
-                    ex = ex.getCause();
+        @Override
+        public void applyChangelog( Map<String, Object> parameters )
+            throws SQLException, LiquibaseException
+        {
+            Liquibase liquibase = null;
+            try
+            {
+                liquibase = newConnectedLiquibase();
+                for( Map.Entry<String, Object> entry : parameters.entrySet() )
+                {
+                    liquibase.getChangeLogParameters().set( entry.getKey(), entry.getValue() );
                 }
-
-                if ( ex instanceof ConnectException ) {
-                    LOGGER.warn( "Could not connect to database; Liquibase should be disabled" );
-                    return;
+                liquibase.update( config.get().contexts().get() );
+            }
+            finally
+            {
+                if( liquibase != null )
+                {
+                    liquibase.getDatabase().close();
                 }
-
-                LOGGER.error( "Liquibase could not perform database migration", e );
-
-            } catch ( ServiceImporterException ex ) {
-
-                LOGGER.warn( "DataSource is not available - database refactoring skipped" );
-
-            } finally {
-
-                SQLUtil.rollbackQuietly( connection );
-                SQLUtil.closeQuietly( connection );
-
             }
         }
-
     }
-
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/libraries/sql-liquibase/src/test/java/org/apache/polygene/library/sql/liquibase/LiquibaseServiceTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-liquibase/src/test/java/org/apache/polygene/library/sql/liquibase/LiquibaseServiceTest.java b/libraries/sql-liquibase/src/test/java/org/apache/polygene/library/sql/liquibase/LiquibaseServiceTest.java
index 108a187..fd39fb3 100644
--- a/libraries/sql-liquibase/src/test/java/org/apache/polygene/library/sql/liquibase/LiquibaseServiceTest.java
+++ b/libraries/sql-liquibase/src/test/java/org/apache/polygene/library/sql/liquibase/LiquibaseServiceTest.java
@@ -19,8 +19,6 @@
  */
 package org.apache.polygene.library.sql.liquibase;
 
-import java.io.IOException;
-import java.sql.SQLException;
 import java.util.List;
 import java.util.function.Function;
 import javax.sql.DataSource;
@@ -60,8 +58,7 @@ import static org.junit.Assert.assertTrue;
 public class LiquibaseServiceTest
 {
     @Test
-    public void testLiquibase()
-        throws SQLException, IOException, ActivationException, AssemblyException
+    public void testLiquibase() throws ActivationException
     {
         final SingletonAssembler assembler = new SingletonAssembler()
         {
@@ -89,9 +86,9 @@ public class LiquibaseServiceTest
                 // START SNIPPET: assembly
                 new LiquibaseAssembler()
                     .withConfig( configModule, Visibility.layer )
+                    .applyChangelogOnStartup()
                     .assemble( module );
                 // END SNIPPET: assembly
-                module.forMixin( LiquibaseConfiguration.class ).declareDefaults().enabled().set( true );
                 module.forMixin( LiquibaseConfiguration.class ).declareDefaults().changeLog().set( "changelog.xml" );
             }
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/libraries/sql/src/main/java/org/apache/polygene/library/sql/common/SQLConfiguration.java
----------------------------------------------------------------------
diff --git a/libraries/sql/src/main/java/org/apache/polygene/library/sql/common/SQLConfiguration.java b/libraries/sql/src/main/java/org/apache/polygene/library/sql/common/SQLConfiguration.java
index 0a0da78..2a62a7e 100644
--- a/libraries/sql/src/main/java/org/apache/polygene/library/sql/common/SQLConfiguration.java
+++ b/libraries/sql/src/main/java/org/apache/polygene/library/sql/common/SQLConfiguration.java
@@ -20,7 +20,6 @@
 package org.apache.polygene.library.sql.common;
 
 import org.apache.polygene.api.common.Optional;
-import org.apache.polygene.api.configuration.ConfigurationComposite;
 import org.apache.polygene.api.property.Property;
 
 /**
@@ -28,13 +27,10 @@ import org.apache.polygene.api.property.Property;
  * database, and given schema name as schema to create tables in.
  */
 public interface SQLConfiguration
-        extends ConfigurationComposite
 {
-
     /**
      * The schema name to use to create/find tables.
      */
     @Optional
     Property<String> schemaName();
-
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/libraries/sql/src/test/java/org/apache/polygene/library/sql/jmx/DataSourceConfigurationManagerServiceTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql/src/test/java/org/apache/polygene/library/sql/jmx/DataSourceConfigurationManagerServiceTest.java b/libraries/sql/src/test/java/org/apache/polygene/library/sql/jmx/DataSourceConfigurationManagerServiceTest.java
index 3645623..fc2a922 100644
--- a/libraries/sql/src/test/java/org/apache/polygene/library/sql/jmx/DataSourceConfigurationManagerServiceTest.java
+++ b/libraries/sql/src/test/java/org/apache/polygene/library/sql/jmx/DataSourceConfigurationManagerServiceTest.java
@@ -30,8 +30,8 @@ import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
 import org.apache.polygene.library.sql.assembly.DataSourceJMXAssembler;
 import org.apache.polygene.library.sql.datasource.DataSources;
 import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
+import org.apache.polygene.library.sql.liquibase.LiquibaseAssembler;
 import org.apache.polygene.library.sql.liquibase.LiquibaseConfiguration;
-import org.apache.polygene.library.sql.liquibase.LiquibaseService;
 import org.apache.polygene.test.EntityTestAssembler;
 import org.junit.Test;
 
@@ -95,10 +95,9 @@ public class DataSourceConfigurationManagerServiceTest
                                              .assemble( testModule );
 
                     // Set up Liquibase service that will create the tables
-                    testModule.services( LiquibaseService.class ).identifiedBy( "liquibase1" ).instantiateOnStartup();
-                    testModule.entities( LiquibaseConfiguration.class );
-                    testModule.forMixin( LiquibaseConfiguration.class ).declareDefaults()
-                              .enabled().set( true );
+                    new LiquibaseAssembler().identifiedBy( "liquibase1" )
+                                            .applyChangelogOnStartup()
+                                            .assemble( testModule );
                     testModule.forMixin( LiquibaseConfiguration.class ).declareDefaults()
                               .changeLog().set( "changelog.xml" );
                 }
@@ -115,12 +114,11 @@ public class DataSourceConfigurationManagerServiceTest
                                              .assemble( testModule2 );
 
                     // Set up Liquibase service that will create the tables
-                    testModule2.services( LiquibaseService.class ).identifiedBy( "liquibase2" ).instantiateOnStartup();
-                    testModule2.entities( LiquibaseConfiguration.class );
-                    testModule2.forMixin( LiquibaseConfiguration.class ).declareDefaults()
-                               .enabled().set( true );
+                    new LiquibaseAssembler().identifiedBy( "liquibase2" )
+                                            .applyChangelogOnStartup()
+                                            .assemble( testModule2 );
                     testModule2.forMixin( LiquibaseConfiguration.class ).declareDefaults()
-                               .changeLog().set( "changelog.xml" );
+                              .changeLog().set( "changelog.xml" );
                 }
 
                 // START SNIPPET: jmx

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/samples/sql-support/src/main/java/org/apache/polygene/sample/sqlsupport/Main.java
----------------------------------------------------------------------
diff --git a/samples/sql-support/src/main/java/org/apache/polygene/sample/sqlsupport/Main.java b/samples/sql-support/src/main/java/org/apache/polygene/sample/sqlsupport/Main.java
index a3cb6aa..5a96f31 100644
--- a/samples/sql-support/src/main/java/org/apache/polygene/sample/sqlsupport/Main.java
+++ b/samples/sql-support/src/main/java/org/apache/polygene/sample/sqlsupport/Main.java
@@ -31,9 +31,7 @@ import org.apache.polygene.api.structure.Module;
 import org.apache.polygene.api.unitofwork.UnitOfWork;
 import org.apache.polygene.bootstrap.Energy4Java;
 import org.apache.polygene.entitystore.sql.assembly.PostgreSQLEntityStoreAssembler;
-import org.apache.polygene.entitystore.sql.internal.SQLs;
 import org.apache.polygene.index.sql.assembly.PostgreSQLIndexQueryAssembler;
-import org.apache.polygene.index.sql.support.postgresql.PostgreSQLAppStartup;
 import org.apache.polygene.library.sql.common.SQLConfiguration;
 import org.apache.polygene.library.sql.common.SQLUtil;
 
@@ -120,9 +118,6 @@ public class Main
                 connection.setAutoCommit( false );
                 connection.setReadOnly( false );
                 String schemaName = config.schemaName().get();
-                if ( schemaName == null ) {
-                    schemaName = SQLs.DEFAULT_SCHEMA_NAME;
-                }
 
                 Statement stmt = null;
                 try {
@@ -146,9 +141,6 @@ public class Main
                 connection.setAutoCommit( false );
                 connection.setReadOnly( false );
                 String schemaName = config.schemaName().get();
-                if ( schemaName == null ) {
-                    schemaName = PostgreSQLAppStartup.DEFAULT_SCHEMA_NAME;
-                }
 
                 Statement stmt = null;
                 try {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/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 5906307..09a0331 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
@@ -26,15 +26,15 @@ import org.apache.polygene.api.usecase.UsecaseBuilder;
 import org.apache.polygene.bootstrap.Assembler;
 import org.apache.polygene.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.ModuleAssembly;
+import org.apache.polygene.entitystore.sql.SQLMapEntityStoreConfiguration;
 import org.apache.polygene.entitystore.sql.assembly.DerbySQLEntityStoreAssembler;
-import org.apache.polygene.entitystore.sql.internal.SQLs;
 import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
-import org.apache.polygene.library.sql.common.SQLConfiguration;
-import org.apache.polygene.library.sql.common.SQLUtil;
 import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
 import org.apache.polygene.test.EntityTestAssembler;
 import org.apache.polygene.test.performance.entitystore.AbstractEntityStorePerformanceTest;
 
+import static org.apache.polygene.entitystore.sql.assembly.DerbySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY;
+
 /**
  * Performance test for DerbySQLEntityStore.
  */
@@ -88,30 +88,22 @@ public class DerbySQLEntityStorePerformanceTest
         {
             return;
         }
-        UnitOfWork uow = this.uowf.newUnitOfWork( UsecaseBuilder.newUsecase(
-            "Delete " + getClass().getSimpleName() + " test data" ) );
+        UnitOfWork uow = uowf.newUnitOfWork( UsecaseBuilder.newUsecase(
+            "Delete " + getClass().getSimpleName() + " test data" )
+        );
         try
         {
-            SQLConfiguration config = uow.get( SQLConfiguration.class,
-                                               DerbySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY );
+            SQLMapEntityStoreConfiguration config = uow.get( SQLMapEntityStoreConfiguration.class,
+                                                             DEFAULT_ENTITYSTORE_IDENTITY );
             Connection connection = serviceFinder.findService( DataSource.class ).get().getConnection();
-            String schemaName = config.schemaName().get();
-            if( schemaName == null )
-            {
-                schemaName = SQLs.DEFAULT_SCHEMA_NAME;
-            }
-
-            Statement stmt = null;
-            try
+            connection.setAutoCommit( false );
+            try( Statement stmt = connection.createStatement() )
             {
-                stmt = connection.createStatement();
-                stmt.execute( String.format( "DELETE FROM %s." + SQLs.TABLE_NAME, schemaName ) );
+                stmt.execute( String.format( "DELETE FROM %s.%s",
+                                             config.schemaName().get(),
+                                             config.entityTableName().get() ) );
                 connection.commit();
             }
-            finally
-            {
-                SQLUtil.closeQuietly( stmt );
-            }
         }
         finally
         {
@@ -119,5 +111,4 @@ public class DerbySQLEntityStorePerformanceTest
             super.cleanUp();
         }
     }
-
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57eea7b3/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/PostgreSQLEntityStorePerformanceTest.java
----------------------------------------------------------------------
diff --git a/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/PostgreSQLEntityStorePerformanceTest.java b/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/PostgreSQLEntityStorePerformanceTest.java
index e0c2bcc..b1e8a17 100644
--- a/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/PostgreSQLEntityStorePerformanceTest.java
+++ b/tests/performance/src/perf/java/org/apache/polygene/test/performance/entitystore/sql/PostgreSQLEntityStorePerformanceTest.java
@@ -19,12 +19,13 @@ package org.apache.polygene.test.performance.entitystore.sql;
 
 import java.sql.Connection;
 import java.sql.Statement;
-import org.junit.Ignore;
+import javax.sql.DataSource;
 import org.apache.polygene.api.common.Visibility;
 import org.apache.polygene.api.structure.Application;
 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.ApplicationAssemblerAdapter;
 import org.apache.polygene.bootstrap.Assembler;
 import org.apache.polygene.bootstrap.AssemblyException;
@@ -32,12 +33,13 @@ import org.apache.polygene.bootstrap.Energy4Java;
 import org.apache.polygene.bootstrap.ModuleAssembly;
 import org.apache.polygene.entitystore.memory.MemoryEntityStoreService;
 import org.apache.polygene.entitystore.sql.assembly.PostgreSQLEntityStoreAssembler;
-import org.apache.polygene.entitystore.sql.internal.SQLs;
 import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
 import org.apache.polygene.library.sql.common.SQLConfiguration;
-import org.apache.polygene.library.sql.common.SQLUtil;
 import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
 import org.apache.polygene.test.performance.entitystore.AbstractEntityStorePerformanceTest;
+import org.junit.Ignore;
+
+import static org.apache.polygene.entitystore.sql.assembly.PostgreSQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY;
 
 /**
  * Performance test for PostgreSQLEntityStore.
@@ -119,30 +121,20 @@ public class PostgreSQLEntityStorePerformanceTest
 
             Module moduleInstance = application.findModule( "Layer 1", "config" );
             UnitOfWorkFactory uowf = moduleInstance.unitOfWorkFactory();
-            UnitOfWork uow = uowf.newUnitOfWork();
+            UnitOfWork uow = uowf.newUnitOfWork(
+                UsecaseBuilder.newUsecase( "Delete " + getClass().getSimpleName() + " test data" )
+            );
             try
             {
-                SQLConfiguration config = uow.get( SQLConfiguration.class,
-                                                   PostgreSQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY );
-                // TODO fix AbstractEntityStorePerformanceTest to extend from AbstractPolygeneTest
-                Connection connection = null; // SQLUtil.getConnection( this.serviceLocator );
+                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();
-                if( schemaName == null )
-                {
-                    schemaName = SQLs.DEFAULT_SCHEMA_NAME;
-                }
-
-                Statement stmt = null;
-                try
+                try( Statement stmt = connection.createStatement() )
                 {
-                    stmt = connection.createStatement();
-                    stmt.execute( String.format( "DELETE FROM %s." + SQLs.TABLE_NAME, schemaName ) );
+                    stmt.execute( String.format( "DROP SCHEMA \"%s\" CASCADE", schemaName ) );
                     connection.commit();
                 }
-                finally
-                {
-                    SQLUtil.closeQuietly( stmt );
-                }
             }
             finally
             {