Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa
diff options
context:
space:
mode:
authorkmoore2008-09-02 17:55:15 +0000
committerkmoore2008-09-02 17:55:15 +0000
commit16880849ffe8982e8a5828c9679638654ede8a34 (patch)
tree4ce1448cba3274bfc6081f7303a3088e7d1b2a44 /jpa
parent8a3b04dfaab2067cbeafe6dc2debf81ba102c357 (diff)
downloadwebtools.dali-16880849ffe8982e8a5828c9679638654ede8a34.tar.gz
webtools.dali-16880849ffe8982e8a5828c9679638654ede8a34.tar.xz
webtools.dali-16880849ffe8982e8a5828c9679638654ede8a34.zip
java resource model support for @Transformation
Diffstat (limited to 'jpa')
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaAnnotationProvider.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/NullTransformation.java93
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/TransformationImpl.java156
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/EclipseLinkJPA.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/TransformationAnnotation.java73
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java3
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TransformationAnnotationTests.java160
7 files changed, 496 insertions, 1 deletions
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 052d91faed..2e5826bb0b 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
@@ -10,10 +10,12 @@
package org.eclipse.jpt.eclipselink.core.internal;
import java.util.Collection;
+import java.util.List;
import org.eclipse.jpt.core.internal.platform.GenericJpaAnnotationProvider;
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.TransformationImpl.TransformationAnnotationDefinition;
public class EclipseLinkJpaAnnotationProvider
extends GenericJpaAnnotationProvider
@@ -26,4 +28,10 @@ public class EclipseLinkJpaAnnotationProvider
definitions.add(ExistenceCheckingAnnotationDefinition.instance());
}
+ @Override
+ //bug 245996 addresses how the attribute mapping annotations should be ordered
+ protected void addAttributeMappingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) {
+ super.addAttributeMappingAnnotationDefinitionsTo(definitions);
+ definitions.add(TransformationAnnotationDefinition.instance());
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/NullTransformation.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/NullTransformation.java
new file mode 100644
index 0000000000..cd04bf925d
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/NullTransformation.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * 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.AbstractJavaResourceNode;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.resource.java.BasicAnnotation;
+import org.eclipse.jpt.core.resource.java.FetchType;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.eclipselink.core.resource.java.TransformationAnnotation;
+
+
+public class NullTransformation extends AbstractJavaResourceNode implements BasicAnnotation, Annotation
+{
+ protected NullTransformation(JavaResourcePersistentMember parent) {
+ super(parent);
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ //null, nothing to initialize
+ }
+
+ public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) {
+ return null;
+ }
+
+ public void newAnnotation() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeAnnotation() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getAnnotationName() {
+ return TransformationAnnotation.ANNOTATION_NAME;
+ }
+
+ @Override
+ public JavaResourcePersistentMember getParent() {
+ return (JavaResourcePersistentMember) super.getParent();
+ }
+
+ protected TransformationAnnotation createTransformationResource() {
+ getParent().setMappingAnnotation(getAnnotationName());
+ return (TransformationAnnotation) getParent().getMappingAnnotation();
+ }
+
+ public FetchType getFetch() {
+ return null;
+ }
+
+ public void setFetch(FetchType fetch) {
+ if (fetch != null) {
+ createTransformationResource().setFetch(fetch);
+ }
+ }
+
+ public Boolean getOptional() {
+ return null;
+ }
+
+ public void setOptional(Boolean optional) {
+ if (optional != null) {
+ createTransformationResource().setOptional(optional);
+ }
+ }
+
+ public void update(CompilationUnit astRoot) {
+ throw new UnsupportedOperationException();
+ }
+
+ public TextRange getTextRange(CompilationUnit astRoot) {
+ return null;
+ }
+
+ public TextRange getFetchTextRange(CompilationUnit astRoot) {
+ return null;
+ }
+
+ public TextRange getOptionalTextRange(CompilationUnit astRoot) {
+ return null;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/TransformationImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/TransformationImpl.java
new file mode 100644
index 0000000000..cb96db3456
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/TransformationImpl.java
@@ -0,0 +1,156 @@
+/*******************************************************************************
+ * 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.BooleanExpressionConverter;
+import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.EnumDeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.core.resource.java.FetchType;
+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.TransformationAnnotation;
+
+
+public class TransformationImpl extends AbstractResourceAnnotation<Attribute> implements TransformationAnnotation
+{
+ private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+
+ private final AnnotationElementAdapter<Boolean> optionalAdapter;
+
+ private final AnnotationElementAdapter<String> fetchAdapter;
+
+ private static final DeclarationAnnotationElementAdapter<Boolean> OPTIONAL_ADAPTER = buildOptionalAdapter();
+
+ private static final DeclarationAnnotationElementAdapter<String> FETCH_ADAPTER = buildFetchAdapter();
+
+ private Boolean optional;
+
+ private FetchType fetch;
+
+ protected TransformationImpl(JavaResourcePersistentAttribute parent, Attribute attribute) {
+ super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER);
+ this.optionalAdapter = new ShortCircuitAnnotationElementAdapter<Boolean>(attribute, OPTIONAL_ADAPTER);
+ this.fetchAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, FETCH_ADAPTER);
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ this.optional = this.optional(astRoot);
+ this.fetch = this.fetch(astRoot);
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ //*************** Basic implementation ****************
+ public Boolean getOptional() {
+ return this.optional;
+ }
+
+ public void setOptional(Boolean newOptional) {
+ if (attributeValueHasNotChanged(this.optional, newOptional)) {
+ return;
+ }
+ Boolean oldOptional = this.optional;
+ this.optional = newOptional;
+ this.optionalAdapter.setValue(newOptional);
+ firePropertyChanged(OPTIONAL_PROPERTY, oldOptional, newOptional);
+ }
+
+ public FetchType getFetch() {
+ return this.fetch;
+ }
+
+ public void setFetch(FetchType newFetch) {
+ if (attributeValueHasNotChanged(this.fetch, newFetch)) {
+ return;
+ }
+ FetchType oldFetch = this.fetch;
+ this.fetch = newFetch;
+ this.fetchAdapter.setValue(FetchType.toJavaAnnotationValue(newFetch));
+ firePropertyChanged(FETCH_PROPERTY, oldFetch, newFetch);
+ }
+
+ public TextRange getFetchTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(FETCH_ADAPTER, astRoot);
+ }
+
+ public TextRange getOptionalTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(OPTIONAL_ADAPTER, astRoot);
+ }
+
+ public void update(CompilationUnit astRoot) {
+ this.setOptional(this.optional(astRoot));
+ this.setFetch(this.fetch(astRoot));
+ }
+
+ protected FetchType fetch(CompilationUnit astRoot) {
+ return FetchType.fromJavaAnnotationValue(this.fetchAdapter.getValue(astRoot));
+ }
+
+ protected Boolean optional(CompilationUnit astRoot) {
+ return this.optionalAdapter.getValue(astRoot);
+ }
+
+ // ********** static methods **********
+ private static DeclarationAnnotationElementAdapter<Boolean> buildOptionalAdapter() {
+ return new ConversionDeclarationAnnotationElementAdapter<Boolean>(DECLARATION_ANNOTATION_ADAPTER, EclipseLinkJPA.TRANSFORMATION__OPTIONAL, false, BooleanExpressionConverter.instance());
+ }
+
+ private static DeclarationAnnotationElementAdapter<String> buildFetchAdapter() {
+ return new EnumDeclarationAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, EclipseLinkJPA.TRANSFORMATION__FETCH, false);
+ }
+
+ public static class TransformationAnnotationDefinition implements AnnotationDefinition
+ {
+ // singleton
+ private static final TransformationAnnotationDefinition INSTANCE = new TransformationAnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static TransformationAnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure non-instantiability.
+ */
+ private TransformationAnnotationDefinition() {
+ super();
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) {
+ return new TransformationImpl((JavaResourcePersistentAttribute) parent, (Attribute) member);
+ }
+
+ public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) {
+ return new NullTransformation(parent);
+ }
+
+ 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 4c140d58db..113aab1a67 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
@@ -76,5 +76,9 @@ public interface EclipseLinkJPA {
String TIME_OF_DAY__MINUTE = "minute";
String TIME_OF_DAY__SECOND = "second";
String TIME_OF_DAY__MILLISECOND = "millisecond";
+
+ String TRANSFORMATION = PACKAGE_ + "Transformation";
+ String TRANSFORMATION__FETCH = "fetch";
+ String TRANSFORMATION__OPTIONAL = "optional";
}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/TransformationAnnotation.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/TransformationAnnotation.java
new file mode 100644
index 0000000000..f98d7d80e4
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/TransformationAnnotation.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * 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.FetchType;
+import org.eclipse.jpt.core.resource.java.JavaResourceNode;
+import org.eclipse.jpt.core.utility.TextRange;
+
+/**
+ * Java resource model interface that corresponds to the Eclipselink
+ * annotation org.eclipse.persistence.annotations.Transformation
+ *
+ * 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 TransformationAnnotation extends JavaResourceNode
+{
+
+ String ANNOTATION_NAME = EclipseLinkJPA.TRANSFORMATION;
+
+ /**
+ * Corresponds to the fetch element of the Transformation annotation.
+ * Returns null if the fetch element does not exist in java.
+ */
+ FetchType getFetch();
+
+ /**
+ * Corresponds to the fetch element of the Transformation annotation.
+ * Set to null to remove the fetch element.
+ */
+ void setFetch(FetchType fetch);
+ String FETCH_PROPERTY = "fetchProperty";
+
+ /**
+ * Corresponds to the optional element of the Transformation annotation.
+ * Returns null if the optional element does not exist in java.
+ */
+ Boolean getOptional();
+
+ /**
+ * Corresponds to the optional element of the Transformation annotation.
+ * Set to null to remove the optional element.
+ */
+ void setOptional(Boolean optional);
+ String OPTIONAL_PROPERTY = "optionalProperty";
+
+ /**
+ * Return the {@link TextRange} for the fetch element. If the fetch element
+ * does not exist return the {@link TextRange} for the Transformation annotation.
+ */
+ TextRange getFetchTextRange(CompilationUnit astRoot);
+
+ /**
+ * Return the {@link TextRange} for the optional element. If the optional element
+ * does not exist return the {@link TextRange} for the Transformation annotation.
+ */
+ TextRange getOptionalTextRange(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 8b99628131..85bf4b13be 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,7 +24,8 @@ public class JptEclipseLinkCoreJavaResourceModelTests {
suite.addTestSuite(CacheTests.class);
suite.addTestSuite(ExistenceCheckingTests.class);
suite.addTestSuite(TimeOfDayTests.class);
-
+ suite.addTestSuite(TransformationAnnotationTests.class);
+
return suite;
}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TransformationAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TransformationAnnotationTests.java
new file mode 100644
index 0000000000..eecfa1a2ee
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TransformationAnnotationTests.java
@@ -0,0 +1,160 @@
+/*******************************************************************************
+ * 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.FetchType;
+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.TransformationAnnotation;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
+
+public class TransformationAnnotationTests extends EclipseLinkJavaResourceModelTestCase {
+
+ public TransformationAnnotationTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTestTransformation() throws Exception {
+ this.createAnnotationAndMembers("Transformation", "boolean optional() default true;");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.TRANSFORMATION);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Transformation");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestTransformationWithOptional() throws Exception {
+ this.createAnnotationAndMembers("Transformation", "boolean optional() default true;");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.TRANSFORMATION);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Transformation(optional=true)");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestTransformationWithFetch() throws Exception {
+ this.createAnnotationAndMembers("Transformation", "boolean optional() default true; FetchType fetch() default FetchType.EAGER;");
+ this.createEnumAndMembers(JPA.PACKAGE, "FetchType", "EAGER, LAZY");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.TRANSFORMATION, JPA.FETCH_TYPE);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Transformation(fetch=FetchType.EAGER)");
+ }
+ });
+ }
+
+ public void testTransformationAnnotation() throws Exception {
+ ICompilationUnit cu = this.createTestTransformation();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ assertNotNull(attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION));
+
+ attributeResource.setMappingAnnotation(null);
+ assertNull(attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION));
+
+ attributeResource.setMappingAnnotation(EclipseLinkJPA.TRANSFORMATION);
+ assertNotNull(attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION));
+ }
+
+ public void testGetOptional() throws Exception {
+ ICompilationUnit cu = this.createTestTransformationWithOptional();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ TransformationAnnotation transformation = (TransformationAnnotation) attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION);
+ assertEquals(Boolean.TRUE, transformation.getOptional());
+ }
+
+ public void testSetOptional() throws Exception {
+ ICompilationUnit cu = this.createTestTransformationWithOptional();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ TransformationAnnotation transformation = (TransformationAnnotation) attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION);
+ assertEquals(Boolean.TRUE, transformation.getOptional());
+
+ transformation.setOptional(Boolean.FALSE);
+ assertEquals(Boolean.FALSE, transformation.getOptional());
+
+ assertSourceContains("@Transformation(optional=false)", cu);
+ }
+
+ public void testSetOptionalNull() throws Exception {
+ ICompilationUnit cu = this.createTestTransformationWithOptional();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ TransformationAnnotation transformation = (TransformationAnnotation) attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION);
+ assertEquals(Boolean.TRUE, transformation.getOptional());
+
+ transformation.setOptional(null);
+ assertNull(transformation.getOptional());
+
+ assertSourceContains("@Transformation", cu);
+ assertSourceDoesNotContain("optional", cu);
+ }
+
+ public void testGetFetch() throws Exception {
+ ICompilationUnit cu = this.createTestTransformationWithFetch();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ TransformationAnnotation transformation = (TransformationAnnotation) attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION);
+ assertEquals(FetchType.EAGER, transformation.getFetch());
+ }
+
+ public void testSetFetch() throws Exception {
+ ICompilationUnit cu = this.createTestTransformationWithFetch();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ TransformationAnnotation transformation = (TransformationAnnotation) attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION);
+ assertEquals(FetchType.EAGER, transformation.getFetch());
+
+ transformation.setFetch(FetchType.LAZY);
+ assertEquals(FetchType.LAZY, transformation.getFetch());
+
+ assertSourceContains("@Transformation(fetch=LAZY)", cu);
+ }
+
+ public void testSetFetchNull() throws Exception {
+ ICompilationUnit cu = this.createTestTransformationWithFetch();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ TransformationAnnotation transformation = (TransformationAnnotation) attributeResource.getMappingAnnotation(EclipseLinkJPA.TRANSFORMATION);
+ assertEquals(FetchType.EAGER, transformation.getFetch());
+
+ transformation.setFetch(null);
+ assertNull(transformation.getFetch());
+
+ assertSourceContains("@Transformation", cu);
+ assertSourceDoesNotContain("fetch", cu);
+ }
+}

Back to the top