db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1477222 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/sql/ impl/jdbc/ impl/sql/ impl/sql/execute/
Date Mon, 29 Apr 2013 17:33:42 GMT
Author: rhillegas
Date: Mon Apr 29 17:33:41 2013
New Revision: 1477222

URL: http://svn.apache.org/r1477222
Log:
DERBY-6206: Cleanup some mutability problems in the rg.apache.derby.impl.sql package.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/ResultDescription.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericResultDescription.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericAggregator.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java?rev=1477222&r1=1477221&r2=1477222&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java Mon Apr
29 17:33:41 2013
@@ -191,6 +191,12 @@ public interface PreparedStatement
 	 */
 	DataTypeDescriptor[]	getParameterTypes();
 
+    /**
+     * Get the type of the parameter at the given (0-based) index.
+     * Raises an exception if the index is out of range.
+     */
+    DataTypeDescriptor  getParameterType( int idx ) throws StandardException;
+
 	/**
 	 *	Return the SQL string that this statement is for.
 	 *

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/ResultDescription.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/ResultDescription.java?rev=1477222&r1=1477221&r2=1477222&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/ResultDescription.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/ResultDescription.java Mon Apr
29 17:33:41 2013
@@ -54,6 +54,11 @@ public interface ResultDescription
 	*/
 	public ResultColumnDescriptor[] getColumnInfo();
 
+    /**
+     * Return the information about a single column (0-based indexing)
+     */
+    public  ResultColumnDescriptor  getColumnInfo( int idx );
+
 	/**
 	 * Returns a ResultColumnDescriptor for the column, given the ordiinal
 	 * position of the column.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java?rev=1477222&r1=1477221&r2=1477222&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
Mon Apr 29 17:33:41 2013
@@ -1552,54 +1552,20 @@ public class EmbedPreparedStatement
 
 
 	/**
-		Check the parameterINdex is in range and return the
-		array of type descriptors.
-
-		@exception SQLException parameter is out of range
-	*/
-	protected final DataTypeDescriptor[] getTypes(int parameterIndex)
-		throws SQLException {
-
-		DataTypeDescriptor[] types = preparedStatement.getParameterTypes();
-
-		if (types == null) {
-			throw newSQLException(SQLState.NO_INPUT_PARAMETERS);
-		}
-
-		/* Check that the parameterIndex is in range. */
-		if (parameterIndex < 1 ||
-				parameterIndex > types.length) {
-
-			/* This message matches the one used by the DBMS */
-			throw newSQLException(SQLState.LANG_INVALID_PARAM_POSITION, 
-            new Integer(parameterIndex), new Integer(types.length));
-		}
-		return types;
-	}
-
-	/**
 		Get the target JDBC type for a parameter. Will throw exceptions
-		if the parameter index is out of range
+		if the parameter index is out of range. The parameterIndex is 1-based.
 
 		@exception SQLException parameter is out of range
 	*/
 	protected int getParameterJDBCType(int parameterIndex)
-		throws SQLException {
-
-		DataTypeDescriptor[] types = getTypes(parameterIndex);
-
-		int type = types[parameterIndex -1] == null ? 
-			Types.OTHER :
-			types[parameterIndex - 1].getTypeId().getJDBCTypeId();
-
-		if (SanityManager.DEBUG) {
-			//int pmType = getEmbedParameterSetMetaData().getParameterType(parameterIndex);
-			//if (type != pmType) {
-				//SanityManager.THROWASSERT("MISMATCH PARAMETER META DATA param " + parameterIndex +
" types " + type + " != " + pmType + "\n" + SQLText);
-			//}
-		}
-
-		return type;
+		throws SQLException
+    {
+        try {
+            DataTypeDescriptor dtd = preparedStatement.getParameterType( parameterIndex-1
);
+
+            return (dtd == null) ? Types.OTHER : dtd.getTypeId().getJDBCTypeId();
+            
+		} catch (StandardException t) { throw EmbedResultSet.noStateChangeException(t); }
 	}
 
     /**
@@ -1610,9 +1576,14 @@ public class EmbedPreparedStatement
      * @throws SQLException if parameter is out of range
      */
     protected final String getParameterSQLType(int parameterIndex)
