Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 350487

Summary: JPA 2.1 Specification defined support for Stored Procedure Calls
Product: z_Archived Reporter: Gordon Yorke <gordon.yorke>
Component: EclipselinkAssignee: Guy Pelletier <guy.pelletier>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: eclipselink.orm-inbox, eric.gwin, guy.pelletier, karenfbutzke, michael.f.obrien, tom.ware, yiping.zhao
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
URL: http://wiki.eclipse.org/EclipseLink/DesignDocs/350487
Whiteboard:
Bug Depends on:    
Bug Blocks: 338610    
Attachments:
Description Flags
Progress patch
none
Updated progress patch
none
Missed resource files from previous patch
none
EclipseLink jar build changes, adding new JPA 2.1 classes
none
Small update to fix test failure from nightlies.
none
Updating some tests to run on MySQL only
none
Removing JPA 2.1 classes from Eclipselink jar
none
Progress patch
none
Update patch to JPA 2.1 APIs
none
Progress patch (July 13)
none
Progress patch (August 23)
none
Progress patch (August 23)
none
Update to last progress patch
none
Progress patch (Sept 13)
none
Progress patch (Sept 27)
none
Update patch (more tests and fixes)
none
Update patch (more tests and fixes)
none
More testing
none
More testing (Oct 18th)
none
More testing (Oct 18th)
none
More testing (Oct 18th)
none
Updates (Nov 5, 2012)
none
XML tests and eclipselink orm schema updates.
none
More testing and fixes (Feb 21, 2013)
none
More testing and fixes (Feb 22, 2013)
none
More testing and fixes (Mar 05, 2013)
none
More testing and fixes (Mar 06, 2013)
none
Small update to avoid errors with JTA usage.
none
More testing and fix to handle positional cursor parameters correctly.
none
More testing and fixes (Mar 14, 2013)
none
Stored procedure support on PostGres
none
DataDirect driver support and another fix for PostgreSQL
none
Amendment to previous patch
none
Sybase Datadirect driver support
none
Oracle DataDirect driver support. none

Description Gordon Yorke CLA 2011-06-27 14:49:55 EDT
Requires implementation of new Stored Procedure Query interface and related interfaces including Named Stored Procedure Queries.

This should mostly be supported in Native EclipseLink bug will require core updates to support multiple resultsets from a single stored procedure call.
Comment 1 Guy Pelletier CLA 2012-02-08 11:00:12 EST
Created attachment 210740 [details]
Progress patch

This is a progress patch of this feature. It is not complete and more patches to follow.

This patch includes:

- Named stored procedure query support though annotations and xml
- Code changes for bug 350727
- EclipseLink project configurations
- New JPA 2.1 test target and jars
- Antbuild.xml changes
Comment 2 Eric Gwin CLA 2012-02-08 11:36:51 EST
The only changes of note for me are:
 - change the IDE to use a variable to point to the lib rather than a direct link. Great!
 - you re-define the javax.persistence20 variable to point to the 2.1 jar. 

Because 2.4.0 may support 10, 2.0, and 2.1 preview. I'd prefer adding a javax.persistence21 variable and changing the classpath dependencies to point to it for now. At the point we remove 1.0 as an option we should be able to simply remove that variable and update references to it rather than reworking the build to allow 2.1/2.0 rather than 2.1/1.0.

I could do the work and hand it to you, or do it post-merge, or you could do it.

Another thing is that eventually we will need to change the eclipselink.jar packaging to change the included classes. If I'm to do that post-merge, I'll need a list of classes that are new to 2.1. I'm not certain what the ramifications will be for testing to leave the jar as is and run 1.0 tests
Comment 3 Guy Pelletier CLA 2012-02-13 11:12:34 EST
Created attachment 210921 [details]
Updated progress patch
Comment 4 Guy Pelletier CLA 2012-02-14 08:17:45 EST
Created attachment 210972 [details]
Missed resource files from previous patch
Comment 5 Guy Pelletier CLA 2012-02-14 15:11:30 EST
Created attachment 211008 [details]
EclipseLink jar build changes, adding new JPA 2.1 classes
Comment 6 Guy Pelletier CLA 2012-02-16 08:28:12 EST
Created attachment 211108 [details]
Small update to fix test failure from nightlies.
Comment 7 Guy Pelletier CLA 2012-02-16 15:31:49 EST
Created attachment 211139 [details]
Updating some tests to run on MySQL only
Comment 8 Guy Pelletier CLA 2012-03-08 09:03:22 EST
Created attachment 212291 [details]
Removing JPA 2.1 classes from Eclipselink jar
Comment 9 Guy Pelletier CLA 2012-06-13 10:50:30 EDT
Created attachment 217279 [details]
Progress patch

