db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1468143 - in /db/derby/code/trunk/java/engine/org/apache/derby: catalog/types/ iapi/services/io/ impl/sql/compile/ impl/sql/execute/
Date Mon, 15 Apr 2013 17:00:54 GMT
Author: rhillegas
Date: Mon Apr 15 17:00:53 2013
New Revision: 1468143

URL: http://svn.apache.org/r1468143
Log:
DERBY-3177: Cleanup suspect coding practices in the types package.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/IndexDescriptorImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/ReferencedColumnsDescriptorImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/RoutineAliasInfo.java
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/RowMultiSetImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/QueryTreeNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java?rev=1468143&r1=1468142&r2=1468143&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/DefaultInfoImpl.java Mon
Apr 15 17:00:53 2013
@@ -21,6 +21,7 @@
 
 package org.apache.derby.catalog.types;
 
+import org.apache.derby.iapi.services.io.ArrayUtil;
 import org.apache.derby.iapi.services.io.StoredFormatIds;
 import org.apache.derby.iapi.services.io.Formatable;
 
@@ -116,7 +117,7 @@ public class DefaultInfoImpl implements 
 	 */
 	public String[] getReferencedColumnNames()
 	{
-		return referencedColumnNames;
+        return ArrayUtil.copy( referencedColumnNames );
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/IndexDescriptorImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/IndexDescriptorImpl.java?rev=1468143&r1=1468142&r2=1468143&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/IndexDescriptorImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/IndexDescriptorImpl.java
Mon Apr 15 17:00:53 2013
@@ -23,6 +23,7 @@ package org.apache.derby.catalog.types;
 
 import org.apache.derby.catalog.IndexDescriptor;
 
+import org.apache.derby.iapi.services.io.ArrayUtil;
 import org.apache.derby.iapi.services.io.Formatable;
 import org.apache.derby.iapi.services.io.StoredFormatIds;
 
@@ -98,8 +99,8 @@ public class IndexDescriptorImpl impleme
 		this.indexType = indexType;
 		this.isUnique = isUnique;
 		this.isUniqueWithDuplicateNulls = isUniqueWithDuplicateNulls;
-		this.baseColumnPositions = baseColumnPositions;
-		this.isAscending = isAscending;
+		this.baseColumnPositions = ArrayUtil.copy( baseColumnPositions );
+		this.isAscending = ArrayUtil.copy( isAscending );
 		this.numberOfOrderedColumns = numberOfOrderedColumns;
 	}
 
@@ -127,7 +128,7 @@ public class IndexDescriptorImpl impleme
 	/** @see IndexDescriptor#baseColumnPositions */
 	public int[] baseColumnPositions()
 	{
-		return baseColumnPositions;
+        return ArrayUtil.copy( baseColumnPositions );
 	}
 
 	/** @see IndexDescriptor#getKeyColumnPosition */
@@ -182,19 +183,19 @@ public class IndexDescriptorImpl impleme
 	/** @see IndexDescriptor#isAscending */
 	public boolean[]		isAscending()
 	{
-		return isAscending;
+        return ArrayUtil.copy( isAscending );
 	}
 
 	/** @see IndexDescriptor#setBaseColumnPositions */
 	public void		setBaseColumnPositions(int[] baseColumnPositions)
 	{
-		this.baseColumnPositions = baseColumnPositions;
+		this.baseColumnPositions = ArrayUtil.copy( baseColumnPositions );
 	}
 
 	/** @see IndexDescriptor#setIsAscending */
 	public void		setIsAscending(boolean[] isAscending)
 	{
-		this.isAscending = isAscending;
+		this.isAscending = ArrayUtil.copy( isAscending );
 	}
 
 	/** @see IndexDescriptor#setNumberOfOrderedColumns */

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/ReferencedColumnsDescriptorImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/ReferencedColumnsDescriptorImpl.java?rev=1468143&r1=1468142&r2=1468143&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/ReferencedColumnsDescriptorImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/ReferencedColumnsDescriptorImpl.java
Mon Apr 15 17:00:53 2013
@@ -22,6 +22,7 @@
 package org.apache.derby.catalog.types;
 
 
+import org.apache.derby.iapi.services.io.ArrayUtil;
 import org.apache.derby.iapi.services.io.Formatable;
 import org.apache.derby.iapi.services.io.StoredFormatIds;
 import org.apache.derby.catalog.ReferencedColumns;
