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: package org.apache.beehive.controls.system.jdbc;
20:
21: import org.apache.beehive.controls.api.ControlException;
22:
23: import java.sql.ResultSet;
24: import java.sql.SQLException;
25: import java.util.Collections;
26: import java.util.Calendar;
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[] _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 resultSet, Class returnTypeClass,
42: Calendar cal) {
43: super (resultSet, returnTypeClass, cal);
44: try {
45: _keys = getKeysFromResultSet();
46: } catch (SQLException e) {
47: throw new ControlException("RowToMapMapper: SQLException: "
48: + e.getMessage(), e);
49: }
50: }
51:
52: /**
53: * Do the mapping.
54: * @return A Map.
55: * @throws ControlException on error.
56: */
57: public Object mapRowToReturnType() {
58: try {
59: return Collections.unmodifiableMap(new ResultSetHashMap(
60: _resultSet, _keys));
61: } catch (SQLException e) {
62: throw new ControlException(
63: "Exception while creating ResultSetHashMap.", e);
64: }
65: }
66: }
|