Includes:

- Entity Manager create stored procedure query API
- Entity Manager register parameter API
- Clean up of metadata processing of queries.
  - No need to pass the class loader around as it is already available for all ORMetadata objects
  - Channel class loading through existing ORMetadata getJavaClass method
- Added new tests
- Remove unused code
Comment 10 Guy Pelletier CLA 2012-06-22 12:02:14 EDT
Created attachment 217750 [details]
Update patch to JPA 2.1 APIs
Comment 11 Guy Pelletier CLA 2012-07-13 11:00:47 EDT
Created attachment 218707 [details]
Progress patch (July 13)
Comment 12 Guy Pelletier CLA 2012-08-23 14:47:13 EDT
Created attachment 220221 [details]
Progress patch (August 23)
Comment 13 Guy Pelletier CLA 2012-08-23 15:44:00 EDT
Created attachment 220223 [details]
Progress patch (August 23)
Comment 14 Guy Pelletier CLA 2012-09-12 08:55:26 EDT
Created attachment 220969 [details]
Update to last progress patch

After review from Gordon Yorke
Comment 15 Guy Pelletier CLA 2012-09-13 12:42:05 EDT
Created attachment 221045 [details]
Progress patch (Sept 13)
Comment 16 Guy Pelletier CLA 2012-09-13 12:42:38 EDT
Comment on attachment 220969 [details]
Update to last progress patch

