polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [31/33] polygene-java git commit: Fixed up all but MYSQL/MariaDb variants of the SQL Entity Store to pass the test suite.
Date Thu, 26 Oct 2017 07:35:01 GMT
Fixed up all but MYSQL/MariaDb variants of the SQL Entity Store to pass the test suite.


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/95882f22
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/95882f22
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/95882f22

Branch: refs/heads/develop
Commit: 95882f22af4f9e3631e844aee49c88de7519c234
Parents: 3cca3c6
Author: niclas <niclas@hedhman.org>
Authored: Thu Oct 26 15:32:08 2017 +0800
Committer: niclas <niclas@hedhman.org>
Committed: Thu Oct 26 15:32:08 2017 +0800

----------------------------------------------------------------------
 .../test/entity/AbstractEntityStoreTest.java    |   3 +-
 dependencies.gradle                             |   6 +-
 extensions/entitystore-sql/build.gradle         |   1 +
 .../polygene/entitystore/sql/EntitiesTable.java |  10 +-
 .../entitystore/sql/JooqDslContext.java         |  23 +++-
 .../polygene/entitystore/sql/MixinTable.java    | 119 +++++++++++++------
 .../entitystore/sql/SqlEntityStoreMixin.java    |  85 +------------
 .../polygene/entitystore/sql/SqlTable.java      |  12 +-
 .../polygene/entitystore/sql/SqlType.java       |  14 +--
 .../sql/DerbySQLEntityStoreTest.java            |  36 ++++--
 .../sql/DerbySQLEntityStoreTestSuite.java       |  31 +++--
 .../entitystore/sql/H2SQLEntityStoreTest.java   |  10 --
 .../sql/H2SQLEntityStoreTestSuite.java          |  10 --
 .../entitystore/sql/MySQLEntityStoreTest.java   |  16 ++-
 .../sql/MySQLEntityStoreTestSuite.java          |  12 +-
 .../sql/PostgreSQLEntityStoreTest.java          |  17 ++-
 .../sql/PostgreSQLEntityStoreTestSuite.java     |  37 +++---
 .../entitystore/sql/SQLiteEntityStoreTest.java  |   8 --
 .../sql/SQLiteEntityStoreTestSuite.java         |  10 --
 .../polygene/entitystore/sql/TearDownUtil.java  |   2 +-
 .../java/org/hedhman/niclas/Experiment.java     |  78 ++++++++++++
 .../restlet/crud/EntityListResource.java        |   2 +-
 .../library/restlet/crud/EntityResource.java    |   2 +-
 .../restlet/resource/CreationResource.java      |   2 +-
 .../restlet/resource/EntryPointResource.java    |  10 +-
 .../restlet/resource/ResourceBuilder.java       |  26 ++--
 .../RestAPIApplication/application.java.tmpl    |   2 +-
 27 files changed, 309 insertions(+), 275 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/core/testsupport/src/main/java/org/apache/polygene/test/entity/AbstractEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/core/testsupport/src/main/java/org/apache/polygene/test/entity/AbstractEntityStoreTest.java b/core/testsupport/src/main/java/org/apache/polygene/test/entity/AbstractEntityStoreTest.java
