You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2008/01/04 20:29:04 UTC

svn commit: r608966 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile: TableElementList.java sqlgrammar.jj

Author: djd
Date: Fri Jan  4 11:29:03 2008
New Revision: 608966

URL: http://svn.apache.org/viewvc?rev=608966&view=rev
Log:
DERBY-2775 (partial) Remove a couple of cases where DataTypeDescriptor.setNullability() was being called and replace with the immutable DataTypeDescriptor calls.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java?rev=608966&r1=608965&r2=608966&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java Fri Jan  4 11:29:03 2008
@@ -936,8 +936,8 @@
 		for (int index = 0; index < rclSize; index++)
 		{
 			String colName = ((ResultColumn) rcl.elementAt(index)).getName();
-            DataTypeDescriptor dtd = getColumnDataTypeDescriptor(colName);
-            dtd.setNullability(false);
+            
+            findColumnDefinition(colName).setNullability(false);
         }
 	}
 
@@ -968,21 +968,10 @@
 
     private DataTypeDescriptor getColumnDataTypeDescriptor(String colName)
     {
-        int size = size();
+        ColumnDefinitionNode col = findColumnDefinition(colName);
+        if (col != null)
+            return col.getType();
 
-        for (int index = 0; index < size; index++)
-        {
-            TableElementNode tableElement = (TableElementNode) elementAt(index);
-
-            if (tableElement instanceof ColumnDefinitionNode)
-            {
-                ColumnDefinitionNode cdn = (ColumnDefinitionNode) tableElement;
-                if (colName.equals(cdn.getColumnName()))
-                {
-                    return cdn.getType();
-                }
-            }
-        }
         return null;
     }
 
@@ -997,31 +986,42 @@
         // check for new columns
         return getColumnDataTypeDescriptor(colName);
     }
+    
+    /**
+     * Find the column definition node in this list that matches
+     * the passed in column name.
+     * @param colName
+     * @return Reference to column definition node or null if the column is
+     * not in the list.
+     */
+    private ColumnDefinitionNode findColumnDefinition(String colName) {
+        int size = size();
+        for (int index = 0; index < size; index++) {
+            TableElementNode tableElement = (TableElementNode) elementAt(index);
+
+            if (tableElement instanceof ColumnDefinitionNode) {
+                ColumnDefinitionNode cdn = (ColumnDefinitionNode) tableElement;
+                if (colName.equals(cdn.getName())) {
+                    return cdn;
+                }
+            }
+        }
+        return null;
+    }
+    
 
 	/**
-	 * Determine whether or not the parameter matches a column name in this list.
-	 *
-	 * @param colName	The column name to search for.
-	 *
-	 * @return boolean  Whether or not a match is found.
-	 */
+     * Determine whether or not the parameter matches a column name in this
+     * list.
+     * 
+     * @param colName
+     *            The column name to search for.
+     * 
+     * @return boolean Whether or not a match is found.
+     */
 	public boolean containsColumnName(String colName)
 	{
-		int size = size();
-		for (int index = 0; index < size; index++)
-		{
-			TableElementNode tableElement = (TableElementNode) elementAt(index);
-
-			if (tableElement instanceof ColumnDefinitionNode)
-			{
-				if (colName.equals(((ColumnDefinitionNode) tableElement).getName()))
-				{
-					return true;
-				}
-			}
-		}
-
-		return false;
+        return findColumnDefinition(colName) != null;
 	}
 }
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=608966&r1=608965&r2=608966&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Fri Jan  4 11:29:03 2008
@@ -3659,7 +3659,7 @@
 TableElementNode
 columnDefinition(TableElementList tableElementList) throws StandardException :
 {
-	DataTypeDescriptor	typeDescriptor = null;
+	DataTypeDescriptor[]	typeDescriptor = new DataTypeDescriptor[1];
 	ValueNode			defaultNode = null;
 	String				columnName;
 	long[]				autoIncrementInfo = new long[4];
@@ -3671,7 +3671,7 @@
 
 	/* identifier() used to be columnName() */
 	columnName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true) 
-		( typeDescriptor = dataTypeDDL() 
+		( typeDescriptor[0] = dataTypeDDL() 
 		)
 	[ defaultNode = defaultAndConstraints(typeDescriptor, tableElementList, columnName, autoIncrementInfo) ]
 	{
@@ -3685,7 +3685,7 @@
 								C_NodeTypes.COLUMN_DEFINITION_NODE,
 								columnName,
 								defaultNode,
-								typeDescriptor,
+								typeDescriptor[0],
 								autoIncrementInfo,
 								getContextManager());
 	}
@@ -3696,7 +3696,7 @@
  * <A NAME="defaultAndConstraints">defaultAndConstraints</A>
  */
 ValueNode
-defaultAndConstraints(DataTypeDescriptor typeDescriptor,
+defaultAndConstraints(DataTypeDescriptor[] typeDescriptor,
 					  TableElementList tableElementList,
 					  String columnName,
 					  long[] autoIncrementInfo) throws StandardException :
@@ -11987,7 +11987,7 @@
  * <A NAME="columnConstraintDefinition">columnConstraintDefinition</A>
  */
 void
-columnConstraintDefinition(DataTypeDescriptor dataTypeDescriptor,
+columnConstraintDefinition(DataTypeDescriptor[] dataTypeDescriptor,
 						   TableElementList tableElementList,
 						   String columnName) throws StandardException :
 {
@@ -12020,7 +12020,7 @@
  */
 ConstraintDefinitionNode
 columnConstraint(TableName constraintName,
-				 DataTypeDescriptor dataTypeDescriptor,
+				 DataTypeDescriptor[] dataTypeDescriptor,
 				 String columnName) throws StandardException :
 {
 	int constraintType;
@@ -12042,7 +12042,7 @@
 		//throw an exception
 		if (explicitNull) 
                    throw StandardException.newException(SQLState.LANG_ADDING_COLUMN_WITH_NULL_AND_NOT_NULL_CONSTRAINT, columnName); 
-		dataTypeDescriptor.setNullability(false);
+		dataTypeDescriptor[0] = dataTypeDescriptor[0].getNullabilityType(false);
 		return null;
 	}
 |