openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtyle...@apache.org
Subject svn commit: r772756 - in /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc: kernel/PreparedStatementManagerImpl.java sql/DBDictionary.java
Date Thu, 07 May 2009 19:57:35 GMT
Author: mtylenda
Date: Thu May  7 19:57:34 2009
New Revision: 772756

URL: http://svn.apache.org/viewvc?rev=772756&view=rev
Log:
OPENJPA-736: Change the way generated keys are retrieved so that the feature works also with
databases other than DB2

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java?rev=772756&r1=772755&r2=772756&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java
Thu May  7 19:57:34 2009
@@ -125,8 +125,7 @@
                         sql).getMessage());
             }
             if (autoAssignColNames != null)
-                populateAutoAssignCols(stmnt, autoAssign, autoAssignColNames, 
-                    row);
+                populateAutoAssignCols(stmnt, autoAssign, row);
             else {
                 StateManagerImpl sm = (StateManagerImpl)row.getPrimaryKey();
                 if (sm != null) {
@@ -168,19 +167,18 @@
      * sql to select the key will be issued from DBDictionary. 
      */
     protected List populateAutoAssignCols(PreparedStatement stmnt, 
-        Column[] autoAssign, String[] autoAssignColNames, RowImpl row) 
+        Column[] autoAssign, RowImpl row) 
         throws SQLException {
         List vals = null;
         if (_dict.supportsGetGeneratedKeys) {
             // set auto assign values to id col
-            vals = getGeneratedKeys(stmnt, autoAssignColNames);
+            vals = getGeneratedKeys(stmnt, autoAssign);
         }
-        setObjectId(vals, autoAssign, autoAssignColNames, row);
+        setObjectId(vals, autoAssign, row);
         return vals;
     }
 
-    protected void setObjectId(List vals, Column[] autoAssign, 
-        String[] autoAssignColNames, RowImpl row) 
+    protected void setObjectId(List vals, Column[] autoAssign, RowImpl row) 
         throws SQLException{
         OpenJPAStateManager sm = row.getPrimaryKey();
         ClassMapping mapping = (ClassMapping) sm.getMetaData();
@@ -203,13 +201,13 @@
      * getGeneratedKeys.
      */
     protected List getGeneratedKeys(PreparedStatement stmnt, 
-        String[] autoAssignColNames) 
+        Column[] autoAssign) 
         throws SQLException {
         ResultSet rs = stmnt.getGeneratedKeys();
-        List vals = new ArrayList();
+        List<Object> vals = new ArrayList<Object>();
         while (rs.next()) {
-            for (int i = 0; i < autoAssignColNames.length; i++)
-                vals.add(rs.getObject(autoAssignColNames[i]));
+            for (int i = 0; i < autoAssign.length; i++)
+                vals.add(rs.getObject(i + 1));
         }
         rs.close();
         return vals;
@@ -228,7 +226,8 @@
             && row.getPrimaryKey() != null) {
             autoAssignColNames = new String[autoAssign.length];
             for (int i = 0; i < autoAssign.length; i++)
-                autoAssignColNames[i] = autoAssign[i].getName();
+                autoAssignColNames[i] =
+                    _dict.convertSchemaCase(autoAssign[i].getName());
         }
         return autoAssignColNames;
     }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=772756&r1=772755&r2=772756&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Thu May  7 19:57:34 2009
@@ -3990,7 +3990,7 @@
      * Convert the specified schema name to a name that the database will
      * be able to understand.
      */
-    protected String convertSchemaCase(String objectName) {
+    public String convertSchemaCase(String objectName) {
         if (objectName == null)
             return null;
 



Mime
View raw message