Bug#511426: SQLCall returntype maintained across NamedQuery create.

Signed-off-by: Will Dazey <dazeydev.3@gmail.com>
Reviewed-by: Lukas Jungmann <lukas.jungmann@oracle.com>
diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/queries/DatasourceCallQueryMechanism.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/queries/DatasourceCallQueryMechanism.java
index 663f260..3846bc8 100644
--- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/queries/DatasourceCallQueryMechanism.java
+++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/queries/DatasourceCallQueryMechanism.java
@@ -1,5 +1,5 @@
 /*******************************************************************************

- * Copyright (c) 1998, 2013 Oracle and/or its affiliates. All rights reserved.

+ * Copyright (c) 1998, 2017 Oracle and/or its affiliates. All rights reserved.
  * This program and the accompanying materials are made available under the 

  * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 

  * which accompanies this distribution. 

@@ -13,6 +13,8 @@
  *       - 350487: JPA 2.1 Specification defined support for Stored Procedure Calls

  *     08/24/2012-2.5 Guy Pelletier 

  *       - 350487: JPA 2.1 Specification defined support for Stored Procedure Calls

+ *     01/31/2017-2.6 Will Dazey
+ *       - 511426: Adding cloning support
  ******************************************************************************/  

 package org.eclipse.persistence.internal.queries;

 

@@ -74,6 +76,22 @@
     }

 

     /**

+     * Clone the DatasourceCall and Vector<DatasourceCall>.
+     */
+    public DatabaseQueryMechanism clone(DatabaseQuery queryClone) {
+        DatasourceCallQueryMechanism clone = (DatasourceCallQueryMechanism)super.clone(queryClone);
+        if(this.call != null) {
+            DatasourceCall callclone = (DatasourceCall)this.call.clone();
+            clone.setCall(callclone);
+        }
+        if(this.calls != null) {
+            Vector callsclone = (Vector)this.calls.clone();
+            clone.setCalls(callsclone);
+        }
+        return clone;
+    }
+
+    /**
      * Read all rows from the database using a cursored stream.

      * @exception  DatabaseException - an error has occurred on the database

      */

diff --git a/jpa/eclipselink.jpa.test.jse/src/org/eclipse/persistence/jpa/test/basic/model/Employee.java b/jpa/eclipselink.jpa.test.jse/src/org/eclipse/persistence/jpa/test/basic/model/Employee.java
index 8243c57..1eb32d1 100644
--- a/jpa/eclipselink.jpa.test.jse/src/org/eclipse/persistence/jpa/test/basic/model/Employee.java
+++ b/jpa/eclipselink.jpa.test.jse/src/org/eclipse/persistence/jpa/test/basic/model/Employee.java
@@ -18,11 +18,13 @@
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
+import javax.persistence.NamedQuery;
 import javax.persistence.Table;
 import javax.persistence.Version;
 
 @Entity
 @Table(name="oepjtbmEmployee")
+@NamedQuery(name="Employee.findAll", query="SELECT e FROM Employee e")
 public class Employee {
 	@Id
 	@GeneratedValue(strategy = GenerationType.IDENTITY)
diff --git a/jpa/eclipselink.jpa.test.jse/src/org/eclipse/persistence/jpa/test/query/TestQueryHints.java b/jpa/eclipselink.jpa.test.jse/src/org/eclipse/persistence/jpa/test/query/TestQueryHints.java
index 5e198c3..03ed99d 100644
--- a/jpa/eclipselink.jpa.test.jse/src/org/eclipse/persistence/jpa/test/query/TestQueryHints.java
+++ b/jpa/eclipselink.jpa.test.jse/src/org/eclipse/persistence/jpa/test/query/TestQueryHints.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2015 IBM Corporation. All rights reserved.
+ * Copyright (c) 2017 IBM Corporation. All rights reserved.
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
  * which accompanies this distribution.
@@ -12,6 +12,8 @@
  *       - 471487: Added test for QueryHints.JDBC_TIMEOUT that checks the executed sql statement
  *     09/03/2015 - Will Dazey
  *       - 456067 : Added tests to check query timeout units
+ *     01/31/2017-2.6 Will Dazey
+ *       - 511426: Adding test to check QueryHints.SCROLLABLE_CURSOR
  ******************************************************************************/
 package org.eclipse.persistence.jpa.test.query;
 
@@ -28,6 +30,7 @@
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Query;
 
+import org.eclipse.persistence.config.HintValues;
 import org.eclipse.persistence.config.PersistenceUnitProperties;
 import org.eclipse.persistence.config.QueryHints;
 import org.eclipse.persistence.config.SessionCustomizer;
@@ -36,6 +39,7 @@
 import org.eclipse.persistence.jpa.test.framework.EmfRunner;
 import org.eclipse.persistence.jpa.test.framework.PUPropertiesProvider;
 import org.eclipse.persistence.jpa.test.framework.Property;
+import org.eclipse.persistence.queries.ScrollableCursor;
 import org.eclipse.persistence.sessions.Connector;
 import org.eclipse.persistence.sessions.DatabaseLogin;
 import org.eclipse.persistence.sessions.Session;
@@ -151,6 +155,51 @@
         }
     }
 
+    /**
+     * Test that setting the Query Hint: QueryHints.SCROLLABLE_CURSOR on a NamedQuery
+     * does not cause subsequent Queries, created using the same name, to throw exception.
+     * 
+     * @throws Exception
+     */
+    @Test
+    public void testMultipleNamedQueryWithScrollableCursor() throws Exception {
+        EntityManager em = null;
+        try {
+            em = emf.createEntityManager();
+            em.getTransaction().begin();
+
+            /*
+             * First create a NamedQuery and return the result list
+             */
+            Query query1 = em.createNamedQuery("Employee.findAll");
+            query1.getResultList();
+
+            /*
+             * Next, create the same NamedQuery, but add the QueryHints.SCROLLABLE_CURSOR hint
+             * and return the ScrollableCursor
+             */
+            Query query2 = em.createNamedQuery("Employee.findAll");
+            query2.setHint(QueryHints.SCROLLABLE_CURSOR, HintValues.TRUE);
+            ScrollableCursor cursor = ((ScrollableCursor) query2.getSingleResult());
+            cursor.close();
+
+            /*
+             * Finally, attempt to create a third NamedQuery, but return a result list
+             * without adding a hint to this Query
+             */
+            Query query3 = em.createNamedQuery("Employee.findAll");
+            query3.getResultList();
+
+            em.getTransaction().rollback();
+        } catch (Exception e) {
+            Assert.fail(e.getLocalizedMessage());
+        } finally {
+            if (em != null) {
+                em.close();
+            }
+        }
+    }
+
     @Override
     public Map<String, Object> getAdditionalPersistenceProperties(String puName) {
         Map<String, Object> map = new HashMap<String, Object>();