Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa
diff options
context:
space:
mode:
authorkmoore2008-09-03 15:22:05 +0000
committerkmoore2008-09-03 15:22:05 +0000
commit051e01c88041fe899f37ff0db52a2ae6336fe553 (patch)
tree0578cec73ff85c6cbcd4b8053cbf93078d885f4e /jpa
parentacba681b728b9c5fd164b81629a5bb27135590f5 (diff)
downloadwebtools.dali-051e01c88041fe899f37ff0db52a2ae6336fe553.tar.gz
webtools.dali-051e01c88041fe899f37ff0db52a2ae6336fe553.tar.xz
webtools.dali-051e01c88041fe899f37ff0db52a2ae6336fe553.zip
eclipselink java resource model support for @ReadTransformer @WriteTransformer
Diffstat (limited to 'jpa')
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ColumnImpl.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaAnnotationProvider.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/NullWriteTransformerColumn.java81
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/ReadTransformerImpl.java152
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/WriteTransformerImpl.java220
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/EclipseLinkJPA.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/ReadTransformerAnnotation.java30
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/TransformerAnnotation.java72
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/WriteTransformerAnnotation.java65
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java2
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ReadTransformerAnnotationTests.java157
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/WriteTransformerAnnotationTests.java241
12 files changed, 1037 insertions, 1 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ColumnImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ColumnImpl.java
index b4f56ed5ab..15c5696645 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ColumnImpl.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ColumnImpl.java
@@ -51,7 +51,7 @@ public class ColumnImpl extends BaseColumnImpl implements ColumnAnnotation, Nest
private Integer scale;
- protected ColumnImpl(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa) {
+ public ColumnImpl(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa) {
super(parent, member, daa);
this.lengthDeclarationAdapter = this.buildIntegerElementAdapter(JPA.COLUMN__LENGTH);
this.lengthAdapter = this.buildShortCircuitIntegerElementAdapter(this.lengthDeclarationAdapter);
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaAnnotationProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaAnnotationProvider.java
index 3e9dd0f712..ccbf1ae06a 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaAnnotationProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaAnnotationProvider.java
@@ -16,7 +16,9 @@ import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
import org.eclipse.jpt.eclipselink.core.internal.resource.java.CacheImpl.CacheAnnotationDefinition;
import org.eclipse.jpt.eclipselink.core.internal.resource.java.ExistenceCheckingImpl.ExistenceCheckingAnnotationDefinition;
import org.eclipse.jpt.eclipselink.core.internal.resource.java.MutableImpl.MutableAnnotationDefinition;
+import org.eclipse.jpt.eclipselink.core.internal.resource.java.ReadTransformerImpl.ReadTransformerAnnotationDefinition;
import org.eclipse.jpt.eclipselink.core.internal.resource.java.TransformationImpl.TransformationAnnotationDefinition;
+import org.eclipse.jpt.eclipselink.core.internal.resource.java.WriteTransformerImpl.WriteTransformerAnnotationDefinition;
public class EclipseLinkJpaAnnotationProvider
extends GenericJpaAnnotationProvider
@@ -40,6 +42,8 @@ public class EclipseLinkJpaAnnotationProvider
protected void addAttributeAnnotationDefinitionsTo(Collection<AnnotationDefinition> definitions) {
super.addAttributeAnnotationDefinitionsTo(definitions);
definitions.add(MutableAnnotationDefinition.instance());
+ definitions.add(ReadTransformerAnnotationDefinition.instance());
+ definitions.add(WriteTransformerAnnotationDefinition.instance());
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/NullWriteTransformerColumn.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/NullWriteTransformerColumn.java
new file mode 100644
index 0000000000..3eac83654c
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/NullWriteTransformerColumn.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.eclipselink.core.internal.resource.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.NullBaseColumn;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.resource.java.ColumnAnnotation;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.eclipselink.core.resource.java.WriteTransformerAnnotation;
+
+
+public class NullWriteTransformerColumn extends NullBaseColumn implements ColumnAnnotation, Annotation
+{
+ public NullWriteTransformerColumn(WriteTransformerAnnotation parent) {
+ super(parent);
+ }
+
+ @Override
+ public WriteTransformerAnnotation getParent() {
+ return (WriteTransformerAnnotation) super.getParent();
+ }
+
+ public String getAnnotationName() {
+ return ColumnAnnotation.ANNOTATION_NAME;
+ }
+
+ @Override
+ protected ColumnAnnotation createColumnResource() {
+ return getParent().addColumn();
+ }
+
+ public Integer getLength() {
+ return null;
+ }
+
+ public void setLength(Integer length) {
+ if (length != null) {
+ createColumnResource().setLength(length);
+ }
+ }
+
+ public Integer getScale() {
+ return null;
+ }
+
+ public void setScale(Integer scale) {
+ if (scale != null) {
+ createColumnResource().setScale(scale);
+ }
+ }
+
+ public Integer getPrecision() {
+ return null;
+ }
+
+ public void setPrecision(Integer precision) {
+ if (precision != null) {
+ createColumnResource().setPrecision(precision);
+ }
+ }
+
+ public TextRange getScaleTextRange(CompilationUnit astRoot) {
+ return null;
+ }
+
+ public TextRange getLengthTextRange(CompilationUnit astRoot) {
+ return null;
+ }
+
+ public TextRange getPrecisionTextRange(CompilationUnit astRoot) {
+ return null;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/ReadTransformerImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/ReadTransformerImpl.java
new file mode 100644
index 0000000000..a83ee96568
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/ReadTransformerImpl.java
@@ -0,0 +1,152 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.eclipselink.core.internal.resource.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.AbstractResourceAnnotation;
+import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleTypeStringExpressionConverter;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.Attribute;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.Member;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA;
+import org.eclipse.jpt.eclipselink.core.resource.java.ReadTransformerAnnotation;
+
+
+public class ReadTransformerImpl extends AbstractResourceAnnotation<Attribute> implements ReadTransformerAnnotation
+{
+ private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+
+ private final AnnotationElementAdapter<String> transformerClassAdapter;
+ private final AnnotationElementAdapter<String> methodAdapter;
+
+ private static final DeclarationAnnotationElementAdapter<String> TRANSFORMER_CLASS_ADAPTER = buildTransformerClassAdapter();
+ private static final DeclarationAnnotationElementAdapter<String> METHOD_ADAPTER = buildMethodAdapter();
+
+
+ private String transformerClass;
+ private String method;
+
+ protected ReadTransformerImpl(JavaResourcePersistentAttribute parent, Attribute attribute) {
+ super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER);
+ this.transformerClassAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, TRANSFORMER_CLASS_ADAPTER);
+ this.methodAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, METHOD_ADAPTER);
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ this.transformerClass = this.transformerClass(astRoot);
+ this.method = this.method(astRoot);
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ //*************** ReadTransformer implementation ****************
+ public String getTransformerClass() {
+ return this.transformerClass;
+ }
+
+ public void setTransformerClass(String newTransformerClass) {
+ if (attributeValueHasNotChanged(this.transformerClass, newTransformerClass)) {
+ return;
+ }
+ String oldTransformerClass = this.transformerClass;
+ this.transformerClass = newTransformerClass;
+ this.transformerClassAdapter.setValue(newTransformerClass);
+ firePropertyChanged(TRANSFORMER_CLASS_PROPERTY, oldTransformerClass, newTransformerClass);
+ }
+
+ public String getMethod() {
+ return this.method;
+ }
+
+ public void setMethod(String newMethod) {
+ if (attributeValueHasNotChanged(this.method, newMethod)) {
+ return;
+ }
+ String oldMethod = this.method;
+ this.method = newMethod;
+ this.methodAdapter.setValue(newMethod);
+ firePropertyChanged(METHOD_PROPERTY, oldMethod, newMethod);
+ }
+
+ public TextRange getTransformerClassTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(TRANSFORMER_CLASS_ADAPTER, astRoot);
+ }
+
+ public TextRange getMethodTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(METHOD_ADAPTER, astRoot);
+ }
+
+ public void update(CompilationUnit astRoot) {
+ this.setTransformerClass(this.transformerClass(astRoot));
+ this.setMethod(this.method(astRoot));
+ }
+
+ protected String transformerClass(CompilationUnit astRoot) {
+ return this.transformerClassAdapter.getValue(astRoot);
+ }
+
+ protected String method(CompilationUnit astRoot) {
+ return this.methodAdapter.getValue(astRoot);
+ }
+
+ // ********** static methods **********
+ private static DeclarationAnnotationElementAdapter<String> buildTransformerClassAdapter() {
+ return new ConversionDeclarationAnnotationElementAdapter<String>(DECLARATION_ANNOTATION_ADAPTER, EclipseLinkJPA.READ_TRANSFORMER__TRANSFORMER_CLASS, false, SimpleTypeStringExpressionConverter.instance());
+ }
+
+ private static DeclarationAnnotationElementAdapter<String> buildMethodAdapter() {
+ return ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, EclipseLinkJPA.READ_TRANSFORMER__METHOD, false);
+ }
+
+ public static class ReadTransformerAnnotationDefinition implements AnnotationDefinition
+ {
+ // singleton
+ private static final ReadTransformerAnnotationDefinition INSTANCE = new ReadTransformerAnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static ReadTransformerAnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure non-instantiability.
+ */
+ private ReadTransformerAnnotationDefinition() {
+ super();
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) {
+ return new ReadTransformerImpl((JavaResourcePersistentAttribute) parent, (Attribute) member);
+ }
+
+ public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) {
+ return null;
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/WriteTransformerImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/WriteTransformerImpl.java
new file mode 100644
index 0000000000..95c3c7cb88
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/WriteTransformerImpl.java
@@ -0,0 +1,220 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.eclipselink.core.internal.resource.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.AbstractResourceAnnotation;
+import org.eclipse.jpt.core.internal.resource.java.ColumnImpl;
+import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.NestedDeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleTypeStringExpressionConverter;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.core.resource.java.ColumnAnnotation;
+import org.eclipse.jpt.core.resource.java.JPA;
+import org.eclipse.jpt.core.resource.java.JavaResourceNode;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.Attribute;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.Member;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA;
+import org.eclipse.jpt.eclipselink.core.resource.java.WriteTransformerAnnotation;
+
+
+public class WriteTransformerImpl extends AbstractResourceAnnotation<Attribute> implements WriteTransformerAnnotation
+{
+ private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+
+ private final AnnotationElementAdapter<String> transformerClassAdapter;
+ private final AnnotationElementAdapter<String> methodAdapter;
+ private final MemberAnnotationAdapter columnAdapter;
+
+ private static final DeclarationAnnotationElementAdapter<String> TRANSFORMER_CLASS_ADAPTER = buildTransformerClassAdapter();
+ private static final DeclarationAnnotationElementAdapter<String> METHOD_ADAPTER = buildMethodAdapter();
+
+ private String transformerClass;
+ private String method;
+ private ColumnImpl column;
+
+
+ protected WriteTransformerImpl(JavaResourcePersistentAttribute parent, Attribute attribute) {
+ super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER);
+ this.transformerClassAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, TRANSFORMER_CLASS_ADAPTER);
+ this.methodAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, METHOD_ADAPTER);
+ this.columnAdapter = new MemberAnnotationAdapter(getMember(), buildColumnAnnotationAdapter(getDeclarationAnnotationAdapter()));
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ this.transformerClass = this.transformerClass(astRoot);
+ this.method = this.method(astRoot);
+ if (this.columnAdapter.getAnnotation(astRoot) != null) {
+ this.column = createColumn(this, getMember(), getDeclarationAnnotationAdapter());
+ this.column.initialize(astRoot);
+ }
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ //*************** WriteTransformer implementation ****************
+ public String getTransformerClass() {
+ return this.transformerClass;
+ }
+
+ public void setTransformerClass(String newTransformerClass) {
+ if (attributeValueHasNotChanged(this.transformerClass, newTransformerClass)) {
+ return;
+ }
+ String oldTransformerClass = this.transformerClass;
+ this.transformerClass = newTransformerClass;
+ this.transformerClassAdapter.setValue(newTransformerClass);
+ firePropertyChanged(TRANSFORMER_CLASS_PROPERTY, oldTransformerClass, newTransformerClass);
+ }
+
+ public String getMethod() {
+ return this.method;
+ }
+
+ public void setMethod(String newMethod) {
+ if (attributeValueHasNotChanged(this.method, newMethod)) {
+ return;
+ }
+ String oldMethod = this.method;
+ this.method = newMethod;
+ this.methodAdapter.setValue(newMethod);
+ firePropertyChanged(METHOD_PROPERTY, oldMethod, newMethod);
+ }
+
+ public ColumnAnnotation getNonNullColumn() {
+ return (getColumn() != null) ? getColumn() : new NullWriteTransformerColumn(this);
+ }
+
+ public ColumnAnnotation getColumn() {
+ return this.column;
+ }
+
+ public ColumnAnnotation addColumn() {
+ ColumnImpl column = createColumn(this, getMember(), getDeclarationAnnotationAdapter());
+ column.newAnnotation();
+ setColumn(column);
+ return column;
+ }
+
+ public void removeColumn() {
+ this.column.removeAnnotation();
+ setColumn(null);
+ }
+
+ protected void setColumn(ColumnImpl newColumn) {
+ ColumnImpl oldColumn = this.column;
+ this.column = newColumn;
+ firePropertyChanged(WriteTransformerAnnotation.COLUMN_PROPERTY, oldColumn, newColumn);
+ }
+
+
+ public TextRange getTransformerClassTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(TRANSFORMER_CLASS_ADAPTER, astRoot);
+ }
+
+ public TextRange getMethodTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(METHOD_ADAPTER, astRoot);
+ }
+
+ public TextRange getColumnTextRange(CompilationUnit astRoot) {
+ if (this.column != null) {
+ return this.column.getTextRange(astRoot);
+ }
+ return getTextRange(astRoot);
+ }
+
+ public void update(CompilationUnit astRoot) {
+ this.setTransformerClass(this.transformerClass(astRoot));
+ this.setMethod(this.method(astRoot));
+ if (this.columnAdapter.getAnnotation(astRoot) == null) {
+ this.setColumn(null);
+ }
+ else {
+ if (getColumn() != null) {
+ getColumn().update(astRoot);
+ }
+ else {
+ ColumnImpl column = createColumn(this, getMember(), getDeclarationAnnotationAdapter());
+ column.initialize(astRoot);
+ this.setColumn(column);
+ }
+ }
+ }
+
+ protected String transformerClass(CompilationUnit astRoot) {
+ return this.transformerClassAdapter.getValue(astRoot);
+ }
+
+ protected String method(CompilationUnit astRoot) {
+ return this.methodAdapter.getValue(astRoot);
+ }
+
+ // ********** static methods **********
+ private static DeclarationAnnotationElementAdapter<String> buildTransformerClassAdapter() {
+ return new ConversionDeclarationAnnotationElementAdapter<String>(DECLARATION_ANNOTATION_ADAPTER, EclipseLinkJPA.WRITE_TRANSFORMER__TRANSFORMER_CLASS, false, SimpleTypeStringExpressionConverter.instance());
+ }
+
+ private static DeclarationAnnotationElementAdapter<String> buildMethodAdapter() {
+ return ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, EclipseLinkJPA.WRITE_TRANSFORMER__METHOD, false);
+ }
+
+ private static DeclarationAnnotationAdapter buildColumnAnnotationAdapter(DeclarationAnnotationAdapter writeTransformerAnnotationAdapter) {
+ return new NestedDeclarationAnnotationAdapter(writeTransformerAnnotationAdapter, EclipseLinkJPA.WRITE_TRANSFORMER__COLUMN, JPA.COLUMN, false);
+ }
+
+ private static ColumnImpl createColumn(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter writeTransformerAnnotationAdapter) {
+ return new ColumnImpl(parent, member, buildColumnAnnotationAdapter(writeTransformerAnnotationAdapter));
+ }
+
+ public static class WriteTransformerAnnotationDefinition implements AnnotationDefinition
+ {
+ // singleton
+ private static final WriteTransformerAnnotationDefinition INSTANCE = new WriteTransformerAnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static WriteTransformerAnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure non-instantiability.
+ */
+ private WriteTransformerAnnotationDefinition() {
+ super();
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) {
+ return new WriteTransformerImpl((JavaResourcePersistentAttribute) parent, (Attribute) member);
+ }
+
+ public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) {
+ return null;
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/EclipseLinkJPA.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/EclipseLinkJPA.java
index fb4d91eaec..985c7a7fe8 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/EclipseLinkJPA.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/EclipseLinkJPA.java
@@ -73,6 +73,10 @@ public interface EclipseLinkJPA {
String MUTABLE = PACKAGE_ + "Mutable";
String MUTABLE__VALUE = "value";
+ String READ_TRANSFORMER = PACKAGE_ + "ReadTransformer";
+ String READ_TRANSFORMER__TRANSFORMER_CLASS = "transformerClass";
+ String READ_TRANSFORMER__METHOD = "method";
+
String TIME_OF_DAY = PACKAGE_ + "TimeOfDay";
String TIME_OF_DAY__HOUR = "hour";
String TIME_OF_DAY__MINUTE = "minute";
@@ -83,4 +87,12 @@ public interface EclipseLinkJPA {
String TRANSFORMATION__FETCH = "fetch";
String TRANSFORMATION__OPTIONAL = "optional";
+ String WRITE_TRANSFORMER = PACKAGE_ + "WriteTransformer";
+ String WRITE_TRANSFORMER__TRANSFORMER_CLASS = "transformerClass";
+ String WRITE_TRANSFORMER__METHOD = "method";
+ String WRITE_TRANSFORMER__COLUMN = "column";
+
+ String WRITE_TRANSFORMERS = PACKAGE_ + "WriteTransformers";
+ String WRITE_TRANSFORMERS__VALUE = "value";
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/ReadTransformerAnnotation.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/ReadTransformerAnnotation.java
new file mode 100644
index 0000000000..900198ef6b
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/ReadTransformerAnnotation.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.eclipselink.core.resource.java;
+
+/**
+ * Java resource model interface that corresponds to the Eclipselink
+ * annotation org.eclipse.persistence.annotations.ReadTransformer
+ *
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @version 2.1
+ * @since 2.1
+ */
+public interface ReadTransformerAnnotation extends TransformerAnnotation
+{
+
+ String ANNOTATION_NAME = EclipseLinkJPA.READ_TRANSFORMER;
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/TransformerAnnotation.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/TransformerAnnotation.java
new file mode 100644
index 0000000000..0ccefdc582
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/TransformerAnnotation.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.eclipselink.core.resource.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.resource.java.JavaResourceNode;
+import org.eclipse.jpt.core.utility.TextRange;
+
+/**
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @version 2.1
+ * @since 2.1
+ */
+public interface TransformerAnnotation extends JavaResourceNode
+{
+
+ /**
+ * Corresponds to the transformerClass element of the *Transformer annotation.
+ * Returns null if the transformerClass element does not exist in java.
+ * Returns the portion of the transformerClass preceding the .class.
+ * <p>
+ * &#64;ReadTransformer(transformerClass=Employee.class)
+ * </p>
+ * will return "Employee"
+ **/
+ String getTransformerClass();
+
+ /**
+ * Corresponds to the transformerClass element of the *Transformer annotation.
+ * Set to null to remove the transformerClass element.
+ */
+ void setTransformerClass(String transformerClass);
+ String TRANSFORMER_CLASS_PROPERTY = "transformerClassProperty";
+
+ /**
+ * Corresponds to the method element of the *Transformer annotation.
+ * Returns null if the method element does not exist in java.
+ **/
+ String getMethod();
+
+ /**
+ * Corresponds to the method element of the *Transformer annotation.
+ * Set to null to remove the method element.
+ */
+ void setMethod(String method);
+ String METHOD_PROPERTY = "methodProperty";
+
+ /**
+ * Return the {@link TextRange} for the transformerClass element. If the transformerClass element
+ * does not exist return the {@link TextRange} for the *Transformer annotation.
+ */
+ TextRange getTransformerClassTextRange(CompilationUnit astRoot);
+
+ /**
+ * Return the {@link TextRange} for the method element. If the method element
+ * does not exist return the {@link TextRange} for the *Transformer annotation.
+ */
+ TextRange getMethodTextRange(CompilationUnit astRoot);
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/WriteTransformerAnnotation.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/WriteTransformerAnnotation.java
new file mode 100644
index 0000000000..1244967e91
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/WriteTransformerAnnotation.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.eclipselink.core.resource.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.resource.java.ColumnAnnotation;
+import org.eclipse.jpt.core.utility.TextRange;
+
+/**
+ * Java resource model interface that corresponds to the Eclipselink
+ * annotation org.eclipse.persistence.annotations.WriteTransformer
+ *
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @version 2.1
+ * @since 2.1
+ */
+public interface WriteTransformerAnnotation extends TransformerAnnotation
+{
+
+ String ANNOTATION_NAME = EclipseLinkJPA.WRITE_TRANSFORMER;
+
+ /**
+ * Corresponds to the column element of the WriteTransformer annotation.
+ * Returns null if the column element does not exist in java.
+ */
+ ColumnAnnotation getColumn();
+
+ /**
+ * Add the column element to the WriteTransformer annotation.
+ */
+ ColumnAnnotation addColumn();
+
+ /**
+ * Remove the column element from the WriteTransformer annotation.
+ */
+ void removeColumn();
+
+ /**
+ * Return a ColumnAnnotation, but do not return null if the column
+ * element does not exist on the WriteTransformer annotation. Instead
+ * return a null object.
+ */
+ ColumnAnnotation getNonNullColumn();
+
+ String COLUMN_PROPERTY = "columnProperty";
+
+ /**
+ * Return the {@link TextRange} for the column element. If the column element
+ * does not exist return the {@link TextRange} for the WriteTransformer annotation.
+ */
+ TextRange getColumnTextRange(CompilationUnit astRoot);
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java
index 55146fe111..eddfef97e6 100644
--- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java
@@ -24,8 +24,10 @@ public class JptEclipseLinkCoreJavaResourceModelTests {
suite.addTestSuite(CacheTests.class);
suite.addTestSuite(ExistenceCheckingTests.class);
suite.addTestSuite(MutableAnnotationTests.class);
+ suite.addTestSuite(ReadTransformerAnnotationTests.class);
suite.addTestSuite(TimeOfDayTests.class);
suite.addTestSuite(TransformationAnnotationTests.class);
+ suite.addTestSuite(WriteTransformerAnnotationTests.class);
return suite;
}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ReadTransformerAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ReadTransformerAnnotationTests.java
new file mode 100644
index 0000000000..0c627df76c
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ReadTransformerAnnotationTests.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java;
+
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA;
+import org.eclipse.jpt.eclipselink.core.resource.java.ReadTransformerAnnotation;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
+
+public class ReadTransformerAnnotationTests extends EclipseLinkJavaResourceModelTestCase {
+
+ public ReadTransformerAnnotationTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTestReadTransformer() throws Exception {
+ this.createAnnotationAndMembers("ReadTransformer", "Class transformerClass() default void.class; String method() default \"\"");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.READ_TRANSFORMER);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@ReadTransformer");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestReadTransformerWithTransformerClass() throws Exception {
+ this.createAnnotationAndMembers("ReadTransformer", "Class transformerClass() default void.class; String method() default \"\"");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.READ_TRANSFORMER);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@ReadTransformer(transformerClass=Foo.class)");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestReadTransformerWithMethod() throws Exception {
+ this.createAnnotationAndMembers("ReadTransformer", "Class transformerClass() default void.class; String method() default \"\"");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.READ_TRANSFORMER);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@ReadTransformer(method=\"transformerMethod\")");
+ }
+ });
+ }
+
+ public void testReadTransformerAnnotation() throws Exception {
+ ICompilationUnit cu = this.createTestReadTransformer();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER));
+
+ attributeResource.removeAnnotation(EclipseLinkJPA.READ_TRANSFORMER) ;
+ assertNull(attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER));
+
+ attributeResource.addAnnotation(EclipseLinkJPA.READ_TRANSFORMER);
+ assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER));
+ }
+
+ public void testGetTransformerClass() throws Exception {
+ ICompilationUnit cu = this.createTestReadTransformerWithTransformerClass();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ ReadTransformerAnnotation readTransformer = (ReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER);
+ assertEquals("Foo", readTransformer.getTransformerClass());
+ }
+
+ public void testSetTransformerClass() throws Exception {
+ ICompilationUnit cu = this.createTestReadTransformerWithTransformerClass();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ ReadTransformerAnnotation readTransformer = (ReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER);
+ assertEquals("Foo", readTransformer.getTransformerClass());
+
+ readTransformer.setTransformerClass("Bar");
+ assertEquals("Bar", readTransformer.getTransformerClass());
+
+ assertSourceContains("@ReadTransformer(transformerClass=Bar.class)", cu);
+ }
+
+ public void testSetTransformerClassNull() throws Exception {
+ ICompilationUnit cu = this.createTestReadTransformerWithTransformerClass();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ ReadTransformerAnnotation readTransformer = (ReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER);
+ assertEquals("Foo", readTransformer.getTransformerClass());
+
+ readTransformer.setTransformerClass(null);
+ assertNull(readTransformer.getTransformerClass());
+
+ assertSourceContains("@ReadTransformer", cu);
+ assertSourceDoesNotContain("transformerClass", cu);
+ }
+
+ public void testGetMethod() throws Exception {
+ ICompilationUnit cu = this.createTestReadTransformerWithMethod();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ ReadTransformerAnnotation readTransformer = (ReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER);
+ assertEquals("transformerMethod", readTransformer.getMethod());
+ }
+
+ public void testSetMethod() throws Exception {
+ ICompilationUnit cu = this.createTestReadTransformerWithMethod();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ ReadTransformerAnnotation readTransformer = (ReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER);
+ assertEquals("transformerMethod", readTransformer.getMethod());
+
+ readTransformer.setMethod("foo");
+ assertEquals("foo", readTransformer.getMethod());
+
+ assertSourceContains("@ReadTransformer(method=\"foo\")", cu);
+ }
+
+ public void testSetMethodNull() throws Exception {
+ ICompilationUnit cu = this.createTestReadTransformerWithMethod();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ ReadTransformerAnnotation readTransformer = (ReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.READ_TRANSFORMER);
+ assertEquals("transformerMethod", readTransformer.getMethod());
+
+ readTransformer.setMethod(null);
+ assertNull(readTransformer.getMethod());
+
+ assertSourceContains("@ReadTransformer", cu);
+ assertSourceDoesNotContain("method", cu);
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/WriteTransformerAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/WriteTransformerAnnotationTests.java
new file mode 100644
index 0000000000..1d2fcea9de
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/WriteTransformerAnnotationTests.java
@@ -0,0 +1,241 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java;
+
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.core.resource.java.JPA;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA;
+import org.eclipse.jpt.eclipselink.core.resource.java.WriteTransformerAnnotation;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
+
+public class WriteTransformerAnnotationTests extends EclipseLinkJavaResourceModelTestCase {
+
+ public WriteTransformerAnnotationTests(String name) {
+ super(name);
+ }
+
+ private void createWriteTransformerAnnotation() throws Exception {
+ this.createAnnotationAndMembers("WriteTransformer", "Class transformerClass() default void.class; String method() default \"\";Column column() default @Column");
+ this.createColumnAnnotation();
+ }
+
+ private void createColumnAnnotation() throws Exception {
+ this.createAnnotationAndMembers(JPA.PACKAGE, "Column",
+ "String name() default \"\"; " +
+ "boolean unique() default false; " +
+ "boolean nullable() default true; " +
+ "boolean insertable() default true; " +
+ "boolean updatable() default true; " +
+ "String columnDefinition() default \"\"; " +
+ "String table() default \"\"; " +
+ "int length() default 255; " +
+ "int precision() default 0; " +
+ "int scale() default 0;");
+ }
+
+ private ICompilationUnit createTestWriteTransformer() throws Exception {
+ createWriteTransformerAnnotation();
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.WRITE_TRANSFORMER);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@WriteTransformer");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestWriteTransformerWithTransformerClass() throws Exception {
+ createWriteTransformerAnnotation();
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.WRITE_TRANSFORMER);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@WriteTransformer(transformerClass=Foo.class)");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestWriteTransformerWithMethod() throws Exception {
+ createWriteTransformerAnnotation();
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.WRITE_TRANSFORMER);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@WriteTransformer(method=\"transformerMethod\")");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestWriteTransformerWithColumn() throws Exception {
+ createWriteTransformerAnnotation();
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.WRITE_TRANSFORMER, JPA.COLUMN);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@WriteTransformer(column=@Column(name=\"FOO\"))");
+ }
+ });
+ }
+
+
+ public void testWriteTransformerAnnotation() throws Exception {
+ ICompilationUnit cu = this.createTestWriteTransformer();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER));
+
+ attributeResource.removeAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER) ;
+ assertNull(attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER));
+
+ attributeResource.addAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER);
+ assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER));
+ }
+
+ public void testGetTransformerClass() throws Exception {
+ ICompilationUnit cu = this.createTestWriteTransformerWithTransformerClass();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER);
+ assertEquals("Foo", writeTransformer.getTransformerClass());
+ }
+
+ public void testSetTransformerClass() throws Exception {
+ ICompilationUnit cu = this.createTestWriteTransformerWithTransformerClass();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER);
+ assertEquals("Foo", writeTransformer.getTransformerClass());
+
+ writeTransformer.setTransformerClass("Bar");
+ assertEquals("Bar", writeTransformer.getTransformerClass());
+
+ assertSourceContains("@WriteTransformer(transformerClass=Bar.class)", cu);
+ }
+
+ public void testSetTransformerClassNull() throws Exception {
+ ICompilationUnit cu = this.createTestWriteTransformerWithTransformerClass();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER);
+ assertEquals("Foo", writeTransformer.getTransformerClass());
+
+ writeTransformer.setTransformerClass(null);
+ assertNull(writeTransformer.getTransformerClass());
+
+ assertSourceContains("@WriteTransformer", cu);
+ assertSourceDoesNotContain("transformerClass", cu);
+ }
+
+ public void testGetMethod() throws Exception {
+ ICompilationUnit cu = this.createTestWriteTransformerWithMethod();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER);
+ assertEquals("transformerMethod", writeTransformer.getMethod());
+ }
+
+ public void testSetMethod() throws Exception {
+ ICompilationUnit cu = this.createTestWriteTransformerWithMethod();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER);
+ assertEquals("transformerMethod", writeTransformer.getMethod());
+
+ writeTransformer.setMethod("foo");
+ assertEquals("foo", writeTransformer.getMethod());
+
+ assertSourceContains("@WriteTransformer(method=\"foo\")", cu);
+ }
+
+ public void testSetMethodNull() throws Exception {
+ ICompilationUnit cu = this.createTestWriteTransformerWithMethod();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER);
+ assertEquals("transformerMethod", writeTransformer.getMethod());
+
+ writeTransformer.setMethod(null);
+ assertNull(writeTransformer.getMethod());
+
+ assertSourceContains("@WriteTransformer", cu);
+ assertSourceDoesNotContain("method", cu);
+ }
+
+
+ public void testGetColumn() throws Exception {
+ ICompilationUnit cu = this.createTestWriteTransformerWithColumn();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER);
+ assertNotNull(writeTransformer.getColumn());
+ assertEquals("FOO", writeTransformer.getColumn().getName());
+ }
+
+ public void testAddColumn() throws Exception {
+ ICompilationUnit cu = this.createTestWriteTransformerWithMethod();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER);
+ assertNull(writeTransformer.getColumn());
+
+ writeTransformer.addColumn();
+
+ assertNotNull(writeTransformer.getColumn());
+ assertSourceContains("@WriteTransformer(method=\"transformerMethod\", column = @Column)", cu);
+
+ writeTransformer.getColumn().setName("BAR");
+ assertSourceContains("@WriteTransformer(method=\"transformerMethod\", column = @Column(name=\"BAR\"))", cu);
+
+ }
+
+ public void testRemoveColumn() throws Exception {
+ ICompilationUnit cu = this.createTestWriteTransformerWithColumn();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ WriteTransformerAnnotation writeTransformer = (WriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.WRITE_TRANSFORMER);
+ assertNotNull(writeTransformer.getColumn());
+ assertEquals("FOO", writeTransformer.getColumn().getName());
+
+ writeTransformer.removeColumn();
+ assertNull(writeTransformer.getColumn());
+
+ assertSourceContains("@WriteTransformer", cu);
+ assertSourceDoesNotContain("column", cu);
+ }
+
+ public void getNonNullColumn() throws Exception {
+
+ }
+}

Back to the top