-            throws SQLException {
-        DataTypeDescriptor[] pTypes = getTypes(parameterIndex);
-        return pTypes[parameterIndex-1].getTypeName();
+            throws SQLException
+    {
+        try {
+            DataTypeDescriptor dtd = preparedStatement.getParameterType( parameterIndex-1
);
+
+            return (dtd == null) ? null : dtd.getTypeName();
+            
+		} catch (StandardException t) { throw EmbedResultSet.noStateChangeException(t); }
     }
 
     /**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java?rev=1477222&r1=1477221&r2=1477222&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
Mon Apr 29 17:33:41 2013
@@ -36,6 +36,7 @@ import org.apache.derby.iapi.services.st
 import org.apache.derby.iapi.services.cache.Cacheable;
 
 import org.apache.derby.catalog.UUID;
+import org.apache.derby.iapi.services.io.ArrayUtil;
 import org.apache.derby.iapi.services.uuid.UUIDFactory;
 import org.apache.derby.iapi.util.ByteArray;
 import org.apache.derby.iapi.util.ReuseFactory;
@@ -48,6 +49,7 @@ import org.apache.derby.iapi.sql.Paramet
 import org.apache.derby.iapi.sql.PreparedStatement;
 import org.apache.derby.iapi.sql.Statement;
 import org.apache.derby.iapi.types.DataTypeDescriptor;
+import org.apache.derby.iapi.types.DataTypeUtilities;
 import org.apache.derby.iapi.sql.ResultDescription;
 import org.apache.derby.iapi.sql.ResultSet;
 import org.apache.derby.iapi.sql.Activation;
@@ -488,9 +490,33 @@ recompileOutOfDatePlan:
 	}
 
 	public DataTypeDescriptor[]	getParameterTypes()	{
-		return paramTypeDescriptors;
+		return (DataTypeDescriptor[]) ArrayUtil.copy( paramTypeDescriptors );
 	}
 
+    /** Return the type of the parameter (0-based indexing) */
+    public DataTypeDescriptor  getParameterType( int idx ) throws StandardException
+    {
+		if ( paramTypeDescriptors == null )
+        {
+			throw StandardException.newException( SQLState.NO_INPUT_PARAMETERS );
+		}
+
+		/* Check that the parameterIndex is in range. */
+		if ( (idx < 0) || (idx >= paramTypeDescriptors.length) )
+        {
+			/* This message matches the one used by the DBMS */
+			throw StandardException.newException
+                (
+                 SQLState.LANG_INVALID_PARAM_POSITION, 
+                 new Integer( idx+1 ),
+                 new Integer( paramTypeDescriptors.length )
+                 );
+		}
+
+        return paramTypeDescriptors[ idx ];
+    }
+    
+
 	public String getSource() {
 		return (sourceTxt != null) ?
 			sourceTxt : 
@@ -571,7 +597,7 @@ recompileOutOfDatePlan:
 	 */
 	public Timestamp getBeginCompileTimestamp()
 	{
-		return beginCompileTimestamp;
+		return DataTypeUtilities.clone( beginCompileTimestamp );
 	}
 
 	/**
@@ -581,7 +607,7 @@ recompileOutOfDatePlan:
 	 */
 	public Timestamp getEndCompileTimestamp()
 	{
-		return endCompileTimestamp;
+		return DataTypeUtilities.clone( endCompileTimestamp );
 	}
 
 	void setCompileTimeWarnings(SQLWarning warnings) {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericResultDescription.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericResultDescription.java?rev=1477222&r1=1477221&r2=1477222&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericResultDescription.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericResultDescription.java
Mon Apr 29 17:33:41 2013
@@ -27,6 +27,7 @@ import org.apache.derby.iapi.sql.ResultD
 
 import org.apache.derby.iapi.services.sanity.SanityManager;
 
+import org.apache.derby.iapi.services.io.ArrayUtil;
 import org.apache.derby.iapi.services.io.StoredFormatIds;
 import org.apache.derby.iapi.services.io.FormatIdUtil;
 import org.apache.derby.iapi.services.io.Formatable;
@@ -145,9 +146,11 @@ public final class GenericResultDescript
 	}
 
 	public ResultColumnDescriptor[] getColumnInfo() {
-		return columns;
+		return (ResultColumnDescriptor[]) ArrayUtil.copy( columns );
 	}
 
+    public  ResultColumnDescriptor  getColumnInfo( int idx ) { return columns[ idx ]; }
+
 	/**
 	 * position is 1-based.
 	 * @see ResultDescription#getColumnDescriptor

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericAggregator.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericAggregator.java?rev=1477222&r1=1477221&r2=1477222&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericAggregator.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericAggregator.java
Mon Apr 29 17:33:41 2013
@@ -312,7 +312,7 @@ class GenericAggregator 
                     (
                      cf,
                      aggInfo.getAggregateName(),
-                     aggInfo.getResultDescription().getColumnInfo()[ 0 ].getType()
+                     aggInfo.getResultDescription().getColumnInfo( 0 ).getType()
                      );
 
 			} catch (Exception e)



Mime
View raw message