index a349309..7e0fd71 100644
--- a/core/testsupport/src/main/java/org/apache/polygene/test/entity/AbstractEntityStoreTest.java
+++ b/core/testsupport/src/main/java/org/apache/polygene/test/entity/AbstractEntityStoreTest.java
@@ -501,7 +501,8 @@ public abstract class AbstractEntityStoreTest
         UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork();
         try
         {
-            Identity identity = createEntity( unitOfWork ).identity().get();
+            TestEntity entity1 = createEntity( unitOfWork );
+            Identity identity = entity1.identity().get();
             unitOfWork.complete();
 
             unitOfWork = unitOfWorkFactory.newUnitOfWork();

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/dependencies.gradle
----------------------------------------------------------------------
diff --git a/dependencies.gradle b/dependencies.gradle
index ff4dd48..7d7608c 100644
--- a/dependencies.gradle
+++ b/dependencies.gradle
@@ -49,7 +49,7 @@ def codahaleMetricsVersion = '3.2.3'
 def commonsDbcpVersion = '2.1.1'
 def commonsLangVersion = '3.6'
 def commonsValidatorVersion = '1.6'
-def derbyVersion = '10.13.1.1'
+def derbyVersion = '10.14.1.0'
 def ehcacheVersion = '3.4.0'
 def elasticsearchVersion = '5.5.2'
 def freemarkerVersion = '2.3.26-incubating'
@@ -64,7 +64,7 @@ def jdbmVersion = '2.4'
 def jedisVersion = '2.9.0'
 def jettyVersion = '9.2.17.v20160517' // 9.3.x Tests fail!
 def johnzonVersion = '1.1.1'
-def jooqVersion = '3.9.5'
+def jooqVersion = '3.10.1'
 def leveldbVersion = '0.9'
 def leveldbJniVersion = '1.8'
 def liquibaseVersion = '3.5.3'
@@ -190,7 +190,7 @@ def junitVersion = '4.12'
 def logbackVersion = '1.2.3' // TODO Replace with Apache Log4j 2
 def mockitoVersion = '2.8.47'
 def mysqlVersion = '6.0.6'
-def postgresqlVersion = '42.1.3'
+def postgresqlVersion = '42.1.4'
 def sqliteVersion = '3.19.3'
 def xmlUnitVersion = '2.3.0'
 dependencies.libraries << [

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/extensions/entitystore-sql/build.gradle
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/build.gradle b/extensions/entitystore-sql/build.gradle
index 8eb353f..cd94f15 100644
--- a/extensions/entitystore-sql/build.gradle
+++ b/extensions/entitystore-sql/build.gradle
@@ -33,6 +33,7 @@ dependencies {
 
   testImplementation polygene.internals.testsupport
   testImplementation polygene.library( 'sql-dbcp' )
+  testImplementation polygene.library( 'sql-bonecp' )
   testImplementation libraries.docker_junit
   testImplementation libraries.h2
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/EntitiesTable.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/EntitiesTable.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/EntitiesTable.java
index 0bd9227..e201b12 100644
--- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/EntitiesTable.java
+++ b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/EntitiesTable.java
@@ -40,6 +40,7 @@ import org.apache.polygene.api.entity.EntityReference;
 import org.apache.polygene.api.identity.HasIdentity;
 import org.apache.polygene.api.identity.StringIdentity;
 import org.apache.polygene.api.property.PropertyDescriptor;
+import org.apache.polygene.api.serialization.Serialization;
 import org.apache.polygene.api.structure.ModuleDescriptor;
 import org.apache.polygene.api.type.EntityCompositeType;
 import org.apache.polygene.api.unitofwork.NoSuchEntityTypeException;
@@ -70,13 +71,15 @@ public class EntitiesTable
     private JooqDslContext dsl;
     private final TypesTable types;
     private String applicationVersion;
+    private Serialization serialization;
     private boolean replacementStrategy = false;  // Figure out later if we should support both and if so, how.
 
-    EntitiesTable( JooqDslContext dsl, TypesTable types, String applicationVersion, String entitiesTableName )
+    EntitiesTable( JooqDslContext dsl, TypesTable types, String applicationVersion, String entitiesTableName, Serialization serialization )
     {
         this.dsl = dsl;
         this.types = types;
         this.applicationVersion = applicationVersion;
+        this.serialization = serialization;
         entitiesTable = dsl.tableOf( entitiesTableName );
     }
 
@@ -162,7 +165,7 @@ public class EntitiesTable
 
     private MixinTable findMixinTable( Class<?> type, EntityDescriptor entityDescriptor )
     {
-        return mixinTablesCache.computeIfAbsent( type, t -> new MixinTable( dsl, types, type, entityDescriptor ) );
+        return mixinTablesCache.computeIfAbsent( type, t -> new MixinTable( dsl, types, type, entityDescriptor, serialization ) );
     }
 
     private Set<Class<?>> mixinsOf( Stream<? extends AssociationDescriptor> stream )
@@ -219,7 +222,7 @@ public class EntitiesTable
         baseEntity.version = "1";
         baseEntity.applicationVersion = applicationVersion;
         baseEntity.identity = reference.identity();
-        baseEntity.currentValueIdentity = StringIdentity.identityOf( UUID.randomUUID().toString() );
+        baseEntity.currentValueIdentity = StringIdentity.identityOf( valueIdentity );
         baseEntity.modifedAt = currentTime;
         baseEntity.createdAt = currentTime;
         return baseEntity;
@@ -237,6 +240,7 @@ public class EntitiesTable
            .set( valueIdentityColumn, entity.currentValueIdentity.toString() )
            .set( versionColumn, entity.version )
            .set( applicationVersionColumn, applicationVersion )
+           .where( identityColumn.eq( entity.identity.toString() ) )
            .execute();
     }
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/JooqDslContext.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/JooqDslContext.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/JooqDslContext.java
index be2f66b..b73978f 100644
--- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/JooqDslContext.java
+++ b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/JooqDslContext.java
@@ -24,21 +24,27 @@ import org.apache.polygene.api.injection.scope.Service;
 import org.apache.polygene.api.injection.scope.Uses;
 import org.apache.polygene.api.mixin.Mixins;
 import org.jooq.Configuration;
+import org.jooq.ConnectionProvider;
 import org.jooq.DSLContext;
 import org.jooq.Name;
 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;
 
 @Mixins( JooqDslContext.Mixin.class )
 public interface JooqDslContext extends DSLContext
 {
     boolean isSchemaCapable();
+
     Name tableNameOf( String tableName );
+
     Table<Record> tableOf( String tableName );
 
     class Mixin
@@ -50,9 +56,12 @@ public interface JooqDslContext extends DSLContext
         public Mixin( @Service DataSource dataSource, @Uses Settings settings, @Uses SQLDialect dialect, @Uses Schema schema )
         {
             this.schema = schema;
+            ConnectionProvider connectionProvider = new DataSourceConnectionProvider( dataSource );
+            TransactionProvider transactionProvider = new ThreadLocalTransactionProvider( connectionProvider, false );
             Configuration configuration = new DefaultConfiguration()
-                .set( dataSource )
                 .set( dialect )
+                .set( connectionProvider )
+                .set( transactionProvider )
                 .set( settings );
             dsl = DSL.using( configuration );
         }
@@ -61,14 +70,16 @@ public interface JooqDslContext extends DSLContext
         public Object invoke( Object o, Method method, Object[] args )
             throws Throwable
         {
-            if(method.getName().equals( "tableOf" )){
-                return DSL.table(tableNameOf( (String) args[0] ) );
+            if( method.getName().equals( "tableOf" ) )
+            {
+                return DSL.table( tableNameOf( (String) args[ 0 ] ) );
             }
-            if(method.getName().equals( "tableNameOf" )){
+            if( method.getName().equals( "tableNameOf" ) )
+            {
                 return tableNameOf( (String) args[ 0 ] );
             }
 
-            if(method.getName().equals( "isSchemaCapable" ))
+            if( method.getName().equals( "isSchemaCapable" ) )
             {
                 return isSchemaCapable();
             }
@@ -82,7 +93,7 @@ public interface JooqDslContext extends DSLContext
 
         private boolean isSchemaCapable()
         {
-            return !dsl.dialect().equals( SQLDialect.SQLITE ) && !dsl.dialect().equals( SQLDialect.MYSQL );
+            return !dsl.dialect().equals( SQLDialect.SQLITE ) && !dsl.dialect().equals( SQLDialect.MYSQL ) && !dsl.dialect().equals( SQLDialect.DERBY );
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/MixinTable.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/MixinTable.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/MixinTable.java
index 9ddfe0e..c55e793 100644
--- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/MixinTable.java
+++ b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/MixinTable.java
@@ -30,6 +30,9 @@ import org.apache.polygene.api.common.QualifiedName;
 import org.apache.polygene.api.entity.EntityDescriptor;
 import org.apache.polygene.api.entity.EntityReference;
 import org.apache.polygene.api.property.PropertyDescriptor;
+import org.apache.polygene.api.serialization.Serialization;
+import org.apache.polygene.api.type.ValueType;
+import org.apache.polygene.spi.PolygeneSPI;
 import org.apache.polygene.spi.entity.ManyAssociationState;
 import org.apache.polygene.spi.entity.NamedAssociationState;
 import org.apache.polygene.spi.entitystore.helpers.DefaultEntityState;
@@ -53,15 +56,17 @@ class MixinTable
     private final List<QualifiedName> manyAssociations = new CopyOnWriteArrayList<>();
     private final List<QualifiedName> namedAssociations = new CopyOnWriteArrayList<>();
 
-    private TypesTable types;
     private final Class<?> mixinType;
+    private Serialization serialization;
+
+    PolygeneSPI spi;
 
     MixinTable( JooqDslContext dsl, TypesTable types, Class<?> mixinType,
-                EntityDescriptor descriptor )
+                EntityDescriptor descriptor, Serialization serialization )
     {
         this.dsl = dsl;
-        this.types = types;
         this.mixinType = mixinType;
+        this.serialization = serialization;
         mixinTable = types.tableFor( mixinType, descriptor );
         mixinAssocsTable = getAssocsTable( descriptor );
 
@@ -101,17 +106,12 @@ class MixinTable
                .set( identityColumn, valueIdentity )
                .set( createdColumn, new Timestamp( System.currentTimeMillis() ) );
 
-        properties.forEach( ( propertyName, propertyField ) -> primaryTable.set( propertyField, state.propertyValueOf( propertyName ) ) );
-        associations.forEach( ( assocName, assocField ) ->
-                              {
-                                  EntityReference reference = state.associationValueOf( assocName );
-                                  String identity = null;
-                                  if( reference != null )
-                                  {
-                                      identity = reference.identity().toString();
-                                  }
-                                  primaryTable.set( assocField, identity );
-                              }
+        properties
+            .entrySet()
+            .stream()
+            .filter( entry -> !entry.getKey().name().equals( "identity" ) )
+            .forEach( entry -> primaryTable.set( entry.getValue(), getStateValue( entry.getValue(), state, entry.getKey() ) ) );
+        associations.forEach( ( assocName, assocField ) -> primaryTable.set( assocField, referenceToString( state, assocName ) )
                             );
         int result = primaryTable.execute();
 
@@ -140,8 +140,11 @@ class MixinTable
                                               set.newRecord();
                                           }
                                       }
-                                      InsertSetMoreStep<Record> assocs = assocsTable.set( Collections.emptyMap() );
-                                      assocs.execute();
+                                      if( counter > 0 )
+                                      {
+                                          InsertSetMoreStep<Record> assocs = assocsTable.set( Collections.emptyMap() );
+                                          assocs.execute();
+                                      }
                                   } );
 
         namedAssociations.forEach( assocName ->
@@ -149,20 +152,23 @@ class MixinTable
                                        InsertSetStep<Record> assocsTable = dsl.insertInto( mixinAssocsTable );
                                        NamedAssociationState entityReferences = state.namedAssociationValueOf( assocName );
                                        int count = entityReferences.count();
-                                       for( String name : entityReferences )
+                                       if( count > 0 )
                                        {
-                                           EntityReference ref = entityReferences.get( name );
-                                           InsertSetMoreStep<Record> set = assocsTable.set( identityColumn, valueIdentity )
-                                                                                      .set( nameColumn, assocName.name() )
-                                                                                      .set( indexColumn, name )
-                                                                                      .set( referenceColumn, ref.identity().toString() );
-                                           if( --count > 0 )
+                                           for( String name : entityReferences )
                                            {
-                                               set.newRecord();
+                                               EntityReference ref = entityReferences.get( name );
+                                               InsertSetMoreStep<Record> set = assocsTable.set( identityColumn, valueIdentity )
+                                                                                          .set( nameColumn, assocName.name() )
+                                                                                          .set( indexColumn, name )
+                                                                                          .set( referenceColumn, ref.identity().toString() );
+                                               if( --count > 0 )
+                                               {
+                                                   set.newRecord();
+                                               }
                                            }
+                                           InsertSetMoreStep<Record> assocs = assocsTable.set( Collections.emptyMap() );
+                                           assocs.execute();
                                        }
-                                       InsertSetMoreStep<Record> assocs = assocsTable.set( Collections.emptyMap() );
-                                       assocs.execute();
                                    } );
     }
 
@@ -209,15 +215,15 @@ class MixinTable
             dsl.update( mixinTable )
                .set( Collections.emptyMap() );  // empty map is a hack to get the right type returned from JOOQ.
 
-        properties.forEach( ( propertyName, propertyField ) -> primaryTable.set( propertyField, state.propertyValueOf( propertyName ) ) );
-        associations.forEach( ( assocName, assocField ) ->
-                              {
-                                  EntityReference reference = state.associationValueOf( assocName );
-                                  primaryTable.set( assocField,
-                                                    reference == null ? null : reference.identity().toString()
-                                                  );
-                              }
-                            );
+        properties
+            .entrySet()
+            .stream()
+            .filter( entry -> !entry.getKey().name().equals( "identity" ) )
+            .forEach( entry -> primaryTable.set( entry.getValue(), getStateValue( entry.getValue(), state, entry.getKey() ) ) );
+
+        // Set the Association<?> fields
+        associations.forEach( ( assocName, assocField ) -> primaryTable.set( assocField, referenceToString( state, assocName ) ) );
+
         int result = primaryTable.execute();
 
         if( mixinAssocsTable != null )
@@ -249,4 +255,47 @@ class MixinTable
             return null;
         }
     }