@@ -80,7 +81,7 @@ public class ReferencedColumnsDescriptor
 
 	public ReferencedColumnsDescriptorImpl(	int[] referencedColumns)
 	{
-		this.referencedColumns = referencedColumns;
+		this.referencedColumns = ArrayUtil.copy( referencedColumns );
 	}
 
 	/**
@@ -94,8 +95,8 @@ public class ReferencedColumnsDescriptor
 	public ReferencedColumnsDescriptorImpl(	int[] referencedColumns,
 			int[] referencedColumnsInTriggerAction)
 	{
-		this.referencedColumns = referencedColumns;
-		this.referencedColumnsInTriggerAction = referencedColumnsInTriggerAction;
+		this.referencedColumns = ArrayUtil.copy( referencedColumns );
+		this.referencedColumnsInTriggerAction = ArrayUtil.copy( referencedColumnsInTriggerAction
);
 	}
 
 	/** Zero-argument constructor for Formatable interface */
@@ -107,7 +108,7 @@ public class ReferencedColumnsDescriptor
 	*/
 	public int[] getReferencedColumnPositions()
 	{
-		return referencedColumns;
+		return ArrayUtil.copy( referencedColumns );
 	}
 	
 	/**
@@ -115,7 +116,7 @@ public class ReferencedColumnsDescriptor
 	*/
 	public int[] getTriggerActionReferencedColumnPositions()
 	{
-		return referencedColumnsInTriggerAction;
+		return ArrayUtil.copy( referencedColumnsInTriggerAction );
 	}
 
 	/* Externalizable interface */

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/RoutineAliasInfo.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/RoutineAliasInfo.java?rev=1468143&r1=1468142&r2=1468143&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/RoutineAliasInfo.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/RoutineAliasInfo.java Mon
Apr 15 17:00:53 2013
@@ -172,9 +172,9 @@ public class RoutineAliasInfo extends Me
 
 		super(methodName);
 		this.parameterCount = parameterCount;
-		this.parameterNames = parameterNames;
-		this.parameterTypes = parameterTypes;
-		this.parameterModes = parameterModes;
+		this.parameterNames = ArrayUtil.copy( parameterNames );
+		setParameterTypes( parameterTypes );
+		this.parameterModes = ArrayUtil.copy( parameterModes );
 		this.dynamicResultSets = dynamicResultSets;
 		this.parameterStyle = parameterStyle;
 		this.sqlOptions = (short) (sqlAllowed & SQL_ALLOWED_MASK);
@@ -232,22 +232,25 @@ public class RoutineAliasInfo extends Me
      * Types of the parameters. If there are no parameters
      * then this may return null (or a zero length array).
      */
-	public TypeDescriptor[] getParameterTypes() {
-		return parameterTypes;
+	public TypeDescriptor[] getParameterTypes()
+    {
+        return TypeDescriptorImpl.copyTypeDescriptors( parameterTypes );
 	}
 
-	public int[] getParameterModes() {
-		return parameterModes;
-	}
+    /** Set the paramter types. Useful if they need to be bound. */
+    public  void    setParameterTypes( TypeDescriptor[] parameterTypes )
+    {
+		this.parameterTypes = TypeDescriptorImpl.copyTypeDescriptors( parameterTypes );
+    }
+
+	public int[] getParameterModes() { return ArrayUtil.copy( parameterModes ); }
         /**
          * Returns an array containing the names of the parameters.
          * As of DERBY 10.3, parameter names are optional (see DERBY-183
          * for more information). If the i-th parameter was unnamed,
          * parameterNames[i] will contain a string of length 0.
          */
-	public String[] getParameterNames() {
-		return parameterNames;
-	}
+	public String[] getParameterNames() { return ArrayUtil.copy( parameterNames );}
 
 	public int getMaxDynamicResultSets() {
 		return dynamicResultSets;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/RowMultiSetImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/RowMultiSetImpl.java?rev=1468143&r1=1468142&r2=1468143&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/RowMultiSetImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/RowMultiSetImpl.java Mon
Apr 15 17:00:53 2013
@@ -22,6 +22,7 @@
 package org.apache.derby.catalog.types;
 import org.apache.derby.catalog.TypeDescriptor;
 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 java.io.ObjectOutput;
 import java.io.ObjectInput;
@@ -86,8 +87,8 @@ public class RowMultiSetImpl extends Bas
      */
     public RowMultiSetImpl( String[] columnNames, TypeDescriptor[] types )
     {
-        _columnNames = columnNames;
-        _types = types;
+        _columnNames = ArrayUtil.copy( columnNames );
+        setTypes( types );
 
         if (
             (columnNames == null ) ||
@@ -107,10 +108,13 @@ public class RowMultiSetImpl extends Bas
     ///////////////////////////////////////////////////////////////////////////////////
 
     /** Get the names of the columns in this row set */
-    public  String[]    getColumnNames()    { return _columnNames; }
+    public  String[]    getColumnNames()    { return ArrayUtil.copy( _columnNames ); }
     
     /** Get the types of the columns in this row set */
-    public  TypeDescriptor[]    getTypes() { return _types; }
+    public  TypeDescriptor[]    getTypes() { return TypeDescriptorImpl.copyTypeDescriptors(
_types ); }
+    
+    /** Set the types of the columns in this row set */
+    public  void    setTypes( TypeDescriptor[] types ) { _types = TypeDescriptorImpl.copyTypeDescriptors(
types ); }
     
     ///////////////////////////////////////////////////////////////////////////////////
     //

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java?rev=1468143&r1=1468142&r2=1468143&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java
Mon Apr 15 17:00:53 2013
@@ -204,6 +204,12 @@ public class TypeDescriptorImpl implemen
 		this.maximumWidth = maximumWidth;
 	}
 
+    /** copy an array of type descriptors */
+    public  static TypeDescriptor[]    copyTypeDescriptors( TypeDescriptor[] original )
+    {
+        return (original == null) ? null : (TypeDescriptor[]) original.clone();
+    }
+    
 	/**
 	 * @see TypeDescriptor#getMaximumWidth
 	 */

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java?rev=1468143&r1=1468142&r2=1468143&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java Mon Apr
15 17:00:53 2013
@@ -29,7 +29,7 @@ import java.lang.reflect.Array;
 
 /**
   Utility class for constructing and reading and writing arrays from/to
-  formatId streams.
+  formatId streams and for performing other operations on arrays.
  
   @version 0.1
  */
@@ -37,6 +37,31 @@ public abstract class ArrayUtil
 {
 	///////////////////////////////////////////////////////////////////
 	//
+	// Methods to copy arrays. We'd like to use java.util.copyOf(), but
+    // we have to run on Java 5.
+	//
+	///////////////////////////////////////////////////////////////////
+
+    /** Copy an array of strings; the original array could be null */
+    public  static  String[]    copy( String[] original )
+    {
+        return (original == null) ? null : (String[]) original.clone();
+    }
+
+    /** Copy a (possibly null) array of booleans */
+    public  static  boolean[]   copy( boolean[] original )
+    {
+        return (original == null) ? null : (boolean[]) original.clone();
+    }
+
+    /** Copy a (possibly null) array of ints */
+    public  static  int[]   copy( int[] original )
+    {
+        return (original == null) ? null : (int[]) original.clone();
+    }
+
+	///////////////////////////////////////////////////////////////////
+	//
 	// Methods for Arrays of OBJECTS.  Cannot be used for an
 	// array of primitives, see below for something for primitives
 	//

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java?rev=1468143&r1=1468142&r2=1468143&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
Mon Apr 15 17:00:53 2013
@@ -531,6 +531,8 @@ public class CreateAliasNode extends DDL
         {
             parameterTypes[ i ] = bindUserCatalogType( parameterTypes[ i ] );
         }
+
+        aliasInfo.setParameterTypes( parameterTypes );
     }
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/QueryTreeNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/QueryTreeNode.java?rev=1468143&r1=1468142&r2=1468143&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/QueryTreeNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/QueryTreeNode.java Mon
Apr 15 17:00:53 2013
@@ -1678,7 +1678,6 @@ public abstract class QueryTreeNode impl
         if ( !originalDTD.getCatalogType().isRowMultiSet() ) { return originalDTD; }
 
         RowMultiSetImpl originalMultiSet = (RowMultiSetImpl) originalDTD.getTypeId().getBaseTypeId();
-        String[] columnNames = originalMultiSet.getColumnNames();
         TypeDescriptor[] columnTypes = originalMultiSet.getTypes();
         int columnCount = columnTypes.length;
 
@@ -1686,6 +1685,7 @@ public abstract class QueryTreeNode impl
         {
             columnTypes[ i ] = bindUserCatalogType( columnTypes[ i ] );
         }
+        originalMultiSet.setTypes( columnTypes );
 
         return originalDTD;
     }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java?rev=1468143&r1=1468142&r2=1468143&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
Mon Apr 15 17:00:53 2013
@@ -2766,17 +2766,27 @@ class AlterTableConstantAction extends D
 
 				boolean[] isAscending = compressIRGs[j].isAscending();
 				boolean reMakeArrays = false;
+				boolean rewriteBaseColumnPositions = false;
 				int size = baseColumnPositions.length;
 				for (int k = 0; k < size; k++)
 				{
 					if (baseColumnPositions[k] > droppedColumnPosition)
+                    {
 						baseColumnPositions[k]--;
+                        rewriteBaseColumnPositions = true;
+                    }
 					else if (baseColumnPositions[k] == droppedColumnPosition)
 					{
 						baseColumnPositions[k] = 0;		// mark it
 						reMakeArrays = true;
 					}
 				}
+
+                if ( rewriteBaseColumnPositions )
+                {
+                    compressIRGs[j].setBaseColumnPositions( baseColumnPositions );
+                }
+                
 				if (reMakeArrays)
 				{
 					size--;



Mime
View raw message