cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1577986 - in /cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne: access/types/ dba/oracle/
Date Sun, 16 Mar 2014 07:10:06 GMT
Author: aadamchik
Date: Sun Mar 16 07:10:05 2014
New Revision: 1577986

URL: http://svn.apache.org/r1577986
Log:
CAY-1918 Replace Oracle LOB hacks with JDBC 4.0 API

Added:
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchQueryWrapper.java
      - copied, changed from r1577911, cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchQueryWrapper.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchTranslator.java
      - copied, changed from r1577911, cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchTranslator.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBInsertBatchTranslator.java
      - copied, changed from r1577911, cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBInsertBatchTranslator.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBUpdateBatchTranslator.java
      - copied, changed from r1577911, cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBUpdateBatchTranslator.java
Removed:
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchAction.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchQueryWrapper.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchTranslator.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBInsertBatchTranslator.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBUpdateBatchTranslator.java
Modified:
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/types/ByteArrayType.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchAction.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleActionBuilder.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleByteArrayType.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleCharType.java

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/types/ByteArrayType.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/types/ByteArrayType.java?rev=1577986&r1=1577985&r2=1577986&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/types/ByteArrayType.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/types/ByteArrayType.java
Sun Mar 16 07:10:05 2014
@@ -152,6 +152,8 @@ public class ByteArrayType implements Ex
     }
 
     protected Blob writeBlob(byte[] bytes) {
+        // TODO: should we use Connection.createBlob() instead? (Like Oracle
+        // ByteArrayType does)
         return bytes != null ? new MemoryBlob(bytes) : null;
     }
 

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchAction.java?rev=1577986&r1=1577985&r2=1577986&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchAction.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchAction.java
Sun Mar 16 07:10:05 2014
@@ -24,50 +24,220 @@ import java.io.Writer;
 import java.lang.reflect.Method;
 import java.sql.Blob;
 import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.Collections;
+import java.util.List;
 
+import org.apache.cayenne.CayenneException;
 import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.access.OperationObserver;
+import org.apache.cayenne.access.translator.batch.BatchParameterBinding;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.log.JdbcEventLogger;
+import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.query.BatchQuery;
+import org.apache.cayenne.query.BatchQueryRow;
+import org.apache.cayenne.query.InsertBatchQuery;
+import org.apache.cayenne.query.SQLAction;
+import org.apache.cayenne.query.UpdateBatchQuery;
 import org.apache.cayenne.util.Util;
 
 /**
  * @since 3.0
  */
