db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r125949 - incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc
Date Fri, 21 Jan 2005 18:14:40 GMT
Author: djd
Date: Fri Jan 21 10:14:39 2005
New Revision: 125949

URL: http://svn.apache.org/viewcvs?view=rev&rev=125949
Log:
Move BigDecimal methods and Blob/Clob methods into or out of JDBC 2.0
Prepared/CallableStatement implementation classes.
Refactor EmbedConnection20 in preparation for removing it.
See design attachment for Derby-97 for details

Modified:
   incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java
   incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement20.java
   incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
   incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection20.java
   incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
   incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement20.java

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java?view=diff&rev=125949&p1=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java&r1=125948&p2=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java&r2=125949
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java
Fri Jan 21 10:14:39 2005
@@ -30,7 +30,6 @@
 import org.apache.derby.iapi.reference.JDBC30Translation;
 import org.apache.derby.iapi.reference.SQLState;
 
-import java.math.BigDecimal;
 import java.sql.CallableStatement;
 import java.sql.SQLException;
 import java.sql.Date;
@@ -356,24 +355,6 @@
 			DataValueDescriptor param = getParms().getParameterForGet(parameterIndex-1);
 			double v = param.getDouble();
 			wasNull = (v == 0.0) && param.isNull();
-			return v;
-		} catch (StandardException e)
-		{
-			throw EmbedResultSet.noStateChangeException(e);
-		}
-
-	}
-
-    /**
-	 * @see CallableStatement#getBigDecimal
-     * @exception SQLException NoOutputParameters thrown.
-     */
-    public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException
-	{
-		checkStatus();
-		try {
-			BigDecimal v =  getParms().getParameterForGet(parameterIndex-1).getBigDecimal();
-			wasNull = (v == null);
 			return v;
 		} catch (StandardException e)
 		{

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement20.java
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement20.java?view=diff&rev=125949&p1=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement20.java&r1=125948&p2=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement20.java&r2=125949
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement20.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement20.java
Fri Jan 21 10:14:39 2005
@@ -250,32 +250,6 @@
      /**
       * JDBC 2.0
       *
-      * Set a BLOB parameter.
-      *
-      * @param i the first parameter is 1, the second is 2, ...
-      * @param x an object representing a BLOB
-      * @exception SQLException Feature not implemented for now.
-      */
-     public void setBlob (int i, Blob x) throws SQLException {
- 		throw Util.notImplemented();
-	 }
- 
-     /**
-      * JDBC 2.0
-      *
-      * Set a CLOB parameter.
-      *
-      * @param i the first parameter is 1, the second is 2, ...
-      * @param x an object representing a CLOB
-      * @exception SQLException Feature not implemented for now.
-      */
-     public void setClob (int i, Clob x) throws SQLException {
- 		throw Util.notImplemented();
-	 }
- 
-     /**
-      * JDBC 2.0
-      *
       * Set an Array parameter.
       *
       * @param i the first parameter is 1, the second is 2, ...
@@ -1158,6 +1132,63 @@
     throws SQLException
 	{
 		throw Util.notImplemented();
+	}
+
+	/*
+	** Methods using BigDecimal, moved out of EmbedPreparedStatement
+	** to allow that class to support JSR169.
+	*/
+	/**
+     * Set a parameter to a java.lang.BigDecimal value.  
+     * The driver converts this to a SQL NUMERIC value when
+     * it sends it to the database.
+     *
+     * @param parameterIndex the first parameter is 1, the second is 2, ...
+     * @param x the parameter value
+	 * @exception SQLException thrown on failure.
+     */
+    public final void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException
{
+		checkStatus();
+		try {
+			/* JDBC is one-based, DBMS is zero-based */
+			getParms().getParameterForSet(parameterIndex - 1).setValue(x);
+
+		} catch (Throwable t) {
+			throw EmbedResultSet.noStateChangeException(t);
+		}
+	}
+    /**
+	 * @see CallableStatement#getBigDecimal
+     * @exception SQLException NoOutputParameters thrown.
+     */
+    public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException
+	{
+		checkStatus();
+		try {
+			BigDecimal v =  getParms().getParameterForGet(parameterIndex-1).getBigDecimal();
+			wasNull = (v == null);
+			return v;
+		} catch (StandardException e)
+		{
+			throw EmbedResultSet.noStateChangeException(e);
+		}
+
+	}
+	/**
+		Allow explict setObject conversions by sub-classes for classes
+		not supported by this variant. In this case handle BigDecimal.
+		@return true if the object was set successfully, false if no valid
+		conversion exists.
+
+		@exception SQLException value could not be set.
+	*/
+	boolean setObjectConvert(int parameterIndex, Object x) throws SQLException
+	{
+		if (x instanceof BigDecimal) {
+			setBigDecimal(parameterIndex, (BigDecimal) x);
+			return true;
+		}
+		return false;
 	}
 }
 

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java?view=diff&rev=125949&p1=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java&r1=125948&p2=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java&r2=125949
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
Fri Jan 21 10:14:39 2005
@@ -1199,6 +1199,39 @@
 		topWarning = null;
 	}
 
+ 	/////////////////////////////////////////////////////////////////////////
+	//
+	//	JDBC 2.0	-	New public methods
+	//
+	/////////////////////////////////////////////////////////////////////////
+
+    /**
+     *
+	 * Get the type-map object associated with this connection.
+	 * By default, the map returned is empty.
+	 * JDBC 2.0 - java.util.Map requires JDK 1
+     *
+     */
+    public final java.util.Map getTypeMap() {
+		// just return an immuntable empty map
+		return java.util.Collections.EMPTY_MAP;
+    }
+
+    /** 
+	 * Install a type-map object as the default type-map for
+	 * this connection.
+	 * JDBC 2.0 - java.util.Map requires JDK 1
+     *
+     * @exception SQLException Feature not implemented for now.
+	 */
+    public final void setTypeMap(java.util.Map map) throws SQLException {
+
+        if( map == null)
+            throw Util.generateCsSQLException(SQLState.INVALID_API_PARAMETER,map,"map",
+                                              "java.sql.Connection.setTypeMap");
+        if(!(map.isEmpty()))
+            throw Util.notImplemented();
+    }
 
 	/////////////////////////////////////////////////////////////////////////
 	//

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection20.java
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection20.java?view=diff&rev=125949&p1=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection20.java&r1=125948&p2=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection20.java&r2=125949
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection20.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection20.java
Fri Jan 21 10:14:39 2005
@@ -84,40 +84,6 @@
 		}
 	}
 
- 	/////////////////////////////////////////////////////////////////////////
-	//
-	//	JDBC 2.0	-	New public methods
-	//
-	/////////////////////////////////////////////////////////////////////////
-
-    /**
-     *
-	 * Get the type-map object associated with this connection.
-	 * By default, the map returned is empty.
-	 * JDBC 2.0 - java.util.Map requires JDK 1
-     *
-     */
-    public java.util.Map getTypeMap() {
-		// just return an empty map
-		return new java.util.Hashtable(0);
-    }
-
-    /** 
-	 * Install a type-map object as the default type-map for
-	 * this connection.
-	 * JDBC 2.0 - java.util.Map requires JDK 1
-     *
-     * @exception SQLException Feature not implemented for now.
-	 */
-    public void setTypeMap(java.util.Map map) throws SQLException {
-
-        if( map == null)
-            throw Util.generateCsSQLException(SQLState.INVALID_API_PARAMETER,map,"map",
-                                              "java.sql.Connection.setTypeMap");
-        if(!(map.isEmpty()))
-            throw Util.notImplemented();
-    }
-
 	/*
 	** methods to be overridden by subimplementations wishing to insert
 	** their classes into the mix.

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java?view=diff&rev=125949&p1=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java&r1=125948&p2=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java&r2=125949
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
Fri Jan 21 10:14:39 2005
@@ -59,7 +59,6 @@
 import java.sql.Clob;
 import java.sql.Blob;
 
-import java.math.BigDecimal;
 import java.io.InputStream;
 import java.io.DataInputStream;
 import java.io.IOException;
@@ -71,7 +70,10 @@
 /**
  *
  * EmbedPreparedStatement is a local JDBC statement.
- *
+  <P><B>Supports</B>
+   <UL>
+   <LI> JSR169
+   </UL>
  */
 public abstract class EmbedPreparedStatement
 	extends EmbedStatement
@@ -432,25 +434,6 @@
 	}
 
     /**
-     * Set a parameter to a java.lang.BigDecimal value.  
-     * The driver converts this to a SQL NUMERIC value when
-     * it sends it to the database.
-     *
-     * @param parameterIndex the first parameter is 1, the second is 2, ...
-     * @param x the parameter value
-	 * @exception SQLException thrown on failure.
-     */
-    public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
-		checkStatus();
-		try {
-			/* JDBC is one-based, DBMS is zero-based */
-			getParms().getParameterForSet(parameterIndex - 1).setValue(x);
-
-		} catch (Throwable t) {
-			throw EmbedResultSet.noStateChangeException(t);
-		}
-	}
-    /**
      * Set a parameter to a Java String value.  The driver converts this
      * to a SQL VARCHAR or LONGVARCHAR value (depending on the arguments
      * size relative to the driver's limits on VARCHARs) when it sends
@@ -967,10 +950,6 @@
 			return;
 		}
 
-		if (x instanceof BigDecimal) {
-			setBigDecimal(parameterIndex, (BigDecimal) x);
-			return;
-		}
 		if (x instanceof Boolean) {
 			setBoolean(parameterIndex, ((Boolean) x).booleanValue());
 			return;
@@ -1020,11 +999,29 @@
 			return;
 		}
 
+		if (setObjectConvert(parameterIndex, x))
+			return;
+
 		
 		throw dataTypeConversion(parameterIndex, x.getClass().getName());
 
 	}
 
+	/**
+		Allow explict setObject conversions by sub-classes for classes
+		not supported by this variant. E.g. BigDecimal
+		This top-level implementation always returns false.
+
+		@return true if the object was set successfully, false if no valid
+		conversion exists.
+
+		@exception SQLException value could not be set.
+	*/
+	boolean setObjectConvert(int parameterIndex, Object x) throws SQLException
+	{
+		return false;
+	}
+
     /**
      * @see java.sql.Statement#execute
 	 * @exception SQLException thrown on failure.
@@ -1095,6 +1092,61 @@
 			throw EmbedResultSet.noStateChangeException(t);
 		}
 	}
+
+
+    /**
+     * JDBC 2.0
+     *
+     * Set a BLOB parameter.
+     *
+     * @param i the first parameter is 1, the second is 2, ...
+     * @param x an object representing a BLOB
+     */
+    public void setBlob (int i, Blob x)
+        throws SQLException
+    {
+        int colType;
+        synchronized (getConnectionSynchronization())
+        {
+            colType = getParameterJDBCType(i);
+        }
+		// DB2: only allow setBlob on a BLOB column.
+		if (colType != Types.BLOB)
+            throw dataTypeConversion(i, "java.sql.Blob");
+
+		if (x == null)
+			setNull(i, Types.BLOB);
+		else
+			setBinaryStreamInternal(i, x.getBinaryStream(), -1);
+	}
+
+    /**
+     * JDBC 2.0
+     *
+     * Set a CLOB parameter.
+     *
+     * @param i the first parameter is 1, the second is 2, ...
+     * @param x an object representing a CLOB
+     */
+    public void setClob (int i, Clob x)
+        throws SQLException
+    {
+        int colType;
+        synchronized (getConnectionSynchronization())
+        {
+            colType = getParameterJDBCType(i);
+        }
+
+		// DB2, only allow setClob on a CLOB column.
+		if (colType != Types.CLOB)
+            throw dataTypeConversion(i, "java.sql.Clob");
+
+		if (x == null)
+			setNull(i, Types.CLOB);
+		else
+			setCharacterStreamInternal(i, x.getCharacterStream(), -1);
+	}
+
 	/**
 	 * Get the ParameterValueSet from the activation
 	 *

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement20.java
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement20.java?view=diff&rev=125949&p1=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement20.java&r1=125948&p2=incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement20.java&r2=125949
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement20.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement20.java
Fri Jan 21 10:14:39 2005
@@ -30,6 +30,8 @@
 
 import java.io.InputStream;
 
+import java.math.BigDecimal;
+
 import java.sql.SQLException;
 import java.sql.SQLWarning;
 import java.sql.Date;
@@ -47,7 +49,10 @@
 /**
  * This class extends the EmbedPreparedStatement class in order to support new
  * methods and classes that come with JDBC 2.0.
- *
+  <P><B>Supports</B>
+   <UL>
+   <LI> JDBC 2.0
+   </UL>
  *	@see org.apache.derby.impl.jdbc.EmbedPreparedStatement
  *
  *	@author francois
@@ -91,58 +96,7 @@
 		throw Util.notImplemented();
 	}
 
-    /**
-     * JDBC 2.0
-     *
-     * Set a BLOB parameter.
-     *
-     * @param i the first parameter is 1, the second is 2, ...
-     * @param x an object representing a BLOB
-     */
-    public void setBlob (int i, Blob x)
-        throws SQLException
-    {
-        int colType;
-        synchronized (getConnectionSynchronization())
-        {
-            colType = getParameterJDBCType(i);
-        }
-		// DB2: only allow setBlob on a BLOB column.
-		if (colType != Types.BLOB)
-            throw dataTypeConversion(i, "java.sql.Blob");
-
-		if (x == null)
-			setNull(i, Types.BLOB);
-		else
-			setBinaryStreamInternal(i, x.getBinaryStream(), -1);
-	}
 
-    /**
-     * JDBC 2.0
-     *
-     * Set a CLOB parameter.
-     *
-     * @param i the first parameter is 1, the second is 2, ...
-     * @param x an object representing a CLOB
-     */
-    public void setClob (int i, Clob x)
-        throws SQLException
-    {
-        int colType;
-        synchronized (getConnectionSynchronization())
-        {
-            colType = getParameterJDBCType(i);
-        }
-
-		// DB2, only allow setClob on a CLOB column.
-		if (colType != Types.CLOB)
-            throw dataTypeConversion(i, "java.sql.Clob");
-
-		if (x == null)
-			setNull(i, Types.CLOB);
-		else
-			setCharacterStreamInternal(i, x.getCharacterStream(), -1);
-	}
 
 
     /**
@@ -156,6 +110,47 @@
      */
     public void setArray (int i, Array x) throws SQLException {
 		throw Util.notImplemented();
+	}
+
+	/*
+	** Methods using BigDecimal, moved out of EmbedPreparedStatement
+	** to allow that class to support JSR169.
+	*/
+	/**
+     * Set a parameter to a java.lang.BigDecimal value.  
+     * The driver converts this to a SQL NUMERIC value when
+     * it sends it to the database.
+     *
+     * @param parameterIndex the first parameter is 1, the second is 2, ...
+     * @param x the parameter value
+	 * @exception SQLException thrown on failure.
+     */
+    public final void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException
{
+		checkStatus();
+		try {
+			/* JDBC is one-based, DBMS is zero-based */
+			getParms().getParameterForSet(parameterIndex - 1).setValue(x);
+
+		} catch (Throwable t) {
+			throw EmbedResultSet.noStateChangeException(t);
+		}
+	}
+
+	/**
+		Allow explict setObject conversions by sub-classes for classes
+		not supported by this variant. In this case handle BigDecimal.
+		@return true if the object was set successfully, false if no valid
+		conversion exists.
+
+		@exception SQLException value could not be set.
+	*/
+	boolean setObjectConvert(int parameterIndex, Object x) throws SQLException
+	{
+		if (x instanceof BigDecimal) {
+			setBigDecimal(parameterIndex, (BigDecimal) x);
+			return true;
+		}
+		return false;
 	}
 }
 

Mime
View raw message