db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r408864 - /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/lob/LOBTest.java
Date Tue, 23 May 2006 09:58:54 GMT
Author: arminw
Date: Tue May 23 02:58:54 2006
New Revision: 408864

URL: http://svn.apache.org/viewvc?rev=408864&view=rev
Log:
fix JDK1.3 compatibility issue, add new test

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/lob/LOBTest.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/lob/LOBTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/lob/LOBTest.java?rev=408864&r1=408863&r2=408864&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/lob/LOBTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/lob/LOBTest.java Tue May
23 02:58:54 2006
@@ -22,10 +22,14 @@
 import java.io.Writer;
 import java.sql.Blob;
 import java.sql.Clob;
+import java.util.Collection;
+import java.util.Iterator;
 
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.SerializationUtils;
 import org.apache.ojb.broker.Identity;
+import org.apache.ojb.broker.query.QueryFactory;
+import org.apache.ojb.broker.query.Criteria;
 import org.apache.ojb.broker.platforms.PlatformHsqldbImpl;
 import org.apache.ojb.broker.util.ObjectModification;
 import org.apache.ojb.junit.PBTestCase;
@@ -62,6 +66,100 @@
         super.tearDown();
     }
 
+// comment out all test when JDK1.3 was used
+
+//#ifdef JDBC30
+
+    public void testQuery() throws Exception
+    {
+        int size = 555;
+
+        byte[] barr = new byte[size];
+        char[] carr = new char[size];
+        for(int i = 0; i < size; i++)
+        {
+            barr[i] = (byte) 'x';
+            carr[i] = 'y';
+        }
+
+        broker.beginTransaction();
+        Blob b = broker.serviceLobHelper().newBlob();
+        b.setBytes(1, barr);
+        Clob c = broker.serviceLobHelper().newClob();
+        c.setString(1, new String(carr));
+        LobObject obj = new LobObject();
+        obj.setBlob(b);
+        obj.setClob(c);
+        broker.store(obj);
+        broker.commitTransaction();
+
+        broker.beginTransaction();
+        Criteria crit = new Criteria();
+        crit.addNotNull("blob");
+        Collection result = broker.getCollectionByQuery(QueryFactory.newQuery(LobObject.class,
crit));
+        for(Iterator iterator = result.iterator(); iterator.hasNext();)
+        {
+            LobObject objRead =  (LobObject) iterator.next();
+            assertNotNull("BLOB expected", objRead.getBlob());
+            objRead.getBlob().length();
+        }
+
+        result = broker.getCollectionByQuery(QueryFactory.newQuery(LobObject.class, crit));
+        for(Iterator iterator = result.iterator(); iterator.hasNext();)
+        {
+            LobObject objRead =  (LobObject) iterator.next();
+            assertNotNull("BLOB expected", objRead.getBlob());
+            objRead.getBlob().length();
+        }
+        broker.commitTransaction();
+    }
+
+    public void testUpdateWithoutRefresh() throws Exception
+    {
+        int size = 555;
+
+        byte[] barr = new byte[size];
+        char[] carr = new char[size];
+        for(int i = 0; i < size; i++)
+        {
+            barr[i] = (byte) 'x';
+            carr[i] = 'y';
+        }
+
+        broker.beginTransaction();
+        Blob b = broker.serviceLobHelper().newBlob();
+        b.setBytes(1, barr);
+        Clob c = broker.serviceLobHelper().newClob();
+        c.setString(1, new String(carr));
+        LobObject obj = new LobObject();
+        obj.setBlob(b);
+        obj.setClob(c);
+        broker.store(obj);
+        broker.commitTransaction();
+
+        broker.beginTransaction();
+        broker.serviceLobHelper().setLobAutoRefresh(false);
+        Identity oid = broker.serviceIdentity().buildIdentity(obj);
+
+        // if no cache is used skip this test
+        if(broker.serviceObjectCache().lookup(oid) == null) return;
+
+        LobObject objRead = (LobObject) broker.getObjectByIdentity(oid);
+        assertNotNull("BLOB was not stored", objRead.getBlob());
+        assertNotNull("CLOB was not stored", objRead.getClob());
+
+        try
+        {
+            broker.store(obj, ObjectModification.UPDATE);
+        }
+        catch(LobException expected)
+        {
+            broker.abortTransaction();
+        }
+
+        if(broker.isInTransaction()) broker.abortTransaction();
+    }
+
     public void testLobAutoRefresh() throws Exception
     {
         int size = 50;
@@ -309,8 +407,12 @@
 
         // try update 2
         broker.beginTransaction();
+
+        // TODO: arminw: seems that under specific conditions this test freeze
+        //here, when test testLOBUpdateSetBlobSetClob() runs against mysql
         objRead = (LobObject) broker.getObjectByIdentity(oid);
         broker.serviceLobHelper().refreshLob(objRead);
+
         try
         {
             switch(updateType)
@@ -676,6 +778,17 @@
         assertEquals("abCDefgh", clob2.getSubString(1, (int) clob2.length()));
     }
 
+
+//#else
+
+/*
+                public void testEmpty()
+                {
+                    ojbSkipTestMessage("Skip all LOB tests when using JDK1.3");
+                }
+*/
+
+//#endif
 
     //*******************************************************
     // inner class - test class



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message