[OPENJPA-2891] default for addGeneratedOption, use switch
diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
index b3efc8a..1087444 100644
--- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
+++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
@@ -317,21 +317,27 @@
SourceCode.Class cls = source.getTopLevelClass();
cls.addAnnotation(StaticMetamodel.class.getName())
.addArgument("value", originalClass + ".class", false);
- if ("false".equals(this.addGeneratedOption)) {
- return;
- }
- if ("force".equals(this.addGeneratedOption)) {
- cls.addAnnotation(javax.annotation.Generated.class.getName())
- .addArgument("value", this.getClass().getName())
- .addArgument("date", this.generationDate.toString());
- }
+ switch (this.addGeneratedOption) {
+ case "false":
+ return;
- // only add the annotation if it is on the classpath for Java 6+.
- if (generatedAnnotation != null && generatedSourceVersion >= 6) {
- cls.addAnnotation(generatedAnnotation.getName())
- .addArgument("value", this.getClass().getName())
- .addArgument("date", this.generationDate.toString());
+ case "force":
+ cls.addAnnotation(javax.annotation.Generated.class.getName())
+ .addArgument("value", this.getClass().getName())
+ .addArgument("date", this.generationDate.toString());
+ break;
+
+ case "auto":
+ // fall through
+ default:
+ // only add the annotation if it is on the classpath for Java 6+.
+ if (generatedAnnotation != null && generatedSourceVersion >= 6) {
+ cls.addAnnotation(generatedAnnotation.getName())
+ .addArgument("value", this.getClass().getName())
+ .addArgument("date", this.generationDate.toString());
+ }
+ break;
}
}
@@ -398,6 +404,11 @@
private void setAddGeneratedAnnotation() {
this.addGeneratedOption = getOptionValue("openjpa.addGeneratedAnnotation");
+
+ if (this.addGeneratedOption == null) {
+ this.addGeneratedOption = "auto";
+ }
+
// only add the annotation if it is on the classpath for Java 6+.
try {
this.generatedAnnotation = Class.forName("javax.annotation.Generated", false, null);