You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2018/10/19 12:23:29 UTC
[7/7] cayenne git commit: CAY-2478 cgen: Generate properties for PK
refactor meaningful PK check
CAY-2478 cgen: Generate properties for PK
refactor meaningful PK check
Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/7b5d73e4
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/7b5d73e4
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/7b5d73e4
Branch: refs/heads/master
Commit: 7b5d73e4e92f2eae5230b87142c4ae4e5a0a6b9c
Parents: 904753b
Author: Nikita Timofeev <st...@gmail.com>
Authored: Fri Oct 19 15:23:10 2018 +0300
Committer: Nikita Timofeev <st...@gmail.com>
Committed: Fri Oct 19 15:23:10 2018 +0300
----------------------------------------------------------------------
.../src/main/java/org/apache/cayenne/gen/EntityUtils.java | 8 +++-----
.../src/main/resources/templates/v4_1/singleclass.vm | 2 +-
cayenne-cgen/src/main/resources/templates/v4_1/superclass.vm | 2 +-
3 files changed, 5 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cayenne/blob/7b5d73e4/cayenne-cgen/src/main/java/org/apache/cayenne/gen/EntityUtils.java
----------------------------------------------------------------------
diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/EntityUtils.java b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/EntityUtils.java
index e5ea590..2923b98 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/EntityUtils.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/EntityUtils.java
@@ -20,11 +20,9 @@
package org.apache.cayenne.gen;
import java.util.Collection;
-import java.util.Objects;
import org.apache.cayenne.CayenneRuntimeException;
import org.apache.cayenne.ObjectId;
-import org.apache.cayenne.dba.TypesMapping;
import org.apache.cayenne.map.DataMap;
import org.apache.cayenne.map.DbAttribute;
import org.apache.cayenne.map.DbEntity;
@@ -268,12 +266,12 @@ public class EntityUtils {
/**
* Checks is the db attribute declared for some object attribute.
- * @param id - db attribute
+ * @param pkAttribute - db attribute for PK
*
* @since 4.1
*/
- public boolean declaresDbAttribute(String id) {
- return objEntity.getAttributes().stream().filter(Objects::nonNull).anyMatch(a -> id.equals(a.getDbAttributePath()));
+ public boolean declaresDbAttribute(DbAttribute pkAttribute) {
+ return objEntity.getAttributeForDbAttribute(pkAttribute) != null;
}
/**
http://git-wip-us.apache.org/repos/asf/cayenne/blob/7b5d73e4/cayenne-cgen/src/main/resources/templates/v4_1/singleclass.vm
----------------------------------------------------------------------
diff --git a/cayenne-cgen/src/main/resources/templates/v4_1/singleclass.vm b/cayenne-cgen/src/main/resources/templates/v4_1/singleclass.vm
index db9fb36..32ae64a 100644
--- a/cayenne-cgen/src/main/resources/templates/v4_1/singleclass.vm
+++ b/cayenne-cgen/src/main/resources/templates/v4_1/singleclass.vm
@@ -77,7 +77,7 @@ public#if("true" == "${object.isAbstract()}") abstract#end class ${subClassName}
###########################
#if( $object.DbEntity )
#foreach( $idAttr in ${object.DbEntity.PrimaryKeys} )
- #if( $createPKProperties && !${importUtils.declaresDbAttribute($idAttr.Name)})
+ #if( $createPKProperties && !${entityUtils.declaresDbAttribute($idAttr)})
#set ( $type = "$importUtils.dbAttributeToJavaType($idAttr)")
public static final Property<$type> ${stringUtils.capitalizedAsConstant($idAttr.Name)}_PK_COLUMN = Property.create(ExpressionFactory.dbPathExp("db:${idAttr.Name}"), ${type}.class});
#else
http://git-wip-us.apache.org/repos/asf/cayenne/blob/7b5d73e4/cayenne-cgen/src/main/resources/templates/v4_1/superclass.vm
----------------------------------------------------------------------
diff --git a/cayenne-cgen/src/main/resources/templates/v4_1/superclass.vm b/cayenne-cgen/src/main/resources/templates/v4_1/superclass.vm
index 559c89d..6f8449d 100644
--- a/cayenne-cgen/src/main/resources/templates/v4_1/superclass.vm
+++ b/cayenne-cgen/src/main/resources/templates/v4_1/superclass.vm
@@ -85,7 +85,7 @@ public abstract class ${superClassName} extends ${baseClassName} {
###########################
#if( $object.DbEntity )
#foreach( $idAttr in ${object.DbEntity.PrimaryKeys} )
- #if( $createPKProperties && !${importUtils.declaresDbAttribute($idAttr.Name)})
+ #if( $createPKProperties && !${entityUtils.declaresDbAttribute($idAttr)})
#set ( $type = "$importUtils.dbAttributeToJavaType($idAttr)")
public static final Property<$type> ${stringUtils.capitalizedAsConstant($idAttr.Name)}_PK_PROPERTY = Property.create(ExpressionFactory.dbPathExp("db:${idAttr.Name}"), ${type}.class);
#end