KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > system > jdbc > RowToHashMapMapper


1 /*
2  * Copyright 2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18
19 package org.apache.beehive.controls.system.jdbc;
20
21 import org.apache.beehive.controls.api.ControlException;
22
23 import java.sql.ResultSet JavaDoc;
24 import java.sql.SQLException JavaDoc;
25 import java.util.Calendar JavaDoc;
26
27 /**
28  * Map a ResultSet row to a java.util.HashMap object
29  */

30 public final class RowToHashMapMapper extends RowMapper {
31
32     private final String JavaDoc[] _keys;
33
34
35     /**
36      * Create a new RowToHashMapMapper.
37      * @param resultSet ResultSet to map
38      * @param returnTypeClass Class to map to.
39      * @param cal Calendar instance for date/time mappings.
40      */

41     RowToHashMapMapper(ResultSet JavaDoc resultSet, Class JavaDoc returnTypeClass, Calendar JavaDoc cal) {
42         super(resultSet, returnTypeClass, cal);
43         try {
44             _keys = getKeysFromResultSet();
45         } catch (SQLException JavaDoc sql) {
46             throw new ControlException("RowToHashMapMapper: SQLException: " + sql.getMessage(), sql);
47         }
48     }
49
50     /**
51      * Do the mapping.
52      * @return A ResultSetHashMap object.
53      * @throws ControlException on error.
54      */

55     public Object JavaDoc mapRowToReturnType() {
56         try {
57             return new ResultSetHashMap(_resultSet, _keys);
58         } catch (SQLException JavaDoc e) {
59             throw new ControlException("Exception creating HashMap return type: ", e);
60         }
61     }
62 }
63
Popular Tags