db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r415081 - /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/lob/LOBTest.java
Date Sun, 18 Jun 2006 00:13:56 GMT
Author: arminw
Date: Sat Jun 17 17:13:56 2006
New Revision: 415081

URL: http://svn.apache.org/viewvc?rev=415081&view=rev
Log:
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=415081&r1=415080&r2=415081&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 Sat Jun
17 17:13:56 2006
@@ -28,9 +28,10 @@
 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.query.Criteria;
+import org.apache.ojb.broker.query.QueryFactory;
+import org.apache.ojb.broker.query.ReportQueryByCriteria;
 import org.apache.ojb.broker.util.ObjectModification;
 import org.apache.ojb.junit.PBTestCase;
 
@@ -70,9 +71,107 @@
 
 //#ifdef JDBC30
 
+
+    public void testReportQuery() throws Exception
+    {
+        int size = 1500;
+
+        byte[] barr = new byte[size];
+        char[] carr = new char[size/10];
+        for(int i = 0; i < size; i++)
+        {
+            barr[i] = (byte) 'x';
+        }
+
+        for(int i = 0; i < size/10; i++)
+        {
+            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");
+        crit.addEqualTo("id", new Integer(obj.getId()));
+        ReportQueryByCriteria q = QueryFactory.newReportQuery(LobObject.class, crit);
+        q.setAttributes(new String[]{"blob", "clob"});
+
+        Iterator result = broker.getReportQueryIteratorByQuery(q);
+        while(result.hasNext())
+        {
+            Object[] arr =  (Object[]) result.next();
+            assertNotNull("BLOB expected", arr[0]);
+            assertNotNull("CLOB expected", arr[1]);
+            Blob bb = (Blob) arr[0];
+            Clob cc = (Clob) arr[1];
+            assertEquals(size, bb.length());
+            assertEquals(size / 10, cc.length());
+        }
+
+        broker.clearCache();
+        result = broker.getReportQueryIteratorByQuery(q);
+        while(result.hasNext())
+        {
+            Object[] arr =  (Object[]) result.next();
+            assertNotNull("BLOB expected", arr[0]);
+            assertNotNull("CLOB expected", arr[1]);
+            Blob bb = (Blob) arr[0];
+            Clob cc = (Clob) arr[1];
+            assertEquals(size, bb.length());
+            assertEquals(size / 10, cc.length());
+        }
+        broker.commitTransaction();
+
+        // without active tx it's not allowed to access LOB content
+        // except we bypass the OJB wrapper
+        result = broker.getReportQueryIteratorByQuery(q);
+        while(result.hasNext())
+        {
+            Object[] arr =  (Object[]) result.next();
+            assertNotNull("BLOB expected", arr[0]);
+            assertNotNull("CLOB expected", arr[1]);
+            Blob bb = (Blob) arr[0];
+            Clob cc = (Clob) arr[1];
+            try
+            {
+                assertEquals(size, bb.length());
+                fail("Exception expected");
+            }
+            catch(LobException e)
+            {
+                // expected
+            }
+            try
+            {
+                assertEquals(size / 10, cc.length());
+                fail("Exception expected");
+            }
+            catch(LobException e)
+            {
+                // expected
+            }
+            // bypass the OJB wrapper
+            Blob realBlob = ((BlobHandle) bb).getBlob();
+            Clob realClob = ((ClobHandle) cc).getClob();
+            assertEquals(size, realBlob.length());
+            assertEquals(size / 10, realClob.length());
+        }
+    }
+
     public void testQuery() throws Exception
     {
-        int size = 555;
+        int size = 500;
 
         byte[] barr = new byte[size];
         char[] carr = new char[size];



---------------------------------------------------------------------
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