summaryrefslogtreecommitdiff
path: root/container-compiler-plugin/src/main/java/io/trygvis/persistence/EntityMirror.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-compiler-plugin/src/main/java/io/trygvis/persistence/EntityMirror.java')
-rw-r--r--container-compiler-plugin/src/main/java/io/trygvis/persistence/EntityMirror.java57
1 files changed, 42 insertions, 15 deletions
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<EntityMirror> {
public final GeneratorConfiguration generatorConfiguration;
- public final List<FieldMirror> fields = new ArrayList<>();
- public final List<FieldMirror> idFields = new ArrayList<>();
+ private final List<FieldMirror> 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<EntityMirror> {
}
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<FieldMirror> getFields() {
+ List<FieldMirror> fields = superEntity != null ? superEntity.getFields() : new ArrayList<FieldMirror>();
+ fields.addAll(this.fields);
+ return fields;
+ }
+
+ // -----------------------------------------------------------------------
+ //
+ // -----------------------------------------------------------------------
+
@Override
public boolean equals(Object o) {
if (this == o) return true;