summaryrefslogtreecommitdiff
path: root/container-compiler-plugin/src/main/java/io
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-08-04 23:08:37 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2013-08-04 23:08:37 +0200
commitdd150071369e825d4b4a59e15ad3291841c7ba13 (patch)
tree4b31b2459a2fe19ea5c812b1baff6013389f5283 /container-compiler-plugin/src/main/java/io
parentfd6f806608d1047296cbb1ae7ea4a989fe23553b (diff)
downloadcontainer-playground-dd150071369e825d4b4a59e15ad3291841c7ba13.tar.gz
container-playground-dd150071369e825d4b4a59e15ad3291841c7ba13.tar.bz2
container-playground-dd150071369e825d4b4a59e15ad3291841c7ba13.tar.xz
container-playground-dd150071369e825d4b4a59e15ad3291841c7ba13.zip
wip
o Fixing bugs.
Diffstat (limited to 'container-compiler-plugin/src/main/java/io')
-rw-r--r--container-compiler-plugin/src/main/java/io/trygvis/persistence/EntityMirror.java46
-rw-r--r--container-compiler-plugin/src/main/java/io/trygvis/persistence/FieldMirror.java19
2 files changed, 42 insertions, 23 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 f0f4ae7..5d6defb 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
@@ -160,31 +160,31 @@ public class EntityMirror implements Comparable<EntityMirror> {
i++;
+ TypeHandler typeHandler;
+ String accessor;
+ String setter;
if (field.fieldType == PRIMITIVE) {
- TypeHandler typeHandler = generatorConfiguration.typeHandler(field.type);
- String access;
- if (field.accessorType == FIELD) {
- access = o.name + "." + field.javaName;
- } else {
- access = o.name + "." + toGetterName(field.javaName) + "()";
- }
- String setter = " stmt." + typeHandler.setter(i, access) + ";";
-
- if (field.notNull) {
- body.add(setter);
- } else {
- body.add(" " + field.type + " " + field.javaName + " = " + access + ";");
- body.add(" if(" + field.javaName + " == null) {");
- body.add(" stmt.setNull(" + i + ", " + typesType + "." + typeHandler.typeName() + ");");
- body.add(" } else {");
- body.add(" " + setter);
- body.add(" }");
- }
- } else if (field.fieldType == REFERENCE) {
+ typeHandler = generatorConfiguration.typeHandler(field.type);
+ accessor = field.fieldAccessor(o);
+ setter = " stmt." + typeHandler.setter(i, accessor) + ";";
+ } else {
EntityMirror referenced = unit.get(field.type);
FieldMirror idField = referenced.getIdField();
- TypeHandler typeHandler = generatorConfiguration.typeHandler(idField.type);
- body.add(" stmt." + typeHandler.setter(i, o.name + "." + field.javaName + "." + idField.javaName) + ";");
+ typeHandler = generatorConfiguration.typeHandler(idField.type);
+ accessor = field.referenceAccessor(o, idField);
+ setter = " stmt." + typeHandler.setter(i, accessor) + ";";
+ accessor = "null";
+ }
+
+ if (field.notNull) {
+ body.add(setter);
+ } else {
+ body.add(" " + field.type + " " + field.javaName + " = " + accessor + ";");
+ body.add(" if(" + field.javaName + " == null) {");
+ body.add(" stmt.setNull(" + i + ", " + typesType + "." + typeHandler.typeName() + ");");
+ body.add(" } else {");
+ body.add(" " + setter);
+ body.add(" }");
}
}
body.add(" stmt.executeUpdate();");
@@ -202,7 +202,7 @@ public class EntityMirror implements Comparable<EntityMirror> {
List<String> arguments = new ArrayList<>();
arguments.add(con.name);
for (FieldMirror field : idFields) {
- if(field.accessorType == FIELD) {
+ if (field.accessorType == FIELD) {
arguments.add(o.name + "." + field.javaName);
} else {
arguments.add(o.name + "." + toGetterName(field.javaName) + "()");
diff --git a/container-compiler-plugin/src/main/java/io/trygvis/persistence/FieldMirror.java b/container-compiler-plugin/src/main/java/io/trygvis/persistence/FieldMirror.java
index 07fa769..5a2d221 100644
--- a/container-compiler-plugin/src/main/java/io/trygvis/persistence/FieldMirror.java
+++ b/container-compiler-plugin/src/main/java/io/trygvis/persistence/FieldMirror.java
@@ -2,6 +2,10 @@ package io.trygvis.persistence;
import io.trygvis.container.compiler.model.TypeRef;
+import static io.trygvis.container.compiler.Utils.toGetterName;
+import static io.trygvis.container.compiler.model.Parameters.ParameterRef;
+import static io.trygvis.persistence.FieldMirror.AccessorType.FIELD;
+
/**
* TODO: a single field might have to be mapped to multiple sql columns.
*/
@@ -37,6 +41,21 @@ public class FieldMirror {
this.unique = unique;
}
+ public String fieldAccessor(ParameterRef o) {
+ return fieldAccessor(o.name);
+ }
+
+ public String referenceAccessor(ParameterRef o, FieldMirror f) {
+ return f.fieldAccessor(o.name + "." + javaName);
+ }
+
+ private String fieldAccessor(String o) {
+ if (accessorType == FIELD) {
+ return o + "." + javaName;
+ }
+ return o + "." + toGetterName(javaName) + "()";
+ }
+
@Override
public String toString() {
return "FieldMirror{" +