package io.trygvis.persistence; import io.trygvis.container.compiler.model.TypeRef; import static io.trygvis.persistence.FieldMirror.FieldType.PRIMITIVE; import static io.trygvis.persistence.FieldMirror.FieldType.REFERENCE; /** * TODO: a single field might have to be mapped to multiple sql columns. */ public abstract class FieldMirror { public final FieldType fieldType; public final TypeRef type; public final String javaName; public final String sqlName; public final boolean id; public final boolean notNull; public final boolean unique; public enum FieldType { PRIMITIVE, REFERENCE, } protected FieldMirror(FieldType fieldType, TypeRef type, String javaName, String sqlName, boolean id, boolean notNull, boolean unique) { this.fieldType = fieldType; this.type = type; this.javaName = javaName; this.sqlName = sqlName; this.id = id; this.notNull = notNull; this.unique = unique; } public static class PrimitiveFieldMirror extends FieldMirror { public PrimitiveFieldMirror(TypeRef typeRef, String javaName, String sqlName, boolean id, boolean notNull, boolean unique) { super(PRIMITIVE, typeRef, javaName, sqlName, id, notNull, unique); } @Override public String toString() { return "PrimitiveFieldMirror{" + "type='" + type + '\'' + ", javaName='" + javaName + '\'' + ", sqlName='" + sqlName + '\'' + ", notNull=" + notNull + ", unique=" + unique + '}'; } } public static class ReferenceFieldMirror extends FieldMirror { public ReferenceFieldMirror(TypeRef typeRef, String javaName, String sqlName, boolean notNull, boolean unique) { super(REFERENCE, typeRef, javaName, sqlName, false, notNull, unique); } @Override public String toString() { return "ReferenceFieldMirror{" + "type='" + type + '\'' + ", javaName='" + javaName + '\'' + ", sqlName='" + sqlName + '\'' + ", notNull=" + notNull + ", unique=" + unique + '}'; } } @Override public abstract String toString(); }