Turns a result set into a map of maps.  I needed it to turn a
result set into a map of state abbreviations keys with state
information maps as values.

It has 2 constructors.  The empty constructor assumes that there
is going to be a column named key that will serve as the map
key.  there is another constructor that takes a String that is
used to identify the key column.

Here is the code.  FYI, I get a depracated warning on the
BasicRowProcessor.instance(), but I was not familiar enough with
the code to know what it does or what it should now be or if it
was even needed.



--- David Graham <[EMAIL PROTECTED]> wrote:

> What does MapMapHandler do?
> 
> David
> 
> --- Norris Shelton <[EMAIL PROTECTED]> wrote:
> 
> > I made a MapMapHandler and wanted someone to look at it to
> see
> > if it is worth submitting.
> > 
> > =====
> > 
> > Norris Shelton
> > Software Engineer
> > Sun Certified Java 1.1 Programmer
> > Appriss, Inc.
> > ICQ# 26487421
> > AIM NorrisEShelton
> > YIM norrisshelton
> > 
> > 
> > 
> >             
> > _______________________________
> > Do you Yahoo!?
> > Declare Yourself - Register online to vote today!
> > http://vote.yahoo.com
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> > For additional commands, e-mail:
> [EMAIL PROTECTED]
> > 
> > 
> 
> 
> 
>               
> _______________________________
> Do you Yahoo!?
> Declare Yourself - Register online to vote today!
> http://vote.yahoo.com
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
> 

=====

Norris Shelton
Software Engineer
Sun Certified Java 1.1 Programmer
Appriss, Inc.
ICQ# 26487421
AIM NorrisEShelton
YIM norrisshelton


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
/*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed 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.
*/
package org.apache.commons.dbutils.handlers;

import org.apache.commons.dbutils.*;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * <code>ResultSetHandler</code> implementation that converts a
 * <code>ResultSet</code> into a <code>List</code> of <code>Map</code>s. This
 * class is thread safe.
 * @author David Graham
 * @author Norris Shelton
 * @see org.apache.commons.dbutils.ResultSetHandler
 */
public class MapMapHandler extends MapListHandler implements ResultSetHandler {

    private String key = "key";

    /**
     * The RowProcessor implementation to use when converting rows into Maps.
     */
    private RowProcessor convert = BasicRowProcessor.instance();

    /**
     * Creates a new instance of MapListHandler using a <code>BasicRowProcessor</code>
     * for conversion.
     */
    public MapMapHandler() {
        super();
    }

    public MapMapHandler(String key) {
        super();
        this.key = key;
    }

    /**
     * Creates a new instance of MapListHandler.
     *
     * @param convert The <code>RowProcessor</code> implementation
     * to use when converting rows into Maps.
     */
    //public MapMapHandler(RowProcessor convert) {
    //    super();
    //    this.convert = convert;
    //}

    /**
     * Converts the <code>ResultSet</code> rows into a <code>Map</code> of
     * <code>Map</code> objects.
     * @return A <code>Map</code> of <code>Map</code>s, never null.
     * @throws java.sql.SQLException
     * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet)
     */
    public Object handle(ResultSet rs) throws SQLException {

        Map results = new HashMap();

        Map temp = null;
        while (rs.next()) {
            temp = convert.toMap(rs);
            results.put(temp.get(key), convert.toMap(rs));
        }

        return results;
    }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to