]> source.dussan.org Git - iciql.git/commitdiff
Make IQTable.inheritColumns works for an arbitrary depth. 14/head
authorMaaartin Grajcar <grajcar@seznam.cz>
Tue, 7 Apr 2015 18:24:19 +0000 (20:24 +0200)
committerMaaartin Grajcar <grajcar@seznam.cz>
Tue, 7 Apr 2015 18:24:19 +0000 (20:24 +0200)
src/main/java/com/iciql/Iciql.java
src/main/java/com/iciql/TableDefinition.java

index b303372b32c4a74c71f0cfff9997e34c6d7772af..302b34d3ba574d55ff5723b91e17e5ce0cf77c70 100644 (file)
@@ -474,8 +474,8 @@ public interface Iciql {
 \r
                /**\r
                 * The inherit columns allows this model class to inherit columns from\r
-                * its super class. Any IQTable annotation present on the super class is\r
-                * ignored. Default: false.\r
+                * its super class. IQTable and IQView annotations present on the super\r
+                * class or above are honored. Default: false.\r
                 */\r
                boolean inheritColumns() default false;\r
 \r
@@ -549,8 +549,8 @@ public interface Iciql {
 \r
                /**\r
                 * The inherit columns allows this model class to inherit columns from\r
-                * its super class. Any IQTable annotation present on the super class is\r
-                * ignored. Default: false.\r
+                * its super class. IQTable and IQView annotations present on the super\r
+                * class or above are honored. Default: false.\r
                 */\r
                boolean inheritColumns() default false;\r
 \r
index e4fff875a6efafd9764e1e7239b9f3ec6b523a30..e07cee6ccb37a4c398370e0a488529dae701cd40 100644 (file)
@@ -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(