db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r406175 - in /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/lob: BlobHandle.java ClobHandle.java LobHandle.java
Date Sun, 14 May 2006 00:44:08 GMT
Author: arminw
Date: Sat May 13 17:44:07 2006
New Revision: 406175

URL: http://svn.apache.org/viewcvs?rev=406175&view=rev
Log:
improve method separation

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/lob/BlobHandle.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/lob/ClobHandle.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/lob/LobHandle.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/lob/BlobHandle.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/lob/BlobHandle.java?rev=406175&r1=406174&r2=406175&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/lob/BlobHandle.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/lob/BlobHandle.java Sat
May 13 17:44:07 2006
@@ -29,89 +29,75 @@
  */
 public class BlobHandle extends LobHandle implements Blob
 {
-    private Blob blob;
-
     BlobHandle(PersistenceBrokerInternal broker, Blob blob)
     {
-        super(broker);
-        this.blob = blob;
-        if(blob instanceof Lob)
-        {
-            setTransient(true);
-        }
-    }
-
-    protected void txFail()
-    {
-        super.txFail();
-        if(!isTransient()) this.blob = null;
+        super(broker, blob);
     }
 
-    protected void txSuccess()
+    /**
+     * Returns the innermost {@link java.sql.Blob} instance.
+     *
+     * @return The innermost wrapped LOB instance.
+     */
+    public Blob getBlob()
     {
-        super.txSuccess();
-        this.blob = null;
+        Blob result = (Blob) getLocator(false);
+        if(result instanceof BlobHandle)
+        {
+            result = ((BlobHandle) result).getBlob();
+        }
+        return result;
     }
 
-    protected void inactivate()
+    private Blob getLocalBlob()
     {
-        super.inactivate();
-        if(!isTransient()) this.blob = null;
+        return (Blob) getLocator(true);
     }
 
     public long length() throws SQLException
     {
-        checkActive();
-        return blob.length();
+        return getLocalBlob().length();
     }
 
     public byte[] getBytes(long pos, int length) throws SQLException
     {
-        checkActive();
-        return blob.getBytes(pos, length);
+        return getLocalBlob().getBytes(pos, length);
     }
 
     public long position(byte pattern[], long start) throws SQLException
     {
-        checkActive();
-        return blob.position(pattern, start);
+        return getLocalBlob().position(pattern, start);
     }
 
     public InputStream getBinaryStream() throws SQLException
     {
-        checkActive();
-        return blob.getBinaryStream();
+        return getLocalBlob().getBinaryStream();
     }
 
     public long position(Blob pattern, long start) throws SQLException
     {
-        checkActive();
-        return blob.position(pattern, start);
+        return getLocalBlob().position(pattern, start);
     }
 //#ifdef JDBC30
 
     public OutputStream setBinaryStream(long pos) throws SQLException
     {
-        checkActive();
-        return blob.setBinaryStream(pos);
+        return getLocalBlob().setBinaryStream(pos);
     }
 
     public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException
     {
-        checkActive();
-        return blob.setBytes(pos, bytes, offset, len);
+        return getLocalBlob().setBytes(pos, bytes, offset, len);
     }
 
     public int setBytes(long pos, byte[] bytes) throws SQLException
     {
-        checkActive();
-        return blob.setBytes(pos, bytes);
+        return getLocalBlob().setBytes(pos, bytes);
     }
 
     public void truncate(long len) throws SQLException
     {
-        checkActive();
-        blob.truncate(len);
+        getLocalBlob().truncate(len);
     }
 
 //#endif

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/lob/ClobHandle.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/lob/ClobHandle.java?rev=406175&r1=406174&r2=406175&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/lob/ClobHandle.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/lob/ClobHandle.java Sat
May 13 17:44:07 2006
@@ -31,102 +31,86 @@
  */
 public class ClobHandle extends LobHandle implements Clob
 {
-    private Clob clob;
-
     ClobHandle(PersistenceBrokerInternal broker, Clob clob)
     {
-        super(broker);
-        this.clob = clob;
-        if(clob instanceof Lob)
-        {
-            setTransient(true);
-        }
-    }
-
-    protected void txFail()
-    {
-        super.txFail();
-        if(!isTransient()) this.clob = null;
+        super(broker, clob);
     }
 
-    protected void txSuccess()
+    /**
+     * Returns the innermost {@link java.sql.Clob} instance.
+     *
+     * @return The innermost wrapped LOB instance.
+     */
+    public Clob getClob()
     {
-        super.txSuccess();
-        this.clob = null;
+        Clob result = (Clob) getLocator(false);
+        if(result instanceof ClobHandle)
+        {
+            result = ((ClobHandle) result).getClob();
+        }
+        return result;
     }
 
-    protected void inactivate()
+    private Clob getLocalClob()
     {
-        super.inactivate();
-        if(!isTransient()) this.clob = null;
+        return (Clob) getLocator(true);
     }
 
     public long length() throws SQLException
     {
-        checkActive();
-        return clob.length();
+        return getLocalClob().length();
     }
 
     public InputStream getAsciiStream() throws SQLException
     {
-        checkActive();
-        return clob.getAsciiStream();
+        return getLocalClob().getAsciiStream();
     }
 
     public Reader getCharacterStream() throws SQLException
     {
-        checkActive();
-        return clob.getCharacterStream();
+        return getLocalClob().getCharacterStream();
     }
 
     public String getSubString(long pos, int length) throws SQLException
     {
-        checkActive();
-        return clob.getSubString(pos, length);
+        return getLocalClob().getSubString(pos, length);
     }
 
     public long position(String searchstr, long start) throws SQLException
     {
-        checkActive();
-        return clob.position(searchstr, start);
+        return getLocalClob().position(searchstr, start);
     }
 
     public long position(Clob searchstr, long start) throws SQLException
     {
-        checkActive();
-        return clob.position(searchstr, start);
+        return getLocalClob().position(searchstr, start);
     }
 
 //#ifdef JDBC30
 
     public int setString(long pos, String str) throws SQLException
     {
-        checkActive();
-        return clob.setString(pos, str);
+        return getLocalClob().setString(pos, str);
     }
 
     public int setString(long pos, String str, int offset, int len) throws SQLException
     {
-        checkActive();
-        return clob.setString(pos, str, offset, len);
+        return getLocalClob().setString(pos, str, offset, len);
     }
 
     public Writer setCharacterStream(long pos) throws SQLException
     {
-        checkActive();
-        return clob.setCharacterStream(pos);
+        return getLocalClob().setCharacterStream(pos);
     }
 
     public OutputStream setAsciiStream(long pos) throws SQLException
     {
-        checkActive();
-        return clob.setAsciiStream(pos);
+        return getLocalClob().setAsciiStream(pos);
     }
 
     public void truncate(long len) throws SQLException
     {
-        checkActive();
-        clob.truncate(len);
+        getLocalClob().truncate(len);
     }
 
 //#endif

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/lob/LobHandle.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/lob/LobHandle.java?rev=406175&r1=406174&r2=406175&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/lob/LobHandle.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/lob/LobHandle.java Sat
May 13 17:44:07 2006
@@ -28,24 +28,33 @@
 {
     private boolean active;
     private boolean isTransient;
+    private Object locator;
 
-    public LobHandle(PersistenceBrokerInternal broker)
+    LobHandle(PersistenceBrokerInternal broker, Object locator)
     {
+        this.locator = locator;
         isTransient = false;
         active = broker.isInTransaction();
+        if(locator instanceof Lob)
+        {
+            setTransient(true);
+        }
         if(active)
         {
             broker.addListener(this, false);
         }
-        /*
-        Think we should allow to query objects with LOB fields without a running
-        PB-tx. If the user try to access the LOB field, method #checkActive() will throw
an
-        exception.
-        */
-//        else
-//        {
-//            throw new LobException("LOB opertations only valid when the used PersistanceBroker
is in PB-tx");
-//        }
+    }
+
+    /**
+     * Return the locator object.
+     *
+     * @param check If <em>true</em> a validation check is done, else simply
the locator is returned.
+     * @return The locator object.
+     */
+    protected Object getLocator(boolean check)
+    {
+        if(check) checkActive();
+        return locator;
     }
 
     public boolean isTransient()
@@ -61,18 +70,21 @@
     protected void txFail()
     {
         this.active = false;
+        if(!isTransient()) this.locator = null;
     }
 
     protected void txSuccess()
     {
         this.active = false;
         this.isTransient = false;
+        this.locator = null;
     }
 
     protected void inactivate()
     {
         this.active = false;
         this.isTransient = false;
+        if(!isTransient()) this.locator = null;
     }
 
     protected boolean isActive()
@@ -84,7 +96,7 @@
     {
         if(!isTransient() && !isActive()) throw new InactiveLobException(
                 "Current LOB is not valid for access (no active PB-tx or PB-tx changed),
"
-                + "refresh the persistent object this LOB belongs too");
+                        + "refresh the persistent object LOB content after PB-tx starts");
     }
 
 



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