db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1453745 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile: CreateIndexNode.java CreateTriggerNode.java OrderedColumnList.java ResultColumnList.java TableElementList.java
Date Thu, 07 Mar 2013 09:36:32 GMT
Author: kahatlen
Date: Thu Mar  7 09:36:31 2013
New Revision: 1453745

URL: http://svn.apache.org/r1453745
Log:
DERBY-6075: Use modern collections in impl/sql/compile

Replace Hashtables used for duplicate checking with HashSets.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateIndexNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderedColumnList.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateIndexNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateIndexNode.java?rev=1453745&r1=1453744&r2=1453745&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateIndexNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateIndexNode.java
Thu Mar  7 09:36:31 2013
@@ -21,7 +21,7 @@
 
 package	org.apache.derby.impl.sql.compile;
 
-import java.util.Hashtable;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Properties;
 
@@ -313,7 +313,7 @@ public class CreateIndexNode extends DDL
 				throws StandardException
 	{
 		int size = columnNameList.size();
-		Hashtable	ht = new Hashtable(size + 2, (float) .999);
+        HashSet seenNames = new HashSet(size + 2, 0.999f);
 		columnNames = new String[size];
 		isAscending = new boolean[size];
 
@@ -331,10 +331,9 @@ public class CreateIndexNode extends DDL
 			else
 				isAscending[index] = true;
 
-			Object object = ht.put(columnNames[index], columnNames[index]);
+            boolean alreadySeen = !seenNames.add(columnNames[index]);
 
-			if (object != null &&
-				((String) object).equals(columnNames[index]))
+			if (alreadySeen)
 			{
 				throw StandardException.newException(SQLState.LANG_DUPLICATE_COLUMN_NAME_CREATE_INDEX,
columnNames[index]);
 			}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java?rev=1453745&r1=1453744&r2=1453745&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java
Thu Mar  7 09:36:31 2013
@@ -24,7 +24,7 @@ package	org.apache.derby.impl.sql.compil
 import java.sql.Timestamp;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.Hashtable;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 
@@ -411,12 +411,12 @@ public class CreateTriggerNode extends D
 		*/
 		if (triggerCols != null && triggerCols.size() != 0)
 		{
-			Hashtable columnNames = new Hashtable();
+            HashSet columnNames = new HashSet();
 			int tcSize = triggerCols.size();
 			for (int i = 0; i < tcSize; i++)
 			{
 				ResultColumn rc  = (ResultColumn) triggerCols.elementAt(i);
-				if (columnNames.put(rc.getName(), rc) != null)
+				if (!columnNames.add(rc.getName()))
 				{
 					throw StandardException.newException(SQLState.LANG_DUPLICATE_COLUMN_IN_TRIGGER_UPDATE,

 											rc.getName(), 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderedColumnList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderedColumnList.java?rev=1453745&r1=1453744&r2=1453745&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderedColumnList.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderedColumnList.java
Thu Mar  7 09:36:31 2013
@@ -21,11 +21,10 @@
 
 package	org.apache.derby.impl.sql.compile;
 
-import org.apache.derby.iapi.store.access.ColumnOrdering;
-
+import java.util.HashSet;
+import org.apache.derby.iapi.util.ReuseFactory;
 import org.apache.derby.impl.sql.execute.IndexColumnOrder;
 
-import java.util.Hashtable;
 
 /**
  * List of OrderedColumns
@@ -52,7 +51,7 @@ public abstract class OrderedColumnList 
 			We don't know how many columns are in the source,
 			so we use a hashtable for lookup of the positions
 		*/
-		Hashtable hashColumns = new Hashtable();
+        HashSet hashColumns = new HashSet();
 
 		actualCols = 0;
 
@@ -64,15 +63,12 @@ public abstract class OrderedColumnList 
 			// order items (store) are 0-based.
 			int position = oc.getColumnPosition() - 1;
 
-			Integer posInt = new Integer(position);
-
-			if (! hashColumns.containsKey(posInt))
+			if (hashColumns.add(ReuseFactory.getInteger(position)))
 			{
 				ordering[i] = new IndexColumnOrder(position,
 												oc.isAscending(),
 												oc.isNullsOrderedLow());
 				actualCols++;
-				hashColumns.put(posInt, posInt);
 			}
 		}
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java?rev=1453745&r1=1453744&r2=1453745&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
Thu Mar  7 09:36:31 2013
@@ -24,9 +24,9 @@ package	org.apache.derby.impl.sql.compil
 import java.lang.reflect.Modifier;
 import java.sql.ResultSetMetaData;
 import java.sql.Types;
-import java.util.Hashtable;
 import java.util.Map;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 
 import org.apache.derby.catalog.types.DefaultInfoImpl;
@@ -951,7 +951,7 @@ public class ResultColumnList extends Qu
 					throws StandardException
 	{
 		int			size = size();
-		Hashtable	ht = new Hashtable(size + 2, (float) .999);
+        HashSet     seenNames = new HashSet(size + 2, 0.999f);
 
 		for (int index = 0; index < size; index++)
 		{
@@ -960,11 +960,9 @@ public class ResultColumnList extends Qu
 
 			/* Verify that this column's name is unique within the list */
 			String colName = rc.getName();
+            boolean alreadySeen = !seenNames.add(colName);
 
-			Object object = ht.put(colName, colName);
-
-			if (object != null &&
-				((String) object).equals(colName))
+			if (alreadySeen)
 			{
 				if (SanityManager.DEBUG)
 				{
@@ -2098,7 +2096,7 @@ public class ResultColumnList extends Qu
 					throws StandardException
 	{
 		int size = size();
-		Hashtable	ht = new Hashtable(size + 2, (float) .999);
+        HashSet seenNames = new HashSet(size + 2, 0.999f);
 		ResultColumn rc;
 
 		for (int index = 0; index < size; index++)
@@ -2108,11 +2106,9 @@ public class ResultColumnList extends Qu
 				throw StandardException.newException(SQLState.LANG_DB2_VIEW_REQUIRES_COLUMN_NAMES);
 			/* Verify that this column's name is unique within the list */
 			String colName = ((ResultColumn) elementAt(index)).getName();
+            boolean alreadySeen = !seenNames.add(colName);
 
-			Object object = ht.put(colName, colName);
-
-			if (object != null &&
-				((String) object).equals(colName))
+			if (alreadySeen)
 			{
 				return colName;
 			}

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=1453745&r1=1453744&r2=1453745&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
Thu Mar  7 09:36:31 2013
@@ -60,10 +60,10 @@ import org.apache.derby.iapi.sql.diction
 import org.apache.derby.catalog.UUID;
 
 import java.util.ArrayList;
-import java.util.Hashtable;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Properties;
+import java.util.Set;
 import java.util.Vector;
 
 /**
@@ -169,10 +169,10 @@ public class TableElementList extends Qu
 		int numAutoCols = 0;
 
 		int			size = size();
-		Hashtable	columnHT = new Hashtable(size + 2, (float) .999);
-		Hashtable	constraintHT = new Hashtable(size + 2, (float) .999);
+        HashSet columnNames = new HashSet(size + 2, 0.999f);
+        HashSet constraintNames = new HashSet(size + 2, 0.999f);
 		//all the primary key/unique key constraints for this table
-		Vector constraintsVector = new Vector();
+        ArrayList constraintsVector = new ArrayList();
 
 		//special case for alter table (td is not null in case of alter table)
 		if (td != null)
@@ -215,7 +215,7 @@ public class TableElementList extends Qu
 				{
 					throw StandardException.newException(SQLState.LANG_LONG_DATA_TYPE_NOT_ALLOWED, cdn.getColumnName());
 				}
-				checkForDuplicateColumns(ddlStmt, columnHT, cdn.getColumnName());
+				checkForDuplicateColumns(ddlStmt, columnNames, cdn.getColumnName());
 				cdn.checkUserType(td);
 				cdn.bindAndValidateDefault(dd, td);
 
@@ -292,7 +292,7 @@ public class TableElementList extends Qu
 			}
 
 			/* Make sure that there are no duplicate constraint names in the list */
-            checkForDuplicateConstraintNames(ddlStmt, constraintHT, cdn.getConstraintMoniker());
+            checkForDuplicateConstraintNames(ddlStmt, constraintNames, cdn.getConstraintMoniker());
 
 			/* Make sure that the constraint we are trying to drop exists */
 			if (cdn.getConstraintType() == DataDictionary.DROP_CONSTRAINT)
@@ -1373,18 +1373,17 @@ public class TableElementList extends Qu
 	 * RESOLVE: This check will also be performed by alter table.
 	 *
 	 * @param ddlStmt	DDLStatementNode which contains this list
-	 * @param ht		Hashtable for enforcing uniqueness.
+     * @param seenNames The column names seen so far (for enforcing uniqueness)
 	 * @param colName	Column name to check for.
 	 *
 	 * @exception StandardException		Thrown on error
 	 */
 	private void checkForDuplicateColumns(DDLStatementNode ddlStmt,
-									Hashtable ht,
+									Set seenNames,
 									String colName)
 			throws StandardException
 	{
-		Object object = ht.put(colName, colName);
-		if (object != null)
+		if (!seenNames.add(colName))
 		{
 			/* RESOLVE - different error messages for create and alter table */
 			if (ddlStmt instanceof CreateTableNode)
@@ -1402,19 +1401,20 @@ public class TableElementList extends Qu
 	 * RESOLVE: This check will also be performed by alter table.
 	 *
 	 * @param ddlStmt	DDLStatementNode which contains this list
+     * @param seenNames The constraint names seen so far (for enforcing
+     *                  uniqueness)
 	 *
 	 * @exception StandardException		Thrown on error
 	 */
 	private void checkForDuplicateConstraintNames(DDLStatementNode ddlStmt,
-									Hashtable ht,
+									Set seenNames,
 									String constraintName)
 			throws StandardException
 	{
 		if (constraintName == null)
 			return;
 
-		Object object = ht.put(constraintName, constraintName);
-		if (object != null) {
+		if (!seenNames.add(constraintName)) {
 
 			/* RESOLVE - different error messages for create and alter table */
 			if (ddlStmt instanceof CreateTableNode)



Mime
View raw message