+
+    private Object getStateValue( Field<Object> field, DefaultEntityState state, QualifiedName name )
+    {
+        PropertyDescriptor property = state.entityDescriptor().state().findPropertyModelByQualifiedName( name );
+        ValueType type = property.valueType();
+        Object value = state.propertyValueOf( name );
+        Class<?> javaType = field.getDataType().getType();
+        int sqlType = field.getDataType().getSQLType();
+
+        if( value == null )
+        {
+            return null;
+        }
+        if( value.getClass().isPrimitive() )
+        {
+            return value;
+        }
+        if( type.equals( ValueType.STRING )
+            || type.equals( ValueType.INTEGER )
+            || type.equals( ValueType.BOOLEAN )
+            || type.equals( ValueType.DOUBLE )
+            || type.equals( ValueType.IDENTITY )
+            || type.equals( ValueType.LONG )
+            || type.equals( ValueType.FLOAT )
+            || type.equals( ValueType.BYTE )
+            || type.equals( ValueType.CHARACTER )
+            || type.equals( ValueType.SHORT )
+            )
+        {
+            return value;
+        }
+        return serialization.serialize( value );
+    }
+
+    private String referenceToString( DefaultEntityState state, QualifiedName assocName )
+    {
+        EntityReference reference = state.associationValueOf( assocName );
+        if( reference == null )
+        {
+            return null;
+        }
+        return reference.identity().toString();
+    }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SqlEntityStoreMixin.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SqlEntityStoreMixin.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SqlEntityStoreMixin.java
index e881636..b2715ce 100644
--- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SqlEntityStoreMixin.java
+++ b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SqlEntityStoreMixin.java
@@ -17,13 +17,8 @@
  */
 package org.apache.polygene.entitystore.sql;
 
-import java.sql.Timestamp;
-import java.time.Duration;
+import java.math.BigInteger;
 import java.time.Instant;
-import java.time.OffsetDateTime;
-import java.time.Period;
-import java.time.ZoneOffset;
-import java.time.ZonedDateTime;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -157,88 +152,13 @@ public class SqlEntityStoreMixin
             || type.equals( ValueType.FLOAT )
             || type.equals( ValueType.BYTE )
             || type.equals( ValueType.CHARACTER )
-            || type.equals( ValueType.ENTITY_REFERENCE )
             || type.equals( ValueType.SHORT )
-            || type.equals( ValueType.BIG_INTEGER )
-            || type.equals( ValueType.BIG_DECIMAL )
             )
         {
             return value;
         }
