db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1454296 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile: DMLModStatementNode.java DeleteNode.java Predicate.java VTIDeferModPolicy.java
Date Fri, 08 Mar 2013 09:13:04 GMT
Author: kahatlen
Date: Fri Mar  8 09:13:04 2013
New Revision: 1454296

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

Replace Hashtable fields with HashSets.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/Predicate.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/VTIDeferModPolicy.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java?rev=1454296&r1=1454295&r2=1454296&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
Fri Mar  8 09:13:04 2013
@@ -22,9 +22,9 @@
 package	org.apache.derby.impl.sql.compile;
 
 import java.util.ArrayList;
-import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.derby.catalog.DefaultInfo;
 import org.apache.derby.catalog.UUID;
@@ -104,10 +104,11 @@ abstract class DMLModStatementNode exten
 	protected long[] fkIndexConglomNumbers; //conglomerate number of the backing index
 	protected  boolean isDependentTable;
 	protected int[][] fkColArrays; 
-	protected Hashtable graphHashTable; 
-                          // Hash Table which maitains the querytreenode graph 
 	protected TableName synonymTableName;
-	
+
+    /** Set of dependent tables for cascading deletes. */
+    Set dependentTables;
+
 	/**
 	 * Initializer for a DMLModStatementNode -- delegate to DMLStatementNode
 	 *

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java?rev=1454296&r1=1454295&r2=1454296&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java Fri
Mar  8 09:13:04 2013
@@ -58,7 +58,7 @@ import org.apache.derby.iapi.services.cl
 import org.apache.derby.iapi.services.io.FormatableProperties;
 
 import java.util.Vector;
-import java.util.Hashtable;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
@@ -338,19 +338,18 @@ public class DeleteNode extends DMLModSt
 
 				if(!isDependentTable){
 					//graph node
-					graphHashTable = new Hashtable();
+                    dependentTables = new HashSet();
 				}
 
-				/*Check whether the current tatget is already been explored.
+				/*Check whether the current target has already been explored.
 			 	*If we are seeing the same table name which we binded earlier
 			 	*means we have cyclic references.
 			 	*/
-				if(!graphHashTable.containsKey(currentTargetTableName))
+				if (dependentTables.add(currentTargetTableName))
 				{
 					cascadeDelete = true;
 					int noDependents = fkTableNames.length;
 					dependentNodes = new StatementNode[noDependents];
-					graphHashTable.put(currentTargetTableName, new Integer(noDependents));
 					for(int i =0 ; i < noDependents ; i ++)
 					{
 						dependentNodes[i] = getDependentTableNode(fkTableNames[i],
@@ -367,7 +366,7 @@ public class DeleteNode extends DMLModSt
 				{
 					String currentTargetTableName = targetTableDescriptor.getSchemaName()
 							 + "." + targetTableDescriptor.getName();
-					graphHashTable.put(currentTargetTableName, new Integer(0));
+                    dependentTables.add(currentTargetTableName);
 
 				}
 			}
@@ -711,7 +710,7 @@ public class DeleteNode extends DMLModSt
 	private StatementNode getDependentTableNode(String tableName, int refAction,
 												ColumnDescriptorList cdl) throws StandardException
 	{
-		StatementNode node=null;
+        DMLModStatementNode node = null;
 
 		int index = tableName.indexOf('.');
 		String schemaName = tableName.substring(0 , index);
@@ -719,22 +718,26 @@ public class DeleteNode extends DMLModSt
 		if(refAction == StatementType.RA_CASCADE)
 		{
 			node = getEmptyDeleteNode(schemaName , tName);
-			((DeleteNode)node).isDependentTable = true;
-			((DeleteNode)node).graphHashTable = graphHashTable;
 		}
 
 		if(refAction == StatementType.RA_SETNULL)
 		{
 			node = getEmptyUpdateNode(schemaName , tName, cdl);
-			((UpdateNode)node).isDependentTable = true;
-			((UpdateNode)node).graphHashTable = graphHashTable;
 		}
 
+        // The dependent node should be marked as such, and it should inherit
+        // the set of dependent tables from the parent so that it can break
+        // out of cycles in the dependency graph.
+        if (node != null) {
+            node.isDependentTable = true;
+            node.dependentTables = dependentTables;
+        }
+
 		return node;
 	}
 
 
-    private StatementNode getEmptyDeleteNode(String schemaName, String targetTableName)
+    private DeleteNode getEmptyDeleteNode(String schemaName, String targetTableName)
         throws StandardException
     {
 
@@ -771,7 +774,7 @@ public class DeleteNode extends DMLModSt
 													 null, /* windows */
 													 getContextManager());
 
-        return (StatementNode) nodeFactory.getNode(
+        return (DeleteNode) nodeFactory.getNode(
                                                     C_NodeTypes.DELETE_NODE,
                                                     tableName,
                                                     resultSet,
@@ -781,7 +784,7 @@ public class DeleteNode extends DMLModSt
 
 
 	
-    private StatementNode getEmptyUpdateNode(String schemaName, 
+    private UpdateNode getEmptyUpdateNode(String schemaName,
 											 String targetTableName,
 											 ColumnDescriptorList cdl)
         throws StandardException
@@ -822,7 +825,7 @@ public class DeleteNode extends DMLModSt
 													 null, /* windows */
                                                      getContextManager());
 
-        return (StatementNode) nodeFactory.getNode(
+        return (UpdateNode) nodeFactory.getNode(
                                                     C_NodeTypes.UPDATE_NODE,
                                                     tableName,
                                                     resultSet,

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/Predicate.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/Predicate.java?rev=1454296&r1=1454295&r2=1454296&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/Predicate.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/Predicate.java Fri Mar
 8 09:13:04 2013
@@ -21,17 +21,14 @@
 
 package	org.apache.derby.impl.sql.compile;
 
-import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;
-import org.apache.derby.impl.sql.compile.ActivationClassBuilder;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.apache.derby.iapi.sql.compile.C_NodeTypes;
-import org.apache.derby.iapi.sql.compile.Visitable;
 import org.apache.derby.iapi.sql.compile.Visitor;
 import org.apache.derby.iapi.sql.compile.OptimizablePredicate;
 import org.apache.derby.iapi.sql.compile.Optimizable;
 
-import org.apache.derby.iapi.sql.dictionary.DataDictionary;
-
 import org.apache.derby.iapi.store.access.ScanController;
 
 import org.apache.derby.iapi.error.StandardException;
@@ -43,9 +40,8 @@ import org.apache.derby.iapi.services.sa
 import org.apache.derby.iapi.types.DataValueDescriptor;
 
 import org.apache.derby.iapi.util.JBitSet;
+import org.apache.derby.iapi.util.ReuseFactory;
 
-import java.util.ArrayList;
-import java.util.Hashtable;
 
 /**
  * A Predicate represents a top level predicate.
@@ -72,7 +68,7 @@ public final class Predicate extends Que
 	/* Hashtable used for tracking the search clause types that have been
 	 * pushed through this predicate (if an equijoin) via transitive closure.
 	 */
-	private Hashtable searchClauseHT;
+    private Set searchClauses;
 
 	// Whether or not this predicate has been scoped; see the
 	// getPredScopedForResultSet() method of this class for more.
@@ -560,15 +556,8 @@ public final class Predicate extends Que
 	 */
 	boolean transitiveSearchClauseAdded(RelationalOperator ro)
 	{
-		if (searchClauseHT == null || 
-			searchClauseHT.get(new Integer(ro.getOperator())) == null)
-		{
-			return false;
-		}
-		else
-		{
-			return true;
-		}
+        return searchClauses != null &&
+            searchClauses.contains(ReuseFactory.getInteger(ro.getOperator()));
 	}
 
 	/**
@@ -581,15 +570,13 @@ public final class Predicate extends Que
 	 */
 	void setTransitiveSearchClauseAdded(RelationalOperator ro)
 	{
-		if (searchClauseHT == null)
-		{
-			searchClauseHT = new Hashtable();
-		}
+        if (searchClauses == null) {
+            searchClauses = new HashSet();
+        }
 		/* I have to remember that this ro has been added to this predicate as a
 		 * transitive search clause.
 		 */
-		Integer i = new Integer(ro.getOperator());
-		searchClauseHT.put(i, i);
+        searchClauses.add(ReuseFactory.getInteger(ro.getOperator()));
 	}
 
 	/**
@@ -840,16 +827,8 @@ public final class Predicate extends Que
 		this.startKey = otherPred.isStartKey();
 		this.stopKey = otherPred.isStopKey();
 		this.isQualifier = otherPred.isQualifier();
-		this.searchClauseHT = otherPred.getSearchClauseHT();
-
-	}
-
-	/**
-	 * Get the search clause Hash Table.
-	 */
+        this.searchClauses = otherPred.searchClauses;
 
-	public Hashtable getSearchClauseHT() {
-		return searchClauseHT;
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/VTIDeferModPolicy.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/VTIDeferModPolicy.java?rev=1454296&r1=1454295&r2=1454296&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/VTIDeferModPolicy.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/VTIDeferModPolicy.java
Fri Mar  8 09:13:04 2013
@@ -28,11 +28,11 @@ import org.apache.derby.iapi.sql.compile
 
 import org.apache.derby.vti.DeferModification;
 
-import java.util.Enumeration;
-import java.util.Hashtable;
-
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
 
 /**
  * This class applies a VTI modification deferral policy to a statement to
@@ -91,13 +91,13 @@ class VTIDeferModPolicy implements Visit
             if( statementType == DeferModification.UPDATE_STATEMENT)
             {
                 // Apply the columnRequiresDefer method to updated columns not in the where
clause.
-                Enumeration columns = deferralSearch.columns.keys();
-                while( columns.hasMoreElements())
+                Iterator columns = deferralSearch.columns.iterator();
+                while (columns.hasNext())
                 {
-                    if( deferralControl.columnRequiresDefer( statementType,
-                                                             (String) columns.nextElement(),
-                                                             false))
+                    if (deferralControl.columnRequiresDefer(
+                            statementType, (String) columns.next(), false)) {
                         return true;
+                    }
                 }
             }
             return deferralSearch.deferred;
@@ -113,7 +113,7 @@ class VTIDeferModPolicy implements Visit
     private DeferModification deferralControl;
     private int statementType;
     private int tableNumber;
-    private Hashtable columns = new Hashtable();
+    private final HashSet columns = new HashSet();
 
     private VTIDeferModPolicy( FromVTI targetVTI,
                                String[] columnNames,
@@ -125,8 +125,7 @@ class VTIDeferModPolicy implements Visit
         tableNumber = targetVTI.getTableNumber();
         if( statementType == DeferModification.UPDATE_STATEMENT && columnNames !=
null)
         {
-            for( int i = 0; i < columnNames.length; i++)
-                columns.put( columnNames[i], columnNames[i]);
+            columns.addAll(Arrays.asList(columnNames));
         }
     }
 
@@ -143,21 +142,19 @@ class VTIDeferModPolicy implements Visit
                     String columnName = cr.getColumnName();
                     if( statementType == DeferModification.DELETE_STATEMENT)
                     {
-                        if( columns.get( columnName) == null)
+                        if (columns.add(columnName))
                         {
-                            columns.put( columnName, columnName);
                             if( deferralControl.columnRequiresDefer( statementType, columnName,
true))
                                 deferred = true;
                         }
                     }
                     else if( statementType == DeferModification.UPDATE_STATEMENT)
                     {
-                        if( columns.get( columnName) != null)
+                        if (columns.remove(columnName))
                         {
                             // This column is referenced in the where clause and is being
updated
                             if( deferralControl.columnRequiresDefer( statementType, columnName,
true))
                                 deferred = true;
-                            columns.remove( columnName); // Only test it once.
                         }
                     }
                 }



Mime
View raw message