>From d42cceaaf0139019b5b9947598a79a44e0581b8b Mon Sep 17 00:00:00 2001
>From: gpelletie <guy.pelletier@oracle.com>
>Date: Wed, 12 Sep 2012 08:49:53 -0400
>Subject: [PATCH 2/2] Bug 350487 - JPA 2.1 Specification defined support for
> Stored Procedure Calls
>
>Update after review of last patch by Gordon Yorke
>---
> .../NamedStoredProcedureQueryTestSuite.java        |  5 +--
> .../internal/jpa/EntityManagerImpl.java            | 28 ++++++++++------
> .../internal/jpa/StoredProcedureQueryImpl.java     | 37 ++++++++++++++--------
> 3 files changed, 45 insertions(+), 25 deletions(-)
>
>diff --git a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa21/advanced/NamedStoredProcedureQueryTestSuite.java b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa21/advanced/NamedStoredProcedureQueryTestSuite.java
>index e5fe3fa..61a6bbc 100644
>--- a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa21/advanced/NamedStoredProcedureQueryTestSuite.java
>+++ b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa21/advanced/NamedStoredProcedureQueryTestSuite.java
>@@ -16,6 +16,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
>+ *     09/12/2012-2.5 Guy Pelletier 
>+ *       - 350487: JPA 2.1 Specification defined support for Stored Procedure Calls
>  ******************************************************************************/  
> package org.eclipse.persistence.testing.tests.jpa21.advanced;
> 
>@@ -441,8 +443,7 @@ public class NamedStoredProcedureQueryTestSuite extends JUnitTestCase {
>                 
>                 List<Address> addressResults = query.getResultList();
>                 
>-                // Should return true (employees to return)
>-                assertTrue("The query did not have more results (Employees).", query.hasMoreResults());
>+                // We know there should be more results so ask for them without checking for has more results.
>                 List<Employee> employeeResults = query.getResultList();
>                 int numberOfEmployes = employeeResults.size();
>                 
>diff --git a/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/EntityManagerImpl.java b/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/EntityManagerImpl.java
>index b794407..fe27f36 100644
>--- a/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/EntityManagerImpl.java
>+++ b/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/EntityManagerImpl.java
>@@ -29,9 +29,12 @@
>  *       - 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
>+ *     09/12/2012-2.5 Guy Pelletier 
>+ *       - 350487: JPA 2.1 Specification defined support for Stored Procedure Calls
>  ******************************************************************************/
> package org.eclipse.persistence.internal.jpa;
> 
>+import java.lang.ref.WeakReference;
> import java.util.*;
> 
> import javax.persistence.*;
>@@ -143,7 +146,7 @@ public class EntityManagerImpl implements org.eclipse.persistence.jpa.JpaEntityM
>     /**
>      * Keep a list of openQueries that are executed in this entity manager.
>      */
>-    protected List<QueryImpl> openQueries;
>+    protected WeakReference<List<QueryImpl>> openQueriesReference;
>     
>     /**
>      * Property to avoid resuming unit of work if going to be closed on commit
>@@ -297,6 +300,17 @@ public class EntityManagerImpl implements org.eclipse.persistence.jpa.JpaEntityM
>     }
> 
>     
>+    /** 
>+     * Return the weak reference to the open queries.
>+     */
>+    protected List<QueryImpl> getOpenQueries() {
>+        if (openQueriesReference == null || openQueriesReference.get() == null) {
>+            openQueriesReference = new WeakReference<List<QueryImpl>>(new ArrayList<QueryImpl>());
>+        }
>+        
>+        return openQueriesReference.get();
>+    }
>+    
>     /**
>      * Queries that leave the connection and are executed against this entity
>      * manager will be added here. On rollback or commit any left over open 
>@@ -305,11 +319,7 @@ public class EntityManagerImpl implements org.eclipse.persistence.jpa.JpaEntityM
>      * @param query
>      */
>     public void addOpenQuery(QueryImpl query) {
>-        if (openQueries == null) {
>-            openQueries = new ArrayList<QueryImpl>();
>-        }
>-        
>-        openQueries.add(query);
>+        getOpenQueries().add(query);
>     	
>         // If there is an open transaction, tag the query to it to be closed
>         // on commite or rollback.
>@@ -1728,10 +1738,8 @@ public class EntityManagerImpl implements org.eclipse.persistence.jpa.JpaEntityM
>      * Close any open queries executed against this entity manager.
>      */
>     protected void closeOpenQueries() {
>-        if (openQueries != null) {
>-            for (QueryImpl openQuery : openQueries) {
>-                openQuery.close();
>-            }
>+        for (QueryImpl openQuery : getOpenQueries()) {
>+            openQuery.close();
>         }
>     }
> 
>diff --git a/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/StoredProcedureQueryImpl.java b/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/StoredProcedureQueryImpl.java
>index c6a71f6..d1d59c1 100644
>--- a/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/StoredProcedureQueryImpl.java
>+++ b/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/StoredProcedureQueryImpl.java
>@@ -22,6 +22,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
>+ *     09/12/2012-2.5 Guy Pelletier 
>+ *       - 350487: JPA 2.1 Specification defined support for Stored Procedure Calls
>  ******************************************************************************/
> package org.eclipse.persistence.internal.jpa;
> 
>@@ -233,15 +235,13 @@ public class StoredProcedureQueryImpl extends QueryImpl implements StoredProcedu
>                 accessor.releaseStatement(executeStatement, query.getSQLString(), executeCall, session);
>             }
>         } catch (SQLException exception) {
>-            // With an external connection pool the connection may be null 
>-            // after this call, if it is we will be unable to determine if 
>-            // it is a connection based exception so treat it as if it wasn't.
>+            // With an external connection pool the connection may be null after 
>+            // this call, if it is we will be unable to determine if it is a 
>+            // connection based exception so treat it as if it wasn't.
>             DatabaseException commException = accessor.processExceptionForCommError(session, exception, null);
>-            if (commException != null) {
>-                throw commException;
>+            if (commException == null) {
>+                throw DatabaseException.sqlException(exception, executeCall, accessor, session, false);
>             }
>-
>-            throw DatabaseException.sqlException(exception, executeCall, accessor, session, false);
>         }
>     }
>     
>@@ -370,6 +370,18 @@ public class StoredProcedureQueryImpl extends QueryImpl implements StoredProcedu
>                 AbstractSession session = (AbstractSession) getActiveSession();
>                 DatabaseAccessor accessor = (DatabaseAccessor) executeCall.getQuery().getAccessor();
>                 ResultSet resultSet = executeStatement.getResultSet();
>+                
>+                // If the result set is closed,  move to the next one if there
>+                // is one. If the result set is closed we have already processed
>+                // that result.
>+                if (resultSet.isClosed()) {
>+                    if (hasMoreResults()) {
>+                        resultSet = executeStatement.getResultSet();
>+                    } else {
>+                        return null;
>+                    }
>+                }
>+                
>                 executeCall.setFields(null);
>                 executeCall.matchFieldOrder(resultSet, accessor, session);
>                 ResultSetMetaData metaData = resultSet.getMetaData();
>@@ -382,14 +394,14 @@ public class StoredProcedureQueryImpl extends QueryImpl implements StoredProcedu
>                 resultSet.close(); // This must be closed in case the statement is cached and not closed.
>                 return ((ResultSetMappingQuery) executeCall.getQuery()).buildObjectsFromRecords(result, ++executeResultSetIndex);
>             }
>-        } catch (LockTimeoutException exception) {
>-            throw exception;
>-        } catch (RuntimeException exception) {
>+        } catch (LockTimeoutException e) {
>+            throw e;
>+        } catch (RuntimeException e) {
>             setRollbackOnly();
>-            throw exception;
>+            throw e;
>         } catch (SQLException e) {
>             setRollbackOnly();
>-            throw new RuntimeException(e);
>+            throw new PersistenceException(e);
>         }
>     }
>     
>@@ -422,7 +434,6 @@ public class StoredProcedureQueryImpl extends QueryImpl implements StoredProcedu
>         return -1;
>     }
>     
>-
>     /**
>      * Returns true if the next result corresponds to a result set,
>      * and false if it is an update count or if there are no results
>-- 
>1.7.11.msysgit.1
>
Comment 17 Guy Pelletier CLA 2012-09-27 11:06:21 EDT
Created attachment 221578 [details]
Progress patch (Sept 27)

Includes REF_CURSOR support for Oracle DB.
Comment 18 Guy Pelletier CLA 2012-09-27 14:22:49 EDT
Last progress patch has been submitted.

All reviewed by Gordon Yorke

New model and tests added to the JPA 2.1 model and tests package.
Comment 19 Guy Pelletier CLA 2012-10-10 13:37:41 EDT
Created attachment 222133 [details]
Update patch (more tests and fixes)
Comment 20 Guy Pelletier CLA 2012-10-11 11:40:07 EDT
Created attachment 222188 [details]
Update patch (more tests and fixes)
Comment 21 Guy Pelletier CLA 2012-10-12 14:17:22 EDT
Created attachment 222246 [details]
More testing
Comment 22 Guy Pelletier CLA 2012-10-18 09:35:17 EDT
Created attachment 222520 [details]
More testing (Oct 18th)
Comment 23 Guy Pelletier CLA 2012-10-18 09:40:52 EDT
Created attachment 222522 [details]
More testing (Oct 18th)
Comment 24 Guy Pelletier CLA 2012-10-18 12:54:44 EDT
Created attachment 222533 [details]
More testing (Oct 18th)
Comment 25 Guy Pelletier CLA 2012-11-05 11:31:19 EST
Created attachment 223188 [details]
Updates (Nov 5, 2012)

Updates after further review of the feature and new testing scenarios.
Comment 26 Guy Pelletier CLA 2013-01-23 11:07:26 EST
Created attachment 225990 [details]
XML tests and eclipselink orm schema updates.

EclipseLink orm schema updates made to align with orm_2_1.xsd.
Comment 27 Guy Pelletier CLA 2013-02-21 15:17:47 EST
Created attachment 227423 [details]
More testing and fixes (Feb 21, 2013)
Comment 28 Guy Pelletier CLA 2013-02-22 14:25:32 EST
Created attachment 227479 [details]
More testing and fixes (Feb 22, 2013)
Comment 29 Guy Pelletier CLA 2013-03-05 13:36:44 EST
Created attachment 227951 [details]
More testing and fixes (Mar 05, 2013)
Comment 30 Guy Pelletier CLA 2013-03-06 10:50:52 EST
Created attachment 227998 [details]
More testing and fixes (Mar 06, 2013)
Comment 31 Guy Pelletier CLA 2013-03-11 11:10:58 EDT
Created attachment 228203 [details]
Small update to avoid errors with JTA usage.
Comment 32 Guy Pelletier CLA 2013-03-13 16:57:07 EDT
Created attachment 228385 [details]
More testing and fix to handle positional cursor parameters correctly.
Comment 33 Guy Pelletier CLA 2013-03-14 13:04:48 EDT
Created attachment 228435 [details]
More testing and fixes (Mar 14, 2013)
Comment 34 Guy Pelletier CLA 2013-03-20 15:29:32 EDT
Created attachment 228739 [details]
Stored procedure support on PostGres

Submitted: Peter Krogh

Reviewed: Gordon Yorke, James Sutherland
Comment 35 Guy Pelletier CLA 2013-03-27 09:48:23 EDT
Created attachment 229094 [details]
DataDirect driver support and another fix for PostgreSQL
Comment 36 Guy Pelletier CLA 2013-03-27 12:05:13 EDT
Created attachment 229107 [details]
Amendment to previous patch
Comment 37 Chris Delahunt CLA 2013-03-27 13:39:13 EDT
*** Bug 402379 has been marked as a duplicate of this bug. ***
Comment 38 Guy Pelletier CLA 2013-03-27 15:26:29 EDT
Created attachment 229128 [details]
Sybase Datadirect driver support
Comment 39 Guy Pelletier CLA 2013-04-01 11:40:49 EDT
Created attachment 229208 [details]
Oracle DataDirect driver support.
Comment 40 Eclipse Webmaster CLA 2022-06-09 10:02:57 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink