Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4464D45D8 for ; Wed, 29 Jun 2011 08:45:07 +0000 (UTC) Received: (qmail 38759 invoked by uid 500); 29 Jun 2011 08:45:06 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 38653 invoked by uid 500); 29 Jun 2011 08:44:59 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 38305 invoked by uid 99); 29 Jun 2011 08:44:53 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Jun 2011 08:44:53 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Jun 2011 08:44:49 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6BBF623889E1; Wed, 29 Jun 2011 08:44:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1141005 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql: catalog/DataDictionaryImpl.java compile/CreateTriggerNode.java Date: Wed, 29 Jun 2011 08:44:28 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110629084428.6BBF623889E1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kahatlen Date: Wed Jun 29 08:44:28 2011 New Revision: 1141005 URL: http://svn.apache.org/viewvc?rev=1141005&view=rev Log: DERBY-5293: Replace bubble sort in DataDictionaryImpl and CreateTriggerNode with Collections.sort() Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTriggerNode.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=1141005&r1=1141004&r2=1141005&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java Wed Jun 29 08:44:28 2011 @@ -155,6 +155,8 @@ import org.apache.derby.iapi.util.IdUtil import java.util.ArrayList; import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; import java.util.GregorianCalendar; import java.util.Hashtable; import java.util.HashMap; @@ -4684,6 +4686,20 @@ public final class DataDictionaryImpl return list; } + /** + * Comparator that can be used for sorting lists of column references + * on the position they have in the SQL query string. + */ + private static final Comparator OFFSET_COMPARATOR = new Comparator() { + public int compare(Object o1, Object o2) { + // Return negative int, zero, or positive int if the first column + // reference has an offset which is smaller than, equal to, or + // greater than the offset of the second column reference. + return ((ColumnReference) o1).getBeginOffset() - + ((ColumnReference) o2).getBeginOffset(); + } + }; + /** * Get the trigger action string associated with the trigger after the * references to old/new transition tables/variables in trigger action @@ -4818,7 +4834,7 @@ public final class DataDictionaryImpl Vector refs = visitor.getList(); /* we need to sort on position in string, beetle 4324 */ - QueryTreeNode[] cols = sortRefs(refs, true); + Collections.sort(refs, OFFSET_COMPARATOR); if (createTriggerTime) { //The purpose of following array(triggerActionColsOnly) is to @@ -4876,9 +4892,9 @@ public final class DataDictionaryImpl //in next version of 10.7 and 10.8. In 10.9, DERBY-1482 was //reimplemented correctly and we started doing the collection and //usage of trigger action columns again in 10.9 - for (int i = 0; i < cols.length; i++) + for (int i = 0; i < refs.size(); i++) { - ColumnReference ref = (ColumnReference) cols[i]; + ColumnReference ref = (ColumnReference) refs.get(i); /* ** Only occurrences of those OLD/NEW transition tables/variables ** are of interest here. There may be intermediate nodes in the @@ -4992,9 +5008,9 @@ public final class DataDictionaryImpl // turns into // DELETE FROM t WHERE c in // (SELECT c FROM new TriggerOldTransitionTable OLD) - for (int i = 0; i < cols.length; i++) + for (int i = 0; i < refs.size(); i++) { - ColumnReference ref = (ColumnReference) cols[i]; + ColumnReference ref = (ColumnReference) refs.get(i); /* ** Only occurrences of those OLD/NEW transition tables/variables ** are of interest here. There may be intermediate nodes in the @@ -5266,43 +5282,6 @@ public final class DataDictionaryImpl } } - /* - ** Sort the refs into array. - */ - private QueryTreeNode[] sortRefs(Vector refs, boolean isRow) - { - int size = refs.size(); - QueryTreeNode[] sorted = (QueryTreeNode[])refs.toArray(new QueryTreeNode[size]); - int i = 0; - /* bubble sort - */ - QueryTreeNode temp; - for (i = 0; i < size - 1; i++) - { - temp = null; - for (int j = 0; j < size - i - 1; j++) - { - if ((isRow && - sorted[j].getBeginOffset() > - sorted[j+1].getBeginOffset() - ) || - (!isRow && - ((FromBaseTable) sorted[j]).getTableNameField().getBeginOffset() > - ((FromBaseTable) sorted[j+1]).getTableNameField().getBeginOffset() - )) - { - temp = sorted[j]; - sorted[j] = sorted[j+1]; - sorted[j+1] = temp; - } - } - if (temp == null) // sorted - break; - } - - return sorted; - } - /** * Get a TriggerDescriptor given its UUID. * 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=1141005&r1=1141004&r2=1141005&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 Wed Jun 29 08:44:28 2011 @@ -22,6 +22,8 @@ package org.apache.derby.impl.sql.compile; import java.sql.Timestamp; +import java.util.Collections; +import java.util.Comparator; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; @@ -454,6 +456,20 @@ public class CreateTriggerNode extends D return (isSessionSchema(triggerTableDescriptor.getSchemaName()) || actionNode.referencesSessionSchema()); } + /** + * Comparator that can be used for sorting lists of FromBaseTables + * on the position they have in the SQL query string. + */ + private static final Comparator OFFSET_COMPARATOR = new Comparator() { + public int compare(Object o1, Object o2) { + // Return negative int, zero, or positive int if the offset of the + // first table is less than, equal to, or greater than the offset + // of the second table. + return ((FromBaseTable) o1).getTableNameField().getBeginOffset() - + ((FromBaseTable) o2).getTableNameField().getBeginOffset(); + } + }; + /* ** BIND OLD/NEW TRANSITION TABLES/VARIABLES AND collect TRIGGER ACTION ** COLUMNS referenced through REFERECING CLAUSE in CREATE TRIGGER statement @@ -587,11 +603,11 @@ public class CreateTriggerNode extends D */ CollectNodesVisitor visitor = new CollectNodesVisitor(FromBaseTable.class); actionNode.accept(visitor); - Vector refs = visitor.getList(); - QueryTreeNode[] tabs = sortRefs(refs, false); - for (int i = 0; i < tabs.length; i++) + Vector tabs = visitor.getList(); + Collections.sort(tabs, OFFSET_COMPARATOR); + for (int i = 0; i < tabs.size(); i++) { - FromBaseTable fromTable = (FromBaseTable) tabs[i]; + FromBaseTable fromTable = (FromBaseTable) tabs.get(i); String refTableName = fromTable.getTableName().getTableName(); String baseTableName = fromTable.getBaseTableName(); if ((baseTableName == null) || @@ -684,43 +700,6 @@ public class CreateTriggerNode extends D return null; } - /* - ** Sort the refs into array. - */ - private QueryTreeNode[] sortRefs(Vector refs, boolean isRow) - { - int size = refs.size(); - QueryTreeNode[] sorted = (QueryTreeNode[]) refs.toArray(new QueryTreeNode[size]); - int i = 0; - /* bubble sort - */ - QueryTreeNode temp; - for (i = 0; i < size - 1; i++) - { - temp = null; - for (int j = 0; j < size - i - 1; j++) - { - if ((isRow && - sorted[j].getBeginOffset() > - sorted[j+1].getBeginOffset() - ) || - (!isRow && - ((FromBaseTable) sorted[j]).getTableNameField().getBeginOffset() > - ((FromBaseTable) sorted[j+1]).getTableNameField().getBeginOffset() - )) - { - temp = sorted[j]; - sorted[j] = sorted[j+1]; - sorted[j+1] = temp; - } - } - if (temp == null) // sorted - break; - } - - return sorted; - } - /* * Forbid references to generated columns in the actions of BEFORE triggers. * This is DERBY-3948, enforcing the following section of the SQL standard: