db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gmon...@apache.org
Subject svn commit: r1041876 - in /db/torque/runtime/trunk/src/java/org/apache/torque/util: ListOrderedMapCI.java SummaryHelper.java
Date Fri, 03 Dec 2010 15:28:24 GMT
Author: gmonroe
Date: Fri Dec  3 15:28:23 2010
New Revision: 1041876

URL: http://svn.apache.org/viewvc?rev=1041876&view=rev
Log:
Refactored SummaryHelper to use case insensitive ListOrderMapCI class.  This fixes problems
with different DB's metadata column names having different cases.

Added:
    db/torque/runtime/trunk/src/java/org/apache/torque/util/ListOrderedMapCI.java
Modified:
    db/torque/runtime/trunk/src/java/org/apache/torque/util/SummaryHelper.java

Added: db/torque/runtime/trunk/src/java/org/apache/torque/util/ListOrderedMapCI.java
URL: http://svn.apache.org/viewvc/db/torque/runtime/trunk/src/java/org/apache/torque/util/ListOrderedMapCI.java?rev=1041876&view=auto
==============================================================================
--- db/torque/runtime/trunk/src/java/org/apache/torque/util/ListOrderedMapCI.java (added)
+++ db/torque/runtime/trunk/src/java/org/apache/torque/util/ListOrderedMapCI.java Fri Dec
 3 15:28:23 2010
@@ -0,0 +1,99 @@
+package org.apache.torque.util;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.collections.map.ListOrderedMap;
+
+/**
+ * A subclass of the Apache Commons ListOrderedMap that has case insensitive
+ * String key methods.  This is done by converting all String keys to 
+ * lower case.
+ *
+ * @author <a href="mailto:greg.monroe@dukece.com">Greg Monroe</a>
+ * @version $Id$
+ */
+public class ListOrderedMapCI extends ListOrderedMap
+{
+    private static final long serialVersionUID = -4349246328751938554L;
+
+    /**
+     * Constructs a new empty ListOrderedMap.
+     */
+    public ListOrderedMapCI() {
+        super();
+    }
+
+    /**
+     * Get the object associated with this key.
+     * 
+     * @param key A case insensitive String.
+     * @return The value for this key
+     */
+    public Object get( String key ) {
+       return super.get( key.toLowerCase() ); 
+    }
+    /**
+     * Adds a value to the end of the list with the specified key.
+     * 
+     * @param key A case insensitive String.
+     * @param value The value to add
+     * @return The value for previously mapped to this key
+     */
+    public Object put( String key, Object value ) {
+        return super.put( key.toLowerCase(), value ); 
+    }
+    /**
+     * Puts a key-value mapping into the map at the specified index.
+     * 
+     * @param index The index at which the mapping should be inserted.  
+     * @param key A case insensitive String.
+     * @param value The value.
+     * @return The value for previously mapped to this key
+     */
+    public Object put( int index, String key, Object value ) {
+        return super.put(index, key.toLowerCase(), value );
+    }
+    /**
+     * Gets the index of the specified key.
+     * 
+     * @param key A case insensitive String.
+     * @return the index, or -1 if not found
+     */
+    public int indexOf( String key ) {
+        return super.indexOf( key.toLowerCase() );
+    }
+    /**
+     * Removes the mapping for the specified key.
+     * @param key A case insensitive String.
+     * @return the removed value, or null if none existed
+     */
+    public Object remove ( String key ) {
+        return super.remove( key.toLowerCase() );
+    }
+    /**
+     * Test if the key exists in the mapping.
+     * 
+     * @param key The case insensitive key to test for.
+     * @return True if the key exists.
+     */
+    public boolean containsKey( String key ) {
+        return super.containsKey( key.toLowerCase());
+    }
+}

Modified: db/torque/runtime/trunk/src/java/org/apache/torque/util/SummaryHelper.java
URL: http://svn.apache.org/viewvc/db/torque/runtime/trunk/src/java/org/apache/torque/util/SummaryHelper.java?rev=1041876&r1=1041875&r2=1041876&view=diff
==============================================================================
--- db/torque/runtime/trunk/src/java/org/apache/torque/util/SummaryHelper.java (original)
+++ db/torque/runtime/trunk/src/java/org/apache/torque/util/SummaryHelper.java Fri Dec  3
15:28:23 2010
@@ -28,7 +28,7 @@ import java.util.Vector;
 
 import org.apache.commons.collections.OrderedMap;
 import org.apache.commons.collections.OrderedMapIterator;
-import org.apache.commons.collections.map.ListOrderedMap;
+// import org.apache.commons.collections.map.ListOrderedMap;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.torque.TorqueException;
@@ -84,7 +84,7 @@ import com.workingdogs.village.Value;
  *
  * @see org.apache.torque.util.functions.FunctionFactory
  * @author <a href="mailto:greg.monroe@dukece.com">Greg Monroe</a>
- * @version $Id
+ * @version $Id$
  */
 public class SummaryHelper
 {
@@ -123,15 +123,16 @@ public class SummaryHelper
     }
     
     /**
-     * Return a list of OrderedMap objects with the results of the summary
-     * query.  The OrderedMap objects have a key of the column name or
-     * function alias and are in the order generated by the query.
+     * Return a list of ListOrderedMapCI objects with the results of the 
+     * summary query.  The ListOrderedMapCI objects have a key of the column 
+     * name or function alias and are in the order generated by the query.
      *
      * @param crit The base criteria to build on.
      * @param conn The DB Connection to use.
      * @return Results as a OrderMap<String,Values> object. 
      * @throws TorqueException
      * @throws DataSetException
+     * @see ListOrderedMapCI
      */
     public List summarize( Criteria crit, Connection conn ) 
                                  throws TorqueException, DataSetException 
@@ -153,7 +154,7 @@ public class SummaryHelper
         Vector resultsList = new Vector(results.size());
         while ( r.hasNext() ) 
         {
-            ListOrderedMap recordMap = new ListOrderedMap();
+            ListOrderedMapCI recordMap = new ListOrderedMapCI();
             Record rec = (Record) r.next();
             String cName = null;
             Value value = null;
@@ -231,7 +232,7 @@ public class SummaryHelper
             if ( ! haveFromTable )    // Last chance. Get it from the func.
             {
                 String col =  f.getArgument(0).toString();
-                if ( col.indexOf('.') >= 0) 
+                if ( col.contains(".") ) 
                 {
                     // Kludgy Where table.col = table.col clause to force
                     // from table identification.
@@ -315,7 +316,7 @@ public class SummaryHelper
     {
         if ( aggregates == null ) 
         {
-            aggregates = new ListOrderedMap();
+            aggregates = new ListOrderedMapCI();
         }
         return aggregates;
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message