summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNan Li2013-02-06 16:18:13 (EST)
committer Karen Butzke2013-02-06 16:18:13 (EST)
commit2666c087bbb234189b915c81df684bc4e086336c (patch)
tree96864b700dd8223a1fbe0ba49da4ddc14b45a775
parentfa44071ffa76305159eeb60a56c978cedc2dae97 (diff)
downloadwebtools.dali-2666c087bbb234189b915c81df684bc4e086336c.zip
webtools.dali-2666c087bbb234189b915c81df684bc4e086336c.tar.gz
webtools.dali-2666c087bbb234189b915c81df684bc4e086336c.tar.bz2
392701 - [JPA 2.1] Named Stored Procedure Query support - Phase 1 Java Resource Model
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/NamedNativeQuery.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/NamedQuery.java22
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Query.java17
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaQuery.java48
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedNativeQuery.java49
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedQuery.java76
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmNamedNativeQuery.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/Generic2_1JpaAnnotationDefinitionProvider.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/NamedStoredProcedureQueries2_1AnnotationDefinition.java60
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/NamedStoredProcedureQuery2_1AnnotationDefinition.java63
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/binary/BinaryNamedStoredProcedureQuery2_1Annotation.java251
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/binary/BinaryStoredProcedureParameter2_1Annotation.java142
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/source/SourceNamedStoredProcedureQuery2_1Annotation.java478
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/source/SourceStoredProcedureParameter2_1Annotation.java319
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryNamedNativeQueryAnnotation.java40
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryNamedQueryAnnotation.java46
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryQueryAnnotation.java38
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceNamedNativeQueryAnnotation.java72
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceNamedQueryAnnotation.java86
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceQueryAnnotation.java66
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceQueryHintAnnotation.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/JPA2_1.java24
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/NamedStoredProcedureQuery2_1Annotation.java171
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/ParameterMode2_1.java67
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/StoredProcedureParameter2_1Annotation.java105
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/java/NamedNativeQueryAnnotation.java25
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/java/NamedQueryAnnotation.java27
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/java/QueryAnnotation.java25
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/NamedNativeQueryPropertyComposite.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/NamedQueryPropertyComposite.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/NamedQueryProperty2_0Composite.java5
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/JavaResource2_1Tests.java33
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/JavaResourceModel2_1TestCase.java32
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/NamedStoredProcedureQueries2_1AnnotationTests.java370
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/NamedStoredProcedureQuery2_1AnnotationTests.java723
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/StoredProcedureParameter2_1AnnotationTests.java154
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/JptJpaCoreResourceModelTests.java4
37 files changed, 3444 insertions, 246 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/NamedNativeQuery.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/NamedNativeQuery.java
index 942c151..bb21fea 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/NamedNativeQuery.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/NamedNativeQuery.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2013 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.
@@ -24,6 +24,16 @@ package org.eclipse.jpt.jpa.core.context;
public interface NamedNativeQuery
extends Query
{
+
+ // ********** query **********
+
+ String QUERY_PROPERTY = "query"; //$NON-NLS-1$
+
+ String getQuery();
+
+ void setQuery(String query);
+
+
// ********** result class **********
String getResultClass();
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/NamedQuery.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/NamedQuery.java
index 92ac55e..98e52cf 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/NamedQuery.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/NamedQuery.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2013 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.
@@ -9,6 +9,9 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.context;
+import java.util.List;
+import org.eclipse.jpt.common.core.utility.TextRange;
+
/**
* named query
* <p>
@@ -24,5 +27,20 @@ package org.eclipse.jpt.jpa.core.context;
public interface NamedQuery
extends Query
{
- // nothing yet
+
+ // ********** query **********
+
+ String QUERY_PROPERTY = "query"; //$NON-NLS-1$
+
+ String getQuery();
+
+ void setQuery(String query);
+
+
+ /**
+ * Returns the list of {@link TextRange} of the query property, which is either a single object
+ * if the string is not split or many objects if the JPQL query is split into many strings.
+ */
+ List<TextRange> getQueryTextRanges();
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Query.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Query.java
index 9308187..ac0b7e0 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Query.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Query.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2013 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.
@@ -48,15 +48,6 @@ public interface Query
NamedNativeQuery.class
);
- // ********** query **********
-
- String QUERY_PROPERTY = "query"; //$NON-NLS-1$
-
- String getQuery();
-
- void setQuery(String query);
-
-
// ********** hints **********
String HINTS_LIST = "hints"; //$NON-NLS-1$
@@ -112,10 +103,4 @@ public interface Query
* Returns the {@link TextRange} of the name property.
*/
TextRange getNameTextRange();
-
- /**
- * Returns the list of {@link TextRange} of the query property, which is either a single object
- * if the string is not split or many objects if the JPQL query is split into many strings.
- */
- List<TextRange> getQueryTextRanges();
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaQuery.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaQuery.java
index f4cba84..f7507ab 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaQuery.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaQuery.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2013 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.
@@ -43,8 +43,6 @@ public abstract class AbstractJavaQuery<A extends QueryAnnotation>
protected String name;
- protected String query;
-
protected final ContextListContainer<JavaQueryHint, QueryHintAnnotation> hintContainer;
@@ -52,7 +50,6 @@ public abstract class AbstractJavaQuery<A extends QueryAnnotation>
super(parent);
this.queryAnnotation = queryAnnotation;
this.name = queryAnnotation.getName();
- this.query = queryAnnotation.getQuery();
this.hintContainer = this.buildHintContainer();
}
@@ -63,7 +60,6 @@ public abstract class AbstractJavaQuery<A extends QueryAnnotation>
public void synchronizeWithResourceModel() {
super.synchronizeWithResourceModel();
this.setName_(this.queryAnnotation.getName());
- this.setQuery_(this.queryAnnotation.getQuery());
this.syncHints();
}
@@ -92,24 +88,6 @@ public abstract class AbstractJavaQuery<A extends QueryAnnotation>
}
- // ********** query **********
-
- public String getQuery() {
- return this.query;
- }
-
- public void setQuery(String query) {
- this.queryAnnotation.setQuery(query);
- this.setQuery_(query);
- }
-
- protected void setQuery_(String query) {
- String old = this.query;
- this.query = query;
- this.firePropertyChanged(QUERY_PROPERTY, old, query);
- }
-
-
// ********** hints **********
public ListIterable<JavaQueryHint> getHints() {
@@ -198,7 +176,6 @@ public abstract class AbstractJavaQuery<A extends QueryAnnotation>
public void validate(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
super.validate(messages, reporter);
this.validateName(messages);
- this.validateQuery(queryHelper, messages, reporter);
}
protected void validateName(List<IMessage> messages) {
@@ -215,24 +192,6 @@ public abstract class AbstractJavaQuery<A extends QueryAnnotation>
}
}
- public void validateQuery(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
- if (StringTools.isBlank(this.query)){
- messages.add(
- DefaultJpaValidationMessages.buildMessage(
- IMessage.HIGH_SEVERITY,
- JpaValidationMessages.QUERY_STATEMENT_UNDEFINED,
- new String[] {this.name},
- this,
- this.getNameTextRange()
- )
- );
- } else {
- this.validateQuery_(queryHelper, messages, reporter);
- }
- }
-
- protected abstract void validateQuery_(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter);
-
public TextRange getValidationTextRange() {
TextRange textRange = this.queryAnnotation.getTextRange();
return (textRange != null) ? textRange : this.getParent().getValidationTextRange();
@@ -242,10 +201,6 @@ public abstract class AbstractJavaQuery<A extends QueryAnnotation>
return this.getValidationTextRange(this.queryAnnotation.getNameTextRange());
}
- public List<TextRange> getQueryTextRanges() {
- return this.queryAnnotation.getQueryTextRanges();
- }
-
public boolean isEquivalentTo(JpaNamedContextNode node) {
return (this != node) &&
(this.getType() == node.getType()) &&
@@ -254,7 +209,6 @@ public abstract class AbstractJavaQuery<A extends QueryAnnotation>
protected boolean isEquivalentTo(Query other) {
return ObjectTools.equals(this.name, other.getName()) &&
- ObjectTools.equals(this.query, other.getQuery()) &&
this.hintsAreEquivalentTo(other);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedNativeQuery.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedNativeQuery.java
index 5629f3e..6668849 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedNativeQuery.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedNativeQuery.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2013 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.
@@ -11,12 +11,15 @@ package org.eclipse.jpt.jpa.core.internal.jpa1.context.java;
import java.util.List;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.jpa.core.context.NamedNativeQuery;
import org.eclipse.jpt.jpa.core.context.Query;
import org.eclipse.jpt.jpa.core.context.java.JavaNamedNativeQuery;
import org.eclipse.jpt.jpa.core.context.java.JavaQueryContainer;
import org.eclipse.jpt.jpa.core.context.orm.OrmQueryContainer;
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaQuery;
+import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
+import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
import org.eclipse.jpt.jpa.core.jpql.JpaJpqlQueryHelper;
import org.eclipse.jpt.jpa.core.resource.java.NamedNativeQueryAnnotation;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
@@ -29,6 +32,8 @@ public class GenericJavaNamedNativeQuery
extends AbstractJavaQuery<NamedNativeQueryAnnotation>
implements JavaNamedNativeQuery
{
+ protected String query;
+
protected String resultClass;
protected String fullyQualifiedResultClass;
@@ -37,6 +42,7 @@ public class GenericJavaNamedNativeQuery
public GenericJavaNamedNativeQuery(JavaQueryContainer parent, NamedNativeQueryAnnotation queryAnnotation) {
super(parent, queryAnnotation);
+ this.query = queryAnnotation.getQuery();
this.resultClass = queryAnnotation.getResultClass();
this.resultSetMapping = queryAnnotation.getResultSetMapping();
}
@@ -47,6 +53,7 @@ public class GenericJavaNamedNativeQuery
@Override
public void synchronizeWithResourceModel() {
super.synchronizeWithResourceModel();
+ this.setQuery_(this.queryAnnotation.getQuery());
this.setResultClass_(this.queryAnnotation.getResultClass());
this.setResultSetMapping_(this.queryAnnotation.getResultSetMapping());
}
@@ -57,6 +64,24 @@ public class GenericJavaNamedNativeQuery
this.setFullyQualifiedResultClass(this.buildFullyQualifiedResultClass());
}
+ // ********** query **********
+
+ public String getQuery() {
+ return this.query;
+ }
+
+ public void setQuery(String query) {
+ this.queryAnnotation.setQuery(query);
+ this.setQuery_(query);
+ }
+
+ protected void setQuery_(String query) {
+ String old = this.query;
+ this.query = query;
+ this.firePropertyChanged(QUERY_PROPERTY, old, query);
+ }
+
+
// ********** result class **********
public String getResultClass() {
@@ -123,8 +148,23 @@ public class GenericJavaNamedNativeQuery
// ********** validation **********
@Override
- protected void validateQuery_(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
- // nothing yet
+ public void validate(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
+ super.validate(messages, reporter);
+ this.validateQuery(messages, reporter);
+ }
+
+ protected void validateQuery(List<IMessage> messages, IReporter reporter) {
+ if (StringTools.isBlank(this.query)){
+ messages.add(
+ DefaultJpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JpaValidationMessages.QUERY_STATEMENT_UNDEFINED,
+ new String[] {this.name},
+ this,
+ this.getNameTextRange()
+ )
+ );
+ }
}
@Override
@@ -134,7 +174,8 @@ public class GenericJavaNamedNativeQuery
}
protected boolean isEquivalentTo(NamedNativeQuery other) {
- return ObjectTools.equals(this.resultClass, other.getResultClass()) &&
+ return ObjectTools.equals(this.query, other.getQuery()) &&
+ ObjectTools.equals(this.resultClass, other.getResultClass()) &&
ObjectTools.equals(this.resultSetMapping, other.getResultSetMapping());
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedQuery.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedQuery.java
index 2067ebf..66d4554 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedQuery.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedQuery.java
@@ -10,11 +10,16 @@
package org.eclipse.jpt.jpa.core.internal.jpa1.context.java;
import java.util.List;
+import org.eclipse.jpt.common.core.utility.TextRange;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.jpa.core.context.NamedQuery;
import org.eclipse.jpt.jpa.core.context.Query;
import org.eclipse.jpt.jpa.core.context.java.JavaQueryContainer;
import org.eclipse.jpt.jpa.core.context.orm.OrmQueryContainer;
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaQuery;
+import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
+import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
import org.eclipse.jpt.jpa.core.jpa2.context.LockModeType2_0;
import org.eclipse.jpt.jpa.core.jpa2.context.NamedQuery2_0;
import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaNamedQuery2_0;
@@ -31,12 +36,15 @@ public class GenericJavaNamedQuery
extends AbstractJavaQuery<NamedQueryAnnotation>
implements JavaNamedQuery2_0
{
+ protected String query;
+
protected LockModeType2_0 specifiedLockMode;
protected LockModeType2_0 defaultLockMode;
public GenericJavaNamedQuery(JavaQueryContainer parent, NamedQueryAnnotation queryAnnotation) {
super(parent, queryAnnotation);
this.specifiedLockMode = this.buildSpecifiedLockMode();
+ this.query = queryAnnotation.getQuery();
}
// ********** synchronize/update **********
@@ -44,6 +52,7 @@ public class GenericJavaNamedQuery
@Override
public void synchronizeWithResourceModel() {
super.synchronizeWithResourceModel();
+ this.setQuery_(this.queryAnnotation.getQuery());
this.setSpecifiedLockMode_(this.buildSpecifiedLockMode());
}
@@ -52,6 +61,27 @@ public class GenericJavaNamedQuery
super.update();
this.setDefaultLockMode(this.buildDefaultLockMode());
}
+
+
+ // ********** query **********
+
+ public String getQuery() {
+ return this.query;
+ }
+
+ public void setQuery(String query) {
+ this.queryAnnotation.setQuery(query);
+ this.setQuery_(query);
+ this.query = this.queryAnnotation.getQuery();
+}
+
+ protected void setQuery_(String query) {
+ String old = this.query;
+ this.query = query;
+ this.firePropertyChanged(QUERY_PROPERTY, old, query);
+ }
+
+
// ********** lock mode **********
public LockModeType2_0 getLockMode() {
@@ -97,6 +127,7 @@ public class GenericJavaNamedQuery
return null;
}
+
// ********** metadata conversion *********
public void convertTo(OrmQueryContainer queryContainer) {
@@ -110,16 +141,41 @@ public class GenericJavaNamedQuery
// ********** validation **********
@Override
+ public void validate(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
+ super.validate(messages, reporter);
+ this.validateQuery(queryHelper, messages, reporter);
+ }
+
+ protected void validateQuery(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
+ if (StringTools.isBlank(this.query)){
+ messages.add(
+ DefaultJpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JpaValidationMessages.QUERY_STATEMENT_UNDEFINED,
+ new String[] {this.name},
+ this,
+ this.getNameTextRange()
+ )
+ );
+ } else {
+ this.validateQuery_(queryHelper, messages, reporter);
+ }
+ }
+
protected void validateQuery_(JpaJpqlQueryHelper queryHelper, List<IMessage> messages, IReporter reporter) {
queryHelper.validate(
- this,
- this.query,
- this.query,
- this.queryAnnotation.getQueryTextRanges(),
- 1,
- JpaJpqlQueryHelper.EscapeType.JAVA,
- messages
- );
+ this,
+ this.query,
+ this.query,
+ this.getQueryTextRanges(),
+ 1,
+ JpaJpqlQueryHelper.EscapeType.JAVA,
+ messages
+ );
+ }
+
+ public List<TextRange> getQueryTextRanges() {
+ return this.queryAnnotation.getQueryTextRanges();
}
@Override
@@ -129,7 +185,7 @@ public class GenericJavaNamedQuery
}
protected boolean isEquivalentTo(NamedQuery other) {
- boolean queriesEquivalent = super.isEquivalentTo(other);
+ boolean queriesEquivalent = ObjectTools.equals(this.query, other.getQuery());
if (this.isJpa2_0Compatible()) {
return queriesEquivalent && this.isEquivalentTo((NamedQuery2_0) other);
}
@@ -145,4 +201,4 @@ public class GenericJavaNamedQuery
public Class<NamedQuery> getType() {
return NamedQuery.class;
}
-} \ No newline at end of file
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmNamedNativeQuery.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmNamedNativeQuery.java
index b6294c4..bef9880 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmNamedNativeQuery.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmNamedNativeQuery.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2013 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.
@@ -9,9 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.jpa1.context.orm;
-import java.util.Collections;
import java.util.List;
-import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.jpa.core.context.JpaContextNode;
@@ -172,10 +170,6 @@ public class GenericOrmNamedNativeQuery
}
}
- public List<TextRange> getQueryTextRanges() {
- return Collections.singletonList(this.xmlQuery.getQueryTextRange());
- }
-
@Override
protected boolean isEquivalentTo(Query other) {
return super.isEquivalentTo(other)
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/Generic2_1JpaAnnotationDefinitionProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/Generic2_1JpaAnnotationDefinitionProvider.java
index 0fea8ec..f3c9096 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/Generic2_1JpaAnnotationDefinitionProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/Generic2_1JpaAnnotationDefinitionProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Oracle. All rights reserved.
+ * Copyright (c) 2012, 2013 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.
@@ -33,6 +33,8 @@ import org.eclipse.jpt.jpa.core.internal.jpa2.resource.java.OrderColumn2_0Annota
import org.eclipse.jpt.jpa.core.internal.jpa2.resource.java.SequenceGenerator2_0AnnotationDefinition;
import org.eclipse.jpt.jpa.core.internal.jpa2.resource.java.StaticMetamodelAnnotationDefinition;
import org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java.Converter2_1AnnotationDefinition;
+import org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java.NamedStoredProcedureQueries2_1AnnotationDefinition;
+import org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java.NamedStoredProcedureQuery2_1AnnotationDefinition;
import org.eclipse.jpt.jpa.core.internal.resource.java.AssociationOverridesAnnotationDefinition;
import org.eclipse.jpt.jpa.core.internal.resource.java.AttributeOverrideAnnotationDefinition;
import org.eclipse.jpt.jpa.core.internal.resource.java.AttributeOverridesAnnotationDefinition;
@@ -134,8 +136,9 @@ public class Generic2_1JpaAnnotationDefinitionProvider
MapKeyEnumerated2_0AnnotationDefinition.instance(),
MapKeyJoinColumns2_0AnnotationDefinition.instance(),
MapKeyTemporal2_0AnnotationDefinition.instance(),
- NamedQueriesAnnotationDefinition.instance(),
NamedNativeQueriesAnnotationDefinition.instance(),
+ NamedQueriesAnnotationDefinition.instance(),
+ NamedStoredProcedureQueries2_1AnnotationDefinition.instance(),
OneToManyAnnotationDefinition.instance(),
OneToOneAnnotationDefinition.instance(),
OrderByAnnotationDefinition.instance(),
@@ -161,9 +164,10 @@ public class Generic2_1JpaAnnotationDefinitionProvider
AttributeOverrideAnnotationDefinition.instance(),
JoinColumnAnnotationDefinition.instance(),
MapKeyJoinColumn2_0AnnotationDefinition.instance(),
- NamedQuery2_0AnnotationDefinition.instance(),
NamedNativeQueryAnnotationDefinition.instance(),
+ NamedQuery2_0AnnotationDefinition.instance(),
+ NamedStoredProcedureQuery2_1AnnotationDefinition.instance(),
PrimaryKeyJoinColumnAnnotationDefinition.instance(),
- SecondaryTableAnnotationDefinition.instance(),
+ SecondaryTableAnnotationDefinition.instance()
};
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/NamedStoredProcedureQueries2_1AnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/NamedStoredProcedureQueries2_1AnnotationDefinition.java
new file mode 100644
index 0000000..f119e0a
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/NamedStoredProcedureQueries2_1AnnotationDefinition.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.jpa.core.internal.jpa2_1.resource.java;
+
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jpt.common.core.internal.resource.java.binary.BinaryNamedAnnotation;
+import org.eclipse.jpt.common.core.internal.resource.java.source.SourceNamedAnnotation;
+import org.eclipse.jpt.common.core.resource.java.Annotation;
+import org.eclipse.jpt.common.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement;
+import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
+
+/**
+ * javax.persistence.NamedStoredProcedureQueries
+ */
+public final class NamedStoredProcedureQueries2_1AnnotationDefinition
+ implements AnnotationDefinition
+{
+ // singleton
+ private static final AnnotationDefinition INSTANCE = new NamedStoredProcedureQueries2_1AnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static AnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure single instance.
+ */
+ private NamedStoredProcedureQueries2_1AnnotationDefinition() {
+ super();
+ }
+
+ public Annotation buildAnnotation(JavaResourceAnnotatedElement parent, AnnotatedElement annotatedElement) {
+ return new SourceNamedAnnotation(parent, annotatedElement, getAnnotationName());
+ }
+
+ public Annotation buildNullAnnotation(JavaResourceAnnotatedElement parent) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Annotation buildAnnotation(JavaResourceAnnotatedElement parent, IAnnotation jdtAnnotation) {
+ return new BinaryNamedAnnotation(parent, jdtAnnotation, getAnnotationName());
+ }
+
+ public String getAnnotationName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_QUERIES;
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/NamedStoredProcedureQuery2_1AnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/NamedStoredProcedureQuery2_1AnnotationDefinition.java
new file mode 100644
index 0000000..3ca9e0a
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/NamedStoredProcedureQuery2_1AnnotationDefinition.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.jpa.core.internal.jpa2_1.resource.java;
+
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement;
+import org.eclipse.jpt.common.core.resource.java.NestableAnnotation;
+import org.eclipse.jpt.common.core.resource.java.NestableAnnotationDefinition;
+import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
+import org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java.binary.BinaryNamedStoredProcedureQuery2_1Annotation;
+import org.eclipse.jpt.jpa.core.internal.jpa2_1.resource.java.source.SourceNamedStoredProcedureQuery2_1Annotation;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
+
+/**
+ * javax.persistence.NamedStoredProcedureQuery
+ */
+public final class NamedStoredProcedureQuery2_1AnnotationDefinition
+ implements NestableAnnotationDefinition
+{
+ // singleton
+ private static final NestableAnnotationDefinition INSTANCE = new NamedStoredProcedureQuery2_1AnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static NestableAnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure single instance.
+ */
+ private NamedStoredProcedureQuery2_1AnnotationDefinition() {
+ super();
+ }
+
+ public NestableAnnotation buildAnnotation(JavaResourceAnnotatedElement parent, AnnotatedElement annotatedElement, int index) {
+ return SourceNamedStoredProcedureQuery2_1Annotation.buildSourceNamedStoredProcedureQuery2_1Annotation(parent, annotatedElement, index);
+ }
+
+ public NestableAnnotation buildAnnotation(JavaResourceAnnotatedElement parent, IAnnotation jdtAnnotation, int index) {
+ return new BinaryNamedStoredProcedureQuery2_1Annotation(parent, jdtAnnotation);
+ }
+
+ public String getNestableAnnotationName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_QUERY;
+ }
+
+ public String getContainerAnnotationName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_QUERIES;
+ }
+
+ public String getElementName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_QUERIES__VALUE;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/binary/BinaryNamedStoredProcedureQuery2_1Annotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/binary/BinaryNamedStoredProcedureQuery2_1Annotation.java
new file mode 100644
index 0000000..cdeb49f
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/binary/BinaryNamedStoredProcedureQuery2_1Annotation.java
@@ -0,0 +1,251 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.jpa.core.internal.jpa2_1.resource.java.binary;
+
+import java.util.Vector;
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
+import org.eclipse.jpt.common.core.utility.TextRange;
+import org.eclipse.jpt.common.utility.internal.iterable.LiveCloneListIterable;
+import org.eclipse.jpt.common.utility.iterable.ListIterable;
+import org.eclipse.jpt.jpa.core.internal.resource.java.binary.BinaryQueryAnnotation;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.NamedStoredProcedureQuery2_1Annotation;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.StoredProcedureParameter2_1Annotation;
+
+/**
+ * javax.persistence.NamedStoredProcedureQuery
+ */
+public final class BinaryNamedStoredProcedureQuery2_1Annotation
+ extends BinaryQueryAnnotation
+ implements NamedStoredProcedureQuery2_1Annotation
+{
+ private String procedureName;
+ private final Vector<StoredProcedureParameter2_1Annotation> parameters;
+ private final Vector<String> resultClasses;
+ private final Vector<String> resultSetMappings;
+
+
+ public BinaryNamedStoredProcedureQuery2_1Annotation(JavaResourceNode parent, IAnnotation jdtAnnotation) {
+ super(parent, jdtAnnotation);
+ this.procedureName = this.buildProcedureName();
+ this.parameters = this.buildParameters();
+ this.resultClasses = this.buildResultClasses();
+ this.resultSetMappings = this.buildResultSetMappings();
+ }
+
+ @Override
+ public void update() {
+ super.update();
+ this.setProcedureName_(this.buildProcedureName());
+ this.updateParameters();
+ this.updateResultClasses();
+ this.updateResultSetMappings();
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ // ********** BinaryNamedStoredProcedureQueryAnnotation implementation **********
+
+ @Override
+ public String getNameElementName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__NAME;
+ }
+
+ @Override
+ public String getHintsElementName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__HINTS;
+ }
+
+ // ********** NamedStoredProcedureQueryAnnotation implementation **********
+
+ //****** procedure name ******
+ public String getProcedureName() {
+ return this.procedureName;
+ }
+
+ public void setProcedureName(String procedureName) {
+ throw new UnsupportedOperationException();
+ }
+
+ private void setProcedureName_(String procedureName) {
+ String old = this.procedureName;
+ this.procedureName = procedureName;
+ this.firePropertyChanged(PROCEDURE_NAME_PROPERTY, old, procedureName);
+ }
+
+ private String buildProcedureName() {
+ return (String) this.getJdtMemberValue(this.getProcedureNameElementName());
+ }
+
+ public String getProcedureNameElementName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__PROCEDURE_NAME;
+ }
+
+ public TextRange getProcedureNameTextRange() {
+ throw new UnsupportedOperationException();
+ }
+
+ // ********* parameters ***********
+ public ListIterable<StoredProcedureParameter2_1Annotation> getParameters() {
+ return new LiveCloneListIterable<StoredProcedureParameter2_1Annotation>(this.parameters);
+ }
+
+ public int getParametersSize() {
+ return this.parameters.size();
+ }
+
+ public StoredProcedureParameter2_1Annotation parameterAt(int index) {
+ return this.parameters.get(index);
+ }
+
+ public StoredProcedureParameter2_1Annotation addParameter(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void moveParameter(int targetIndex, int sourceIndex) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeParameter(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ private Vector<StoredProcedureParameter2_1Annotation> buildParameters() {
+ Object[] jdtParameters = this.getJdtMemberValues(this.getParametersElementName());
+ Vector<StoredProcedureParameter2_1Annotation> result = new Vector<StoredProcedureParameter2_1Annotation>(jdtParameters.length);
+ for (Object jdtParameter : jdtParameters) {
+ result.add(new BinaryStoredProcedureParameter2_1Annotation(this, (IAnnotation) jdtParameter));
+ }
+ return result;
+ }
+
+ private String getParametersElementName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__PARAMETERS;
+ }
+
+ // TODO
+ private void updateParameters() {
+ throw new UnsupportedOperationException();
+ }
+
+ // *********** result classes **********
+ public ListIterable<String> getResultClasses() {
+ return new LiveCloneListIterable<String>(this.resultClasses);
+ }
+
+ public int getResultClassesSize() {
+ return this.resultClasses.size();
+ }
+
+ public String resultClassAt(int index) {
+ return this.resultClasses.elementAt(index);
+ }
+
+ public void addResultClass(String resultClass) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addResultClass(int index, String resultClass) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void moveResultClass(int targetIndex, int sourceIndex) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean resultClassTouches(int pos) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeResultClass(String resultClass) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeResultClass(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ private Vector<String> buildResultClasses() {
+ Object[] jdtResultClasses = this.getJdtMemberValues(this.getResultClassesElementName());
+ Vector<String> result = new Vector<String>(jdtResultClasses.length);
+ for (Object resultClass : jdtResultClasses) {
+ result.add((String) resultClass);
+ }
+ return result;
+ }
+
+ private String getResultClassesElementName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__RESULT_CLASSES;
+ }
+
+ //TODO
+ private void updateResultClasses() {
+ throw new UnsupportedOperationException();
+ }
+
+ // *********** result set mappings **********
+ public ListIterable<String> getResultSetMappings() {
+ return new LiveCloneListIterable<String>(this.resultSetMappings);
+ }
+
+ public int getResultSetMappingsSize() {
+ return this.resultSetMappings.size();
+ }
+
+ public String resultSetMappingAt(int index) {
+ return this.resultSetMappings.elementAt(index);
+ }
+
+ public void addResultSetMapping(String resultSetMapping) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addResultSetMapping(int index, String resultSetMapping) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void moveResultSetMapping(int targetIndex, int sourceIndex) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean resultSetMappingTouches(int pos) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeResultSetMapping(String resultSetMapping) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeResultSetMapping(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ private Vector<String> buildResultSetMappings() {
+ Object[] jdtResultSetMappings = this.getJdtMemberValues(this.getResultSetMappingsElementName());
+ Vector<String> result = new Vector<String>(jdtResultSetMappings.length);
+ for (Object resultSetMapping : jdtResultSetMappings) {
+ result.add((String) resultSetMapping);
+ }
+ return result;
+ }
+
+ private String getResultSetMappingsElementName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__RESULT_SET_MAPPINGS;
+ }
+
+ //TODO
+ private void updateResultSetMappings() {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/binary/BinaryStoredProcedureParameter2_1Annotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/binary/BinaryStoredProcedureParameter2_1Annotation.java
new file mode 100644
index 0000000..244ff1c
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/binary/BinaryStoredProcedureParameter2_1Annotation.java
@@ -0,0 +1,142 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.jpa.core.internal.jpa2_1.resource.java.binary;
+
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jpt.common.core.internal.resource.java.binary.BinaryAnnotation;
+import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
+import org.eclipse.jpt.common.core.utility.TextRange;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.ParameterMode2_1;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.StoredProcedureParameter2_1Annotation;
+
+/**
+ * javax.persistence.StoredProcedureParameter
+ */
+public final class BinaryStoredProcedureParameter2_1Annotation
+ extends BinaryAnnotation
+ implements StoredProcedureParameter2_1Annotation
+{
+ private String name;
+ private ParameterMode2_1 mode;
+ private String type;
+
+
+ public BinaryStoredProcedureParameter2_1Annotation(JavaResourceNode parent, IAnnotation jdtAnnotation) {
+ super(parent, jdtAnnotation);
+ this.name = this.buildName();
+ this.mode = this.buildMode();
+ this.type = this.buildType();
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ @Override
+ public void update() {
+ super.update();
+ this.setName_(this.buildName());
+ this.setMode_(this.buildMode());
+ this.setType_(this.buildType());
+ }
+
+
+ // ********** BinaryStoredProcedureParameterAnnotation implementation **********
+
+ String getNameElementName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER__NAME;
+ }
+
+ String getModeElementName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER__MODE;
+ }
+
+ String getTypeElementName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER__TYPE;
+ }
+
+ // ********** StoredProcedureParameterAnnotation implementation **********
+
+ // ***** name
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ private void setName_(String name) {
+ String old = this.name;
+ this.name = name;
+ this.firePropertyChanged(NAME_PROPERTY, old, name);
+ }
+
+ private String buildName() {
+ return (String) this.getJdtMemberValue(this.getNameElementName());
+ }
+
+ public TextRange getNameTextRange() {
+ throw new UnsupportedOperationException();
+ }
+
+ // ***** mode
+ public ParameterMode2_1 getMode() {
+ return this.mode;
+ }
+
+ public void setMode(ParameterMode2_1 mode) {
+ throw new UnsupportedOperationException();
+ }
+
+ private void setMode_(ParameterMode2_1 mode) {
+ ParameterMode2_1 old = this.mode;
+ this.mode = mode;
+ this.firePropertyChanged(MODE_PROPERTY, old, mode);
+ }
+
+ private ParameterMode2_1 buildMode() {
+ return ParameterMode2_1.fromJavaAnnotationValue(this.getJdtMemberValue(this.getModeElementName()));
+ }
+
+ public TextRange getModeTextRange() {
+ throw new UnsupportedOperationException();
+ }
+
+ // ***** type
+ public String getType() {
+ return this.type;
+ }
+
+ public void setType(String type) {
+ throw new UnsupportedOperationException();
+ }
+
+ private void setType_(String type) {
+ String old = this.type;
+ this.type = type;
+ this.firePropertyChanged(TYPE_PROPERTY, old, type);
+ }
+
+ private String buildType() {
+ return (String) this.getJdtMemberValue(this.getTypeElementName());
+ }
+
+ public TextRange getTypeTextRange() {
+ throw new UnsupportedOperationException();
+ }
+
+ // ***** fully-qualified type name
+ public String getFullyQualifiedTypeName() {
+ return this.type;
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/source/SourceNamedStoredProcedureQuery2_1Annotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/source/SourceNamedStoredProcedureQuery2_1Annotation.java
new file mode 100644
index 0000000..0675cee
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/source/SourceNamedStoredProcedureQuery2_1Annotation.java
@@ -0,0 +1,478 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.jpa.core.internal.jpa2_1.resource.java.source;
+
+import java.util.Arrays;
+import java.util.Vector;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jpt.common.core.internal.utility.jdt.AnnotatedElementAnnotationElementAdapter;
+import org.eclipse.jpt.common.core.internal.utility.jdt.AnnotationStringArrayExpressionConverter;
+import org.eclipse.jpt.common.core.internal.utility.jdt.CombinationIndexedDeclarationAnnotationAdapter;
+import org.eclipse.jpt.common.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.common.core.internal.utility.jdt.ElementIndexedAnnotationAdapter;
+import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
+import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement;
+import org.eclipse.jpt.common.core.utility.TextRange;
+import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
+import org.eclipse.jpt.common.core.utility.jdt.AnnotationElementAdapter;
+import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
+import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.common.core.utility.jdt.ExpressionConverter;
+import org.eclipse.jpt.common.core.utility.jdt.IndexedAnnotationAdapter;
+import org.eclipse.jpt.common.core.utility.jdt.IndexedDeclarationAnnotationAdapter;
+import org.eclipse.jpt.common.utility.internal.collection.ListTools;
+import org.eclipse.jpt.common.utility.internal.iterable.LiveCloneListIterable;
+import org.eclipse.jpt.common.utility.iterable.ListIterable;
+import org.eclipse.jpt.jpa.core.internal.resource.java.source.SourceQueryAnnotation;
+import org.eclipse.jpt.jpa.core.internal.resource.java.source.SourceQueryHintAnnotation;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.NamedStoredProcedureQuery2_1Annotation;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.StoredProcedureParameter2_1Annotation;
+import org.eclipse.jpt.jpa.core.resource.java.QueryHintAnnotation;
+
+/**
+ * <code>javax.persistence.NamedStoredProcedureQuery</code>
+ */
+public final class SourceNamedStoredProcedureQuery2_1Annotation
+ extends SourceQueryAnnotation
+ implements NamedStoredProcedureQuery2_1Annotation
+{
+ private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+ private static final DeclarationAnnotationAdapter CONTAINER_DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES);
+
+ DeclarationAnnotationElementAdapter<String> procedureNameDeclarationAdapter;
+ AnnotationElementAdapter<String> procedureNameAdapter;
+ String procedureName;
+ TextRange procedureNameTextRange;
+
+ final StoredProcedureParameterAnnotationContainer storedProcedureParametersContainer = new StoredProcedureParameterAnnotationContainer();
+
+ private DeclarationAnnotationElementAdapter<String[]> resultClassesDeclarationAdapter;
+ private AnnotationElementAdapter<String[]> resultClassesAdapter;
+ private final Vector<String> resultClasses = new Vector<String>();
+ private TextRange resultClassesTextRange;
+
+ /**
+ * TODO: Need to handle fullyQualifiedResultClassName/fqResultClassNameStale for each of the result classes
+ private final Vector<String> fullyQualifiedResultClassNames = new Vector<String>();
+ // we need a flag since the f-q name can be null
+ private boolean fqResultClassNameStale = true;
+
+ I think you can model this after what Paul recently did in
+ org.eclipse.jpt.jaxb.core.internal.resource.java.source.SourceXmlSeeAlsoAnnotation
+ */
+
+ private DeclarationAnnotationElementAdapter<String[]> resultSetMappingsDeclarationAdapter;
+ private AnnotationElementAdapter<String[]> resultSetMappingsAdapter;
+ private final Vector<String> resultSetMappings = new Vector<String>();
+ private TextRange resultSetMappingsTextRange;
+
+ public static SourceNamedStoredProcedureQuery2_1Annotation buildSourceNamedStoredProcedureQuery2_1Annotation(
+ JavaResourceAnnotatedElement parent,
+ AnnotatedElement element,
+ int index)
+ {
+ IndexedDeclarationAnnotationAdapter idaa = buildNamedStoredProcedureQuery2_1DeclarationAnnotationAdapter(index);
+ IndexedAnnotationAdapter iaa = buildNamedStoredProcedureQuery2_1AnnotationAdapter(element, idaa);
+ return new SourceNamedStoredProcedureQuery2_1Annotation(
+ parent,
+ element,
+ idaa,
+ iaa);
+ }
+
+ private SourceNamedStoredProcedureQuery2_1Annotation(
+ JavaResourceAnnotatedElement parent,
+ AnnotatedElement element,
+ IndexedDeclarationAnnotationAdapter daa,
+ IndexedAnnotationAdapter annotationAdapter)
+ {
+ super(parent, element, daa, annotationAdapter);
+ this.procedureNameDeclarationAdapter = this.buildProcedureNameDeclarationAdapter();
+ this.procedureNameAdapter = this.buildProcedureNameAdapter();
+ this.resultClassesDeclarationAdapter = this.buildResultClassesDeclarationAdapter();
+ this.resultClassesAdapter = this.buildResultClassesAdapter();
+ this.resultSetMappingsDeclarationAdapter = this.buildResultSetMappingsDeclarationAdapter();
+ this.resultSetMappingsAdapter = this.buildResultSetMappingsAdapter();
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ @Override
+ public void initialize(Annotation astAnnotation) {
+ super.initialize(astAnnotation);
+
+ this.procedureName = this.buildProcedureName(astAnnotation);
+ this.procedureNameTextRange = this.buildProcedureNameTextRange(astAnnotation);
+
+ this.storedProcedureParametersContainer.initializeFromContainerAnnotation(astAnnotation);
+
+ this.initializeResultClasses(astAnnotation);
+ this.resultClassesTextRange = this.buildResultClassesTextRange(astAnnotation);
+
+ this.initializeResultSetMappings(astAnnotation);
+ this.resultSetMappingsTextRange = this.buildResultSetMappingsTextRange(astAnnotation);
+ }
+
+ @Override
+ public void synchronizeWith(Annotation astAnnotation) {
+ super.synchronizeWith(astAnnotation);
+
+ this.syncProcedureName(this.buildProcedureName(astAnnotation));
+ this.procedureNameTextRange = this.buildProcedureNameTextRange(astAnnotation);
+
+ this.storedProcedureParametersContainer.synchronize(astAnnotation);
+
+ this.syncResultClasses(astAnnotation);
+ this.resultClassesTextRange = this.buildResultClassesTextRange(astAnnotation);
+
+ this.syncResultSetMappings(astAnnotation);
+ this.resultSetMappingsTextRange = this.buildResultSetMappingsTextRange(astAnnotation);
+
+ }
+
+ // ********** AbstractNamedStoredProcedureQuery2_1Annotation implementation **********
+
+ @Override
+ public String getNameElementName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__NAME;
+ }
+
+ @Override
+ public String getHintsElementName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__HINTS;
+ }
+
+ @Override
+ public QueryHintAnnotation buildHint(int index) {
+ return SourceQueryHintAnnotation.buildNamedStoredProcedureQuery2_1QueryHint(this, this.annotatedElement, this.daa, index);
+ }
+
+
+ // ********** NamedStoredProcedureQuery2_1Annotation implementation **********
+
+ String getProcedureNameElementName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__PROCEDURE_NAME;
+ }
+
+ String getParametersElementName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__PARAMETERS;
+ }
+
+ public StoredProcedureParameter2_1Annotation buildParameter(int index) {
+ return SourceStoredProcedureParameter2_1Annotation.buildNamedStoredProcedureQuery2_1Parameter(this, this.annotatedElement, this.daa, index);
+ }
+
+ String getResultClassesElementName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__RESULT_CLASSES;
+ }
+
+ String getResultSetMappingsElementName() {
+ return JPA2_1.NAMED_STORED_PROCEDURE_QUERY__RESULT_SET_MAPPINGS;
+ }
+
+ // ***** procedure name
+ public String getProcedureName() {
+ return this.procedureName;
+ }
+
+ public void setProcedureName(String procedureName) {
+ if (this.attributeValueHasChanged(this.procedureName, procedureName)) {
+ this.procedureName = procedureName;
+ this.procedureNameAdapter.setValue(procedureName);
+ }
+ }
+
+ private void syncProcedureName(String procedureName) {
+ String old = this.procedureName;
+ this.procedureName = procedureName;
+ this.firePropertyChanged(PROCEDURE_NAME_PROPERTY, old, procedureName);
+ }
+
+ private String buildProcedureName(Annotation astAnnotation) {
+ return this.procedureNameAdapter.getValue(astAnnotation);
+ }
+
+ public TextRange getProcedureNameTextRange() {
+ return this.procedureNameTextRange;
+ }
+
+ private TextRange buildProcedureNameTextRange(Annotation astAnnotation) {
+ return this.getElementTextRange(this.procedureNameDeclarationAdapter, astAnnotation);
+ }
+
+ private DeclarationAnnotationElementAdapter<String> buildProcedureNameDeclarationAdapter() {
+ return ConversionDeclarationAnnotationElementAdapter.forStrings(this.daa, this.getProcedureNameElementName());
+ }
+
+ private AnnotationElementAdapter<String> buildProcedureNameAdapter() {
+ return this.buildStringElementAdapter(this.procedureNameDeclarationAdapter);
+ }
+
+
+ // ***** parameters
+ public ListIterable<StoredProcedureParameter2_1Annotation> getParameters() {
+ return this.storedProcedureParametersContainer.getNestedAnnotations();
+ }
+
+ public int getParametersSize() {
+ return this.storedProcedureParametersContainer.getNestedAnnotationsSize();
+ }
+
+ public StoredProcedureParameter2_1Annotation parameterAt(int index) {
+ return this.storedProcedureParametersContainer.getNestedAnnotation(index);
+ }
+
+ public StoredProcedureParameter2_1Annotation addParameter(int index) {
+ return this.storedProcedureParametersContainer.addNestedAnnotation(index);
+ }
+
+ public void moveParameter(int targetIndex, int sourceIndex) {
+ this.storedProcedureParametersContainer.moveNestedAnnotation(targetIndex, sourceIndex);
+ }
+
+ public void removeParameter(int index) {
+ this.storedProcedureParametersContainer.removeNestedAnnotation(index);
+ }
+
+
+ // ***** result classes
+ public ListIterable<String> getResultClasses() {
+ return new LiveCloneListIterable<String>(this.resultClasses);
+ }
+
+ public int getResultClassesSize() {
+ return this.resultClasses.size();
+ }
+
+ public String resultClassAt(int index) {
+ return this.resultClasses.elementAt(index);
+ }
+
+ public void addResultClass(String resultClass) {
+ this.addResultClass(this.resultClasses.size(), resultClass);
+ }
+
+ public void addResultClass(int index, String resultClass) {
+ this.resultClasses.add(index, resultClass);
+ this.writeResultClasses();
+ }
+
+ public void moveResultClass(int targetIndex, int sourceIndex) {
+ ListTools.move(this.resultClasses, targetIndex, sourceIndex);
+ this.writeResultClasses();
+ }
+
+ public void removeResultClass(String resultClass) {
+ this.resultClasses.remove(resultClass);
+ this.writeResultClasses();
+ }
+
+ public void removeResultClass(int index) {
+ this.resultClasses.remove(index);
+ this.writeResultClasses();
+ }
+
+ private void writeResultClasses() {
+ this.resultClassesAdapter.setValue(this.resultClasses.toArray(new String[this.resultClasses.size()]));
+ }
+
+ private void initializeResultClasses(Annotation astAnnotation) {
+ String[] astResultClasses = this.resultClassesAdapter.getValue(astAnnotation);
+ for (int i = 0; i < astResultClasses.length; i++) {
+ this.resultClasses.add(astResultClasses[i]);
+ }
+ }
+
+ private void syncResultClasses(Annotation astAnnotation) {
+ String[] javaResultClasses = this.resultClassesAdapter.getValue(astAnnotation);
+ this.synchronizeList(Arrays.asList(javaResultClasses), this.resultClasses, RESULT_CLASSES_LIST);
+ }
+
+ private TextRange buildResultClassesTextRange(Annotation astAnnotation) {
+ return this.getElementTextRange(this.resultClassesDeclarationAdapter, astAnnotation);
+ }
+
+ public boolean resultClassesTouches(int pos) {
+ return this.textRangeTouches(this.resultClassesTextRange, pos);
+ }
+
+ private DeclarationAnnotationElementAdapter<String[]> buildResultClassesDeclarationAdapter() {
+ return buildResultClassesArrayAnnotationElementAdapter(this.daa, JPA2_1.NAMED_STORED_PROCEDURE_QUERY__RESULT_CLASSES);
+ }
+
+ private AnnotationElementAdapter<String[]> buildResultClassesAdapter() {
+ return this.buildAnnotationElementAdapter(this.resultClassesDeclarationAdapter);
+ }
+
+
+ // ***** result set mappings
+ public ListIterable<String> getResultSetMappings() {
+ return new LiveCloneListIterable<String>(this.resultSetMappings);
+ }
+
+ public int getResultSetMappingsSize() {
+ return this.resultSetMappings.size();
+ }
+
+ public String resultSetMappingAt(int index) {
+ return this.resultSetMappings.elementAt(index);
+ }
+
+ public void addResultSetMapping(String resultClass) {
+ this.addResultSetMapping(this.resultSetMappings.size(), resultClass);
+ }
+
+ public void addResultSetMapping(int index, String resultClass) {
+ this.resultSetMappings.add(index, resultClass);
+ this.writeResultSetMappings();
+ }
+
+ public void moveResultSetMapping(int targetIndex, int sourceIndex) {
+ ListTools.move(this.resultSetMappings, targetIndex, sourceIndex);
+ this.writeResultSetMappings();
+ }
+
+ public void removeResultSetMapping(String resultSetMapping) {
+ this.resultSetMappings.remove(resultSetMapping);
+ this.writeResultSetMappings();
+ }
+
+ public void removeResultSetMapping(int index) {
+ this.resultSetMappings.remove(index);
+ this.writeResultSetMappings();
+ }
+
+ private void writeResultSetMappings() {
+ this.resultSetMappingsAdapter.setValue(this.resultSetMappings.toArray(new String[this.resultSetMappings.size()]));
+ }
+
+ private void initializeResultSetMappings(Annotation astAnnotation) {
+ String[] astResultClasses = this.resultSetMappingsAdapter.getValue(astAnnotation);
+ for (int i = 0; i < astResultClasses.length; i++) {
+ this.resultSetMappings.add(astResultClasses[i]);
+ }
+ }
+
+ private void syncResultSetMappings(Annotation astAnnotation) {
+ String[] javaResultClasses = this.resultSetMappingsAdapter.getValue(astAnnotation);
+ this.synchronizeList(Arrays.asList(javaResultClasses), this.resultSetMappings, RESULT_SET_MAPPINGS_LIST);
+ }
+
+ private TextRange buildResultSetMappingsTextRange(Annotation astAnnotation) {
+ return this.getElementTextRange(this.resultSetMappingsDeclarationAdapter, astAnnotation);
+ }
+
+ public boolean resultSetMappingsTouches(int pos) {
+ return this.textRangeTouches(this.resultSetMappingsTextRange, pos);
+ }
+
+ private DeclarationAnnotationElementAdapter<String[]> buildResultSetMappingsDeclarationAdapter() {
+ return buildResultSetMappingsArrayAnnotationElementAdapter(this.daa, JPA2_1.NAMED_STORED_PROCEDURE_QUERY__RESULT_SET_MAPPINGS);
+ }
+
+ private AnnotationElementAdapter<String[]> buildResultSetMappingsAdapter() {
+ return this.buildAnnotationElementAdapter(this.resultSetMappingsDeclarationAdapter);
+ }
+
+ // **********
+ private AnnotationElementAdapter<String[]> buildAnnotationElementAdapter(DeclarationAnnotationElementAdapter<String[]> daea) {
+ return new AnnotatedElementAnnotationElementAdapter<String[]>(this.annotatedElement, daea);
+ }
+
+ private static DeclarationAnnotationElementAdapter<String[]> buildResultClassesArrayAnnotationElementAdapter(
+ DeclarationAnnotationAdapter annotationAdapter,
+ String elementName)
+ {
+ return buildArrayAnnotationElementAdapter(
+ annotationAdapter,
+ elementName,
+ AnnotationStringArrayExpressionConverter.forTypes());
+ }
+
+ private static DeclarationAnnotationElementAdapter<String[]> buildResultSetMappingsArrayAnnotationElementAdapter(
+ DeclarationAnnotationAdapter annotationAdapter,
+ String elementName)
+ {
+ return buildArrayAnnotationElementAdapter(
+ annotationAdapter,
+ elementName,
+ AnnotationStringArrayExpressionConverter.forStrings());
+ }
+
+ private static DeclarationAnnotationElementAdapter<String[]> buildArrayAnnotationElementAdapter(
+ DeclarationAnnotationAdapter annotationAdapter,
+ String elementName,
+ ExpressionConverter<String[]> converter)
+ {
+ return new ConversionDeclarationAnnotationElementAdapter<String[]>(
+ annotationAdapter,
+ elementName,
+ converter);
+ }
+
+
+ // ********** stored procedure parameter container **********
+ /**
+ * adapt the AnnotationContainer interface to the xml schema's xmlns
+ */
+ class StoredProcedureParameterAnnotationContainer
+ extends AnnotationContainer<StoredProcedureParameter2_1Annotation>
+ {
+ @Override
+ protected String getNestedAnnotationsListName() {
+ return PARAMETERS_LIST;
+ }
+ @Override
+ protected String getElementName() {
+ return SourceNamedStoredProcedureQuery2_1Annotation.this.getParametersElementName();
+ }
+ @Override
+ protected String getNestedAnnotationName() {
+ return StoredProcedureParameter2_1Annotation.ANNOTATION_NAME;
+ }
+ @Override
+ protected StoredProcedureParameter2_1Annotation buildNestedAnnotation(int index) {
+ return SourceNamedStoredProcedureQuery2_1Annotation.this.buildParameter(index);
+ }
+ }
+
+ // ********** misc **********
+
+ @Override
+ public boolean isUnset() {
+ return super.isUnset() &&
+ (this.procedureName == null) &&
+ (this.storedProcedureParametersContainer.isEmpty()) &&
+ (this.resultClasses.isEmpty()) &&
+ (this.resultSetMappings.isEmpty());
+ }
+
+ // ********** static methods **********
+
+ private static IndexedAnnotationAdapter buildNamedStoredProcedureQuery2_1AnnotationAdapter(
+ AnnotatedElement annotatedElement,
+ IndexedDeclarationAnnotationAdapter idaa)
+ {
+ return new ElementIndexedAnnotationAdapter(annotatedElement, idaa);
+ }
+
+ private static IndexedDeclarationAnnotationAdapter buildNamedStoredProcedureQuery2_1DeclarationAnnotationAdapter(int index)
+ {
+ return new CombinationIndexedDeclarationAnnotationAdapter(
+ DECLARATION_ANNOTATION_ADAPTER,
+ CONTAINER_DECLARATION_ANNOTATION_ADAPTER,
+ index,
+ ANNOTATION_NAME);
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/source/SourceStoredProcedureParameter2_1Annotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/source/SourceStoredProcedureParameter2_1Annotation.java
new file mode 100644
index 0000000..c610e32
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/resource/java/source/SourceStoredProcedureParameter2_1Annotation.java
@@ -0,0 +1,319 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.jpa.core.internal.jpa2_1.resource.java.source;
+
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jpt.common.core.internal.resource.java.source.SourceAnnotation;
+import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
+import org.eclipse.jpt.common.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.common.core.internal.utility.jdt.ElementIndexedAnnotationAdapter;
+import org.eclipse.jpt.common.core.internal.utility.jdt.EnumDeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.common.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter;
+import org.eclipse.jpt.common.core.internal.utility.jdt.TypeStringExpressionConverter;
+import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
+import org.eclipse.jpt.common.core.utility.TextRange;
+import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
+import org.eclipse.jpt.common.core.utility.jdt.AnnotationElementAdapter;
+import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
+import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.common.core.utility.jdt.ExpressionConverter;
+import org.eclipse.jpt.common.core.utility.jdt.IndexedDeclarationAnnotationAdapter;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.ParameterMode2_1;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.StoredProcedureParameter2_1Annotation;
+
+/**
+ * <code>javax.persistence.StoredProcedureParameter</code>
+ */
+public final class SourceStoredProcedureParameter2_1Annotation
+ extends SourceAnnotation
+ implements StoredProcedureParameter2_1Annotation
+{
+ private DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter;
+ private AnnotationElementAdapter<String> nameAdapter;
+ private String name;
+ private TextRange nameTextRange;
+
+ private DeclarationAnnotationElementAdapter<String> modeDeclarationAdapter;
+ private AnnotationElementAdapter<String> modeAdapter;
+ private ParameterMode2_1 mode;
+ private TextRange modeTextRange;
+
+ private DeclarationAnnotationElementAdapter<String> typeDeclarationAdapter;
+ private AnnotationElementAdapter<String> typeAdapter;
+ private String type;
+ private TextRange typeTextRange;
+
+ private String fullyQualifiedTypeName;
+ // we need a flag since the f-q name can be null
+ private boolean fqTypeNameStale = true;
+
+ public static SourceStoredProcedureParameter2_1Annotation buildNamedStoredProcedureQuery2_1Parameter(
+ JavaResourceNode parent,
+ AnnotatedElement element,
+ DeclarationAnnotationAdapter namedStoredProcedureQueryAdapter,
+ int index)
+ {
+ return buildNestedSourceStoredProcedureParameter2_1Annotation(
+ parent,
+ element,
+ buildStoredProcedureParameter2_1AnnotationAdapter(namedStoredProcedureQueryAdapter,
+ index));
+ }
+
+
+ public static SourceStoredProcedureParameter2_1Annotation buildNestedSourceStoredProcedureParameter2_1Annotation(
+ JavaResourceNode parent,
+ AnnotatedElement element,
+ IndexedDeclarationAnnotationAdapter idaa)
+ {
+ return new SourceStoredProcedureParameter2_1Annotation(
+ parent,
+ element,
+ idaa);
+ }
+
+ private SourceStoredProcedureParameter2_1Annotation(
+ JavaResourceNode parent,
+ AnnotatedElement element,
+ IndexedDeclarationAnnotationAdapter idaa)
+ {
+ super(parent, element, idaa, new ElementIndexedAnnotationAdapter(element, idaa));
+ this.nameDeclarationAdapter = this.buildNameDeclarationAdapter();
+ this.nameAdapter = this.buildNameAdapter();
+ this.modeDeclarationAdapter = this.buildModeDeclarationAdapter();
+ this.modeAdapter = this.buildModeAdapter();
+ this.typeDeclarationAdapter = this.buildTypeDeclarationAdapter();
+ this.typeAdapter = this.buildTypeAdapter();
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ @Override
+ public void initialize(Annotation astAnnotation) {
+ super.initialize(astAnnotation);
+ this.name = this.buildName(astAnnotation);
+ this.nameTextRange = this.buildNameTextRange(astAnnotation);
+
+ this.mode = this.buildMode(astAnnotation);
+ this.modeTextRange = this.buildModeTextRange(astAnnotation);
+
+ this.type = this.buildType(astAnnotation);
+ this.typeTextRange = this.buildTypeTextRange(astAnnotation);
+ }
+
+ @Override
+ public void synchronizeWith(Annotation astAnnotation) {
+ super.synchronizeWith(astAnnotation);
+ this.syncName(this.buildName(astAnnotation));
+ this.nameTextRange = this.buildNameTextRange(astAnnotation);
+
+ this.syncMode(this.buildMode(astAnnotation));
+ this.modeTextRange = this.buildModeTextRange(astAnnotation);
+
+ this.syncType(this.buildType(astAnnotation));
+ this.typeTextRange = this.buildTypeTextRange(astAnnotation);
+ }
+
+
+ // ********** StoredProcedureParameterAnnotation implementation **********
+
+ // ***** name
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ if (this.attributeValueHasChanged(this.name, name)) {
+ this.name = name;
+ this.nameAdapter.setValue(name);
+ }
+ }
+
+ private void syncName(String astName) {
+ String old = this.name;
+ this.name = astName;
+ this.firePropertyChanged(NAME_PROPERTY, old, astName);
+ }
+
+ private String buildName(Annotation astAnnotation) {
+ return this.nameAdapter.getValue(astAnnotation);
+ }
+
+ public TextRange getNameTextRange() {
+ return this.nameTextRange;
+ }
+
+ private TextRange buildNameTextRange(Annotation astAnnotation) {
+ return this.getElementTextRange(this.nameDeclarationAdapter, astAnnotation);
+ }
+
+ private DeclarationAnnotationElementAdapter<String> buildNameDeclarationAdapter() {
+ return ConversionDeclarationAnnotationElementAdapter.forStrings(this.daa, JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER__NAME);
+ }
+
+ private AnnotationElementAdapter<String> buildNameAdapter() {
+ return this.buildStringElementAdapter(this.nameDeclarationAdapter);
+ }
+
+ // ***** mode
+ public ParameterMode2_1 getMode() {
+ return this.mode;
+ }
+
+ public void setMode(ParameterMode2_1 mode) {
+ if (this.attributeValueHasChanged(this.mode, mode)) {
+ this.mode = mode;
+ this.modeAdapter.setValue(ParameterMode2_1.toJavaAnnotationValue(mode));
+ }
+ }
+
+ private void syncMode(ParameterMode2_1 astValue) {
+ ParameterMode2_1 old = this.mode;
+ this.mode = astValue;
+ this.firePropertyChanged(MODE_PROPERTY, old, astValue);
+ }
+
+ private ParameterMode2_1 buildMode(Annotation astAnnotation) {
+ return ParameterMode2_1.fromJavaAnnotationValue(this.modeAdapter.getValue(astAnnotation));
+ }
+
+ public TextRange getModeTextRange() {
+ return this.modeTextRange;
+ }
+
+ private TextRange buildModeTextRange(Annotation astAnnotation) {
+ return this.getElementTextRange(this.modeDeclarationAdapter, astAnnotation);
+ }
+
+ private DeclarationAnnotationElementAdapter<String> buildModeDeclarationAdapter() {
+ return new EnumDeclarationAnnotationElementAdapter(this.daa, JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER__MODE);
+ }
+
+ private AnnotationElementAdapter<String> buildModeAdapter() {
+ return this.buildStringElementAdapter(this.modeDeclarationAdapter);
+ }
+
+ // ***** type
+ public String getType() {
+ return this.type;
+ }
+
+ public void setType(String type) {
+ if (this.attributeValueHasChanged(this.type, type)) {
+ this.type = type;
+ this.fqTypeNameStale = true;
+ this.typeAdapter.setValue(type);
+ }
+ }
+
+ private void syncType(String astType) {
+ if (this.attributeValueHasChanged(this.type, astType)) {
+ this.syncType_(astType);
+ }
+ }
+
+ private void syncType_(String astType) {
+ String old = this.type;
+ this.type = astType;
+ this.fqTypeNameStale = true;
+ this.firePropertyChanged(TYPE_PROPERTY, old, astType);
+ }
+
+ private String buildType(Annotation astAnnotation) {
+ return this.typeAdapter.getValue(astAnnotation);
+ }
+
+ public TextRange getTypeTextRange() {
+ return this.typeTextRange;
+ }
+
+ private TextRange buildTypeTextRange(Annotation astAnnotation) {
+ return this.getElementTextRange(this.typeDeclarationAdapter, astAnnotation);
+ }
+
+ private DeclarationAnnotationElementAdapter<String> buildTypeDeclarationAdapter() {
+ return buildTypeDeclarationAdapter(this.daa, JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER__TYPE);
+ }
+
+ private static DeclarationAnnotationElementAdapter<String> buildTypeDeclarationAdapter(
+ DeclarationAnnotationAdapter annotationAdapter,
+ String elementName)
+ {
+ return buildAnnotationElementAdapter(
+ annotationAdapter,
+ elementName,
+ TypeStringExpressionConverter.instance());
+ }
+
+ private static DeclarationAnnotationElementAdapter<String> buildAnnotationElementAdapter(
+ DeclarationAnnotationAdapter annotationAdapter,
+ String elementName,
+ ExpressionConverter<String> converter)
+ {
+ return new ConversionDeclarationAnnotationElementAdapter<String>(
+ annotationAdapter,
+ elementName,
+ converter);
+ }
+
+ private AnnotationElementAdapter<String> buildTypeAdapter() {
+ return this.buildStringElementAdapter(this.typeDeclarationAdapter);
+ }
+
+ // ***** fully-qualified type name
+ public String getFullyQualifiedTypeName() {
+ if (this.fqTypeNameStale) {
+ this.fullyQualifiedTypeName = this.buildFullyQualifiedTypeName();
+ this.fqTypeNameStale = false;
+ }
+ return this.fullyQualifiedTypeName;
+ }
+
+ private String buildFullyQualifiedTypeName() {
+ return (this.type == null) ? null : this.buildFullyQualifiedTypeName_();
+ }
+
+ private String buildFullyQualifiedTypeName_() {
+ return ASTTools.resolveFullyQualifiedName(this.typeAdapter.getExpression(this.buildASTRoot()));
+ }
+
+
+ // ********** misc **********
+
+ @Override
+ public boolean isUnset() {
+ return super.isUnset() &&
+ (this.name == null) &&
+ (this.mode == null) &&
+ (this.type == null);
+ }
+
+ @Override
+ public void toString(StringBuilder sb) {
+ sb.append(this.name);
+ }
+
+
+ // ********** static methods **********
+ private static IndexedDeclarationAnnotationAdapter buildStoredProcedureParameter2_1AnnotationAdapter(
+ DeclarationAnnotationAdapter namedStoredProcedureQuery2_1Adapter,
+ int index)
+ {
+ return new NestedIndexedDeclarationAnnotationAdapter(
+ namedStoredProcedureQuery2_1Adapter,
+ JPA2_1.NAMED_STORED_PROCEDURE_QUERY__PARAMETERS,
+ index,
+ ANNOTATION_NAME);
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryNamedNativeQueryAnnotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryNamedNativeQueryAnnotation.java
index bcb3e04..a90992a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryNamedNativeQueryAnnotation.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryNamedNativeQueryAnnotation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2013 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.
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.resource.java.binary;
+import java.util.List;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
import org.eclipse.jpt.common.core.utility.TextRange;
@@ -22,12 +23,14 @@ public final class BinaryNamedNativeQueryAnnotation
extends BinaryQueryAnnotation
implements NamedNativeQueryAnnotation
{
+ private String query;
private String resultClass;
private String resultSetMapping;
public BinaryNamedNativeQueryAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) {
super(parent, jdtAnnotation);
+ this.query = this.buildQuery();
this.resultClass = this.buildResultClass();
this.resultSetMapping = this.buildResultSetMapping();
}
@@ -39,30 +42,53 @@ public final class BinaryNamedNativeQueryAnnotation
@Override
public void update() {
super.update();
+ this.setQuery_(this.buildQuery());
this.setResultClass_(this.buildResultClass());
this.setResultSetMapping_(this.buildResultSetMapping());
}
- // ********** BinaryBaseNamedQueryAnnotation implementation **********
+ // ********** BinaryNamedNativeQueryAnnotation implementation **********
@Override
- String getNameElementName() {
+ public String getNameElementName() {
return JPA.NAMED_NATIVE_QUERY__NAME;
}
@Override
+ public String getHintsElementName() {
+ return JPA.NAMED_NATIVE_QUERY__HINTS;
+ }
+
+
+ // ********** NamedNativeQueryAnnotation implementation **********
+
String getQueryElementName() {
return JPA.NAMED_NATIVE_QUERY__QUERY;
}
- @Override
- String getHintsElementName() {
- return JPA.NAMED_NATIVE_QUERY__HINTS;
+ // ***** query
+ public String getQuery() {
+ return this.query;
}
+ public void setQuery(String query) {
+ throw new UnsupportedOperationException();
+ }
- // ********** NamedNativeQueryAnnotation implementation **********
+ private void setQuery_(String query) {
+ String old = this.query;
+ this.query = query;
+ this.firePropertyChanged(QUERY_PROPERTY, old, query);
+ }
+
+ private String buildQuery() {
+ return (String) this.getJdtMemberValue(this.getQueryElementName());
+ }
+
+ public List<TextRange> getQueryTextRanges() {
+ throw new UnsupportedOperationException();
+ }
// ***** result class
public String getResultClass() {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryNamedQueryAnnotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryNamedQueryAnnotation.java
index 878abcb..f8a3e40 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryNamedQueryAnnotation.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryNamedQueryAnnotation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2013 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.
@@ -9,8 +9,10 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.resource.java.binary;
+import java.util.List;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
+import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.jpa.core.resource.java.JPA;
import org.eclipse.jpt.jpa.core.resource.java.NamedQueryAnnotation;
@@ -21,30 +23,64 @@ public abstract class BinaryNamedQueryAnnotation
extends BinaryQueryAnnotation
implements NamedQueryAnnotation
{
+ private String query;
+
public BinaryNamedQueryAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) {
super(parent, jdtAnnotation);
+ this.query = this.buildQuery();
}
public String getAnnotationName() {
return ANNOTATION_NAME;
}
+ @Override
+ public void update() {
+ super.update();
+ this.setQuery_(this.buildQuery());
+ }
- // ********** BinaryBaseNamedQueryAnnotation implementation **********
+
+ // ********** BinaryNamedQueryAnnotation implementation **********
@Override
- String getNameElementName() {
+ public String getNameElementName() {
return JPA.NAMED_QUERY__NAME;
}
- @Override
String getQueryElementName() {
return JPA.NAMED_QUERY__QUERY;
}
@Override
- String getHintsElementName() {
+ public String getHintsElementName() {
return JPA.NAMED_QUERY__HINTS;
}
+
+ // ********** NamedNativeQueryAnnotation implementation **********
+
+ // ***** query
+ public String getQuery() {
+ return this.query;
+ }
+
+ public void setQuery(String query) {
+ throw new UnsupportedOperationException();
+ }
+
+ private void setQuery_(String query) {
+ String old = this.query;
+ this.query = query;
+ this.firePropertyChanged(QUERY_PROPERTY, old, query);
+ }
+
+ private String buildQuery() {
+ return (String) this.getJdtMemberValue(this.getQueryElementName());
+ }
+
+ public List<TextRange> getQueryTextRanges() {
+ throw new UnsupportedOperationException();
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryQueryAnnotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryQueryAnnotation.java
index 7c08b89..2c1ae1b 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryQueryAnnotation.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryQueryAnnotation.java
@@ -9,7 +9,6 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.resource.java.binary;
-import java.util.List;
import java.util.Vector;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jpt.common.core.internal.resource.java.binary.BinaryAnnotation;
@@ -23,20 +22,19 @@ import org.eclipse.jpt.jpa.core.resource.java.QueryHintAnnotation;
/**
* javax.persistence.NamedQuery
* javax.persistence.NamedNativeQuery
+ * javax.persistence.NamedStoredProcedureQuery
*/
-abstract class BinaryQueryAnnotation
+public abstract class BinaryQueryAnnotation
extends BinaryAnnotation
implements QueryAnnotation
{
String name;
- String query;
final Vector<QueryHintAnnotation> hints;
- BinaryQueryAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) {
+ protected BinaryQueryAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) {
super(parent, jdtAnnotation);
this.name = this.buildName();
- this.query = this.buildQuery();
this.hints = this.buildHints();
}
@@ -44,7 +42,6 @@ abstract class BinaryQueryAnnotation
public void update() {
super.update();
this.setName_(this.buildName());
- this.setQuery_(this.buildQuery());
this.updateHints();
}
@@ -75,37 +72,12 @@ abstract class BinaryQueryAnnotation
return (String) this.getJdtMemberValue(this.getNameElementName());
}
- abstract String getNameElementName();
+ public abstract String getNameElementName();
public TextRange getNameTextRange() {
throw new UnsupportedOperationException();
}
- // ***** query
- public String getQuery() {
- return this.query;
- }
-
- public void setQuery(String query) {
- throw new UnsupportedOperationException();
- }
-
- private void setQuery_(String query) {
- String old = this.query;
- this.query = query;
- this.firePropertyChanged(QUERY_PROPERTY, old, query);
- }
-
- private String buildQuery() {
- return (String) this.getJdtMemberValue(this.getQueryElementName());
- }
-
- abstract String getQueryElementName();
-
- public List<TextRange> getQueryTextRanges() {
- throw new UnsupportedOperationException();
- }
-
// ***** hints
public ListIterable<QueryHintAnnotation> getHints() {
@@ -141,7 +113,7 @@ abstract class BinaryQueryAnnotation
return result;
}
- abstract String getHintsElementName();
+ public abstract String getHintsElementName();
// TODO
private void updateHints() {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceNamedNativeQueryAnnotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceNamedNativeQueryAnnotation.java
index 38cf034..f17fd50 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceNamedNativeQueryAnnotation.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceNamedNativeQueryAnnotation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2013 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.
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.resource.java.source;
+import java.util.List;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
import org.eclipse.jpt.common.core.internal.utility.jdt.CombinationIndexedDeclarationAnnotationAdapter;
@@ -38,6 +39,11 @@ public final class SourceNamedNativeQueryAnnotation
private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
private static final DeclarationAnnotationAdapter CONTAINER_DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA.NAMED_NATIVE_QUERIES);
+ DeclarationAnnotationElementAdapter<String> queryDeclarationAdapter;
+ AnnotationElementAdapter<String> queryAdapter;
+ String query;
+ List<TextRange> queryTextRanges;
+
private DeclarationAnnotationElementAdapter<String> resultClassDeclarationAdapter;
private AnnotationElementAdapter<String> resultClassAdapter;
private String resultClass;
@@ -71,6 +77,8 @@ public final class SourceNamedNativeQueryAnnotation
IndexedDeclarationAnnotationAdapter daa,
IndexedAnnotationAdapter annotationAdapter) {
super(parent, element, daa, annotationAdapter);
+ this.queryDeclarationAdapter = this.buildQueryDeclarationAdapter();
+ this.queryAdapter = this.buildQueryAdapter();
this.resultClassDeclarationAdapter = this.buildResultClassDeclarationAdapter();
this.resultClassAdapter = this.buildResultClassAdapter();
this.resultSetMappingDeclarationAdapter = this.buildResultSetMappingAdapter(daa);
@@ -84,6 +92,9 @@ public final class SourceNamedNativeQueryAnnotation
@Override
public void initialize(Annotation astAnnotation) {
super.initialize(astAnnotation);
+
+ this.query = this.buildQuery(astAnnotation);
+ this.queryTextRanges = this.buildQueryTextRanges(astAnnotation);
this.resultClass = this.buildResultClass(astAnnotation);
this.resultClassTextRange = this.buildResultClassTextRange(astAnnotation);
@@ -95,6 +106,9 @@ public final class SourceNamedNativeQueryAnnotation
@Override
public void synchronizeWith(Annotation astAnnotation) {
super.synchronizeWith(astAnnotation);
+
+ this.syncQuery(this.buildQuery(astAnnotation));
+ this.queryTextRanges = this.buildQueryTextRanges(astAnnotation);
this.syncResultClass(this.buildResultClass(astAnnotation));
this.resultClassTextRange = this.buildResultClassTextRange(astAnnotation);
@@ -104,31 +118,68 @@ public final class SourceNamedNativeQueryAnnotation
}
- // ********** AbstractBaseNamedQueryAnnotation implementation **********
+ // ********** AbstractNamedNativeQueryAnnotation implementation **********
@Override
- String getNameElementName() {
+ public String getNameElementName() {
return JPA.NAMED_NATIVE_QUERY__NAME;
}
@Override
- String getQueryElementName() {
- return JPA.NAMED_NATIVE_QUERY__QUERY;
- }
-
- @Override
- String getHintsElementName() {
+ public String getHintsElementName() {
return JPA.NAMED_NATIVE_QUERY__HINTS;
}
@Override
- QueryHintAnnotation buildHint(int index) {
+ public QueryHintAnnotation buildHint(int index) {
return SourceQueryHintAnnotation.buildNamedNativeQueryQueryHint(this, this.annotatedElement, this.daa, index);
}
// ********** NamedNativeQueryAnnotation implementation **********
+ String getQueryElementName() {
+ return JPA.NAMED_NATIVE_QUERY__QUERY;
+ }
+
+ // ***** query
+ public String getQuery() {
+ return this.query;
+ }
+
+ public void setQuery(String query) {
+ if (this.attributeValueHasChanged(this.query, query)) {
+ this.query = query;
+ this.queryAdapter.setValue(query);
+ }
+ }
+
+ private void syncQuery(String annotationQuery) {
+ String old = this.query;
+ this.query = annotationQuery;
+ this.firePropertyChanged(QUERY_PROPERTY, old, annotationQuery);
+ }
+
+ private String buildQuery(Annotation astAnnotation) {
+ return this.queryAdapter.getValue(astAnnotation);
+ }
+
+ public List<TextRange> getQueryTextRanges() {
+ return this.queryTextRanges;
+ }
+
+ private List<TextRange> buildQueryTextRanges(Annotation astAnnotation) {
+ return this.getElementTextRanges(this.queryDeclarationAdapter, astAnnotation);
+ }
+
+ private DeclarationAnnotationElementAdapter<String> buildQueryDeclarationAdapter() {
+ return ConversionDeclarationAnnotationElementAdapter.forStrings(this.daa, this.getQueryElementName());
+ }
+
+ private AnnotationElementAdapter<String> buildQueryAdapter() {
+ return this.buildStringElementAdapter(this.queryDeclarationAdapter);
+ }
+
// ***** result class
public String getResultClass() {
return this.resultClass;
@@ -236,6 +287,7 @@ public final class SourceNamedNativeQueryAnnotation
@Override
public boolean isUnset() {
return super.isUnset() &&
+ (this.query == null) &&
(this.resultClass == null) &&
(this.resultSetMapping == null);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceNamedQueryAnnotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceNamedQueryAnnotation.java
index 6dc5549..bb818e8 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceNamedQueryAnnotation.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceNamedQueryAnnotation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2013 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.
@@ -9,13 +9,19 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.resource.java.source;
+import java.util.List;
+import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jpt.common.core.internal.utility.jdt.CombinationIndexedDeclarationAnnotationAdapter;
+import org.eclipse.jpt.common.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
import org.eclipse.jpt.common.core.internal.utility.jdt.ElementIndexedAnnotationAdapter;
import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
+import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
import org.eclipse.jpt.common.core.utility.jdt.AnnotationAdapter;
+import org.eclipse.jpt.common.core.utility.jdt.AnnotationElementAdapter;
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
+import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationElementAdapter;
import org.eclipse.jpt.common.core.utility.jdt.IndexedAnnotationAdapter;
import org.eclipse.jpt.common.core.utility.jdt.IndexedDeclarationAnnotationAdapter;
import org.eclipse.jpt.jpa.core.resource.java.JPA;
@@ -32,39 +38,107 @@ public abstract class SourceNamedQueryAnnotation
private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
private static final DeclarationAnnotationAdapter CONTAINER_DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA.NAMED_QUERIES);
+ DeclarationAnnotationElementAdapter<String> queryDeclarationAdapter;
+ AnnotationElementAdapter<String> queryAdapter;
+ String query;
+ List<TextRange> queryTextRanges;
protected SourceNamedQueryAnnotation(JavaResourceNode parent, AnnotatedElement element, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) {
super(parent, element, daa, annotationAdapter);
+ this.queryDeclarationAdapter = this.buildQueryDeclarationAdapter();
+ this.queryAdapter = this.buildQueryAdapter();
}
-
public String getAnnotationName() {
return ANNOTATION_NAME;
}
+ @Override
+ public void initialize(Annotation astAnnotation) {
+ super.initialize(astAnnotation);
+
+ this.query = this.buildQuery(astAnnotation);
+ this.queryTextRanges = this.buildQueryTextRanges(astAnnotation);
+ }
+
+ @Override
+ public void synchronizeWith(Annotation astAnnotation) {
+ super.synchronizeWith(astAnnotation);
+
+ this.syncQuery(this.buildQuery(astAnnotation));
+ this.queryTextRanges = this.buildQueryTextRanges(astAnnotation);
+ }
// ********** AbstractBaseNamedQueryAnnotation implementation **********
@Override
- String getNameElementName() {
+ public String getNameElementName() {
return JPA.NAMED_QUERY__NAME;
}
- @Override
String getQueryElementName() {
return JPA.NAMED_QUERY__QUERY;
}
@Override
- String getHintsElementName() {
+ public String getHintsElementName() {
return JPA.NAMED_QUERY__HINTS;
}
@Override
- QueryHintAnnotation buildHint(int index) {
+ public QueryHintAnnotation buildHint(int index) {
return SourceQueryHintAnnotation.buildNamedQueryQueryHint(this, this.annotatedElement, this.daa, index);
}
+ // ***** query
+ public String getQuery() {
+ return this.query;
+ }
+
+ public void setQuery(String query) {
+ if (this.attributeValueHasChanged(this.query, query)) {
+ this.query = query;
+ this.queryAdapter.setValue(query);
+ }
+ }
+
+ private void syncQuery(String annotationQuery) {
+ String old = this.query;
+ this.query = annotationQuery;
+ this.firePropertyChanged(QUERY_PROPERTY, old, annotationQuery);
+ }
+
+ private String buildQuery(Annotation astAnnotation) {
+ return this.queryAdapter.getValue(astAnnotation);
+ }
+
+ public List<TextRange> getQueryTextRanges() {
+ return this.queryTextRanges;
+ }
+
+ private List<TextRange> buildQueryTextRanges(Annotation astAnnotation) {
+ return this.getElementTextRanges(this.queryDeclarationAdapter, astAnnotation);
+ }
+
+ private DeclarationAnnotationElementAdapter<String> buildQueryDeclarationAdapter() {
+ return ConversionDeclarationAnnotationElementAdapter.forStrings(this.daa, this.getQueryElementName());
+ }
+
+ private AnnotationElementAdapter<String> buildQueryAdapter() {
+ return this.buildStringElementAdapter(this.queryDeclarationAdapter);
+ }
+
+ // ********** misc **********
+
+ @Override
+ public boolean isUnset() {
+ return super.isUnset() &&
+ (this.query == null);
+ }
+
+
+ // ********** static methods **********
+
protected static IndexedAnnotationAdapter buildNamedQueryAnnotationAdapter(AnnotatedElement annotatedElement, IndexedDeclarationAnnotationAdapter idaa) {
return new ElementIndexedAnnotationAdapter(annotatedElement, idaa);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceQueryAnnotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceQueryAnnotation.java
index e1d0bb6..53512da 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceQueryAnnotation.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceQueryAnnotation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2013 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.
@@ -9,7 +9,6 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.resource.java.source;
-import java.util.List;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jpt.common.core.internal.resource.java.source.SourceAnnotation;
import org.eclipse.jpt.common.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
@@ -28,9 +27,10 @@ import org.eclipse.jpt.jpa.core.resource.java.QueryHintAnnotation;
* <ul>
* <li><code>javax.persistence.NamedQuery</code>
* <li><code>javax.persistence.NamedNativeQuery</code>
+ * <li><code>javax.persistence.NamedStoredProcedureQuery</code>
* </ul>
*/
-abstract class SourceQueryAnnotation
+public abstract class SourceQueryAnnotation
extends SourceAnnotation
implements QueryAnnotation
{
@@ -39,20 +39,14 @@ abstract class SourceQueryAnnotation
String name;
TextRange nameTextRange;
- DeclarationAnnotationElementAdapter<String> queryDeclarationAdapter;
- AnnotationElementAdapter<String> queryAdapter;
- String query;
- List<TextRange> queryTextRanges;
-
final QueryHintsAnnotationContainer hintsContainer = new QueryHintsAnnotationContainer();
- SourceQueryAnnotation(JavaResourceNode parent, AnnotatedElement element, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) {
+ protected SourceQueryAnnotation(JavaResourceNode parent, AnnotatedElement element, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) {
super(parent, element, daa, annotationAdapter);
this.nameDeclarationAdapter = this.buildNameDeclarationAdapter();
this.nameAdapter = this.buildNameAdapter();
- this.queryDeclarationAdapter = this.buildQueryDeclarationAdapter();
- this.queryAdapter = this.buildQueryAdapter();
+
}
@Override
@@ -60,8 +54,6 @@ abstract class SourceQueryAnnotation
super.initialize(astAnnotation);
this.name = this.buildName(astAnnotation);
this.nameTextRange = this.buildNameTextRange(astAnnotation);
- this.query = this.buildQuery(astAnnotation);
- this.queryTextRanges = this.buildQueryTextRanges(astAnnotation);
this.hintsContainer.initializeFromContainerAnnotation(astAnnotation);
}
@@ -70,8 +62,6 @@ abstract class SourceQueryAnnotation
super.synchronizeWith(astAnnotation);
this.syncName(this.buildName(astAnnotation));
this.nameTextRange = this.buildNameTextRange(astAnnotation);
- this.syncQuery(this.buildQuery(astAnnotation));
- this.queryTextRanges = this.buildQueryTextRanges(astAnnotation);
this.hintsContainer.synchronize(astAnnotation);
}
@@ -116,47 +106,8 @@ abstract class SourceQueryAnnotation
return this.buildStringElementAdapter(this.nameDeclarationAdapter);
}
- abstract String getNameElementName();
-
- // ***** query
- public String getQuery() {
- return this.query;
- }
-
- public void setQuery(String query) {
- if (this.attributeValueHasChanged(this.query, query)) {
- this.query = query;
- this.queryAdapter.setValue(query);
- }
- }
-
- private void syncQuery(String annotationQuery) {
- String old = this.query;
- this.query = annotationQuery;
- this.firePropertyChanged(QUERY_PROPERTY, old, annotationQuery);
- }
-
- private String buildQuery(Annotation astAnnotation) {
- return this.queryAdapter.getValue(astAnnotation);
- }
-
- public List<TextRange> getQueryTextRanges() {
- return this.queryTextRanges;
- }
-
- private List<TextRange> buildQueryTextRanges(Annotation astAnnotation) {
- return this.getElementTextRanges(this.queryDeclarationAdapter, astAnnotation);
- }
-
- private DeclarationAnnotationElementAdapter<String> buildQueryDeclarationAdapter() {
- return ConversionDeclarationAnnotationElementAdapter.forStrings(this.daa, this.getQueryElementName());
- }
-
- private AnnotationElementAdapter<String> buildQueryAdapter() {
- return this.buildStringElementAdapter(this.queryDeclarationAdapter);
- }
+ protected abstract String getNameElementName();
- abstract String getQueryElementName();
// ***** hints
@@ -184,9 +135,9 @@ abstract class SourceQueryAnnotation
this.hintsContainer.removeNestedAnnotation(index);
}
- abstract QueryHintAnnotation buildHint(int index);
+ protected abstract QueryHintAnnotation buildHint(int index);
- abstract String getHintsElementName();
+ protected abstract String getHintsElementName();
// ********** misc **********
@@ -195,7 +146,6 @@ abstract class SourceQueryAnnotation
public boolean isUnset() {
return super.isUnset() &&
(this.name == null) &&
- (this.query == null) &&
this.hintsContainer.isEmpty();
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceQueryHintAnnotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceQueryHintAnnotation.java
index 0b1ee9c..7ac7e31 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceQueryHintAnnotation.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceQueryHintAnnotation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2013 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.
@@ -21,6 +21,7 @@ import org.eclipse.jpt.common.core.utility.jdt.AnnotationElementAdapter;
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationElementAdapter;
import org.eclipse.jpt.common.core.utility.jdt.IndexedDeclarationAnnotationAdapter;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
import org.eclipse.jpt.jpa.core.resource.java.JPA;
import org.eclipse.jpt.jpa.core.resource.java.QueryHintAnnotation;
@@ -50,6 +51,10 @@ public final class SourceQueryHintAnnotation
return buildNestedSourceQueryHintAnnotation(parent, element, buildNamedNativeQueryQueryHintAnnotationAdapter(namedNativeQueryAdapter, index));
}
+ public static SourceQueryHintAnnotation buildNamedStoredProcedureQuery2_1QueryHint(JavaResourceNode parent, AnnotatedElement element, DeclarationAnnotationAdapter namedStoredProcedureQuery2_1Adapter, int index) {
+ return buildNestedSourceQueryHintAnnotation(parent, element, buildNamedStoredProcedureQuery2_1QueryHintAnnotationAdapter(namedStoredProcedureQuery2_1Adapter, index));
+ }
+
public static SourceQueryHintAnnotation buildNestedSourceQueryHintAnnotation(
JavaResourceNode parent,
AnnotatedElement element,
@@ -193,4 +198,7 @@ public final class SourceQueryHintAnnotation
private static IndexedDeclarationAnnotationAdapter buildNamedNativeQueryQueryHintAnnotationAdapter(DeclarationAnnotationAdapter namedNativeQueryAdapter, int index) {
return new NestedIndexedDeclarationAnnotationAdapter(namedNativeQueryAdapter, JPA.NAMED_NATIVE_QUERY__HINTS, index, ANNOTATION_NAME);
}
+ private static IndexedDeclarationAnnotationAdapter buildNamedStoredProcedureQuery2_1QueryHintAnnotationAdapter(DeclarationAnnotationAdapter namedStoredProcedureQuery2_1Adapter, int index) {
+ return new NestedIndexedDeclarationAnnotationAdapter(namedStoredProcedureQuery2_1Adapter, JPA2_1.NAMED_STORED_PROCEDURE_QUERY__HINTS, index, ANNOTATION_NAME);
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/JPA2_1.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/JPA2_1.java
index 37a569f..cef9a92 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/JPA2_1.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/JPA2_1.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Oracle. All rights reserved.
+ * Copyright (c) 2012, 2013 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.
@@ -36,5 +36,27 @@ public interface JPA2_1
// JPA 2.1 annotations
String CONVERTER = PACKAGE_ + "Converter";
String CONVERTER__AUTO_APPLY = "autoApply";
+
+ String NAMED_STORED_PROCEDURE_QUERIES = PACKAGE_ + "NamedStoredProcedureQueries";
+ String NAMED_STORED_PROCEDURE_QUERIES__VALUE = "value";
+ String NAMED_STORED_PROCEDURE_QUERY =PACKAGE_ + "NamedStoredProcedureQuery";
+ String NAMED_STORED_PROCEDURE_QUERY__NAME = "name";
+ String NAMED_STORED_PROCEDURE_QUERY__PROCEDURE_NAME= "procedureName";
+ String NAMED_STORED_PROCEDURE_QUERY__PARAMETERS = "parameters";
+ String NAMED_STORED_PROCEDURE_QUERY__RESULT_CLASSES = "resultClasses";
+ String NAMED_STORED_PROCEDURE_QUERY__RESULT_SET_MAPPINGS= "resultSetMappings";
+ String NAMED_STORED_PROCEDURE_QUERY__HINTS = "hints";
+ String NAMED_STORED_PROCEDURE_PARAMETER = PACKAGE_ + "StoredProcedureParameter";
+ String NAMED_STORED_PROCEDURE_PARAMETER__NAME = "name";
+ String NAMED_STORED_PROCEDURE_PARAMETER__MODE = "mode";
+ String NAMED_STORED_PROCEDURE_PARAMETER__TYPE = "type";
+
+ // JPA 2.1 enums
+ String PARAMETER_MODE = PACKAGE_ + "ParameterMode";
+ String PARAMETER_MODE_ = PARAMETER_MODE + '.';
+ String PARAMETER_MODE__IN = PARAMETER_MODE_ + "IN";
+ String PARAMETER_MODE__INOUT = PARAMETER_MODE_ + "INOUT";
+ String PARAMETER_MODE__OUT = PARAMETER_MODE_ + "OUT";
+ String PARAMETER_MODE__REF_CURSOR= PARAMETER_MODE_ + "REF_CURSOR";
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/NamedStoredProcedureQuery2_1Annotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/NamedStoredProcedureQuery2_1Annotation.java
new file mode 100644
index 0000000..23d5317
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/NamedStoredProcedureQuery2_1Annotation.java
@@ -0,0 +1,171 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.jpa.core.jpa2_1.resource.java;
+
+import org.eclipse.jpt.common.core.utility.TextRange;
+import org.eclipse.jpt.common.utility.iterable.ListIterable;
+import org.eclipse.jpt.jpa.core.resource.java.QueryAnnotation;
+
+/**
+ * Corresponds to the JPA annotation
+ * <code>javax.persistence.NamedStoredProcedureQuery</code>
+ * <p>
+ * 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 3.3
+ * @since 3.3
+ */
+public interface NamedStoredProcedureQuery2_1Annotation
+ extends QueryAnnotation
+{
+ String ANNOTATION_NAME = JPA2_1.NAMED_STORED_PROCEDURE_QUERY;
+
+
+ // ********** procedure name **********
+
+ /**
+ * Corresponds to the 'procedureName' element of the NamedStoredProcedureQuery annotation.
+ * Return null if the element does not exist in Java.
+ */
+ String getProcedureName();
+ String PROCEDURE_NAME_PROPERTY = "procedureName"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'procedureName' element of the NamedStoredProcedureQuery annotation.
+ * Set to null to remove the element.
+ */
+ void setProcedureName(String procedureName);
+
+ /**
+ * Return the {@link TextRange} for the 'procedureName' element. If element
+ * does not exist return the {@link TextRange} for the NamedStoredProcedureQuery annotation.
+ */
+ TextRange getProcedureNameTextRange();
+
+
+ // ********** parameters **********
+
+ /**
+ * Corresponds to the 'parameters' element of the NamedStoredProcedureQuery annotation.
+ * Return an empty iterator if the element does not exist in Java.
+ */
+ ListIterable<StoredProcedureParameter2_1Annotation> getParameters();
+ String PARAMETERS_LIST = "parameters"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'parameters' element of the NamedStoredProcedureQuery annotation.
+ */
+ int getParametersSize();
+
+ /**
+ * Corresponds to the 'parameters' element of the NamedStoredProcedureQuery annotation.
+ */
+ StoredProcedureParameter2_1Annotation parameterAt(int index);
+
+ /**
+ * Corresponds to the 'parameters' element of the NamedStoredProcedureQuery annotation.
+ */
+ StoredProcedureParameter2_1Annotation addParameter(int index);
+
+ /**
+ * Corresponds to the 'parameters' element of the NamedStoredProcedureQuery annotation.
+ */
+ void moveParameter(int targetIndex, int sourceIndex);
+
+ /**
+ * Corresponds to the 'parameters' element of the NamedStoredProcedureQuery annotation.
+ */
+ void removeParameter(int index);
+
+
+ // ********** result classes **********
+
+ /**
+ * Corresponds to the 'resultClasses' element of the NamedStoredProcedureQuery annotation.
+ * Return an empty iterator if the element does not exist in Java.
+ */
+ ListIterable<String> getResultClasses();
+ String RESULT_CLASSES_LIST = "resultClasses"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'resultClasses' element of the NamedStoredProcedureQuery annotation.
+ */
+ int getResultClassesSize();
+
+ /**
+ * Corresponds to the 'resultClasses' element of the NamedStoredProcedureQuery annotation.
+ */
+ String resultClassAt(int index);
+
+ /**
+ * Corresponds to the 'resultClasses' element of the NamedStoredProcedureQuery annotation.
+ */
+ void addResultClass(String resultClass);
+
+ /**
+ * Corresponds to the 'resultClasses' element of the NamedStoredProcedureQuery annotation.
+ */
+ void moveResultClass(int targetIndex, int sourceIndex);
+
+ /**
+ * Corresponds to the 'resultClasses' element of the NamedStoredProcedureQuery annotation.
+ */
+ void removeResultClass(String resultClass);
+
+ /**
+ * Corresponds to the 'resultClasses' element of the NamedStoredProcedureQuery annotation.
+ */
+ void removeResultClass(int index);
+
+
+ // ********** result set mappings **********
+
+ /**
+ * Corresponds to the 'resultSetMappings' element of the NamedStoredProcedureQuery annotation.
+ * Return an empty iterator if the element does not exist in Java.
+ */
+ ListIterable<String> getResultSetMappings();
+ String RESULT_SET_MAPPINGS_LIST = "resultSetMappings"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'resultSetMappings' element of the NamedStoredProcedureQuery annotation.
+ */
+ int getResultSetMappingsSize();
+
+ /**
+ * Corresponds to the 'resultSetMappings' element of the NamedStoredProcedureQuery annotation.
+ */
+ String resultSetMappingAt(int index);
+
+ /**
+ * Corresponds to the 'resultSetMappings' element of the NamedStoredProcedureQuery annotation.
+ */
+ void addResultSetMapping(String resultSetMapping);
+
+ /**
+ * Corresponds to the 'resultSetMappings' element of the NamedStoredProcedureQuery annotation.
+ */
+ void moveResultSetMapping(int targetIndex, int sourceIndex);
+
+ /**
+ * Corresponds to the 'resultSetMappings' element of the NamedStoredProcedureQuery annotation.
+ */
+ void removeResultSetMapping(String resultSetMapping);
+
+ /**
+ * Corresponds to the 'resultSetMappings' element of the NamedStoredProcedureQuery annotation.
+ */
+ void removeResultSetMapping(int index);
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/ParameterMode2_1.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/ParameterMode2_1.java
new file mode 100644
index 0000000..8e4dc8c
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/ParameterMode2_1.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.jpa.core.jpa2_1.resource.java;
+
+
+/**
+ * Corresponds to the JPA 2.1 enum
+ * javax.persistence.ParameterMode
+ * <p>
+ * 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 3.3
+ * @since 3.3
+ */
+public enum ParameterMode2_1
+{
+
+ IN(JPA2_1.PARAMETER_MODE__IN),
+ INOUT(JPA2_1.PARAMETER_MODE__INOUT),
+ OUT(JPA2_1.PARAMETER_MODE__OUT),
+ REF_CURSOR(JPA2_1.PARAMETER_MODE__REF_CURSOR);
+
+
+ private String javaAnnotationValue;
+
+ ParameterMode2_1(String javaAnnotationValue) {
+ if (javaAnnotationValue == null) {
+ throw new NullPointerException();
+ }
+ this.javaAnnotationValue = javaAnnotationValue;
+ }
+
+ public String getJavaAnnotationValue() {
+ return this.javaAnnotationValue;
+ }
+
+
+ // ********** static methods **********
+
+ public static ParameterMode2_1 fromJavaAnnotationValue(Object javaAnnotationValue) {
+ return (javaAnnotationValue == null) ? null : fromJavaAnnotationValue_(javaAnnotationValue);
+ }
+
+ private static ParameterMode2_1 fromJavaAnnotationValue_(Object javaAnnotationValue) {
+ for (ParameterMode2_1 parameterMode : ParameterMode2_1.values()) {
+ if (parameterMode.getJavaAnnotationValue().equals(javaAnnotationValue)) {
+ return parameterMode;
+ }
+ }
+ return null;
+ }
+
+ public static String toJavaAnnotationValue(ParameterMode2_1 parameterMode) {
+ return (parameterMode == null) ? null : parameterMode.getJavaAnnotationValue();
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/StoredProcedureParameter2_1Annotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/StoredProcedureParameter2_1Annotation.java
new file mode 100644
index 0000000..1f0a943
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2_1/resource/java/StoredProcedureParameter2_1Annotation.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.jpa.core.jpa2_1.resource.java;
+
+import org.eclipse.jpt.common.core.resource.java.NestableAnnotation;
+import org.eclipse.jpt.common.core.utility.TextRange;
+
+/**
+ * Corresponds to the JPA annotation
+ * <code>javax.persistence.StoredProcedureParameter</code>
+ * <p>
+ * 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 3.3
+ * @since 3.3
+ */
+public interface StoredProcedureParameter2_1Annotation
+ extends NestableAnnotation
+{
+ String ANNOTATION_NAME = JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER;
+
+ // ********* name **********
+ /**
+ * Corresponds to the 'name' element of the StoredProcedureParameter annotation.
+ * Return null if the element does not exist in the annotation
+ */
+ String getName();
+ String NAME_PROPERTY = "name"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'name' element of the StoredProcedureParameter annotation.
+ * Setting to null will remove the element.
+ */
+ void setName(String name);
+
+ /**
+ * Return the {@link TextRange} for the 'name' element. If the element
+ * does not exist return the {@link TextRange} for the StoredProcedureParameter annotation.
+ */
+ TextRange getNameTextRange();
+
+ // *********** mode *************
+
+ /**
+ * Corresponds to the 'mode' element of the StoredProcedureParameter annotation.
+ * Return null if the element does not exist in the annotation
+ */
+ ParameterMode2_1 getMode();
+ String MODE_PROPERTY = "mode"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'mode' element of the StoredProcedureParameter annotation.
+ * Setting to null will remove the element.
+ */
+ void setMode(ParameterMode2_1 mode);
+
+ /**
+ * Return the {@link TextRange} for the 'mode' element. If the element
+ * does not exist return the {@link TextRange} for the StoredProcedureParameter annotation.
+ */
+ TextRange getModeTextRange();
+
+ // ********** type ***********
+
+ /**
+ * Corresponds to the 'type' element of the StoredProcedureParameter annotation.
+ * Return null if the element does not exist in the annotation
+ */
+ String getType();
+ String TYPE_PROPERTY = "type"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'type' element of the StoredProcedureParameter annotation.
+ * Setting to null will remove the element.
+ */
+ void setType(String type);
+
+ /**
+ * Return the {@link TextRange} for the 'type' element. If the element
+ * does not exist return the {@link TextRange} for the StoredProcedureParameter annotation.
+ */
+ TextRange getTypeTextRange();
+
+ /**
+ * Return the named native query's fully-qualified type name as
+ * resolved by the AST's bindings.
+ * <pre>
+ * &#64;NamedStoredProcedureQuery(type=Employee.class)
+ * </pre>
+ * will return <code>"model.Employee"</code> if there is an import for
+ * <code>model.Employee</code>.
+ */
+ String getFullyQualifiedTypeName();
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/java/NamedNativeQueryAnnotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/java/NamedNativeQueryAnnotation.java
index 67b3c2b..b87c089 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/java/NamedNativeQueryAnnotation.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/java/NamedNativeQueryAnnotation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2013 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.
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.resource.java;
+import java.util.List;
import org.eclipse.jpt.common.core.utility.TextRange;
@@ -31,6 +32,28 @@ public interface NamedNativeQueryAnnotation
String ANNOTATION_NAME = JPA.NAMED_NATIVE_QUERY;
+ // ********** query **********
+
+ /**
+ * Corresponds to the 'query' element of the *Query annotation.
+ * Return null if the element does not exist in Java.
+ */
+ String getQuery();
+ String QUERY_PROPERTY = "query"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'query' element of the *Query annotation.
+ * Set to null to remove the element.
+ */
+ void setQuery(String query);
+
+ /**
+ * Return the {@link TextRange} for the 'query' element. If element
+ * does not exist return the {@link TextRange} for the *Query annotation.
+ */
+ List<TextRange> getQueryTextRanges();
+
+
// ********** result class **********
/**
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/java/NamedQueryAnnotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/java/NamedQueryAnnotation.java
index e0c098e..b1ae05d 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/java/NamedQueryAnnotation.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/java/NamedQueryAnnotation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2013 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.
@@ -9,6 +9,9 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.resource.java;
+import java.util.List;
+import org.eclipse.jpt.common.core.utility.TextRange;
+
/**
* Corresponds to the JPA annotation
* <code>javax.persistence.NamedQuery</code>
@@ -26,4 +29,26 @@ public interface NamedQueryAnnotation
extends QueryAnnotation
{
String ANNOTATION_NAME = JPA.NAMED_QUERY;
+
+ // ********** query **********
+
+ /**
+ * Corresponds to the 'query' element of the *Query annotation.
+ * Return null if the element does not exist in Java.
+ */
+ String getQuery();
+ String QUERY_PROPERTY = "query"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'query' element of the *Query annotation.
+ * Set to null to remove the element.
+ */
+ void setQuery(String query);
+
+ /**
+ * Return the {@link TextRange} for the 'query' element. If element
+ * does not exist return the {@link TextRange} for the *Query annotation.
+ */
+ List<TextRange> getQueryTextRanges();
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/java/QueryAnnotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/java/QueryAnnotation.java
index 5a5fb99..231ab4a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/java/QueryAnnotation.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/java/QueryAnnotation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2013 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.
@@ -9,7 +9,6 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.resource.java;
-import java.util.List;
import org.eclipse.jpt.common.core.resource.java.NestableAnnotation;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.utility.iterable.ListIterable;
@@ -53,28 +52,6 @@ public interface QueryAnnotation
TextRange getNameTextRange();
- // ********** query **********
-
- /**
- * Corresponds to the 'query' element of the *Query annotation.
- * Return null if the element does not exist in Java.
- */
- String getQuery();
- String QUERY_PROPERTY = "query"; //$NON-NLS-1$
-
- /**
- * Corresponds to the 'query' element of the *Query annotation.
- * Set to null to remove the element.
- */
- void setQuery(String query);
-
- /**
- * Return the {@link TextRange} for the 'query' element. If element
- * does not exist return the {@link TextRange} for the *Query annotation.
- */
- List<TextRange> getQueryTextRanges();
-
-
// ********** hints **********
/**
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/NamedNativeQueryPropertyComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/NamedNativeQueryPropertyComposite.java
index d025568..2980f08 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/NamedNativeQueryPropertyComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/NamedNativeQueryPropertyComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2013 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.
@@ -13,8 +13,8 @@ import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jpt.common.ui.internal.widgets.ClassChooserPane;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.context.NamedNativeQuery;
import org.eclipse.jpt.jpa.core.context.Query;
import org.eclipse.swt.SWT;
@@ -121,7 +121,7 @@ public class NamedNativeQueryPropertyComposite extends Pane<NamedNativeQuery>
}
private ModifiablePropertyValueModel<String> buildQueryHolder() {
- return new PropertyAspectAdapter<NamedNativeQuery, String>(getSubjectHolder(), Query.QUERY_PROPERTY) {
+ return new PropertyAspectAdapter<NamedNativeQuery, String>(getSubjectHolder(), NamedNativeQuery.QUERY_PROPERTY) {
@Override
protected String buildValue_() {
return this.subject.getQuery();
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/NamedQueryPropertyComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/NamedQueryPropertyComposite.java
index 8bd6e2c..c9ea3d5 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/NamedQueryPropertyComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/NamedQueryPropertyComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2013 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.
@@ -83,7 +83,7 @@ public class NamedQueryPropertyComposite<T extends NamedQuery> extends Pane<T> {
}
protected ModifiablePropertyValueModel<String> buildQueryHolder() {
- return new PropertyAspectAdapter<NamedQuery, String>(getSubjectHolder(), Query.QUERY_PROPERTY) {
+ return new PropertyAspectAdapter<NamedQuery, String>(getSubjectHolder(), NamedQuery.QUERY_PROPERTY) {
@Override
protected String buildValue_() {
return this.subject.getQuery();
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/NamedQueryProperty2_0Composite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/NamedQueryProperty2_0Composite.java
index 7b63d6b..b438609 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/NamedQueryProperty2_0Composite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/NamedQueryProperty2_0Composite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2009, 2012 Oracle. All rights reserved.
+* Copyright (c) 2009, 2013 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.
@@ -16,6 +16,7 @@ import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.JpaPreferences;
+import org.eclipse.jpt.jpa.core.context.NamedQuery;
import org.eclipse.jpt.jpa.core.context.Query;
import org.eclipse.jpt.jpa.core.jpa2.context.LockModeType2_0;
import org.eclipse.jpt.jpa.core.jpa2.context.NamedQuery2_0;
@@ -91,7 +92,7 @@ public class NamedQueryProperty2_0Composite extends Pane<NamedQuery2_0> {
}
protected ModifiablePropertyValueModel<String> buildQueryHolder() {
- return new PropertyAspectAdapter<NamedQuery2_0, String>(getSubjectHolder(), Query.QUERY_PROPERTY) {
+ return new PropertyAspectAdapter<NamedQuery2_0, String>(getSubjectHolder(), NamedQuery.QUERY_PROPERTY) {
@Override
protected String buildValue_() {
return this.subject.getQuery();
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/JavaResource2_1Tests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/JavaResource2_1Tests.java
new file mode 100644
index 0000000..d36f879
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/JavaResource2_1Tests.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.jpa.core.tests.internal.jpa2_1.resource.java;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class JavaResource2_1Tests
+{
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(JavaResource2_1Tests.class.getPackage().getName());
+
+ suite.addTestSuite(NamedStoredProcedureQuery2_1AnnotationTests.class);
+ suite.addTestSuite(NamedStoredProcedureQueries2_1AnnotationTests.class);
+ suite.addTestSuite(StoredProcedureParameter2_1AnnotationTests.class);
+
+ return suite;
+ }
+
+ private JavaResource2_1Tests() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/JavaResourceModel2_1TestCase.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/JavaResourceModel2_1TestCase.java
new file mode 100644
index 0000000..440bb69
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/JavaResourceModel2_1TestCase.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.jpa.core.tests.internal.jpa2_1.resource.java;
+
+import org.eclipse.jpt.common.core.AnnotationProvider;
+import org.eclipse.jpt.jpa.core.internal.JpaAnnotationProvider;
+import org.eclipse.jpt.jpa.core.internal.jpa2_1.Generic2_1JpaAnnotationDefinitionProvider;
+import org.eclipse.jpt.jpa.core.tests.internal.resource.java.JpaJavaResourceModelTestCase;
+
+public class JavaResourceModel2_1TestCase
+ extends JpaJavaResourceModelTestCase
+{
+
+
+ public JavaResourceModel2_1TestCase(String name) {
+ super(name);
+ }
+
+ @Override
+ protected AnnotationProvider buildAnnotationProvider() {
+ return new JpaAnnotationProvider(
+ Generic2_1JpaAnnotationDefinitionProvider.instance());
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/NamedStoredProcedureQueries2_1AnnotationTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/NamedStoredProcedureQueries2_1AnnotationTests.java
new file mode 100644
index 0000000..d371f5e
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/NamedStoredProcedureQueries2_1AnnotationTests.java
@@ -0,0 +1,370 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.jpa.core.tests.internal.jpa2_1.resource.java;
+
+import java.util.Iterator;
+import java.util.ListIterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
+import org.eclipse.jpt.common.core.resource.java.NestableAnnotation;
+import org.eclipse.jpt.common.utility.internal.iterator.ArrayIterator;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.NamedStoredProcedureQuery2_1Annotation;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.StoredProcedureParameter2_1Annotation;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.QueryHintAnnotation;
+
+@SuppressWarnings("nls")
+public class NamedStoredProcedureQueries2_1AnnotationTests
+ extends JavaResourceModel2_1TestCase
+{
+
+ private static final String QUERY_NAME = "myQuery";
+ private static final String QUERY_PROCEDURE_NAME = "myProcedure";
+
+ public NamedStoredProcedureQueries2_1AnnotationTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTestNamedStoredProcedureQueries() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@NamedStoredProcedureQueries(@NamedStoredProcedureQuery)");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestNamedStoredProcedureQueryWithName() throws Exception {
+ return createTestQueryWithStringElement("name", QUERY_NAME);
+ }
+
+ private ICompilationUnit createTestNamedStoredProcedureQueryWithProcedureName() throws Exception {
+ return createTestQueryWithStringElement("procedureName", QUERY_PROCEDURE_NAME);
+ }
+
+ private ICompilationUnit createTestQueryWithStringElement(final String elementName, final String value) throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@NamedStoredProcedureQueries(@NamedStoredProcedureQuery(" + elementName + " = \"" + value + "\"))");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestNamedStoredProcedureQueryWithParameters() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES, JPA2_1.NAMED_STORED_PROCEDURE_QUERY, JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER, JPA2_1.PARAMETER_MODE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@NamedStoredProcedureQueries(@NamedStoredProcedureQuery(parameters = {@StoredProcedureParameter(name = \"BAR\", " +
+ "mode=ParameterMode.IN, type=Integer.class), @StoredProcedureParameter}))");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestNamedStoredProcedureQueryWithResultClasses() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@NamedStoredProcedureQueries(@NamedStoredProcedureQuery(resultClasses={Employee.class, Address.class})");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestNamedStoredProcedureQueryWithResultSetMappings() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@NamedStoredProcedureQueries(@NamedStoredProcedureQuery(resultSetMappings={\"EmployeeResultSetMapping\", \"AddressResultSetMapping\"})");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestNamedStoredProcedureQueryWithHints() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES, JPA2_1.NAMED_STORED_PROCEDURE_QUERY, JPA.QUERY_HINT);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@NamedStoredProcedureQueries(@NamedStoredProcedureQuery(hints = {@QueryHint(name = \"BAR\", value = \"FOO\"), @QueryHint}))");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestNamedStoredProcedureQuery() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERY, JPA.QUERY_HINT);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@NamedStoredProcedureQuery(name = \"foo\", hints = @QueryHint(name = \"BAR\", value = \"FOO\"))");
+ }
+ });
+ }
+
+ public void testNamedStoredProcedureQuery() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueries();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ assertNotNull(namedQuery);
+ }
+
+ // ******** name *********
+
+ public void testGetName() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithName();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ assertEquals(QUERY_NAME, namedQuery.getName());
+ }
+
+ public void testSetName() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithName();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ assertEquals(QUERY_NAME, namedQuery.getName());
+
+ namedQuery.setName("foo");
+ assertEquals("foo", namedQuery.getName());
+
+ assertSourceContains("@NamedStoredProcedureQuery(name = \"foo\")", cu);
+
+ namedQuery.setName(null);
+ assertNull(namedQuery.getName());
+
+ assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
+ }
+
+ // ********** procedure name ************
+
+ public void testGetProcedureName() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithProcedureName();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ assertEquals(QUERY_PROCEDURE_NAME, namedQuery.getProcedureName());
+ }
+
+ public void testSetProcedureName() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithProcedureName();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ assertEquals(QUERY_PROCEDURE_NAME, namedQuery.getProcedureName());
+
+ namedQuery.setProcedureName("foo");
+ assertEquals("foo", namedQuery.getProcedureName());
+
+ assertSourceContains("@NamedStoredProcedureQuery(procedureName = \"foo\")", cu);
+
+ namedQuery.setProcedureName(null);
+ assertNull(namedQuery.getProcedureName());
+
+ assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
+ }
+
+ // *********** parameters *********
+
+ public void testParameters1() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueries();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ assertEquals(0, namedQuery.getParametersSize());
+ }
+
+ public void testParameters2() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ assertEquals(2, namedQuery.getParametersSize());
+
+ ListIterator<StoredProcedureParameter2_1Annotation> iterator = namedQuery.getParameters().iterator();
+ assertEquals("BAR", iterator.next().getName());
+ assertNull(iterator.next().getName());
+ }
+
+ // *********** result classes *******
+
+ public void testResultClasses1() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueries();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ assertEquals(0, namedQuery.getResultClassesSize());
+ }
+
+ public void testResultClasses2() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultClasses();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ assertEquals(2, namedQuery.getResultClassesSize());
+
+ ListIterator<String> iterator = namedQuery.getResultClasses().iterator();
+ assertEquals("Employee", iterator.next());
+ assertEquals("Address", iterator.next());
+
+ }
+
+ // ********** result set mappings ********
+
+ public void testResultSetMappings1() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueries();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ assertEquals(0, namedQuery.getResultSetMappingsSize());
+ }
+
+ public void testResultSetMappings2() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultSetMappings();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ assertEquals(2, namedQuery.getResultSetMappingsSize());
+
+ ListIterator<String> iterator = namedQuery.getResultSetMappings().iterator();
+ assertEquals("EmployeeResultSetMapping", iterator.next());
+ assertEquals("AddressResultSetMapping", iterator.next());
+
+ }
+
+ // *********** hints ********
+
+ public void testHints1() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueries();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ assertEquals(0, namedQuery.getHintsSize());
+ }
+
+ public void testHints2() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithHints();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ assertEquals(2, namedQuery.getHintsSize());
+
+ ListIterator<QueryHintAnnotation> iterator = namedQuery.getHints().iterator();
+ assertEquals("BAR", iterator.next().getName());
+ assertNull(iterator.next().getName());
+ }
+
+ // ********** other tests ********
+
+ public void testAddNamedQueryCopyExisting() throws Exception {
+ ICompilationUnit cu = createTestNamedStoredProcedureQuery();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ String expected1 = "@NamedStoredProcedureQueries({";
+ String expected2 = "@NamedStoredProcedureQuery(name = \"foo\", hints = @QueryHint(name = \"BAR\", value = \"FOO\")),";
+ String expected3 = "@NamedStoredProcedureQuery(name = \"BAR\") })";
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.addAnnotation(1, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ namedQuery.setName("BAR");
+ assertSourceContains(expected1, cu);
+ assertSourceContains(expected2, cu);
+ assertSourceContains(expected3, cu);
+
+ assertNull(resourceType.getAnnotation(JPA2_1.NAMED_STORED_PROCEDURE_QUERY));
+ assertNotNull(resourceType.getContainerAnnotation(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES));
+ assertNotNull(resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY));
+ assertEquals(2, resourceType.getAnnotationsSize(JPA2_1.NAMED_STORED_PROCEDURE_QUERY));
+ }
+
+ public void testAddNamedQueryToBeginningOfList() throws Exception {
+ ICompilationUnit cu = createTestNamedStoredProcedureQuery();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ String expected1 = "@NamedStoredProcedureQueries({";
+ String expected2 = "@NamedStoredProcedureQuery(name = \"foo\", hints = @QueryHint(name = \"BAR\", value = \"FOO\")),";
+ String expected3 = "@NamedStoredProcedureQuery(name = \"BAR\") })";
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.addAnnotation(1, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ namedQuery.setName("BAR");
+ assertSourceContains(expected1, cu);
+ assertSourceContains(expected2, cu);
+ assertSourceContains(expected3, cu);
+
+ expected2 = "@NamedStoredProcedureQuery(name = \"BAZ\"),";
+ expected3 = "@NamedStoredProcedureQuery(name = \"foo\", hints = @QueryHint(name = \"BAR\", value = \"FOO\")), @NamedStoredProcedureQuery(name = \"BAR\") })";
+ namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.addAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ namedQuery.setName("BAZ");
+ assertSourceContains(expected1, cu);
+ assertSourceContains(expected2, cu);
+ assertSourceContains(expected3, cu);
+
+ Iterator<NestableAnnotation> namedQueries = resourceType.getAnnotations(JPA2_1.NAMED_STORED_PROCEDURE_QUERY).iterator();
+ assertEquals("BAZ", ((NamedStoredProcedureQuery2_1Annotation) namedQueries.next()).getName());
+ assertEquals("foo", ((NamedStoredProcedureQuery2_1Annotation) namedQueries.next()).getName());
+ assertEquals("BAR", ((NamedStoredProcedureQuery2_1Annotation) namedQueries.next()).getName());
+
+ assertNull(resourceType.getAnnotation(JPA2_1.NAMED_STORED_PROCEDURE_QUERY));
+ assertNotNull(resourceType.getContainerAnnotation(JPA2_1.NAMED_STORED_PROCEDURE_QUERIES));
+ assertNotNull(resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY));
+ assertEquals(3, resourceType.getAnnotationsSize(JPA2_1.NAMED_STORED_PROCEDURE_QUERY));
+ }
+
+ public void testRemoveNamedQueryCopyExisting() throws Exception {
+ ICompilationUnit cu = createTestNamedStoredProcedureQuery();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ String expected1 = "@NamedStoredProcedureQueries({";
+ String expected2 = "@NamedStoredProcedureQuery(name = \"foo\", hints = @QueryHint(name = \"BAR\", value = \"FOO\")),";
+ String expected3 = "@NamedStoredProcedureQuery(name = \"BAR\") })";
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.addAnnotation(1, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ namedQuery.setName("BAR");
+ assertSourceContains(expected1, cu);
+ assertSourceContains(expected2, cu);
+ assertSourceContains(expected3, cu);
+
+ expected1 = "@NamedStoredProcedureQuery(name = \"foo\", hints = @QueryHint(name = \"BAR\", value = \"FOO\"))";
+ resourceType.removeAnnotation(1, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ assertSourceContains(expected1, cu);
+ assertSourceDoesNotContain("@NamedStoredProcedureQueries", cu);
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/NamedStoredProcedureQuery2_1AnnotationTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/NamedStoredProcedureQuery2_1AnnotationTests.java
new file mode 100644
index 0000000..77c5b6a
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/NamedStoredProcedureQuery2_1AnnotationTests.java
@@ -0,0 +1,723 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.jpa.core.tests.internal.jpa2_1.resource.java;
+
+import java.util.Iterator;
+import java.util.ListIterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
+import org.eclipse.jpt.common.utility.internal.iterator.ArrayIterator;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.NamedStoredProcedureQuery2_1Annotation;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.StoredProcedureParameter2_1Annotation;
+import org.eclipse.jpt.jpa.core.resource.java.JPA;
+import org.eclipse.jpt.jpa.core.resource.java.QueryHintAnnotation;
+
+@SuppressWarnings("nls")
+public class NamedStoredProcedureQuery2_1AnnotationTests
+ extends JavaResourceModel2_1TestCase
+{
+
+ private static final String QUERY_NAME = "myQuery";
+ private static final String PROCEDURE_NAME = "myProcedure";
+
+ public NamedStoredProcedureQuery2_1AnnotationTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTestNamedStoredProcedureQuery() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@NamedStoredProcedureQuery");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestNamedStoredProcedureQueryWithName() throws Exception {
+ return createTestNamedStoredProcedureQueryWithStringElement("name", QUERY_NAME);
+ }
+
+ private ICompilationUnit createTestNamedNativeQueryWithProcedureName() throws Exception {
+ return createTestNamedStoredProcedureQueryWithStringElement("procedureName", PROCEDURE_NAME);
+ }
+
+
+ private ICompilationUnit createTestNamedStoredProcedureQueryWithStringElement(final String elementName, final String value) throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@NamedStoredProcedureQuery(" + elementName + " = \"" + value + "\")");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestNamedStoredProcedureQueryWithParameters() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERY, JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER, JPA2_1.PARAMETER_MODE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@NamedStoredProcedureQuery(parameters = {@StoredProcedureParameter(name = \"BAR\", " +
+ "mode=ParameterMode.IN, type=Integer.class), @StoredProcedureParameter})");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestNamedStoredProcedureQueryWithResultClasses() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@NamedStoredProcedureQuery(resultClasses = { Employee.class, Address.class })");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestNamedStoredProcedureQueryWithResultSetMappings() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@NamedStoredProcedureQuery(resultSetMappings = { \"EmpRSMapping\", \"AddrRSMapping\" })");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestNamedStoredProcedureQueryWithHints() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERY, JPA.QUERY_HINT);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@NamedStoredProcedureQuery(hints = {@QueryHint(name = \"BAR\", value = \"FOO\"), @QueryHint})");
+ }
+ });
+ }
+
+ public void testNamedStoredProcedureQuery() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ assertNotNull(namedQuery);
+ }
+
+ // ************ name ***********
+
+ public void testGetName() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithName();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ assertEquals(QUERY_NAME, namedQuery.getName());
+ }
+
+ public void testSetName() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithName();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ assertEquals(QUERY_NAME, namedQuery.getName());
+
+ namedQuery.setName("foo");
+ assertEquals("foo", namedQuery.getName());
+
+ assertSourceContains("@NamedStoredProcedureQuery(name = \"foo\")", cu);
+
+ namedQuery.setName(null);
+ assertNull(namedQuery.getName());
+
+ assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
+ }
+
+ // ************ procedure name ***************
+
+ public void testGetProcedureName() throws Exception {
+ ICompilationUnit cu = this.createTestNamedNativeQueryWithProcedureName();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ assertEquals(PROCEDURE_NAME, namedQuery.getProcedureName());
+ }
+
+ public void testSetProcedureName() throws Exception {
+ ICompilationUnit cu = this.createTestNamedNativeQueryWithProcedureName();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ assertEquals(PROCEDURE_NAME, namedQuery.getProcedureName());
+
+ namedQuery.setProcedureName("foo");
+ assertEquals("foo", namedQuery.getProcedureName());
+
+ assertSourceContains("@NamedStoredProcedureQuery(procedureName = \"foo\")", cu);
+
+ namedQuery.setProcedureName(null);
+ assertNull(namedQuery.getProcedureName());
+
+ assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
+ }
+
+ // ************ parameters *********
+
+ public void testParameters1() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ assertEquals(0, namedQuery.getParametersSize());
+ }
+
+ public void testParameters2() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ namedQuery.addParameter(0);
+ namedQuery.addParameter(1);
+
+ assertEquals(2, namedQuery.getParametersSize());
+ }
+
+ public void testParameters3() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ assertEquals(2, namedQuery.getParametersSize());
+
+ ListIterator<StoredProcedureParameter2_1Annotation> iterator = namedQuery.getParameters().iterator();
+ assertEquals("BAR", iterator.next().getName());
+ assertNull(iterator.next().getName());
+ }
+
+ public void testAddParameter() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ namedQuery.addParameter(0).setName("FOO");
+ namedQuery.addParameter(1);
+ namedQuery.addParameter(0).setName("BAR");
+
+ assertEquals("BAR", namedQuery.parameterAt(0).getName());
+ assertEquals("FOO", namedQuery.parameterAt(1).getName());
+ assertNull(namedQuery.parameterAt(2).getName());
+ assertSourceContains("@NamedStoredProcedureQuery(parameters = {@StoredProcedureParameter(name = \"BAR\")," +
+ "@StoredProcedureParameter(name = \"FOO\"), @StoredProcedureParameter})", cu);
+ }
+
+ public void testRemoveParameter() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ namedQuery.addParameter(0).setName("BAZ");
+
+ assertEquals("BAZ", namedQuery.parameterAt(0).getName());
+ assertEquals("BAR", namedQuery.parameterAt(1).getName());
+ assertNull(namedQuery.parameterAt(2).getName());
+ assertEquals(3, namedQuery.getParametersSize());
+
+ namedQuery.removeParameter(2);
+ assertEquals("BAZ", namedQuery.parameterAt(0).getName());
+ assertEquals("BAR", namedQuery.parameterAt(1).getName());
+ assertEquals(2, namedQuery.getParametersSize());
+ assertSourceContains("@NamedStoredProcedureQuery(parameters = {@StoredProcedureParameter(name = \"BAZ\"), " +
+ "@StoredProcedureParameter(name = \"BAR\", mode=ParameterMode.IN, type=Integer.class)})", cu);
+
+ namedQuery.removeParameter(0);
+ assertEquals("BAR", namedQuery.parameterAt(0).getName());
+ assertEquals(1, namedQuery.getParametersSize());
+ assertSourceContains("@NamedStoredProcedureQuery(parameters = " +
+ "@StoredProcedureParameter(name = \"BAR\", mode=ParameterMode.IN, type=Integer.class))", cu);
+
+ namedQuery.removeParameter(0);
+ assertEquals(0, namedQuery.getParametersSize());
+ assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
+ }
+
+ public void testMoveParameter1() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ namedQuery.addParameter(0).setName("BAZ");
+
+ assertEquals("BAZ", namedQuery.parameterAt(0).getName());
+ assertEquals("BAR", namedQuery.parameterAt(1).getName());
+ assertNull(namedQuery.parameterAt(2).getName());
+ assertEquals(3, namedQuery.getParametersSize());
+
+ namedQuery.moveParameter(2, 0);
+
+ assertEquals("BAR", namedQuery.parameterAt(0).getName());
+ assertNull(namedQuery.parameterAt(1).getName());
+ assertEquals("BAZ", namedQuery.parameterAt(2).getName());
+ assertEquals(3, namedQuery.getParametersSize());
+ assertSourceContains("@NamedStoredProcedureQuery(parameters = {@StoredProcedureParameter(name = \"BAR\", mode=ParameterMode.IN, type=Integer.class), " +
+ "@StoredProcedureParameter, @StoredProcedureParameter(name = \"BAZ\")})", cu);
+ }
+
+ public void testMoveParameter2() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ namedQuery.addParameter(0).setName("BAZ");
+
+ assertEquals("BAZ", namedQuery.parameterAt(0).getName());
+ assertEquals("BAR", namedQuery.parameterAt(1).getName());
+ assertNull(namedQuery.parameterAt(2).getName());
+ assertEquals(3, namedQuery.getParametersSize());
+
+ namedQuery.moveParameter(0, 2);
+
+ assertNull(namedQuery.parameterAt(0).getName());
+ assertEquals("BAZ", namedQuery.parameterAt(1).getName());
+ assertEquals("BAR", namedQuery.parameterAt(2).getName());
+ assertEquals(3, namedQuery.getParametersSize());
+ assertSourceContains("@NamedStoredProcedureQuery(parameters = {@StoredProcedureParameter, @StoredProcedureParameter(name = \"BAZ\"), " +
+ "@StoredProcedureParameter(name = \"BAR\", mode=ParameterMode.IN, type=Integer.class)})", cu);
+ }
+
+ // ************ result classes *********
+
+ public void testResultClasses1() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ assertEquals(0, namedQuery.getResultClassesSize());
+ }
+
+ public void testResultClasses2() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultClasses();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ assertEquals(2, namedQuery.getResultClassesSize());
+
+ ListIterator<String> iterator = namedQuery.getResultClasses().iterator();
+ assertEquals("Employee", iterator.next());
+ assertEquals("Address", iterator.next());
+ }
+
+ public void testAddResultClass() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ namedQuery.addResultClass("Project");
+ namedQuery.addResultClass("Phone");
+
+ assertEquals(2, namedQuery.getResultClassesSize());
+
+ assertEquals("Project", namedQuery.resultClassAt(0));
+ assertEquals("Phone", namedQuery.resultClassAt(1));
+ assertSourceContains("@NamedStoredProcedureQuery(resultClasses = { Project.class, Phone.class })", cu);
+ }
+
+ public void testRemoveResultClass1() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultClasses();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ namedQuery.addResultClass("Project");
+
+ assertEquals("Employee", namedQuery.resultClassAt(0));
+ assertEquals("Address", namedQuery.resultClassAt(1));
+ assertEquals("Project", namedQuery.resultClassAt(2));
+ assertEquals(3, namedQuery.getResultClassesSize());
+
+ namedQuery.removeResultClass(1);
+ assertEquals("Employee", namedQuery.resultClassAt(0));
+ assertEquals("Project", namedQuery.resultClassAt(1));
+ assertEquals(2, namedQuery.getResultClassesSize());
+ assertSourceContains("@NamedStoredProcedureQuery(resultClasses = { Employee.class, Project.class })", cu);
+
+ namedQuery.removeResultClass(0);
+ assertEquals("Project", namedQuery.resultClassAt(0));
+ assertEquals(1, namedQuery.getResultClassesSize());
+ assertSourceContains("@NamedStoredProcedureQuery(resultClasses = Project.class)", cu);
+
+ namedQuery.removeResultClass(0);
+ assertEquals(0, namedQuery.getResultClassesSize());
+ assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
+ }
+
+ public void testRemoveResultClass2() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultClasses();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ namedQuery.addResultClass("Project");
+
+ assertEquals("Employee", namedQuery.resultClassAt(0));
+ assertEquals("Address", namedQuery.resultClassAt(1));
+ assertEquals("Project", namedQuery.resultClassAt(2));
+ assertEquals(3, namedQuery.getResultClassesSize());
+
+ namedQuery.removeResultClass("Address");
+ assertEquals("Employee", namedQuery.resultClassAt(0));
+ assertEquals("Project", namedQuery.resultClassAt(1));
+ assertEquals(2, namedQuery.getResultClassesSize());
+ assertSourceContains("@NamedStoredProcedureQuery(resultClasses = { Employee.class, Project.class })", cu);
+
+ namedQuery.removeResultClass("Employee");
+ assertEquals("Project", namedQuery.resultClassAt(0));
+ assertEquals(1, namedQuery.getResultClassesSize());
+ assertSourceContains("@NamedStoredProcedureQuery(resultClasses = Project.class)", cu);
+
+ namedQuery.removeResultClass("Project");
+ assertEquals(0, namedQuery.getResultClassesSize());
+ assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
+ }
+
+ public void testMoveResultClass1() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultClasses();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ namedQuery.addResultClass("Project");
+
+ assertEquals("Employee", namedQuery.resultClassAt(0));
+ assertEquals("Address", namedQuery.resultClassAt(1));
+ assertEquals("Project", namedQuery.resultClassAt(2));
+ assertEquals(3, namedQuery.getResultClassesSize());
+
+ namedQuery.moveResultClass(2, 0);
+
+ assertEquals("Address", namedQuery.resultClassAt(0));
+ assertEquals("Project", namedQuery.resultClassAt(1));
+ assertEquals("Employee", namedQuery.resultClassAt(2));
+ assertEquals(3, namedQuery.getResultClassesSize());
+ assertSourceContains("@NamedStoredProcedureQuery(resultClasses = { Address.class, Project.class, Employee.class })", cu);
+ }
+
+ public void testMoveResultClass2() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultClasses();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ namedQuery.addResultClass("Project");
+
+ assertEquals("Employee", namedQuery.resultClassAt(0));
+ assertEquals("Address", namedQuery.resultClassAt(1));
+ assertEquals("Project", namedQuery.resultClassAt(2));
+ assertEquals(3, namedQuery.getResultClassesSize());
+
+ namedQuery.moveResultClass(0, 2);
+
+ assertEquals("Project", namedQuery.resultClassAt(0));
+ assertEquals("Employee", namedQuery.resultClassAt(1));
+ assertEquals("Address", namedQuery.resultClassAt(2));
+ assertEquals(3, namedQuery.getResultClassesSize());
+ assertSourceContains("@NamedStoredProcedureQuery(resultClasses = { Project.class, Employee.class, Address.class })", cu);
+ }
+
+
+ // ************ result set mappings *********
+
+ public void testResultSetMappings1() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ assertEquals(0, namedQuery.getResultSetMappingsSize());
+ }
+
+ public void testResultSetMappings2() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultSetMappings();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ assertEquals(2, namedQuery.getResultSetMappingsSize());
+
+ ListIterator<String> iterator = namedQuery.getResultSetMappings().iterator();
+ assertEquals("EmpRSMapping", iterator.next());
+ assertEquals("AddrRSMapping", iterator.next());
+ assertSourceContains("@NamedStoredProcedureQuery(resultSetMappings = { \"EmpRSMapping\", \"AddrRSMapping\" })", cu);
+ }
+
+ public void testAddResultSetMapping() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ namedQuery.addResultSetMapping("ProjRSMapping");
+ namedQuery.addResultSetMapping("PhRSMapping");
+
+ assertEquals(2, namedQuery.getResultSetMappingsSize());
+
+ assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(0));
+ assertEquals("PhRSMapping", namedQuery.resultSetMappingAt(1));
+ assertSourceContains("@NamedStoredProcedureQuery(resultSetMappings = { \"ProjRSMapping\", \"PhRSMapping\" })", cu);
+ }
+
+ public void testRemoveResultSetMapping1() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultSetMappings();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ namedQuery.addResultSetMapping("ProjRSMapping");
+
+ assertEquals("EmpRSMapping", namedQuery.resultSetMappingAt(0));
+ assertEquals("AddrRSMapping", namedQuery.resultSetMappingAt(1));
+ assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(2));
+ assertEquals(3, namedQuery.getResultSetMappingsSize());
+
+ namedQuery.removeResultSetMapping(1);
+ assertEquals("EmpRSMapping", namedQuery.resultSetMappingAt(0));
+ assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(1));
+ assertEquals(2, namedQuery.getResultSetMappingsSize());
+ assertSourceContains("@NamedStoredProcedureQuery(resultSetMappings = { \"EmpRSMapping\", \"ProjRSMapping\" })", cu);
+
+ namedQuery.removeResultSetMapping(0);
+ assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(0));
+ assertEquals(1, namedQuery.getResultSetMappingsSize());
+ assertSourceContains("@NamedStoredProcedureQuery(resultSetMappings = \"ProjRSMapping\")", cu);
+
+ namedQuery.removeResultSetMapping(0);
+ assertEquals(0, namedQuery.getResultSetMappingsSize());
+ assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
+ }
+
+ public void testRemoveResultSetMapping2() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultSetMappings();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ namedQuery.addResultSetMapping("ProjRSMapping");
+
+ assertEquals("EmpRSMapping", namedQuery.resultSetMappingAt(0));
+ assertEquals("AddrRSMapping", namedQuery.resultSetMappingAt(1));
+ assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(2));
+ assertEquals(3, namedQuery.getResultSetMappingsSize());
+
+ namedQuery.removeResultSetMapping("AddrRSMapping");
+ assertEquals("EmpRSMapping", namedQuery.resultSetMappingAt(0));
+ assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(1));
+ assertEquals(2, namedQuery.getResultSetMappingsSize());
+ assertSourceContains("@NamedStoredProcedureQuery(resultSetMappings = { \"EmpRSMapping\", \"ProjRSMapping\" })", cu);
+
+ namedQuery.removeResultSetMapping("EmpRSMapping");
+ assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(0));
+ assertEquals(1, namedQuery.getResultSetMappingsSize());
+ assertSourceContains("@NamedStoredProcedureQuery(resultSetMappings = \"ProjRSMapping\")", cu);
+
+ namedQuery.removeResultSetMapping("ProjRSMapping");
+ assertEquals(0, namedQuery.getResultSetMappingsSize());
+ assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
+ }
+ public void testMoveResultSetMapping1() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultSetMappings();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ namedQuery.addResultSetMapping("ProjRSMapping");
+
+ assertEquals("EmpRSMapping", namedQuery.resultSetMappingAt(0));
+ assertEquals("AddrRSMapping", namedQuery.resultSetMappingAt(1));
+ assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(2));
+ assertEquals(3, namedQuery.getResultSetMappingsSize());
+
+ namedQuery.moveResultSetMapping(2, 0);
+
+ assertEquals("AddrRSMapping", namedQuery.resultSetMappingAt(0));
+ assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(1));
+ assertEquals("EmpRSMapping", namedQuery.resultSetMappingAt(2));
+ assertEquals(3, namedQuery.getResultSetMappingsSize());
+ assertSourceContains("@NamedStoredProcedureQuery(resultSetMappings = { \"AddrRSMapping\", \"ProjRSMapping\", \"EmpRSMapping\" })", cu);
+ }
+
+ public void testMoveResultSetMapping2() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithResultSetMappings();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ namedQuery.addResultSetMapping("ProjRSMapping");
+
+ assertEquals("EmpRSMapping", namedQuery.resultSetMappingAt(0));
+ assertEquals("AddrRSMapping", namedQuery.resultSetMappingAt(1));
+ assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(2));
+ assertEquals(3, namedQuery.getResultSetMappingsSize());
+
+ namedQuery.moveResultSetMapping(0, 2);
+
+ assertEquals("ProjRSMapping", namedQuery.resultSetMappingAt(0));
+ assertEquals("EmpRSMapping", namedQuery.resultSetMappingAt(1));
+ assertEquals("AddrRSMapping", namedQuery.resultSetMappingAt(2));
+ assertEquals(3, namedQuery.getResultSetMappingsSize());
+ assertSourceContains("@NamedStoredProcedureQuery(resultSetMappings = { \"ProjRSMapping\", \"EmpRSMapping\", \"AddrRSMapping\" })", cu);
+ }
+
+ // *********** hints ************
+
+ public void testHints1() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ assertEquals(0, namedQuery.getHintsSize());
+ }
+
+ public void testHints2() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ namedQuery.addHint(0);
+ namedQuery.addHint(1);
+
+ assertEquals(2, namedQuery.getHintsSize());
+ }
+
+ public void testHints3() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithHints();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ assertEquals(2, namedQuery.getHintsSize());
+
+ ListIterator<QueryHintAnnotation> iterator = namedQuery.getHints().iterator();
+ assertEquals("BAR", iterator.next().getName());
+ assertNull(iterator.next().getName());
+ }
+
+ public void testAddHint() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQuery();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ namedQuery.addHint(0).setName("FOO");
+ namedQuery.addHint(1);
+ namedQuery.addHint(0).setName("BAR");
+
+ assertEquals("BAR", namedQuery.hintAt(0).getName());
+ assertEquals("FOO", namedQuery.hintAt(1).getName());
+ assertNull(namedQuery.hintAt(2).getName());
+ assertSourceContains("@NamedStoredProcedureQuery(hints = {@QueryHint(name = \"BAR\"),@QueryHint(name = \"FOO\"), @QueryHint})", cu);
+ }
+
+ public void testRemoveHint() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithHints();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ namedQuery.addHint(0).setName("BAZ");
+
+ assertEquals("BAZ", namedQuery.hintAt(0).getName());
+ assertEquals("BAR", namedQuery.hintAt(1).getName());
+ assertNull(namedQuery.hintAt(2).getName());
+ assertEquals(3, namedQuery.getHintsSize());
+
+ namedQuery.removeHint(2);
+ assertEquals("BAZ", namedQuery.hintAt(0).getName());
+ assertEquals("BAR", namedQuery.hintAt(1).getName());
+ assertEquals(2, namedQuery.getHintsSize());
+ assertSourceContains("@NamedStoredProcedureQuery(hints = {@QueryHint(name = \"BAZ\"), @QueryHint(name = \"BAR\", value = \"FOO\")})", cu);
+
+ namedQuery.removeHint(0);
+ assertEquals("BAR", namedQuery.hintAt(0).getName());
+ assertEquals(1, namedQuery.getHintsSize());
+ assertSourceContains("@NamedStoredProcedureQuery(hints = @QueryHint(name = \"BAR\", value = \"FOO\"))", cu);
+
+
+ namedQuery.removeHint(0);
+ assertEquals(0, namedQuery.getHintsSize());
+ assertSourceDoesNotContain("@NamedStoredProcedureQuery(", cu);
+ }
+
+ public void testMoveHint1() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithHints();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+
+ namedQuery.addHint(0).setName("BAZ");
+
+ assertEquals("BAZ", namedQuery.hintAt(0).getName());
+ assertEquals("BAR", namedQuery.hintAt(1).getName());
+ assertNull(namedQuery.hintAt(2).getName());
+ assertEquals(3, namedQuery.getHintsSize());
+
+ namedQuery.moveHint(2, 0);
+
+ assertEquals("BAR", namedQuery.hintAt(0).getName());
+ assertNull(namedQuery.hintAt(1).getName());
+ assertEquals("BAZ", namedQuery.hintAt(2).getName());
+ assertEquals(3, namedQuery.getHintsSize());
+ assertSourceContains("@NamedStoredProcedureQuery(hints = {@QueryHint(name = \"BAR\", value = \"FOO\"), @QueryHint, @QueryHint(name = \"BAZ\")})", cu);
+ }
+
+ public void testMoveHint2() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithHints();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ namedQuery.addHint(0).setName("BAZ");
+
+ assertEquals("BAZ", namedQuery.hintAt(0).getName());
+ assertEquals("BAR", namedQuery.hintAt(1).getName());
+ assertNull(namedQuery.hintAt(2).getName());
+ assertEquals(3, namedQuery.getHintsSize());
+
+ namedQuery.moveHint(0, 2);
+
+ assertNull(namedQuery.hintAt(0).getName());
+ assertEquals("BAZ", namedQuery.hintAt(1).getName());
+ assertEquals("BAR", namedQuery.hintAt(2).getName());
+ assertEquals(3, namedQuery.getHintsSize());
+ assertSourceContains("@NamedStoredProcedureQuery(hints = {@QueryHint, @QueryHint(name = \"BAZ\"), @QueryHint(name = \"BAR\", value = \"FOO\")})", cu);
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/StoredProcedureParameter2_1AnnotationTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/StoredProcedureParameter2_1AnnotationTests.java
new file mode 100644
index 0000000..a4397e2
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2_1/resource/java/StoredProcedureParameter2_1AnnotationTests.java
@@ -0,0 +1,154 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.jpa.core.tests.internal.jpa2_1.resource.java;
+
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
+import org.eclipse.jpt.common.utility.internal.iterator.ArrayIterator;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.JPA2_1;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.NamedStoredProcedureQuery2_1Annotation;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.ParameterMode2_1;
+import org.eclipse.jpt.jpa.core.jpa2_1.resource.java.StoredProcedureParameter2_1Annotation;
+
+@SuppressWarnings("nls")
+public class StoredProcedureParameter2_1AnnotationTests
+ extends JavaResourceModel2_1TestCase
+{
+
+ public StoredProcedureParameter2_1AnnotationTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTestNamedStoredProcedureQueryWithParameters() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_1.NAMED_STORED_PROCEDURE_QUERY, JPA2_1.NAMED_STORED_PROCEDURE_PARAMETER, JPA2_1.PARAMETER_MODE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@NamedStoredProcedureQuery(parameters = {@StoredProcedureParameter(name = \"MyParameter\", mode = ParameterMode.IN, type = MyType.class), @StoredProcedureParameter})");
+ }
+ });
+ }
+
+ public void testNamedStoredProcedureQueryWithParameters() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ assertEquals(2, namedQuery.getParametersSize());
+ StoredProcedureParameter2_1Annotation parameter = namedQuery.parameterAt(0);
+ assertEquals("MyParameter", parameter.getName());
+ parameter = namedQuery.parameterAt(1);
+ assertNull(parameter.getName());
+ }
+
+ // ******** name *********
+
+ public void testGetName() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ StoredProcedureParameter2_1Annotation parameter = namedQuery.parameterAt(0);
+ assertEquals("MyParameter", parameter.getName());
+ }
+
+ public void testSetName() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ StoredProcedureParameter2_1Annotation parameter = namedQuery.parameterAt(0);
+ assertEquals("MyParameter", parameter.getName());
+
+ parameter.setName("foo");
+ assertEquals("foo", parameter.getName());
+
+ assertSourceContains("@StoredProcedureParameter(name = \"foo\", mode = ParameterMode.IN, type = MyType.class)", cu);
+ }
+
+ // ******* mode *********
+
+ public void testGetMode() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ StoredProcedureParameter2_1Annotation parameter = namedQuery.parameterAt(0);
+ assertEquals(ParameterMode2_1.IN, parameter.getMode());
+ }
+
+ public void testSetMode() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ StoredProcedureParameter2_1Annotation parameter = namedQuery.parameterAt(0);
+ assertEquals(ParameterMode2_1.IN, parameter.getMode());
+
+ parameter.setMode(ParameterMode2_1.INOUT);
+ assertEquals(ParameterMode2_1.INOUT, parameter.getMode());
+ assertSourceContains("@StoredProcedureParameter(name = \"MyParameter\", mode = INOUT, type = MyType.class)", cu);
+
+ parameter.setMode(null);
+ assertNull(parameter.getMode());
+ assertSourceDoesNotContain("mode", cu);
+ assertSourceContains("@StoredProcedureParameter(name = \"MyParameter\", type = MyType.class)", cu);
+ }
+
+ // ******* type *********
+ public void testGetType() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ StoredProcedureParameter2_1Annotation parameter = namedQuery.parameterAt(0);
+
+ assertEquals("MyType", parameter.getType());
+ }
+
+ public void testSetType() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ StoredProcedureParameter2_1Annotation parameter = namedQuery.parameterAt(0);
+
+ assertEquals("MyType", parameter.getType());
+
+ parameter.setType("Foo");
+ assertEquals("Foo", parameter.getType());
+ assertSourceContains("@StoredProcedureParameter(name = \"MyParameter\", mode = ParameterMode.IN, type = Foo.class", cu);
+
+ parameter.setType(null);
+ assertNull(parameter.getType());
+ assertSourceDoesNotContain("type", cu);
+ assertSourceContains("@StoredProcedureParameter(name = \"MyParameter\", mode = ParameterMode.IN", cu);
+ }
+
+ public void testGetFullyQualifiedClass() throws Exception {
+ ICompilationUnit cu = this.createTestNamedStoredProcedureQueryWithParameters();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+
+ NamedStoredProcedureQuery2_1Annotation namedQuery = (NamedStoredProcedureQuery2_1Annotation) resourceType.getAnnotation(0, JPA2_1.NAMED_STORED_PROCEDURE_QUERY);
+ StoredProcedureParameter2_1Annotation parameter = namedQuery.parameterAt(0);
+
+ assertNotNull(parameter.getType());
+ assertEquals("MyType", parameter.getFullyQualifiedTypeName());
+
+ parameter.setType(TYPE_NAME);
+
+ assertEquals(FULLY_QUALIFIED_TYPE_NAME, parameter.getFullyQualifiedTypeName());
+ assertSourceContains("@StoredProcedureParameter(name = \"MyParameter\", mode = ParameterMode.IN, type = " + TYPE_NAME + ".class)", cu);
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/JptJpaCoreResourceModelTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/JptJpaCoreResourceModelTests.java
index 856925d..9a38379 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/JptJpaCoreResourceModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/JptJpaCoreResourceModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2013 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.
@@ -14,6 +14,7 @@ import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.jpt.jpa.core.tests.internal.JptJpaCoreTests;
import org.eclipse.jpt.jpa.core.tests.internal.jpa2.resource.java.JavaResource2_0Tests;
+import org.eclipse.jpt.jpa.core.tests.internal.jpa2_1.resource.java.JavaResource2_1Tests;
import org.eclipse.jpt.jpa.core.tests.internal.resource.java.JptJavaResourceTests;
/**
@@ -29,6 +30,7 @@ public class JptJpaCoreResourceModelTests
if (JptJpaCoreTests.requiredJarsExists()) {
suite.addTest(JptJavaResourceTests.suite());
suite.addTest(JavaResource2_0Tests.suite());
+ suite.addTest(JavaResource2_1Tests.suite());
} else {
suite.addTest(TestSuite.warning(JptJpaCoreTests.buildMissingJarErrorMessage()));
}