summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Moger <james.moger@gmail.com>2015-04-07 19:19:12 -0400
committerJames Moger <james.moger@gmail.com>2015-04-07 19:19:12 -0400
commitff3df66cdebab32ca8c7f06d45ec2c817abe70bb (patch)
tree92a9d446de99e82206a4c444539b4cebfaab01c7
parent2ada578502b7c4f9052ac1eca920b0ed4e84161e (diff)
parentc2b20d57a0c20fb457dc3d11ee7febdb1f3e14f8 (diff)
downloadiciql-ff3df66cdebab32ca8c7f06d45ec2c817abe70bb.tar.gz
iciql-ff3df66cdebab32ca8c7f06d45ec2c817abe70bb.zip
Merge pull request #14 from Maaartinus/master
Make IQTable.inheritColumns works for an arbitrary depth.
-rw-r--r--src/main/java/com/iciql/Iciql.java8
-rw-r--r--src/main/java/com/iciql/TableDefinition.java44
2 files changed, 26 insertions, 26 deletions
diff --git a/src/main/java/com/iciql/Iciql.java b/src/main/java/com/iciql/Iciql.java
index b303372..302b34d 100644
--- a/src/main/java/com/iciql/Iciql.java
+++ b/src/main/java/com/iciql/Iciql.java
@@ -474,8 +474,8 @@ public interface Iciql {
/**
* The inherit columns allows this model class to inherit columns from
- * its super class. Any IQTable annotation present on the super class is
- * ignored. Default: false.
+ * its super class. IQTable and IQView annotations present on the super
+ * class or above are honored. Default: false.
*/
boolean inheritColumns() default false;
@@ -549,8 +549,8 @@ public interface Iciql {
/**
* The inherit columns allows this model class to inherit columns from
- * its super class. Any IQTable annotation present on the super class is
- * ignored. Default: false.
+ * its super class. IQTable and IQView annotations present on the super
+ * class or above are honored. Default: false.
*/
boolean inheritColumns() default false;
diff --git a/src/main/java/com/iciql/TableDefinition.java b/src/main/java/com/iciql/TableDefinition.java
index e4fff87..e07cee6 100644
--- a/src/main/java/com/iciql/TableDefinition.java
+++ b/src/main/java/com/iciql/TableDefinition.java
@@ -439,28 +439,7 @@ public class TableDefinition<T> {
inheritColumns = viewAnnotation.inheritColumns();
}
- List<Field> classFields = Utils.newArrayList();
- classFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
- if (inheritColumns) {
- Class<?> superClass = clazz.getSuperclass();
- classFields.addAll(Arrays.asList(superClass.getDeclaredFields()));
-
- if (superClass.isAnnotationPresent(IQView.class)) {
- IQView superView = superClass.getAnnotation(IQView.class);
- if (superView.inheritColumns()) {
- // inherit columns from super.super.class
- Class<?> superSuperClass = superClass.getSuperclass();
- classFields.addAll(Arrays.asList(superSuperClass.getDeclaredFields()));
- }
- } else if (superClass.isAnnotationPresent(IQTable.class)) {
- IQTable superTable = superClass.getAnnotation(IQTable.class);
- if (superTable.inheritColumns()) {
- // inherit columns from super.super.class
- Class<?> superSuperClass = superClass.getSuperclass();
- classFields.addAll(Arrays.asList(superSuperClass.getDeclaredFields()));
- }
- }
- }
+ List<Field> classFields = classFields(inheritColumns);
Set<FieldDefinition> uniqueFields = new LinkedHashSet<FieldDefinition>();
T defaultObject = Db.instance(clazz);
@@ -606,6 +585,27 @@ public class TableDefinition<T> {
}
}
+ private List<Field> classFields(boolean inheritColumns) {
+ List<Field> classFields = Utils.newArrayList();
+ classFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
+ Class<?> superClass = clazz;
+ while (inheritColumns) {
+ superClass = superClass.getSuperclass();
+ classFields.addAll(Arrays.asList(superClass.getDeclaredFields()));
+
+ if (superClass.isAnnotationPresent(IQView.class)) {
+ IQView superView = superClass.getAnnotation(IQView.class);
+ inheritColumns = superView.inheritColumns();
+ } else if (superClass.isAnnotationPresent(IQTable.class)) {
+ IQTable superTable = superClass.getAnnotation(IQTable.class);
+ inheritColumns = superTable.inheritColumns();
+ } else {
+ inheritColumns = false;
+ }
+ }
+ return classFields;
+ }
+
void checkMultipleBooleans() {
if (multiplePrimitiveBools) {
throw new IciqlException(