db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r652087 - in /db/derby/code/branches/10.3/java: drda/org/apache/derby/impl/drda/ engine/org/apache/derby/iapi/jdbc/ engine/org/apache/derby/impl/jdbc/
Date Tue, 29 Apr 2008 20:25:00 GMT
Author: kmarsden
Date: Tue Apr 29 13:25:00 2008
New Revision: 652087

URL: http://svn.apache.org/viewvc?rev=652087&view=rev
Log:

DERBY-2885 Cleanup of EmbedConnection.clearLOBMapping():
revision  552325
Contributed by Knut Anders Hatlen

DERBY-3576 Merge EngineBlob and EngineClob into a single interface
revision 642707
Contributed by Kritian Waagan.

DERBY-3354  Select from large lob table with embedded gives OutOfMemoryError
revision 644755, 644764
Contributed by Anurag Shekhar



Added:
    db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineLOB.java   (with
props)
Removed:
    db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineBlob.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineClob.java
Modified:
    db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java

Modified: db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?rev=652087&r1=652086&r2=652087&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Tue
Apr 29 13:25:00 2008
@@ -61,8 +61,7 @@
 import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
 import org.apache.derby.iapi.tools.i18n.LocalizedResource;
 import org.apache.derby.iapi.jdbc.AuthenticationService;
-import org.apache.derby.iapi.jdbc.EngineBlob;
-import org.apache.derby.iapi.jdbc.EngineClob;
+import org.apache.derby.iapi.jdbc.EngineLOB;
 import org.apache.derby.iapi.jdbc.EngineResultSet;
 import org.apache.derby.impl.jdbc.EmbedSQLException;
 import org.apache.derby.impl.jdbc.Util;
@@ -7387,10 +7386,8 @@
 						writer.writeLDBytes((byte[]) val, index);
 					break;
 				case DRDAConstants.DRDA_TYPE_NLOBLOC:
-					writer.writeInt(((EngineBlob) val).getLocator());
-					break;
 				case DRDAConstants.DRDA_TYPE_NCLOBLOC:
-					writer.writeInt(((EngineClob) val).getLocator());
+					writer.writeInt(((EngineLOB)val).getLocator());
 					break;
 				default:
 					if (SanityManager.DEBUG) 

Added: db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineLOB.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineLOB.java?rev=652087&view=auto
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineLOB.java (added)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineLOB.java Tue
Apr 29 13:25:00 2008
@@ -0,0 +1,54 @@
+/*
+
+   Derby - Class org.apache.derby.iapi.jdbc.EngineLOB
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derby.iapi.jdbc;
+
+import java.sql.SQLException;
+
+/**
+ * Additional methods the embedded engine exposes on all of its large object
+ * (LOB) implementations.
+ * <p>
+ * An internal API only, mainly for the network server.
+ * <p>
+ * <b>Implementation note</b>: If a new method is needed, that only applies to
+ * one specific large object type (for instance a Blob), one should consider
+ * creating a new interface that extends from this one.
+ */
+public interface EngineLOB {
+
+    /**
+     * Returns LOB locator key.
+     * <p>
+     * The key can be used with {@link EmbedConnection#getLobMapping} to
+     * retrieve this LOB at a later time.
+     *
+     * @return Locator key for this LOB
+     */
+    public int getLocator();
+
+    /**
+     * Frees all resources assoicated with this LOB.
+     *
+     * @throws SQLException if an error occurs during cleanup
+     */
+    public void free() throws SQLException;
+}

Propchange: db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineLOB.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java?rev=652087&r1=652086&r2=652087&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java Tue
Apr 29 13:25:00 2008
@@ -24,7 +24,7 @@
 
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.error.StandardException;
-import org.apache.derby.iapi.jdbc.EngineBlob;
+import org.apache.derby.iapi.jdbc.EngineLOB;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.types.DataValueDescriptor;
@@ -68,14 +68,14 @@
 
  */
 
-final class EmbedBlob extends ConnectionChild implements Blob, EngineBlob
+final class EmbedBlob extends ConnectionChild implements Blob, EngineLOB
 {
     // blob is either materialized or still in stream
     private boolean         materialized;
     private InputStream     myStream;
     
     // locator key for lob. used by Network Server.
-    private final int             locator;
+    private int             locator;
     
     /*
      * Length of the BLOB if known. Set to -1 if
@@ -117,7 +117,7 @@
              materialized = true;
              //add entry in connection so it can be cleared 
              //when transaction is not valid
-             locator = con.addLOBMapping (this);
+             con.addLOBReference (this);
          }
          catch (IOException e) {
              throw Util.setStreamFailure (e);
@@ -193,7 +193,7 @@
         pos = 0;
         //add entry in connection so it can be cleared 
         //when transaction is not valid
-        this.locator = con.addLOBMapping (this);
+        con.addLOBReference (this);
     }
 
 
@@ -906,6 +906,8 @@
         //valid
         isValid = false;
         
+        //remove entry from connection
+        localConn.removeLOBMapping(locator);
         //initialialize length to default value -1
         myLength = -1;
         
@@ -1000,6 +1002,9 @@
      * @return The locator identifying this blob
      */
     public int getLocator() {
+        if (locator == 0) {
+            locator = localConn.addLOBMapping(this);
+        }
         return locator;
     }
 }

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java?rev=652087&r1=652086&r2=652087&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java Tue
Apr 29 13:25:00 2008
@@ -24,7 +24,7 @@
 
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.error.StandardException;
-import org.apache.derby.iapi.jdbc.EngineClob;
+import org.apache.derby.iapi.jdbc.EngineLOB;
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.types.DataValueDescriptor;
 import org.apache.derby.iapi.types.Resetable;
@@ -67,7 +67,7 @@
         new update methods can safely be added into implementation.
    </UL>
  */
-final class EmbedClob extends ConnectionChild implements Clob, EngineClob
+final class EmbedClob extends ConnectionChild implements Clob, EngineLOB
 {
 
     /**
@@ -79,7 +79,7 @@
     /** Tells whether the Clob has been freed or not. */
     private boolean isValid = true;
 
-    private final int locator;
+    private int locator;
     
     /**
      * Creates an empty Clob object.
@@ -91,7 +91,7 @@
     EmbedClob(EmbedConnection con) throws SQLException {
         super(con);
         this.clob = new TemporaryClob (con.getDBName(), this);
-        this.locator = con.addLOBMapping (this);
+        con.addLOBReference (this);
     }
 
     /**
@@ -156,7 +156,7 @@
                 throw se;
             }
         }
-        this.locator = con.addLOBMapping (this);
+        con.addLOBReference (this);
     }
 
     /**
@@ -663,6 +663,7 @@
             } catch (IOException e) {
                 throw Util.setStreamFailure(e);
             } finally {
+                localConn.removeLOBMapping(locator);
                 this.clob = null;
             }
         }
@@ -791,6 +792,9 @@
      * @return locator value for this Clob.
      */
     public int getLocator() {
+        if (locator == 0) {
+            locator = localConn.addLOBMapping(this);
+        }
         return locator;
     }
 }

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java?rev=652087&r1=652086&r2=652087&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
Tue Apr 29 13:25:00 2008
@@ -61,10 +61,13 @@
 import java.sql.SQLWarning;
 import java.sql.Statement;
 
+import java.util.Map;
+import java.util.WeakHashMap;
 import java.util.HashMap;
 import java.util.Properties;
 import java.util.Iterator;
 
+import org.apache.derby.iapi.jdbc.EngineLOB;
 import org.apache.derby.impl.jdbc.authentication.NoneAuthenticationServiceImpl;
 
 /**
@@ -126,6 +129,13 @@
 	private HashMap lobHashMap = null;
 	private int lobHMKey = 0;
 
+    /**
+     * Map to keep track of all the lobs associated with this
+     * connection. These lobs will be cleared after the transaction
+     * is no longer valid or when connection is closed
+     */
+    private WeakHashMap lobReferences = null;
+
 	//////////////////////////////////////////////////////////
 	// STATE (copied to new nested connections, but nesting
 	// specific)
@@ -2358,21 +2368,17 @@
 		//free all the lob resources in the HashMap
 		//initialize the locator value to 0 and
 		//the hash table object to null.
-		if (rootConnection.lobHashMap != null) {
-			for (Iterator e = getlobHMObj().values().iterator();
-				e.hasNext() ;) {
-				Object obj = e.next();
-				if (obj instanceof Clob)  {
-					EmbedClob temp = (EmbedClob)obj;
-					temp.free();
-				}
-				if (obj instanceof Blob) {
-					EmbedBlob temp = (EmbedBlob)obj;
-					temp.free();
-				}
+		Map map = rootConnection.lobReferences;
+		if (map != null) {
+            Iterator it = map.keySet ().iterator ();
+            while (it.hasNext()) {
+                ((EngineLOB)it.next()).free();
 			}
-			getlobHMObj().clear();
+			map.clear();
 		}
+        if (rootConnection.lobHashMap != null) {
+            rootConnection.lobHashMap.clear ();
+        }
 	}
 
 	/**
@@ -2403,6 +2409,18 @@
                 return newKey;
 	}
 
+    /**
+     * Adds an entry of the lob in WeakHashMap. These entries are used
+     * for cleanup during commit/rollback or close.
+     * @param lobReference LOB Object
+     */
+    void addLOBReference (Object lobReference) {
+        if (rootConnection.lobReferences == null) {
+            rootConnection.lobReferences = new WeakHashMap ();
+        }
+        rootConnection.lobReferences.put (lobReference, null);
+    }
+
 	/**
 	* Return the Hash Map in the root connection
 	* @return the HashMap that contains the locator to LOB object mapping

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java?rev=652087&r1=652086&r2=652087&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java
Tue Apr 29 13:25:00 2008
@@ -27,8 +27,7 @@
 import java.sql.DriverManager;
 import java.sql.SQLException;
 
-import org.apache.derby.iapi.jdbc.EngineBlob;
-import org.apache.derby.iapi.jdbc.EngineClob;
+import org.apache.derby.iapi.jdbc.EngineLOB;
 import org.apache.derby.iapi.reference.SQLState;
 
 /**
@@ -44,7 +43,7 @@
      * @throws a SQLException.
      */
     public static int CLOBCREATELOCATOR() throws SQLException {
-        EngineClob clob = (EngineClob) getEmbedConnection().createClob();
+        EngineLOB clob = (EngineLOB)getEmbedConnection().createClob();
         return clob.getLocator();
     }
 
@@ -203,7 +202,7 @@
      * @throws a SQLException.
      */
     public static int BLOBCREATELOCATOR() throws SQLException {
-        EngineBlob blob = (EngineBlob) getEmbedConnection().createBlob();
+        EngineLOB blob = (EngineLOB)getEmbedConnection().createBlob();
         return blob.getLocator();
     }
 



Mime
View raw message