summaryrefslogtreecommitdiff
path: root/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/EntityHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-compiler-plugin/src/main/java/io/trygvis/container/compiler/EntityHandler.java')
-rw-r--r--container-compiler-plugin/src/main/java/io/trygvis/container/compiler/EntityHandler.java35
1 files changed, 15 insertions, 20 deletions
diff --git a/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/EntityHandler.java b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/EntityHandler.java
index fc7ca4f..ad36988 100644
--- a/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/EntityHandler.java
+++ b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/EntityHandler.java
@@ -1,10 +1,6 @@
package io.trygvis.container.compiler;
import io.trygvis.container.compiler.model.ClassG;
-import io.trygvis.container.compiler.model.FieldRef;
-import io.trygvis.container.compiler.model.ParameterRef;
-import io.trygvis.container.compiler.model.Parameters;
-import io.trygvis.container.compiler.model.TypeRef;
import io.trygvis.persistence.EntityMirror;
import io.trygvis.persistence.FieldMirror;
import io.trygvis.persistence.GeneratorSupport;
@@ -23,13 +19,11 @@ import javax.lang.model.type.TypeMirror;
import javax.persistence.Id;
import javax.tools.JavaFileObject;
import java.io.PrintWriter;
-import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import static io.trygvis.container.compiler.Utils.toFieldName;
import static io.trygvis.persistence.FieldMirror.PrimitiveFieldMirror;
import static java.lang.Character.isUpperCase;
import static javax.lang.model.util.ElementFilter.fieldsIn;
@@ -45,7 +39,7 @@ public class EntityHandler extends AbstractHandler {
public void phase1(Set<TypeElement> sqlEntities, Set<PackageElement> packages) throws Exception {
for (TypeElement entity : sqlEntities) {
- AnnotationMirror sqlEntity = findAnnotation(SqlEntity.class, entity.getAnnotationMirrors());
+ AnnotationMirror sqlEntity = findAnnotation(SqlEntity.class, entity);
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> v : sqlEntity.getElementValues().entrySet()) {
switch (v.getKey().getSimpleName().toString()) {
case "value":
@@ -63,24 +57,24 @@ public class EntityHandler extends AbstractHandler {
System.out.println("packages = " + packages);
if (packages.size() == 0) {
- throw new RuntimeException("There has to be exactly one @SqlEntitySet annotated package.");
+ throw new CompilerException(null, "There has to be exactly one @SqlEntitySet annotated package.");
}
+ packageElement = packages.iterator().next();
+
if (packages.size() != 1) {
- throw new RuntimeException("There can only be one @SqlEntitySet annotated package.");
+ throw new CompilerException(packageElement, "There can only be one @SqlEntitySet annotated package.");
}
-
- packageElement = packages.iterator().next();
}
- private AnnotationMirror findAnnotation(Class<?> c, List<? extends AnnotationMirror> annotations) {
- TypeElement t = elements.getTypeElement(c.getCanonicalName());
- for (AnnotationMirror a : annotations) {
- if (types.isSameType(a.getAnnotationType(), t.asType())) {
+ private AnnotationMirror findAnnotation(Class<?> c, TypeElement type) {
+ TypeMirror annotationType = elements.getTypeElement(c.getCanonicalName()).asType();
+ for (AnnotationMirror a : type.getAnnotationMirrors()) {
+ if (types.isSameType(a.getAnnotationType(), annotationType)) {
return a;
}
}
- throw new RuntimeException("Could not find annotation " + c.getSimpleName());
+ throw new CompilerException(type, "Could not find annotation " + c.getSimpleName());
}
public void processEntity(TypeElement element) throws Exception {
@@ -99,10 +93,10 @@ public class EntityHandler extends AbstractHandler {
}
if (idFields.size() == 0) {
- throw new RuntimeException("An @Entity is required to have at least one @Id field.");
+ throw new CompilerException(element, "An @Entity is required to have at least one @Id field.");
}
if (idFields.size() != 1) {
- throw new RuntimeException("This implementation only support a single @Id annotated field.");
+ throw new CompilerException(element, "This implementation only support a single @Id annotated field.");
}
String p = elements.getPackageOf(element).getQualifiedName().toString();
@@ -137,12 +131,12 @@ public class EntityHandler extends AbstractHandler {
field = new PrimitiveFieldMirror(var, javaName, sqlName, id, notNull);
} else if (generatorSupport.hasTypeHandler(type)) {
if (id) {
- throw new RuntimeException("A @Id field has to be a primitive or embedded.");
+ throw new CompilerException(var, "A @Id field has to be a primitive or embedded.");
}
field = new FieldMirror.ReferenceFieldMirror(var, javaName, sqlName, notNull);
} else {
- throw new RuntimeException("Missing type handler for type: " + type);
+ throw new CompilerException(var, "Missing type handler for type: " + type);
}
// System.out.println("field = " + field);
return field;
@@ -152,6 +146,7 @@ public class EntityHandler extends AbstractHandler {
return var.getAnnotation(Id.class) != null;
}
+ // TODO: Rename DAO to Session.
public void phase3() throws Exception {
String p = packageElement.getQualifiedName().toString();