01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19:
20: package org.apache.beehive.controls.system.jdbc;
21:
22: import org.apache.beehive.controls.api.ControlException;
23:
24: import java.sql.ResultSet;
25: import java.sql.SQLException;
26: import java.util.Calendar;
27:
28: /**
29: * Map a ResultSet row to a java.util.HashMap object
30: */
31: public final class RowToHashMapMapper extends RowMapper {
32:
33: private final String[] _keys;
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 resultSet, Class returnTypeClass,
42: Calendar cal) {
43: super (resultSet, returnTypeClass, cal);
44: try {
45: _keys = getKeysFromResultSet();
46: } catch (SQLException sql) {
47: throw new ControlException(
48: "RowToHashMapMapper: SQLException: "
49: + sql.getMessage(), sql);
50: }
51: }
52:
53: /**
54: * Do the mapping.
55: * @return A ResultSetHashMap object.
56: * @throws ControlException on error.
57: */
58: public Object mapRowToReturnType() {
59: try {
60: return new ResultSetHashMap(_resultSet, _keys);
61: } catch (SQLException e) {
62: throw new ControlException(
63: "Exception creating HashMap return type: ", e);
64: }
65: }
66: }
|