-class Oracle8LOBBatchAction extends OracleLOBBatchAction {
+class Oracle8LOBBatchAction implements SQLAction {
+
+    private BatchQuery query;
+    private DbAdapter adapter;
+    private JdbcEventLogger logger;
+
+    private static void bind(DbAdapter adapter, PreparedStatement statement, List<BatchParameterBinding>
bindings)
+            throws SQLException, Exception {
+        int len = bindings.size();
+        for (int i = 0; i < len; i++) {
+            BatchParameterBinding b = bindings.get(i);
+            adapter.bindParameter(statement, b.getValue(), i + 1, b.getAttribute().getType(),
b.getAttribute()
+                    .getScale());
+        }
+    }
 
     Oracle8LOBBatchAction(BatchQuery query, DbAdapter adapter, JdbcEventLogger logger) {
-        super(query, adapter, logger);
+        this.adapter = adapter;
+        this.query = query;
+        this.logger = logger;
+    }
+
+    @Override
+    public void performAction(Connection connection, OperationObserver observer) throws SQLException,
Exception {
+
+        Oracle8LOBBatchTranslator translator;
+        if (query instanceof InsertBatchQuery) {
+            translator = new Oracle8LOBInsertBatchTranslator((InsertBatchQuery) query, adapter);
+        } else if (query instanceof UpdateBatchQuery) {
+            translator = new Oracle8LOBUpdateBatchTranslator((UpdateBatchQuery) query, adapter);
+        } else {
+            throw new CayenneException("Unsupported batch type for special LOB processing:
" + query);
+        }
+
+        translator.setTrimFunction(OracleAdapter.TRIM_FUNCTION);
+        translator.setNewBlobFunction(OracleAdapter.NEW_BLOB_FUNCTION);
+        translator.setNewClobFunction(OracleAdapter.NEW_CLOB_FUNCTION);
+
+        // no batching is done, queries are translated
+        // for each batch set, since prepared statements
+        // may be different depending on whether LOBs are NULL or not..
+
+        Oracle8LOBBatchQueryWrapper selectQuery = new Oracle8LOBBatchQueryWrapper(query);
+        List<DbAttribute> qualifierAttributes = selectQuery.getDbAttributesForLOBSelectQualifier();
+
+        for (BatchQueryRow row : query.getRows()) {
+
+            selectQuery.indexLOBAttributes(row);
+
+            int updated = 0;
+            String updateStr = translator.createSqlString(row);
+
+            // 1. run row update
+            logger.logQuery(updateStr, Collections.EMPTY_LIST);
+            PreparedStatement statement = connection.prepareStatement(updateStr);
+            try {
+
+                List<BatchParameterBinding> bindings = translator.createBindings(row);
+                logger.logQueryParameters("bind", bindings);
+
+                bind(adapter, statement, bindings);
+
+                updated = statement.executeUpdate();
+                logger.logUpdateCount(updated);
+            } finally {
+                try {
+                    statement.close();
+                } catch (Exception e) {
+                }
+            }
+
+            // 2. run row LOB update (SELECT...FOR UPDATE and writing out LOBs)
+            processLOBRow(connection, translator, selectQuery, qualifierAttributes, row);
+
+            // finally, notify delegate that the row was updated
+            observer.nextCount(query, updated);
+        }
+    }
+
+    void processLOBRow(Connection con, Oracle8LOBBatchTranslator queryBuilder, Oracle8LOBBatchQueryWrapper
selectQuery,
+            List<DbAttribute> qualifierAttributes, BatchQueryRow row) throws SQLException,
Exception {
+
+        List<DbAttribute> lobAttributes = selectQuery.getDbAttributesForUpdatedLOBColumns();
+        if (lobAttributes.size() == 0) {
+            return;
+        }
+
+        boolean isLoggable = logger.isLoggable();
+
+        List<Object> qualifierValues = selectQuery.getValuesForLOBSelectQualifier(row);
+        List<Object> lobValues = selectQuery.getValuesForUpdatedLOBColumns();
+        int parametersSize = qualifierValues.size();
+        int lobSize = lobAttributes.size();
+
+        String selectStr = queryBuilder.createLOBSelectString(lobAttributes, qualifierAttributes);
+
+        if (isLoggable) {
+            logger.logQuery(selectStr, qualifierValues);
+            logger.logQueryParameters("write LOB", null, lobValues, false);
+        }
+
+        PreparedStatement selectStatement = con.prepareStatement(selectStr);
+        try {
+            for (int i = 0; i < parametersSize; i++) {
+                Object value = qualifierValues.get(i);
+                DbAttribute attribute = qualifierAttributes.get(i);
+
+                adapter.bindParameter(selectStatement, value, i + 1, attribute.getType(),
attribute.getScale());
+            }
+
+            ResultSet result = selectStatement.executeQuery();
+
+            try {
+                if (!result.next()) {
+                    throw new CayenneRuntimeException("Missing LOB row.");
+                }
+
+                // read the only expected row
+
+                for (int i = 0; i < lobSize; i++) {
+                    DbAttribute attribute = lobAttributes.get(i);
+                    int type = attribute.getType();
+
+                    if (type == Types.CLOB) {
+                        Clob clob = result.getClob(i + 1);
+                        Object clobVal = lobValues.get(i);
+
+                        if (clobVal instanceof char[]) {
+                            writeClob(clob, (char[]) clobVal);
+                        } else {
+                            writeClob(clob, clobVal.toString());
+                        }
+                    } else if (type == Types.BLOB) {
+                        Blob blob = result.getBlob(i + 1);
+
+                        Object blobVal = lobValues.get(i);
+                        if (blobVal instanceof byte[]) {
+                            writeBlob(blob, (byte[]) blobVal);
+                        } else {
+                            String className = (blobVal != null) ? blobVal.getClass().getName()
: null;
+                            throw new CayenneRuntimeException("Unsupported class of BLOB
value: " + className);
+                        }
+                    } else {
+                        throw new CayenneRuntimeException("Only BLOB or CLOB is expected
here, got: " + type);
+                    }
+                }
+
+                if (result.next()) {
+                    throw new CayenneRuntimeException("More than one LOB row found.");
+                }
+            } finally {
+                try {
+                    result.close();
+                } catch (Exception e) {
+                }
+            }
+        } finally {
+            try {
+                selectStatement.close();
+            } catch (Exception e) {
+            }
+        }
     }
 
     /**
-     * Override the Oracle writeBlob() method to be compatible with Oracle8 drivers.
+     * 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.)
+        // 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 {
+            } finally {
                 out.close();
             }
-        }
-        catch (Exception e) {
-            throw new CayenneRuntimeException("Error processing BLOB.", Util
-                    .unwindException(e));
+        } catch (Exception e) {
+            throw new CayenneRuntimeException("Error processing BLOB.", Util.unwindException(e));
         }
     }
 
     /**
-     * Override the Oracle writeClob() method to be compatible with Oracle8 drivers.
+     * Override the Oracle writeClob() method to be compatible with Oracle8
+     * drivers.
      */
-    @Override
     protected void writeClob(Clob clob, char[] value) {
         Method getWriterMethod = Oracle8Adapter.getWriterFromClobMethod();
         try {
@@ -75,22 +245,19 @@ class Oracle8LOBBatchAction extends Orac
             try {
                 out.write(value);
                 out.flush();
-            }
-            finally {
+            } finally {
                 out.close();
             }
 
-        }
-        catch (Exception e) {
-            throw new CayenneRuntimeException("Error processing CLOB.", Util
-                    .unwindException(e));
+        } catch (Exception e) {
+            throw new CayenneRuntimeException("Error processing CLOB.", Util.unwindException(e));
         }
     }
 
     /**
-     * Override the Oracle writeClob() method to be compatible with Oracle8 drivers.
+     * Override the Oracle writeClob() method to be compatible with Oracle8
+     * drivers.
      */
-    @Override
     protected void writeClob(Clob clob, String value) {
         Method getWriterMethod = Oracle8Adapter.getWriterFromClobMethod();
         try {
@@ -98,14 +265,11 @@ class Oracle8LOBBatchAction extends Orac
             try {
                 out.write(value);
                 out.flush();
-            }
-            finally {
+            } finally {
                 out.close();
             }
-        }
-        catch (Exception e) {
-            throw new CayenneRuntimeException("Error processing CLOB.", Util
-                    .unwindException(e));
+        } catch (Exception e) {
+            throw new CayenneRuntimeException("Error processing CLOB.", Util.unwindException(e));
         }
     }
 }

Copied: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchQueryWrapper.java
(from r1577911, cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchQueryWrapper.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchQueryWrapper.java?p2=cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchQueryWrapper.java&p1=cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchQueryWrapper.java&r1=1577911&r2=1577986&rev=1577986&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchQueryWrapper.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchQueryWrapper.java
Sun Mar 16 07:10:05 2014
@@ -37,7 +37,7 @@ import org.apache.cayenne.query.BatchQue
  * columns processing.
  * 
  */
-class OracleLOBBatchQueryWrapper {
+class Oracle8LOBBatchQueryWrapper {
 
     protected BatchQuery query;
 
@@ -48,7 +48,7 @@ class OracleLOBBatchQueryWrapper {
     protected boolean[] allLOBAttributes;
     protected Object[] updatedLOBAttributes;
 
-    OracleLOBBatchQueryWrapper(BatchQuery query) {
+    Oracle8LOBBatchQueryWrapper(BatchQuery query) {
         this.query = query;
         this.dbAttributes = query.getDbAttributes();
 

Copied: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchTranslator.java
(from r1577911, cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchTranslator.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchTranslator.java?p2=cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchTranslator.java&p1=cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchTranslator.java&r1=1577911&r2=1577986&rev=1577986&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBBatchTranslator.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchTranslator.java
Sun Mar 16 07:10:05 2014
@@ -39,12 +39,12 @@ import org.apache.cayenne.query.BatchQue
  * Superclass of query builders for the DML operations involving LOBs.
  * 
  */
-abstract class OracleLOBBatchTranslator extends BatchTranslator {
+abstract class Oracle8LOBBatchTranslator extends BatchTranslator {
 
     protected String newClobFunction;
     protected String newBlobFunction;
 
-    OracleLOBBatchTranslator(BatchQuery query, DbAdapter adapter) {
+    Oracle8LOBBatchTranslator(BatchQuery query, DbAdapter adapter) {
         super(query, adapter);
     }
 

Copied: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBInsertBatchTranslator.java
(from r1577911, cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBInsertBatchTranslator.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBInsertBatchTranslator.java?p2=cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBInsertBatchTranslator.java&p1=cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBInsertBatchTranslator.java&r1=1577911&r2=1577986&rev=1577986&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBInsertBatchTranslator.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBInsertBatchTranslator.java
Sun Mar 16 07:10:05 2014
@@ -29,9 +29,9 @@ import org.apache.cayenne.map.DbAttribut
 import org.apache.cayenne.query.BatchQueryRow;
 import org.apache.cayenne.query.InsertBatchQuery;
 
-class OracleLOBInsertBatchTranslator extends OracleLOBBatchTranslator {
+class Oracle8LOBInsertBatchTranslator extends Oracle8LOBBatchTranslator {
 
-    OracleLOBInsertBatchTranslator(InsertBatchQuery query, DbAdapter adapter) {
+    Oracle8LOBInsertBatchTranslator(InsertBatchQuery query, DbAdapter adapter) {
         super(query, adapter);
     }
 

Copied: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBUpdateBatchTranslator.java
(from r1577911, cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBUpdateBatchTranslator.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBUpdateBatchTranslator.java?p2=cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBUpdateBatchTranslator.java&p1=cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBUpdateBatchTranslator.java&r1=1577911&r2=1577986&rev=1577986&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleLOBUpdateBatchTranslator.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBUpdateBatchTranslator.java
Sun Mar 16 07:10:05 2014
@@ -29,9 +29,9 @@ import org.apache.cayenne.map.DbAttribut
 import org.apache.cayenne.query.BatchQueryRow;
 import org.apache.cayenne.query.UpdateBatchQuery;
 
-class OracleLOBUpdateBatchTranslator extends OracleLOBBatchTranslator {
+class Oracle8LOBUpdateBatchTranslator extends Oracle8LOBBatchTranslator {
 
-    OracleLOBUpdateBatchTranslator(UpdateBatchQuery query, DbAdapter adapter) {
+    Oracle8LOBUpdateBatchTranslator(UpdateBatchQuery query, DbAdapter adapter) {
         super(query, adapter);
     }
 

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleActionBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleActionBuilder.java?rev=1577986&r1=1577985&r2=1577986&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleActionBuilder.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleActionBuilder.java
Sun Mar 16 07:10:05 2014
@@ -44,19 +44,13 @@ class OracleActionBuilder extends JdbcAc
     @Override
     public SQLAction batchAction(BatchQuery query) {
 
-        // special handling for LOB updates
-        if (OracleAdapter.isSupportsOracleLOB() && OracleAdapter.updatesLOBColumns(query))
{
-            return new OracleLOBBatchAction(query, dataNode.getAdapter(), dataNode.getJdbcEventLogger());
-        } else {
-
-            // optimistic locking is not supported in batches due to JDBC driver
-            // limitations
-            boolean useOptimisticLock = query.isUsingOptimisticLocking();
-            boolean runningAsBatch = !useOptimisticLock && dataNode.getAdapter().supportsBatchUpdates();
-
-            return new OracleBatchAction(query, dataNode, runningAsBatch);
-        }
+        // optimistic locking is not supported in batches due to JDBC driver
+        // limitations
+        // TODO: is this still true with ojdbc6.jar?
+        boolean useOptimisticLock = query.isUsingOptimisticLocking();
+        boolean runningAsBatch = !useOptimisticLock && dataNode.getAdapter().supportsBatchUpdates();
 
+        return new OracleBatchAction(query, dataNode, runningAsBatch);
     }
 
     @Override

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleByteArrayType.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleByteArrayType.java?rev=1577986&r1=1577985&r2=1577986&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleByteArrayType.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleByteArrayType.java
Sun Mar 16 07:10:05 2014
@@ -18,7 +18,7 @@
  ****************************************************************/
 package org.apache.cayenne.dba.oracle;
 
-import java.io.ByteArrayInputStream;
+import java.sql.Blob;
 import java.sql.PreparedStatement;
 import java.sql.Types;
 
@@ -40,10 +40,12 @@ public class OracleByteArrayType extends
             int scale) throws Exception {
         if (type == Types.BLOB) {
             if (isUsingBlobs()) {
-                byte[] bytes = (byte[])val;
-                st.setBinaryStream(pos, new ByteArrayInputStream(bytes), bytes.length);
-            }
-            else {
+                
+                Blob blob = st.getConnection().createBlob();
+                blob.setBytes(1,  (byte[]) val);
+                st.setBlob(pos, blob);
+                
+            } else {
                 st.setBytes(pos, (byte[]) val);
             }
         }

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleCharType.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleCharType.java?rev=1577986&r1=1577985&r2=1577986&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleCharType.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleCharType.java
Sun Mar 16 07:10:05 2014
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.cayenne.dba.oracle;
 
+import java.sql.Clob;
 import java.sql.PreparedStatement;
 import java.sql.Types;
 
@@ -45,7 +46,16 @@ public class OracleCharType extends Char
             int type,
             int precision) throws Exception {
         if (type == Types.CLOB) {
-            st.setString(pos, (String) val);
+
+            if (isUsingClobs()) {
+
+                Clob clob = st.getConnection().createClob();
+                clob.setString(1, (String) val);
+                st.setClob(pos, clob);
+                
+            } else {
+                st.setString(pos, (String) val);
+            }
         }
         else {
             // use exactly this method to solve CAY-1470



Mime
View raw message