Author: aadamchik
Date: Wed Nov 25 16:38:37 2009
New Revision: 884189

URL: http://svn.apache.org/viewvc?rev=884189&view=rev
Log:
CAY-1307 Error committing CLOB on Oracle8

patch by Bryan Lewis

Added:
    
cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchAction.java
Modified:
    
cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt
    
cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8ActionBuilder.java
    
cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchAction.java

Modified: 
cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: 
http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=884189&r1=884188&r2=884189&view=diff
==============================================================================
--- 
cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt 
(original)
+++ 
cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt 
Wed Nov 25 16:38:37 2009
@@ -15,6 +15,7 @@
 Bug Fixes Since beta1:
 
 CAY-1305 EJBQL doesn't support null parameters
+CAY-1307 Error committing CLOB on Oracle8
 CAY-1309 many validation errors when we remove dbEntity 
 
 ----------------------------------

Modified: 
cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8ActionBuilder.java
URL: 
http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8ActionBuilder.java?rev=884189&r1=884188&r2=884189&view=diff
==============================================================================
--- 
cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8ActionBuilder.java
 (original)
+++ 
cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8ActionBuilder.java
 Wed Nov 25 16:38:37 2009
@@ -21,6 +21,7 @@
 
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.query.BatchQuery;
 import org.apache.cayenne.query.SQLAction;
 import org.apache.cayenne.query.SQLTemplate;
 import org.apache.cayenne.query.SelectQuery;
@@ -45,4 +46,26 @@
     public SQLAction objectSelectAction(SelectQuery query) {
         return new Oracle8SelectAction(query, getAdapter(), 
getEntityResolver());
     }
+
+    @Override
+    public SQLAction batchAction(BatchQuery query) {
+        // special handling for LOB updates
+        if (OracleAdapter.isSupportsOracleLOB() && 
OracleAdapter.updatesLOBColumns(query)) {
+            // Special action for Oracle8.  See CAY-1307.
+            return new Oracle8LOBBatchAction(query, getAdapter());
+        }
+        else {
+            // optimistic locking is not supported in batches due to JDBC 
driver
+            // limitations
+            boolean useOptimisticLock = query.isUsingOptimisticLocking();
+            boolean runningAsBatch = !useOptimisticLock && 
adapter.supportsBatchUpdates();
+
+            OracleBatchAction action = new OracleBatchAction(
+                    query,
+                    getAdapter(),
+                    getEntityResolver());
+            action.setBatch(runningAsBatch);
+            return action;
+        }
+    }
 }

Added: 
cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchAction.java
URL: 
http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchAction.java?rev=884189&view=auto
==============================================================================
--- 
cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchAction.java
 (added)
+++ 
cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchAction.java
 Wed Nov 25 16:38:37 2009
@@ -0,0 +1,110 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.dba.oracle;
+
+import java.io.OutputStream;
+import java.io.Writer;
+import java.lang.reflect.Method;
+import java.sql.Blob;
+import java.sql.Clob;
+
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.query.BatchQuery;
+import org.apache.cayenne.util.Util;
+
+/**
+ * @since 3.0
+ */
+class Oracle8LOBBatchAction extends OracleLOBBatchAction {
+
+    Oracle8LOBBatchAction(BatchQuery query, DbAdapter adapter) {
+        super(query, adapter);
+    }
+
+    /**
+     * Override the Oracle writeBlob() method to be compatible with Oracle8 
drivers.
+     */
+    @Override
+    protected void writeBlob(Blob blob, byte[] value) {
+        // Fix for CAY-1307.  For Oracle8, get the method found by reflection 
in
+        // OracleAdapter.  (Code taken from Cayenne 2.)
+        Method getBinaryStreamMethod = 
Oracle8Adapter.getOutputStreamFromBlobMethod();
+        try {
+            OutputStream out = (OutputStream) 
getBinaryStreamMethod.invoke(blob, (Object[]) null);
+            try {
+                out.write(value);
+                out.flush();
+            }
+            finally {
+                out.close();
+            }
+        }
+        catch (Exception e) {
+            throw new CayenneRuntimeException("Error processing BLOB.", Util
+                    .unwindException(e));
+        }
+    }
+
+    /**
+     * Override the Oracle writeClob() method to be compatible with Oracle8 
drivers.
+     */
+    @Override
+    protected void writeClob(Clob clob, char[] value) {
+        Method getWriterMethod = OracleAdapter.getWriterFromClobMethod();
+        try {
+            Writer out = (Writer) getWriterMethod.invoke(clob, (Object[]) 
null);
+            try {
+                out.write(value);
+                out.flush();
+            }
+            finally {
+                out.close();
+            }
+
+        }
+        catch (Exception e) {
+            throw new CayenneRuntimeException("Error processing CLOB.", Util
+                    .unwindException(e));
+        }
+    }
+
+    /**
+     * Override the Oracle writeClob() method to be compatible with Oracle8 
drivers.
+     */
+    @Override
+    protected void writeClob(Clob clob, String value) {
+        Method getWriterMethod = OracleAdapter.getWriterFromClobMethod();
+        try {
+            Writer out = (Writer) getWriterMethod.invoke(clob, (Object[]) 
null);
+            try {
+                out.write(value);
+                out.flush();
+            }
+            finally {
+                out.close();
+            }
+        }
+        catch (Exception e) {
+            throw new CayenneRuntimeException("Error processing CLOB.", Util
+                    .unwindException(e));
+        }
+    }
+}

Modified: 
cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchAction.java
URL: 
http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchAction.java?rev=884189&r1=884188&r2=884189&view=diff
==============================================================================
--- 
cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchAction.java
 (original)
+++ 
cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchAction.java
 Wed Nov 25 16:38:37 2009
@@ -245,7 +245,7 @@
      * Writing of LOBs is not supported prior to JDBC 3.0 and has to be done 
using Oracle
      * driver utilities, using reflection.
      */
-    private void writeBlob(Blob blob, byte[] value) {
+    protected void writeBlob(Blob blob, byte[] value) {
 
         try {
             OutputStream out = blob.setBinaryStream(0);
@@ -267,7 +267,7 @@
      * Writing of LOBs is not supported prior to JDBC 3.0 and has to be done 
using Oracle
      * driver utilities.
      */
-    private void writeClob(Clob clob, char[] value) {
+    protected void writeClob(Clob clob, char[] value) {
         try {
 
             Writer out = clob.setCharacterStream(0);
@@ -290,7 +290,7 @@
      * Writing of LOBs is not supported prior to JDBC 3.0 and has to be done 
using Oracle
      * driver utilities.
      */
-    private void writeClob(Clob clob, String value) {
+    protected void writeClob(Clob clob, String value) {
         try {
 
             Writer out = clob.setCharacterStream(0);


Reply via email to