From 0b31aebb2e7f0d241a301f117b140a712dc1d3c1 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 27 Sep 2007 16:57:05 +0000 Subject: [PATCH] Fixed @Transient handling. --- .../jdbc/depot/tools/GenRecordTask.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/java/com/samskivert/jdbc/depot/tools/GenRecordTask.java b/src/java/com/samskivert/jdbc/depot/tools/GenRecordTask.java index cd0ca19..966f256 100644 --- a/src/java/com/samskivert/jdbc/depot/tools/GenRecordTask.java +++ b/src/java/com/samskivert/jdbc/depot/tools/GenRecordTask.java @@ -156,14 +156,10 @@ public class GenRecordTask extends Task // determine which fields make up our primary key; we'd just use Class.getFields() but // that returns things in a random order whereas ClassUtil returns fields in // declaration order starting from the top-most class and going down the line - FIELD_LOOP: for (Field field : ClassUtil.getFields(rclass)) { - // iterate becase getAnnotation() fails if we're dealing with multiple classloaders - for (Annotation a : field.getAnnotations()) { - if (Id.class.getName().equals(a.annotationType().getName())) { - kflist.add(field); - continue FIELD_LOOP; - } + if (hasAnnotation(field, Id.class)) { + kflist.add(field); + continue; } } } @@ -370,7 +366,7 @@ public class GenRecordTask extends Task { int mods = field.getModifiers(); return Modifier.isPublic(mods) && !Modifier.isStatic(mods) && - !Modifier.isTransient(mods) && (field.getAnnotation(Transient.class) == null); + !Modifier.isTransient(mods) && !hasAnnotation(field, Transient.class); } /** @@ -414,6 +410,17 @@ public class GenRecordTask extends Task return writer.toString(); } + protected static boolean hasAnnotation (Field field, Class annotation) + { + // iterate becase getAnnotation() fails if we're dealing with multiple classloaders + for (Annotation a : field.getAnnotations()) { + if (annotation.getName().equals(a.annotationType().getName())) { + return true; + } + } + return false; + } + /** * Reads in the supplied source file and locates the package and class or interface name and * returns a fully qualified class name.