Author: arminw
Date: Tue Jun 13 12:11:01 2006
New Revision: 413954

URL: http://svn.apache.org/viewvc?rev=413954&view=rev
Log:
check fields for active LOB content

Modified:
    
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
    
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java

Modified: 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
URL: 
http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java?rev=413954&r1=413953&r2=413954&view=diff
==============================================================================
--- 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
 (original)
+++ 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
 Tue Jun 13 12:11:01 2006
@@ -28,6 +28,7 @@
 import org.apache.ojb.broker.PersistenceBroker;
 import org.apache.ojb.broker.PersistenceBrokerException;
 import org.apache.ojb.broker.PersistenceBrokerSQLException;
+import org.apache.ojb.broker.lob.LobHandle;
 import org.apache.ojb.broker.accesslayer.sql.SelectStatement;
 import org.apache.ojb.broker.core.ValueContainer;
 import org.apache.ojb.broker.metadata.ArgumentDescriptor;
@@ -498,7 +499,23 @@
         {
             // workaround for issue with optimistic locking with enabled batch 
mode
             boolean batchSetting = preHandleBatchProcess(cld);
+
+            // we can only update LOB content when it's associated with 
current tx
+            if(cld.hasLobField())
+            {
+                FieldDescriptor[] fields = cld.getLobFields();
+                for(int i = 0; i < fields.length; i++)
+                {
+                    FieldDescriptor field = fields[i];
+                    Object o = field.getPersistentField().get(obj);
+                    if(o instanceof LobHandle)
+                    {
+                        ((LobHandle) o).checkActive();
+                    }
+                }
+            }
             stmt = sm.getUpdateStatement(cld);
+
             if (stmt == null)
             {
                 logger.error("getUpdateStatement returned a null statement");

Modified: 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java
URL: 
http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java?rev=413954&r1=413953&r2=413954&view=diff
==============================================================================
--- 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java
 (original)
+++ 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java
 Tue Jun 13 12:11:01 2006
@@ -32,6 +32,7 @@
 import org.apache.ojb.broker.accesslayer.JoinSyntaxTypes;
 import org.apache.ojb.broker.lob.BlobHandle;
 import org.apache.ojb.broker.lob.ClobHandle;
+import org.apache.ojb.broker.lob.LobHandle;
 import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
 import org.apache.ojb.broker.query.LikeCriteria;
 import org.apache.ojb.broker.util.SqlHelper;
@@ -319,19 +320,32 @@
             /*
             we use method advised by JDBC 3.0 specification (see 16.3.2)
             */
-            if(value instanceof BlobHandle && ((BlobHandle) 
value).isTransient())
+            if(value instanceof LobHandle)
             {
-                int length = (int) b.length();
-                if(b.length() < 0)
+                LobHandle handle = (LobHandle) value;
+                // found new LOB object value
+                if(handle.isTransient())
                 {
-                    /*
-                    We need the length of the specified stream to use 
#setBinaryStream
-                    This workaround seems to work for many DB (hsql, mysql, 
maxdb), the
-                    stream is read till EOF without throwing an exception
-                    */
-                    length = Integer.MAX_VALUE;
+                    int length = (int) b.length();
+                    if(b.length() < 0)
+                    {
+                        /*
+                        We need the length of the specified stream to use 
#setBinaryStream
+                        This workaround seems to work for many DB (hsql, 
mysql, maxdb), the
+                        stream is read till EOF without throwing an exception
+                        */
+                        length = Integer.MAX_VALUE;
+                    }
+                    ps.setBinaryStream(index, b.getBinaryStream(), length);
+                }
+                else
+                {
+                    if(detectLocatorsUpdateState(ps))
+                    {
+                        handle.checkActive();
+                        ps.setBlob(index, b);
+                    }
                 }
-                ps.setBinaryStream(index, b.getBinaryStream(), length);
             }
             else if(detectLocatorsUpdateState(ps))
             {
@@ -365,19 +379,32 @@
             /*
             we use method advised by JDBC 3.0 specification (see 16.3.2)
             */
-            if(value instanceof ClobHandle && ((ClobHandle) 
value).isTransient())
+            if(value instanceof LobHandle)
             {
-                int length = (int) c.length();
-                if(c.length() < 0)
+                LobHandle handle = (LobHandle) value;
+                // found new LOB object value
+                if(handle.isTransient())
                 {
-                    /*
-                    We need the length of the specified stream to use 
#setCharacterStream
-                    This workaround seems to work for many DB (hsql, mysql, 
maxdb), the
-                    reader is read till EOF without throwing an exception
-                    */
-                    length = Integer.MAX_VALUE;
+                    int length = (int) c.length();
+                    if(c.length() < 0)
+                    {
+                        /*
+                        We need the length of the specified stream to use 
#setCharacterStream
+                        This workaround seems to work for many DB (hsql, 
mysql, maxdb), the
+                        reader is read till EOF without throwing an exception
+                        */
+                        length = Integer.MAX_VALUE;
+                    }
+                    ps.setCharacterStream(index, c.getCharacterStream(), 
length);
+                }
+                else
+                {
+                    if(detectLocatorsUpdateState(ps))
+                    {
+                        handle.checkActive();
+                        ps.setClob(index, c);
+                    }
                 }
-                ps.setCharacterStream(index, c.getCharacterStream(), length);
             }
             else if(detectLocatorsUpdateState(ps))
             {



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to