KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collections JavaDoc;
26 import java.util.Calendar JavaDoc;
27
28 /**
29  * Map a ResultSet row to a java.util.Map object.
30  */

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

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

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