cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1151968 - in /cayenne/main/trunk: build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/ framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/ itests/cayenne-runtime-itest/src/test/java/org/apache/c...
Date Thu, 28 Jul 2011 18:49:45 GMT
Author: aadamchik
Date: Thu Jul 28 18:49:43 2011
New Revision: 1151968

URL: http://svn.apache.org/viewvc?rev=1151968&view=rev
Log:
clearing up JDBC use to address Oracle shortcomings

Modified:
    cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/DBHelper.java
    cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/TableHelper.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CDOMany2OneTest.java
    cayenne/main/trunk/itests/cayenne-runtime-itest/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeIntegrationTest.java

Modified: cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/DBHelper.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/DBHelper.java?rev=1151968&r1=1151967&r2=1151968&view=diff
==============================================================================
--- cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/DBHelper.java
(original)
+++ cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/DBHelper.java
Thu Jul 28 18:49:43 2011
@@ -81,9 +81,11 @@ public class DBHelper {
     }
 
     /**
-     * Inserts a single row.
+     * Inserts a single row. Columns types can be null and will be determined from
+     * ParameterMetaData in this case. The later scenario will not work if values contains
+     * nulls and the DB is Oracle.
      */
-    public void insert(String table, String[] columns, Object[] values)
+    public void insert(String table, String[] columns, Object[] values, int[] columnTypes)
             throws SQLException {
 
         if (columns.length != values.length) {
@@ -122,12 +124,22 @@ public class DBHelper {
 
                     if (values[i] == null) {
 
-                        // check for the right NULL type
-                        if (parameters == null) {
-                            parameters = st.getParameterMetaData();
+                        int type;
+
+                        if (columnTypes == null) {
+
+                            // check for the right NULL type
+                            if (parameters == null) {
+                                parameters = st.getParameterMetaData();
+                            }
+
+                            type = parameters.getParameterType(i + 1);
+                        }
+                        else {
+                            type = columnTypes[i];
                         }
 
-                        st.setNull(i + 1, parameters.getParameterType(i + 1));
+                        st.setNull(i + 1, type);
                     }
                     else {
                         st.setObject(i + 1, values[i]);
@@ -144,6 +156,7 @@ public class DBHelper {
         finally {
             c.close();
         }
+
     }
 
     public int deleteAll(String tableName) throws SQLException {

Modified: cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/TableHelper.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/TableHelper.java?rev=1151968&r1=1151967&r2=1151968&view=diff
==============================================================================
--- cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/TableHelper.java
(original)
+++ cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/TableHelper.java
Thu Jul 28 18:49:43 2011
@@ -31,6 +31,7 @@ public class TableHelper {
     protected String tableName;
     protected DBHelper dbHelper;
     protected String[] columns;
+    protected int[] columnTypes;
 
     public TableHelper(DBHelper dbHelper, String tableName) {
         this.dbHelper = dbHelper;
@@ -66,6 +67,16 @@ public class TableHelper {
         return this;
     }
 
+    /**
+     * Sets JDBC types of the table columns. Setting column types may be needed when
+     * inserting NULL values in certain DB's (Oracle) that can't figure out parameter
+     * types from PreparedStatement metadata.
+     */
+    public TableHelper setColumnTypes(int... columnTypes) {
+        this.columnTypes = columnTypes;
+        return this;
+    }
+
     public TableHelper insert(Object... values) throws SQLException {
         if (this.columns == null) {
             throw new IllegalStateException("Call 'setColumns' to prepare insert");
@@ -76,7 +87,13 @@ public class TableHelper {
                     "Columns and values arrays are of different size");
         }
 
-        dbHelper.insert(tableName, columns, values);
+        if (columnTypes != null && columns.length != columnTypes.length) {
+            throw new IllegalArgumentException(
+                    "Columns and columnTypes arrays are of different size");
+        }
+
+        dbHelper.insert(tableName, columns, values, columnTypes);
+
         return this;
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CDOMany2OneTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CDOMany2OneTest.java?rev=1151968&r1=1151967&r2=1151968&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CDOMany2OneTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CDOMany2OneTest.java
Thu Jul 28 18:49:43 2011
@@ -37,6 +37,7 @@ import org.apache.cayenne.testdo.testmap
 import org.apache.cayenne.testdo.testmap.ROPainting;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.hsqldb.Types;
 
 @UseServerRuntime(ServerCase.TESTMAP_PROJECT)
 public class CDOMany2OneTest extends ServerCase {
@@ -68,7 +69,9 @@ public class CDOMany2OneTest extends Ser
         tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
 
         tPainting = new TableHelper(dbHelper, "PAINTING");
-        tPainting.setColumns("PAINTING_ID", "PAINTING_TITLE", "ARTIST_ID", "GALLERY_ID");
+        tPainting
+                .setColumns("PAINTING_ID", "PAINTING_TITLE", "ARTIST_ID", "GALLERY_ID")
+                .setColumnTypes(Types.INTEGER, Types.VARCHAR, Types.BIGINT, Types.INTEGER);
 
         tGallery = new TableHelper(dbHelper, "GALLERY");
         tGallery.setColumns("GALLERY_ID", "GALLERY_NAME");

Modified: cayenne/main/trunk/itests/cayenne-runtime-itest/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeIntegrationTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-runtime-itest/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeIntegrationTest.java?rev=1151968&r1=1151967&r2=1151968&view=diff
==============================================================================
--- cayenne/main/trunk/itests/cayenne-runtime-itest/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeIntegrationTest.java
(original)
+++ cayenne/main/trunk/itests/cayenne-runtime-itest/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeIntegrationTest.java
Thu Jul 28 18:49:43 2011
@@ -89,7 +89,7 @@ public class ServerRuntimeIntegrationTes
 		DBHelper dbUtils = getDbUtils();
 		dbUtils.deleteAll("TABLE1");
 		dbUtils.insert("TABLE1", new String[] { "ID", "NAME" }, new Object[] {
-				1, "Abc" });
+				1, "Abc" }, null);
 
 		SelectQuery query = new SelectQuery(Table1.class);
 



Mime
View raw message