\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
\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
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);
}
}
+ 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(