You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by ni...@apache.org on 2017/10/26 07:34:43 UTC

[13/33] polygene-java git commit: Fixed the Association testcase failure.

Fixed the Association testcase failure.

Signed-off-by: niclas <ni...@hedhman.org>


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

Branch: refs/heads/develop
Commit: 80a19d7bf25de27eb5e357c85c92a9d230ec1dda
Parents: 572883f
Author: niclas <ni...@hedhman.org>
Authored: Sun Jun 11 14:39:35 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Sun Jun 11 14:39:35 2017 +0800

----------------------------------------------------------------------
 extensions/entitystore-jooq/dev-status.xml      |  2 +-
 .../entitystore/jooq/JooqEntityStoreMixin.java  |  1 +
 .../polygene/entitystore/jooq/MixinTable.java   | 91 +++++++-------------
 3 files changed, 35 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/80a19d7b/extensions/entitystore-jooq/dev-status.xml
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/dev-status.xml b/extensions/entitystore-jooq/dev-status.xml
index 6710bdd..b6d4c31 100644
--- a/extensions/entitystore-jooq/dev-status.xml
+++ b/extensions/entitystore-jooq/dev-status.xml
@@ -27,7 +27,7 @@
         <codebase>early</codebase>
 
         <!-- none, brief, good, complete -->
-        <documentation>none</documentation>
+        <documentation>brief</documentation>
 
         <!-- none, some, good, complete -->
         <unittests>good</unittests>

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/80a19d7b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java
index 5a062d8..1daa78b 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java
@@ -85,6 +85,7 @@ public class JooqEntityStoreMixin
     {
         AssociationStateDescriptor stateDescriptor = baseEntity.type.state();
         Map<QualifiedName, Object> properties = new HashMap<>();
+        properties.put( HasIdentity.IDENTITY_STATE_NAME, baseEntity.identity );
         stateDescriptor.properties()
                        .filter( prop -> !HasIdentity.IDENTITY_STATE_NAME.equals( prop.qualifiedName() ) )
                        .forEach( prop ->

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/80a19d7b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/MixinTable.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/MixinTable.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/MixinTable.java
index 257134e..c7b219b 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/MixinTable.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/MixinTable.java
@@ -25,7 +25,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.function.Consumer;
 import org.apache.polygene.api.association.AssociationDescriptor;
 import org.apache.polygene.api.common.QualifiedName;
 import org.apache.polygene.api.entity.EntityDescriptor;
@@ -95,7 +94,7 @@ class MixinTable
 
         descriptor.valueType().namedAssociations()
                   .filter( this::isThisMixin )
-                  .forEach( assocDescriptor -> manyAssociations.add( assocDescriptor.qualifiedName() ) );
+                  .forEach( assocDescriptor -> namedAssociations.add( assocDescriptor.qualifiedName() ) );
     }
 
     void insertMixinState( DefaultEntityState state, String valueIdentity )
@@ -127,21 +126,47 @@ class MixinTable
 
     private void insertManyAndNamedAssociations( DefaultEntityState state, String valueIdentity )
     {
-        InsertSetStep<Record> assocsTable = dsl.insertInto( mixinAssocsTable );
         manyAssociations.forEach( assocName ->
                                   {
+                                      InsertSetStep<Record> assocsTable = dsl.insertInto( mixinAssocsTable );
                                       ManyAssociationState entityReferences = state.manyAssociationValueOf( assocName );
-                                      entityReferences.stream().forEach( setManyAssociation( assocName, valueIdentity, assocsTable ) );
+                                      int endCount = entityReferences.count();
+                                      int counter = 0;
+                                      for( EntityReference ref : entityReferences )
+                                      {
+                                          InsertSetMoreStep<Record> set = assocsTable.set( identityColumn, valueIdentity )
+                                                                                     .set( nameColumn, assocName.name() )
+                                                                                     .set( indexColumn, "" + counter++ )
+                                                                                     .set( referenceColumn, ref == null ? null : ref.identity().toString() );
+                                          if( ++counter < endCount )
+                                          {
+                                              set.newRecord();
+                                          }
+                                      }
+                                      InsertSetMoreStep<Record> assocs = assocsTable.set( Collections.emptyMap() );
+                                      assocs.execute();
                                   } );
 
         namedAssociations.forEach( assocName ->
                                    {
+                                       InsertSetStep<Record> assocsTable = dsl.insertInto( mixinAssocsTable );
                                        NamedAssociationState entityReferences = state.namedAssociationValueOf( assocName );
-                                       entityReferences.stream().forEach( setNamedAssociation( assocName, valueIdentity, assocsTable ) );
+                                       int count = entityReferences.count();
+                                       for( String name : entityReferences )
+                                       {
+                                           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();
     }
 
     Table<Record> associationsTable()
@@ -149,56 +174,6 @@ class MixinTable
         return mixinAssocsTable;
     }
 
-    /**
-     * Writes one ManyAssoc Reference to the _ASSOCS table.
-     * <ul>
-     * <li>identityColumn - valueIdentity of primaryTable row</li>
-     * <li>nameColumn - index in the of association in state holder</li>
-     * <li>indexColumn - the position within the many association, starting at 0</li>
-     * <li>referenceColumn - referenced entity's identity</li>
-     * </ul>
-     */
-    private Consumer<? super EntityReference> setManyAssociation( QualifiedName assocName,
-                                                                  String valueIdentity,
-                                                                  InsertSetStep<Record> assocsTable )
-    {
-        return new Consumer<EntityReference>()
-        {
-            private int counter = 0;
-
-            @Override
-            public void accept( EntityReference ref )
-            {
-                InsertSetMoreStep<Record> set = assocsTable.set( identityColumn, valueIdentity )
-                                                           .set( nameColumn, assocName.name() )
-                                                           .set( indexColumn, "" + counter++ )
-                                                           .set( referenceColumn, ref == null ? null : ref.identity().toString() );
-            }
-        };
-    }
-
-    /**
-     * Writes one Named Reference to the _ASSOCS table.
-     * <ul>
-     * <li>identityColumn - valueIdentity of primaryTable row</li>
-     * <li>nameColumn - name of association in state holder</li>
-     * <li>indexColumn - the key/lookup name of the reference</li>
-     * <li>referenceColumn - referenced entity's identity</li>
-     * </ul>
-     */
-    private Consumer<? super Map.Entry<String, EntityReference>> setNamedAssociation( QualifiedName assocName,
-                                                                                      String valueIdentity,
-                                                                                      InsertSetStep<Record> assocsTable )
-    {
-        return ref ->
-        {
-            InsertSetMoreStep<Record> set = assocsTable.set( identityColumn, valueIdentity )
-                                                       .set( nameColumn, assocName.name() )
-                                                       .set( indexColumn, ref.getKey() )
-                                                       .set( referenceColumn, ref.getValue().identity().toString() );
-        };
-    }
-
     private boolean isThisMixin( PropertyDescriptor descriptor )
     {
         Class<?> declaringClass = declaredIn( descriptor );