Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa
diff options
context:
space:
mode:
authorkmoore2008-09-02 18:18:18 +0000
committerkmoore2008-09-02 18:18:18 +0000
commitc4f2ff4e8d2a6556599b8e1553bb2334b7722053 (patch)
tree271624febcbebca66c183e89e31ff735f4ea4194 /jpa
parentbff9aff18439f620e701e714f8ff4bec56cceefa (diff)
downloadwebtools.dali-c4f2ff4e8d2a6556599b8e1553bb2334b7722053.tar.gz
webtools.dali-c4f2ff4e8d2a6556599b8e1553bb2334b7722053.tar.xz
webtools.dali-c4f2ff4e8d2a6556599b8e1553bb2334b7722053.zip
java resource model support for @Mutable
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/MutableImpl.java121
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/EclipseLinkJPA.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/MutableAnnotation.java54
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java1
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/MutableAnnotationTests.java112
6 files changed, 298 insertions, 0 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 2e5826bb0b..3e9dd0f712 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
@@ -15,6 +15,7 @@ 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.MutableImpl.MutableAnnotationDefinition;
import org.eclipse.jpt.eclipselink.core.internal.resource.java.TransformationImpl.TransformationAnnotationDefinition;
public class EclipseLinkJpaAnnotationProvider
@@ -34,4 +35,11 @@ public class EclipseLinkJpaAnnotationProvider
super.addAttributeMappingAnnotationDefinitionsTo(definitions);
definitions.add(TransformationAnnotationDefinition.instance());
}
+
+ @Override
+ protected void addAttributeAnnotationDefinitionsTo(Collection<AnnotationDefinition> definitions) {
+ super.addAttributeAnnotationDefinitionsTo(definitions);
+ definitions.add(MutableAnnotationDefinition.instance());
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/MutableImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/MutableImpl.java
new file mode 100644
index 0000000000..eaa210b384
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/MutableImpl.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * 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.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.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.MutableAnnotation;
+
+
+public class MutableImpl extends AbstractResourceAnnotation<Attribute> implements MutableAnnotation
+{
+ private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+
+ private final AnnotationElementAdapter<Boolean> valueAdapter;
+
+ private static final DeclarationAnnotationElementAdapter<Boolean> VALUE_ADAPTER = buildValueAdapter();
+
+
+ private Boolean value;
+
+ protected MutableImpl(JavaResourcePersistentAttribute parent, Attribute attribute) {
+ super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER);
+ this.valueAdapter = new ShortCircuitAnnotationElementAdapter<Boolean>(attribute, VALUE_ADAPTER);
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ this.value = this.value(astRoot);
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ //*************** Basic implementation ****************
+ public Boolean getValue() {
+ return this.value;
+ }
+
+ public void setValue(Boolean newValue) {
+ if (attributeValueHasNotChanged(this.value, newValue)) {
+ return;
+ }
+ Boolean oldValue = this.value;
+ this.value = newValue;
+ this.valueAdapter.setValue(newValue);
+ firePropertyChanged(VALUE_PROPERTY, oldValue, newValue);
+ }
+
+ public TextRange getValueTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(VALUE_ADAPTER, astRoot);
+ }
+
+ public void update(CompilationUnit astRoot) {
+ this.setValue(this.value(astRoot));
+ }
+
+ protected Boolean value(CompilationUnit astRoot) {
+ return this.valueAdapter.getValue(astRoot);
+ }
+
+ // ********** static methods **********
+ private static DeclarationAnnotationElementAdapter<Boolean> buildValueAdapter() {
+ return new ConversionDeclarationAnnotationElementAdapter<Boolean>(DECLARATION_ANNOTATION_ADAPTER, EclipseLinkJPA.MUTABLE__VALUE, false, BooleanExpressionConverter.instance());
+ }
+
+
+ public static class MutableAnnotationDefinition implements AnnotationDefinition
+ {
+ // singleton
+ private static final MutableAnnotationDefinition INSTANCE = new MutableAnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static MutableAnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure non-instantiability.
+ */
+ private MutableAnnotationDefinition() {
+ super();
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) {
+ return new MutableImpl((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 113aab1a67..fb4d91eaec 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
@@ -70,6 +70,8 @@ public interface EclipseLinkJPA {
String EXISTENCE_TYPE__ASSUME_EXISTENCE = EXISTENCE_TYPE_ + "ASSUME_EXISTENCE";
String EXISTENCE_TYPE__ASSUME_NON_EXISTENCE = EXISTENCE_TYPE_ + "ASSUME_NON_EXISTENCE";
+ String MUTABLE = PACKAGE_ + "Mutable";
+ String MUTABLE__VALUE = "value";
String TIME_OF_DAY = PACKAGE_ + "TimeOfDay";
String TIME_OF_DAY__HOUR = "hour";
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/MutableAnnotation.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/MutableAnnotation.java
new file mode 100644
index 0000000000..00626875db
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/MutableAnnotation.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Java resource model interface that corresponds to the Eclipselink
+ * annotation org.eclipse.persistence.annotations.Mutable
+ *
+ * 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 MutableAnnotation extends JavaResourceNode
+{
+
+ String ANNOTATION_NAME = EclipseLinkJPA.MUTABLE;
+
+
+ /**
+ * Corresponds to the value element of the Mutable annotation.
+ * Returns null if the value element does not exist in java.
+ */
+ Boolean getValue();
+
+ /**
+ * Corresponds to the value element of the Mutable annotation.
+ * Set to null to remove the value element.
+ */
+ void setValue(Boolean value);
+ String VALUE_PROPERTY = "valueProperty";
+
+ /**
+ * Return the {@link TextRange} for the value element. If the value element
+ * does not exist return the {@link TextRange} for the Mutable annotation.
+ */
+ TextRange getValueTextRange(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 85bf4b13be..55146fe111 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
@@ -23,6 +23,7 @@ public class JptEclipseLinkCoreJavaResourceModelTests {
suite.addTestSuite(CacheTests.class);
suite.addTestSuite(ExistenceCheckingTests.class);
+ suite.addTestSuite(MutableAnnotationTests.class);
suite.addTestSuite(TimeOfDayTests.class);
suite.addTestSuite(TransformationAnnotationTests.class);
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/MutableAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/MutableAnnotationTests.java
new file mode 100644
index 0000000000..eeb2415c08
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/MutableAnnotationTests.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * 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.MutableAnnotation;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
+
+public class MutableAnnotationTests extends EclipseLinkJavaResourceModelTestCase {
+
+ public MutableAnnotationTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTestMutable() throws Exception {
+ this.createAnnotationAndMembers("Mutable", "boolean value() default true;");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.MUTABLE);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Mutable");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestMutableWithValue() throws Exception {
+ this.createAnnotationAndMembers("Mutable", "boolean value() default true;");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.MUTABLE);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Mutable(value=true)");
+ }
+ });
+ }
+
+
+
+ public void testMutableAnnotation() throws Exception {
+ ICompilationUnit cu = this.createTestMutable();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.MUTABLE));
+
+ attributeResource.removeAnnotation(EclipseLinkJPA.MUTABLE);
+ assertNull(attributeResource.getAnnotation(EclipseLinkJPA.MUTABLE));
+
+ attributeResource.addAnnotation(EclipseLinkJPA.MUTABLE);
+ assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.MUTABLE));
+ }
+
+ public void testGetValue() throws Exception {
+ ICompilationUnit cu = this.createTestMutableWithValue();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ MutableAnnotation mutableAnnotation = (MutableAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.MUTABLE);
+ assertEquals(Boolean.TRUE, mutableAnnotation.getValue());
+ }
+
+ public void testSetValue() throws Exception {
+ ICompilationUnit cu = this.createTestMutableWithValue();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ MutableAnnotation mutableAnnotation = (MutableAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.MUTABLE);
+ assertEquals(Boolean.TRUE, mutableAnnotation.getValue());
+
+ mutableAnnotation.setValue(Boolean.FALSE);
+ assertEquals(Boolean.FALSE, mutableAnnotation.getValue());
+
+ assertSourceContains("@Mutable(value=false)", cu);
+
+ mutableAnnotation.setValue(null);
+ mutableAnnotation.setValue(Boolean.FALSE);
+ assertSourceContains("@Mutable(false)", cu);
+ }
+
+ public void testSetValueNull() throws Exception {
+ ICompilationUnit cu = this.createTestMutableWithValue();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ MutableAnnotation mutableAnnotation = (MutableAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.MUTABLE);
+ assertEquals(Boolean.TRUE, mutableAnnotation.getValue());
+
+ mutableAnnotation.setValue(null);
+ assertNull(mutableAnnotation.getValue());
+
+ assertSourceContains("@Mutable", cu);
+ assertSourceDoesNotContain("value", cu);
+ }
+
+}

Back to the top