-        if( type.equals( ValueType.INSTANT ) )  // Instant type contains timezone (why?), and we promise to always return in UTC (or is that just bad testcases, and that we actually promise to return original instant timezone?).
-        {
-            if( value instanceof Instant )
-            {
-                return Instant.ofEpochMilli( ( (Instant) value ).toEpochMilli() );
-            }
-            if( value instanceof OffsetDateTime )
-            {
-                return Instant.ofEpochMilli( ( (OffsetDateTime) value ).toInstant().toEpochMilli() );
-            }
-            if( value instanceof ZonedDateTime )
-            {
-                return Instant.ofEpochMilli( ( (ZonedDateTime) value ).toInstant().toEpochMilli() );
-            }
-        }
-        if( type.equals( ValueType.ZONED_DATE_TIME ) )
-        {
-            if( value instanceof ZonedDateTime )
-            {
-                return ( (ZonedDateTime) value ).withZoneSameInstant( ZoneOffset.UTC );
-            }
-            if( value instanceof OffsetDateTime )
-            {
-                return ( (OffsetDateTime) value ).toZonedDateTime().withZoneSameInstant( ZoneOffset.UTC );
-            }
-        }
-        if( type.equals( ValueType.OFFSET_DATE_TIME ) )
-        {
-            if( value instanceof OffsetDateTime )
-            {
-                return ( (OffsetDateTime) value ).withOffsetSameInstant( ZoneOffset.UTC );
-            }
-            if( value instanceof ZonedDateTime )
-            {
-                return ( (ZonedDateTime) value ).toOffsetDateTime().withOffsetSameInstant( ZoneOffset.UTC );
-            }
-        }
-        if( type.equals( ValueType.LOCAL_DATE_TIME ) )
-        {
-            if( value instanceof Timestamp )
-            {
-                return ( (Timestamp) value ).toLocalDateTime();
-            }
-        }
-        if( type.equals( ValueType.PERIOD ) )
-        {
-            if( value instanceof String )
-            {
-                return Period.parse( (String) value );
-            }
-        }
-        if( type.equals( ValueType.DURATION ) )
-        {
-            if( value instanceof String )
-            {
-                return Duration.parse( (String) value );
-            }
-        }
-        if( type.equals( ValueType.LOCAL_DATE ) )
-        {
-            if( value instanceof java.sql.Date )
-            {
-                return ( (java.sql.Date) value ).toLocalDate();
-            }
-        }
-        if( type.equals( ValueType.LOCAL_TIME ) )
-        {
-            if( value instanceof java.sql.Time )
-            {
-                return ( (java.sql.Time) value ).toLocalTime();
-            }
-        }
         // otherwise, we deal with a serialized value.
-        return serialization.deserialize( module, type, (String) value );
+        return serialization.deserialize( module, type, value.toString() );
     }
 
     private void addNamedAssociation( AssociationStateDescriptor stateDescriptor, Map<QualifiedName, Map<String, EntityReference>> namedAssocs, AssociationValue associationValue )
@@ -356,7 +276,6 @@ public class SqlEntityStoreMixin
                                                 removeState( state );
                                             }
                                         }
-
                                     } );
         }
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SqlTable.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SqlTable.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SqlTable.java
index 9b2f7c6..36fc983 100644
--- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SqlTable.java
+++ b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SqlTable.java
@@ -19,7 +19,6 @@ package org.apache.polygene.entitystore.sql;
 
 import java.util.function.Consumer;
 import java.util.stream.Stream;
-import javax.sql.DataSource;
 import org.apache.polygene.api.composite.TransientBuilderFactory;
 import org.apache.polygene.api.configuration.Configuration;
 import org.apache.polygene.api.entity.EntityDescriptor;
@@ -29,6 +28,7 @@ import org.apache.polygene.api.injection.scope.Structure;
 import org.apache.polygene.api.injection.scope.This;
 import org.apache.polygene.api.injection.scope.Uses;
 import org.apache.polygene.api.mixin.Mixins;
+import org.apache.polygene.api.serialization.Serialization;
 import org.apache.polygene.api.service.ServiceActivation;
 import org.apache.polygene.api.service.ServiceDescriptor;
 import org.apache.polygene.api.structure.Application;
@@ -39,7 +39,6 @@ import org.jooq.Record;
 import org.jooq.SQLDialect;
 import org.jooq.Schema;
 import org.jooq.SelectQuery;
-import org.jooq.conf.RenderNameStyle;
 import org.jooq.conf.Settings;
 import org.jooq.impl.DSL;
 
@@ -125,7 +124,7 @@ public interface SqlTable extends ServiceActivation
         private Configuration<SqlEntityStoreConfiguration> configuration;
 
         @Service
-        private DataSource datasource;
+        private Serialization serialization;
 
         @Uses
         private ServiceDescriptor serviceDescriptor;
@@ -196,8 +195,7 @@ public interface SqlTable extends ServiceActivation
             SqlEntityStoreConfiguration config = this.configuration.get();
             SQLDialect dialect = getSqlDialect( config );
             Settings settings = serviceDescriptor
-                .metaInfo( Settings.class )
-                .withRenderNameStyle( RenderNameStyle.QUOTED );
+                .metaInfo( Settings.class );
 
             String schemaName = config.schemaName().get();
             String typesTableName = config.typesTableName().get();
@@ -207,7 +205,7 @@ public interface SqlTable extends ServiceActivation
             dsl = tbf.newTransient( JooqDslContext.class, settings, dialect, schema );
 
             types = new TypesTable( dsl, dialect, typesTableName );
-            entitiesTable = new EntitiesTable( dsl, types, application.version(), entitiesTableName );
+            entitiesTable = new EntitiesTable( dsl, types, application.version(), entitiesTableName, serialization );
 
             if( config.createIfMissing().get() )
             {
@@ -250,7 +248,7 @@ public interface SqlTable extends ServiceActivation
 
         private SQLDialect getSqlDialect( SqlEntityStoreConfiguration config )
         {
-            SQLDialect dialect = null;
+            SQLDialect dialect;
             String dialectString = config.dialect().get();
             if( dialectString.length() == 0 )
             {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SqlType.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SqlType.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SqlType.java
index 21de44d..982b3f5 100644
--- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SqlType.java
+++ b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SqlType.java
@@ -62,7 +62,7 @@ class SqlType
         }
         if( Instant.class.isAssignableFrom( propertyType ) )
         {
-            return (DataType<T>) SQLDataType.TIMESTAMPWITHTIMEZONE;
+            return (DataType<T>) SQLDataType.VARCHAR;
         }
         if( Interval.class.isAssignableFrom( propertyType ) )
         {
@@ -74,23 +74,23 @@ class SqlType
         }
         if( LocalDate.class.isAssignableFrom( propertyType ) )
         {
-            return (DataType<T>) SQLDataType.LOCALDATE;
+            return (DataType<T>) SQLDataType.VARCHAR;
         }
         if( LocalTime.class.isAssignableFrom( propertyType ) )
         {
-            return (DataType<T>) SQLDataType.LOCALTIME;
+            return (DataType<T>) SQLDataType.VARCHAR;
         }
         if( LocalDateTime.class.isAssignableFrom( propertyType ) )
         {
-            return (DataType<T>) SQLDataType.LOCALDATETIME;
+            return (DataType<T>) SQLDataType.VARCHAR;
         }
         if( ZonedDateTime.class.isAssignableFrom( propertyType ) )
         {
-            return (DataType<T>) SQLDataType.OFFSETDATETIME;
+            return (DataType<T>) SQLDataType.VARCHAR;
         }
         if( OffsetDateTime.class.isAssignableFrom( propertyType ) )
         {
-            return (DataType<T>) SQLDataType.OFFSETDATETIME;
+            return (DataType<T>) SQLDataType.VARCHAR;
         }
         if( Character.class.isAssignableFrom( propertyType ) )
         {
@@ -114,7 +114,7 @@ class SqlType
         }
         if( BigInteger.class.isAssignableFrom( propertyType ) )
         {
-            return (DataType<T>) SQLDataType.DECIMAL(50, 0);
+            return (DataType<T>) SQLDataType.DECIMAL;
         }
         if( propertyType.isPrimitive() )
         {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/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 5d7fc3d..0cff573 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
@@ -20,27 +20,27 @@
 package org.apache.polygene.entitystore.sql;
 
 import java.sql.Connection;
-import java.sql.Statement;
-import javax.sql.DataSource;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import org.apache.derby.jdbc.AutoloadedDriver;
+import org.apache.derby.jdbc.Driver42;
+import org.apache.derby.jdbc.EmbeddedDriver;
 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.usecase.UsecaseBuilder;
 import org.apache.polygene.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.ModuleAssembly;
-import org.apache.polygene.entitystore.sql.assembly.AbstractSQLEntityStoreAssembler;
 import org.apache.polygene.entitystore.sql.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.junit.Ignore;
-
-import static org.apache.polygene.api.usecase.UsecaseBuilder.newUsecase;
 
 public class DerbySQLEntityStoreTest
     extends AbstractEntityStoreTest
 {
+    private String storageModuleName;
+    private String storageLayerName;
+
     @Override
     // START SNIPPET: assembly
     public void assemble( ModuleAssembly module )
@@ -48,6 +48,8 @@ public class DerbySQLEntityStoreTest
     {
         // END SNIPPET: assembly
         super.assemble( module );
+        storageModuleName = module.name();
+        storageLayerName = module.layer().name();
         ModuleAssembly config = module.layer().module( "config" );
         new EntityTestAssembler().defaultServicesVisibleIn( Visibility.layer ).assemble( config );
 
@@ -79,8 +81,22 @@ public class DerbySQLEntityStoreTest
     public void tearDown()
         throws Exception
     {
-        Module storageModule = application.findModule( "Infrastructure Layer", "Storage Module" );
-        TearDownUtil.cleanupSQL( storageModule, getClass().getSimpleName() );
         super.tearDown();
+        try
+        {
+            DriverManager.getConnection( "jdbc:derby:memory:testdb;drop=true" );
+        }
+        catch( SQLException e )
+        {
+            // ignore, it is EXPECTED to get an exception when the database shuts down. No idea why.
+        }
+        try
+        {
+            DriverManager.getConnection( "jdbc:derby:memory:testdb;shutdown=true" );
+        }
+        catch( SQLException e )
+        {
+            // ignore, it is EXPECTED to get an exception when the database shuts down. No idea why.
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/DerbySQLEntityStoreTestSuite.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/DerbySQLEntityStoreTestSuite.java b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/DerbySQLEntityStoreTestSuite.java
index a6fa218..1af981d 100644
--- a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/DerbySQLEntityStoreTestSuite.java
+++ b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/DerbySQLEntityStoreTestSuite.java
@@ -19,24 +19,15 @@
  */
 package org.apache.polygene.entitystore.sql;
 
-import java.sql.Connection;
-import java.sql.Statement;
-import javax.sql.DataSource;
+import java.sql.DriverManager;
+import java.sql.SQLException;
 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.sql.SqlEntityStoreConfiguration;
-import org.apache.polygene.entitystore.sql.assembly.AbstractSQLEntityStoreAssembler;
 import org.apache.polygene.entitystore.sql.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 org.junit.Ignore;
-
-import static org.apache.polygene.entitystore.sql.assembly.DerbySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY;
 
 public class DerbySQLEntityStoreTestSuite extends EntityStoreTestSuite
 {
@@ -70,8 +61,22 @@ public class DerbySQLEntityStoreTestSuite extends EntityStoreTestSuite
     public void tearDown()
         throws Exception
     {
-        Module storageModule = application.findModule( "Infrastructure Layer", "Storage Module" );
-        TearDownUtil.cleanupSQL( storageModule, getClass().getSimpleName() );
         super.tearDown();
+        try
+        {
+            DriverManager.getConnection( "jdbc:derby:memory:testdb;drop=true" );
+        }
+        catch( SQLException e )
+        {
+            // ignore, it is EXPECTED to get an exception when the database shuts down. No idea why.
+        }
+        try
+        {
+            DriverManager.getConnection( "jdbc:derby:memory:testdb;shutdown=true" );
+        }
+        catch( SQLException e )
+        {
+            // ignore, it is EXPECTED to get an exception when the database shuts down. No idea why.
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/H2SQLEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/H2SQLEntityStoreTest.java b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/H2SQLEntityStoreTest.java
index 2b997c8..eea919a 100644
--- a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/H2SQLEntityStoreTest.java
+++ b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/H2SQLEntityStoreTest.java
@@ -29,7 +29,6 @@ import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
 import org.apache.polygene.test.EntityTestAssembler;
 import org.apache.polygene.test.entity.AbstractEntityStoreTest;
 import org.junit.After;
-import org.junit.Ignore;
 
 public class H2SQLEntityStoreTest
     extends AbstractEntityStoreTest
@@ -67,13 +66,4 @@ public class H2SQLEntityStoreTest
             .assemble( module );
     }
     // END SNIPPET: assembly
-
-    @After
-    public void tearDown()
-        throws Exception
-    {
-        Module storageModule = application.findModule( "Infrastructure Layer", "Storage Module" );
-        TearDownUtil.cleanupSQL( storageModule, getClass().getSimpleName() );
-        super.tearDown();
-    }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/H2SQLEntityStoreTestSuite.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/H2SQLEntityStoreTestSuite.java b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/H2SQLEntityStoreTestSuite.java
index 32dfcb2..9546dad 100644
--- a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/H2SQLEntityStoreTestSuite.java
+++ b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/H2SQLEntityStoreTestSuite.java
@@ -27,7 +27,6 @@ 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.junit.After;
-import org.junit.Ignore;
 
 public class H2SQLEntityStoreTestSuite extends EntityStoreTestSuite
 {
@@ -57,13 +56,4 @@ public class H2SQLEntityStoreTestSuite extends EntityStoreTestSuite
             .assemble( module );
     }
 
-    @After
-    public void tearDown()
-        throws Exception
-    {
-        Module storageModule = application.findModule( "Infrastructure Layer", "Storage Module" );
-        TearDownUtil.cleanupSQL( storageModule, getClass().getSimpleName() );
-        super.tearDown();
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/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 dd9759b..94ece0d 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
@@ -19,17 +19,11 @@
  */
 package org.apache.polygene.entitystore.sql;
 
-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.structure.Module;
-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.sql.assembly.AbstractSQLEntityStoreAssembler;
 import org.apache.polygene.entitystore.sql.assembly.MySQLEntityStoreAssembler;
 import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
 import org.apache.polygene.library.sql.datasource.DataSourceConfiguration;
@@ -38,7 +32,6 @@ import org.apache.polygene.test.EntityTestAssembler;
 import org.apache.polygene.test.docker.DockerRule;
 import org.apache.polygene.test.entity.AbstractEntityStoreTest;
 import org.junit.ClassRule;
-import org.junit.Ignore;
 
 public class MySQLEntityStoreTest
     extends AbstractEntityStoreTest
@@ -57,6 +50,9 @@ public class MySQLEntityStoreTest
 //        , "mysqld: ready for connections"   TODO: add this after next release of tdomzal/junit-docker-rule
     );
 
+    private String storageModuleName;
+    private String storageLayerName;
+
     @Override
     // START SNIPPET: assembly
     public void assemble( ModuleAssembly module )
@@ -64,6 +60,8 @@ public class MySQLEntityStoreTest
     {
         // END SNIPPET: assembly
         super.assemble( module );
+        storageModuleName = module.name();
+        storageLayerName = module.layer().name();
         ModuleAssembly config = module.layer().module( "config" );
         new EntityTestAssembler().defaultServicesVisibleIn( Visibility.layer ).assemble( config );
 
@@ -103,8 +101,8 @@ public class MySQLEntityStoreTest
     public void tearDown()
         throws Exception
     {
-        Module storageModule = application.findModule( "Infrastructure Layer", "Storage Module" );
-        TearDownUtil.cleanupSQL( storageModule, getClass().getSimpleName() );
+        Module storageModule = application.findModule( storageLayerName, storageModuleName );
+        TearDownUtil.dropSchema( storageModule, getClass().getSimpleName() );
         super.tearDown();
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/MySQLEntityStoreTestSuite.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/MySQLEntityStoreTestSuite.java b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/MySQLEntityStoreTestSuite.java
index c3d2919..893a158 100644
--- a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/MySQLEntityStoreTestSuite.java
+++ b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/MySQLEntityStoreTestSuite.java
@@ -19,17 +19,10 @@
  */
 package org.apache.polygene.entitystore.sql;
 
-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.bootstrap.ModuleAssembly;
-import org.apache.polygene.entitystore.sql.assembly.AbstractSQLEntityStoreAssembler;
 import org.apache.polygene.entitystore.sql.assembly.MySQLEntityStoreAssembler;
 import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
 import org.apache.polygene.library.sql.datasource.DataSourceConfiguration;
@@ -37,9 +30,6 @@ 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.junit.ClassRule;
-import org.junit.Ignore;
-
-import static org.apache.polygene.api.usecase.UsecaseBuilder.newUsecase;
 
 public class MySQLEntityStoreTestSuite extends EntityStoreTestSuite
 {
@@ -95,7 +85,7 @@ public class MySQLEntityStoreTestSuite extends EntityStoreTestSuite
         throws Exception
     {
         Module storageModule = application.findModule( "Infrastructure Layer", "Storage Module" );
-        TearDownUtil.cleanupSQL( storageModule, getClass().getSimpleName() );
+        TearDownUtil.dropSchema( storageModule, getClass().getSimpleName() );
         super.tearDown();
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/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 d7ef07c..a682398 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
@@ -19,20 +19,14 @@
  */
 package org.apache.polygene.entitystore.sql;
 
-import java.sql.Connection;
-import java.sql.Statement;
 import java.util.HashMap;
 import java.util.Map;
-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.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.ModuleAssembly;
-import org.apache.polygene.entitystore.sql.assembly.AbstractSQLEntityStoreAssembler;
 import org.apache.polygene.entitystore.sql.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;
@@ -40,8 +34,6 @@ import org.apache.polygene.test.docker.DockerRule;
 import org.apache.polygene.test.entity.AbstractEntityStoreTest;
 import org.junit.ClassRule;
 
-import static org.apache.polygene.api.usecase.UsecaseBuilder.newUsecase;
-
 public class PostgreSQLEntityStoreTest
     extends AbstractEntityStoreTest
 {
@@ -60,6 +52,9 @@ public class PostgreSQLEntityStoreTest
                                  "PostgreSQL init process complete; ready for start up." );
     }
 
+    private String storageModuleName;
+    private String storageLayerName;
+
     @Override
     // START SNIPPET: assembly
     public void assemble( ModuleAssembly module )
@@ -67,6 +62,8 @@ public class PostgreSQLEntityStoreTest
     {
         // END SNIPPET: assembly
         super.assemble( module );
+        storageModuleName = module.name();
+        storageLayerName = module.layer().name();
         ModuleAssembly config = module.layer().module( "config" );
         new EntityTestAssembler().defaultServicesVisibleIn( Visibility.layer ).assemble( config );
 
@@ -110,8 +107,8 @@ public class PostgreSQLEntityStoreTest
     public void tearDown()
         throws Exception
     {
-        Module storageModule = application.findModule( "Infrastructure Layer", "Storage Module" );
-        TearDownUtil.cleanupSQL( storageModule, getClass().getSimpleName() );
+        Module storageModule = application.findModule( storageLayerName, storageModuleName );
+        TearDownUtil.dropSchema( storageModule, getClass().getSimpleName() );
         super.tearDown();
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/PostgreSQLEntityStoreTestSuite.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/PostgreSQLEntityStoreTestSuite.java b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/PostgreSQLEntityStoreTestSuite.java
index d35fce0..487ad9f 100644
--- a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/PostgreSQLEntityStoreTestSuite.java
+++ b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/PostgreSQLEntityStoreTestSuite.java
@@ -19,33 +19,35 @@
  */
 package org.apache.polygene.entitystore.sql;
 
-import java.sql.Connection;
-import java.sql.Statement;
-import javax.sql.DataSource;
+import java.util.HashMap;
+import java.util.Map;
 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.bootstrap.ModuleAssembly;
-import org.apache.polygene.entitystore.sql.assembly.AbstractSQLEntityStoreAssembler;
 import org.apache.polygene.entitystore.sql.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.junit.ClassRule;
 
-import static org.apache.polygene.api.usecase.UsecaseBuilder.newUsecase;
-
 public class PostgreSQLEntityStoreTestSuite extends EntityStoreTestSuite
 {
     @ClassRule
-    public static final DockerRule DOCKER = new DockerRule( "postgres",
-                                                            3000L,
-                                                            "PostgreSQL init process complete; ready for start up." );
+    public static final DockerRule DOCKER;
+
+    static
+    {
+        Map<String,String> environment = new HashMap<>();
+        environment.put( "POSTGRES_USER", System.getProperty( "user.name" ));
+        environment.put( "POSTGRES_PASSWORD", "ThisIsGreat!");
+
+        DOCKER = new DockerRule( "postgres",
+                                 environment,
+                                 3000L,
+                                 "PostgreSQL init process complete; ready for start up." );
+    }
 
     @Override
     protected void defineStorageModule( ModuleAssembly module )
@@ -74,8 +76,11 @@ public class PostgreSQLEntityStoreTestSuite extends EntityStoreTestSuite
 
         String host = DOCKER.getDockerHost();
         int port = DOCKER.getExposedContainerPort( "5432/tcp" );
-        configModule.forMixin( DataSourceConfiguration.class ).declareDefaults()
-                    .url().set( "jdbc:postgresql://" + host + ":" + port + "/jdbc_test_db" );
+        DataSourceConfiguration defaults = configModule.forMixin( DataSourceConfiguration.class ).declareDefaults();
+        defaults.url().set( "jdbc:postgresql://" + host + ":" + port + "/jdbc_test_db" );
+        defaults.username().set( System.getProperty( "user.name" ) );
+        defaults.password().set( "ThisIsGreat!" );
+
         // START SNIPPET: assembly
     }
     // END SNIPPET: assembly
@@ -85,7 +90,7 @@ public class PostgreSQLEntityStoreTestSuite extends EntityStoreTestSuite
         throws Exception
     {
         Module storageModule = application.findModule( "Infrastructure Layer", "Storage Module" );
-        TearDownUtil.cleanupSQL(storageModule, getClass().getSimpleName());
+        TearDownUtil.dropSchema( storageModule, getClass().getSimpleName() );
         super.tearDown();
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/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 14a52a0..ad2ecc1 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
@@ -75,12 +75,4 @@ public class SQLiteEntityStoreTest extends AbstractEntityStoreTest
     }
     // END SNIPPET: assembly
 
-    @After
-    public void tearDown()
-        throws Exception
-    {
-        Module storageModule = application.findModule( "Infrastructure Layer", "Storage Module" );
-        TearDownUtil.cleanupSQL( storageModule, getClass().getSimpleName() );
-        super.tearDown();
-    }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/SQLiteEntityStoreTestSuite.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/SQLiteEntityStoreTestSuite.java b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/SQLiteEntityStoreTestSuite.java
index 678309b..39f2c05 100644
--- a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/SQLiteEntityStoreTestSuite.java
+++ b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/SQLiteEntityStoreTestSuite.java
@@ -64,14 +64,4 @@ public class SQLiteEntityStoreTestSuite extends EntityStoreTestSuite
             .withConfig( configModule, Visibility.application )
             .assemble( module );
     }
-
-    @After
-    public void tearDown()
-        throws Exception
-    {
-        Module storageModule = application.findModule( "Infrastructure Layer", "Storage Module" );
-        TearDownUtil.cleanupSQL( storageModule, getClass().getSimpleName() );
-        super.tearDown();
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/TearDownUtil.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/TearDownUtil.java b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/TearDownUtil.java
index 31a15d5..00f1e24 100644
--- a/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/TearDownUtil.java
+++ b/extensions/entitystore-sql/src/test/java/org/apache/polygene/entitystore/sql/TearDownUtil.java
@@ -16,7 +16,7 @@ import static org.apache.polygene.api.usecase.UsecaseBuilder.newUsecase;
 public class TearDownUtil
 {
 
-    public static void cleanupSQL( Module storageModule, String testName )
+    public static void dropSchema( Module storageModule, String testName )
         throws Exception
     {
         String usecaseName = "Delete " + testName + " test data";

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/extensions/entitystore-sql/src/test/java/org/hedhman/niclas/Experiment.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/test/java/org/hedhman/niclas/Experiment.java b/extensions/entitystore-sql/src/test/java/org/hedhman/niclas/Experiment.java
new file mode 100644
index 0000000..27ed3f2
--- /dev/null
+++ b/extensions/entitystore-sql/src/test/java/org/hedhman/niclas/Experiment.java
@@ -0,0 +1,78 @@
+package org.hedhman.niclas;
+
+import javax.sql.DataSource;
+import org.apache.commons.dbcp2.BasicDataSource;
+import org.jooq.Configuration;
+import org.jooq.ConnectionProvider;
+import org.jooq.DSLContext;
+import org.jooq.DataType;
+import org.jooq.Field;
+import org.jooq.Name;
+import org.jooq.Record;
+import org.jooq.SQLDialect;
+import org.jooq.Table;
+import org.jooq.TransactionProvider;
+import org.jooq.conf.RenderNameStyle;
+import org.jooq.conf.Settings;
+import org.jooq.impl.DSL;
+import org.jooq.impl.DataSourceConnectionProvider;
+import org.jooq.impl.DefaultConfiguration;
+import org.jooq.impl.SQLDataType;
+import org.jooq.impl.TableImpl;
+import org.jooq.impl.ThreadLocalTransactionProvider;
+import org.junit.Test;
+
+public class Experiment
+{
+    @Test
+    public void test1()
+        throws Exception
+    {
+        String host = "127.0.0.1";
+        int port = 3306;
+        DataSource dataSource = dbcpDataSource( host, port );
+        Settings settings = new Settings().withRenderNameStyle( RenderNameStyle.QUOTED );
+        SQLDialect dialect = SQLDialect.MARIADB;
+
+        ConnectionProvider connectionProvider = new DataSourceConnectionProvider( dataSource );
+        TransactionProvider transactionProvider = new ThreadLocalTransactionProvider( connectionProvider, false );
+        Configuration configuration = new DefaultConfiguration()
+            .set( dialect )
+            .set( connectionProvider )
+            .set( transactionProvider )
+            .set( settings );
+
+        DSLContext dsl = DSL.using( configuration );
+
+        Field<String> identityColumn = DSL.field( DSL.name( "_identity" ), SQLDataType.VARCHAR );
+        Name entitiesTableName = DSL.name( "ENTITIES" );
+        Table<Record> entitiesTable = new TableImpl<Record>( entitiesTableName );
+        dsl.transaction( t -> {
+
+            dsl.createTableIfNotExists( entitiesTable )
+               .column( identityColumn )
+               .execute();
+        });
+
+        dsl.transaction( t -> {
+            dsl.insertInto( entitiesTable )
+               .set( identityColumn, "12" )
+               .execute();
+        });
+    }
+
+    private DataSource dbcpDataSource( String host, int port )
+        throws Exception
+    {
+        BasicDataSource pool = new BasicDataSource();
+
+        String driverClass = "com.mysql.jdbc.Driver";
+        Class.forName( driverClass );
+        pool.setDriverClassName( driverClass );
+        pool.setUrl( "jdbc:mysql://" + host + ":" + port + "/testdb" );
+        pool.setUsername( "root" );
+        pool.setPassword( "testing" );
+        pool.setDefaultAutoCommit( false );
+        return pool;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityListResource.java
----------------------------------------------------------------------
diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityListResource.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityListResource.java
index 175ee7c..f397893 100644
--- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityListResource.java
+++ b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityListResource.java
@@ -96,7 +96,7 @@ public interface EntityListResource<T extends HasIdentity> extends ServerResourc
             Class<T> entityType = parameters.entityType().get();
             Identity identity = identityManager.generate(entityType, name);
             locator.find( entityType ).create( identity );
-            return resourceBuilder.createRestLink( identity.toString(), base, Method.GET );
+            return resourceBuilder.createBaseLink( identity.toString(), base, Method.GET, "Name form" );
         }
 
         @SuppressWarnings( "unchecked" )

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityResource.java
----------------------------------------------------------------------
diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityResource.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityResource.java
index 91b05ea..3cf9434 100644
--- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityResource.java
+++ b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityResource.java
@@ -130,7 +130,7 @@ public interface EntityResource<T extends HasIdentity> extends ServerResource<T>
                 throw new RuntimeException( message, e );
             }
             Reference base = parameters.request().get().getResourceRef();
-            return resourceBuilder.createRestLink( "", base, org.restlet.data.Method.GET );
+            return resourceBuilder.createBaseLink( "", base, org.restlet.data.Method.GET, "" );
         }
 
         private Object createParametersComposite( RestForm form, Class<?> argType )

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/CreationResource.java
----------------------------------------------------------------------
diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/CreationResource.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/CreationResource.java
index cee4b23..cf84933 100644
--- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/CreationResource.java
+++ b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/CreationResource.java
@@ -70,7 +70,7 @@ public interface CreationResource<T extends HasIdentity> extends ServerResource<
             Identity identity = identityManager.generate( entityType, name );
             locator.find( entityType ).create( identity );
             doParameterization( form, entityType, identity );
-            return resourceBuilder.createRestLink( identity.toString(), parameters.request().get().getResourceRef(), Method.GET );
+            return resourceBuilder.createBaseLink( identity.toString(), parameters.request().get().getResourceRef(), Method.GET, "" );
         }
 
         private <P> void doParameterization( RestForm form, Class entityType, Identity identity )

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/EntryPointResource.java
----------------------------------------------------------------------
diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/EntryPointResource.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/EntryPointResource.java
index 2e56c8a..3efcc2e 100644
--- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/EntryPointResource.java
+++ b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/EntryPointResource.java
@@ -78,14 +78,12 @@ public interface EntryPointResource extends ServerResource<EntryPoint>
                         Reference hostRef = parameters.request().get().getOriginalRef();
 //                        Reference reference = new Reference( hostRef, template.getPattern() );
                         RestLink link;
-                        if( route.getDescription() == null )
+                        String description = route.getDescription();
+                        if( description == null )
                         {
-                            link = resourceBuilder.createRestLink( template.getPattern(), hostRef, Method.GET );
-                        }
-                        else
-                        {
-                            link = resourceBuilder.createRestLink( template.getPattern(), hostRef, Method.GET, route.getDescription() );
+                            description = "";
                         }
+                        link = resourceBuilder.createLeafLink( template.getPattern(), hostRef, Method.GET, description );
                         entryPoints.put( route.getName(), link );
                     }
                 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/ResourceBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/ResourceBuilder.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/ResourceBuilder.java
index fded105..b3cb1b2 100644
--- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/ResourceBuilder.java
+++ b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/ResourceBuilder.java
@@ -51,13 +51,13 @@ public interface ResourceBuilder
 
     EntityRef createEntityRef( Identity name, RestLink get, RestLink put, RestLink delete );
 
-    RestLink createRestLink( String name, Reference base, Method method );
+    RestLink createBaseLink( String name, Reference base, Method method, String description );
 
-    RestLink createRestLink( String name, Reference base, Method method, String description );
+    RestLink createLeafLink( String name, Reference base, Method method, String description );
 
     Command createCommand( Reference base );
 
-    RestForm createNameForm( Reference base );
+    RestForm createNameForm( Reference base, String formName );
 
     FormField createFormField( String name, String type );
 
@@ -89,9 +89,9 @@ public interface ResourceBuilder
         {
             String name = identityManager.extractName( identity );
 
-            RestLink get = createRestLink( name, base, Method.GET );
-            RestLink put = createRestLink( name, base, Method.PUT );
-            RestLink delete = createRestLink( name, base, Method.DELETE );
+            RestLink get = createBaseLink( name, base, Method.GET, "Fetch " + name );
+            RestLink put = createBaseLink( name, base, Method.PUT, "Save " + name );
+            RestLink delete = createBaseLink( name, base, Method.DELETE, "Delete " + name );
             return createEntityRef( identity, get, put, delete );
         }
 
@@ -108,22 +108,24 @@ public interface ResourceBuilder
         }
 
         @Override
-        public RestLink createRestLink( String name, Reference base, Method method )
+        public RestLink createBaseLink( String name, Reference base, Method method, String description )
         {
             ValueBuilder<RestLink> builder = vbf.newValueBuilder( RestLink.class );
             RestLink prototype = builder.prototype();
             String path = base.toUri().resolve( name ).getPath();
             prototype.path().set( path.endsWith( "/" ) ? path : path + "/" );
             prototype.method().set( method.getName() );
+            prototype.description().set( description );
             return builder.newInstance();
         }
 
         @Override
-        public RestLink createRestLink( String name, Reference base, Method method, String description )
+        public RestLink createLeafLink( String name, Reference base, Method method, String description )
         {
             ValueBuilder<RestLink> builder = vbf.newValueBuilder( RestLink.class );
             RestLink prototype = builder.prototype();
-            prototype.path().set( base.toUri().resolve( name ).getPath() + "/" );
+            String path = base.toUri().resolve( name ).getPath();
+            prototype.path().set( path );
             prototype.method().set( method.getName() );
             prototype.description().set( description );
             return builder.newInstance();
@@ -131,17 +133,17 @@ public interface ResourceBuilder
 
         public Command createCommand( Reference base )
         {
-            RestForm form = createNameForm( base );
+            RestForm form = createNameForm( base, "create" );
             ValueBuilder<Command> builder = vbf.newValueBuilder( Command.class );
             builder.prototype().name().set( "create" );
             builder.prototype().form().set( form );
             return builder.newInstance();
         }
 
-        public RestForm createNameForm( Reference base )
+        public RestForm createNameForm( Reference base, String formName )
         {
             ValueBuilder<RestForm> builder = vbf.newValueBuilder( RestForm.class );
-            builder.prototype().link().set( createRestLink( "form", base, Method.POST ) );
+            builder.prototype().link().set( createBaseLink( formName, base, Method.POST, "" ) );
             builder.prototype().fields().set( Collections.singletonList( createFormField( "name", FormField.TEXT ) ) );
             return builder.newInstance();
         }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/95882f22/tools/generator-polygene/app/templates/RestAPIApplication/application.java.tmpl
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/app/templates/RestAPIApplication/application.java.tmpl b/tools/generator-polygene/app/templates/RestAPIApplication/application.java.tmpl
index e188755..1b418c5 100644
--- a/tools/generator-polygene/app/templates/RestAPIApplication/application.java.tmpl
+++ b/tools/generator-polygene/app/templates/RestAPIApplication/application.java.tmpl
@@ -55,7 +55,7 @@ for( var moduleName in polygene.modules) {
     var module = polygene.modules[moduleName];
     for( var idx2 in module.cruds ) {
         var crud = module.cruds[idx2];
-%>        addResourcePath( "<%= crud.name.toLowerCase() %>", <%= crud.name %>.class, basePath );
+%>        addResourcePath( "<%= crud.name.toLowerCase() %>/", <%= crud.name %>.class, basePath );
 <%
     }
 }


Mime
View raw message