From e78c0a1e4a4ebc71502dceccc9ae640862b7ce9e Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 11 Aug 2013 22:35:02 +0200 Subject: o Overhauling inheritance, adding a decent start of support for @MappedSuperclass. --- .../java/io/trygvis/persistence/EntityMirror.java | 57 ++++++++++++++++------ 1 file changed, 42 insertions(+), 15 deletions(-) (limited to 'container-compiler-plugin/src/main/java/io/trygvis/persistence/EntityMirror.java') diff --git a/container-compiler-plugin/src/main/java/io/trygvis/persistence/EntityMirror.java b/container-compiler-plugin/src/main/java/io/trygvis/persistence/EntityMirror.java index 85523dc..3f6816d 100644 --- a/container-compiler-plugin/src/main/java/io/trygvis/persistence/EntityMirror.java +++ b/container-compiler-plugin/src/main/java/io/trygvis/persistence/EntityMirror.java @@ -1,39 +1,50 @@ package io.trygvis.persistence; +import io.trygvis.container.compiler.CompilerException; import io.trygvis.container.compiler.model.TypeRef; import java.util.ArrayList; import java.util.List; +import static java.util.Collections.addAll; + public class EntityMirror implements Comparable { public final GeneratorConfiguration generatorConfiguration; - public final List fields = new ArrayList<>(); - public final List idFields = new ArrayList<>(); + private final List fields = new ArrayList<>(); public final TypeRef type; + public final boolean concrete; public final String tableName; public final TypeRef rowType; public final TypeRef daoType; public final TypeRef utilsType; public TypeRef idType; + /** + * The nearest @MappedSuperclass + */ + public EntityMirror superEntity; - public EntityMirror(GeneratorConfiguration generatorConfiguration, TypeRef type, String tableName) { + public EntityMirror(GeneratorConfiguration generatorConfiguration, TypeRef type, boolean concrete, + EntityMirror superEntity, String tableName) { this.generatorConfiguration = generatorConfiguration; this.type = type; - this.tableName = tableName; + this.concrete = concrete; + this.superEntity = superEntity; - this.rowType = new TypeRef(type.plainName + "Row"); - this.daoType = new TypeRef(type.plainName + "Dao").args(type.args); - this.utilsType = new TypeRef(type.plainName + "Dao.Utils").args(type.args); + if (concrete) { + this.tableName = tableName; + this.rowType = new TypeRef(type.plainName + "Row"); + this.daoType = new TypeRef(type.plainName + "Dao").args(type.args); + this.utilsType = new TypeRef(type.plainName + "Dao.Utils").args(type.args); + } else { + this.tableName = null; + this.rowType = null; + this.daoType = null; + this.utilsType = null; + } } public void add(FieldMirror... fields) { - for (FieldMirror field : fields) { - this.fields.add(field); - if (field.id) { - this.idFields.add(field); - } - - } + addAll(this.fields, fields); } public void setIdType(TypeRef idType) { @@ -41,9 +52,25 @@ public class EntityMirror implements Comparable { } public FieldMirror getIdField() { - return idFields.get(0); + for (FieldMirror f : getFields()) { + if (f.id) { + return f; + } + } + + throw new CompilerException("Internal error: no @Id field defined on " + type); } + public List getFields() { + List fields = superEntity != null ? superEntity.getFields() : new ArrayList(); + fields.addAll(this.fields); + return fields; + } + + // ----------------------------------------------------------------------- + // + // ----------------------------------------------------------------------- + @Override public boolean equals(Object o) { if (this == o) return true; -- cgit v1.2.3