1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.dao.jdbc.spring;
16  
17  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
18  import com.liferay.portal.kernel.dao.jdbc.RowMapper;
19  
20  import java.sql.ResultSet;
21  import java.sql.SQLException;
22  
23  import javax.sql.DataSource;
24  
25  import org.springframework.jdbc.core.SqlParameter;
26  
27  /**
28   * <a href="MappingSqlQueryImpl.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class MappingSqlQueryImpl<T>
33      extends org.springframework.jdbc.object.MappingSqlQuery<T>
34      implements MappingSqlQuery<T> {
35  
36      public MappingSqlQueryImpl(
37          DataSource dataSource, String sql, int[] types,
38          RowMapper<T> rowMapper) {
39  
40          super(dataSource, sql);
41  
42          for (int type : types) {
43              declareParameter(new SqlParameter(type));
44          }
45  
46          _rowMapper = rowMapper;
47  
48          compile();
49      }
50  
51      protected T mapRow(ResultSet rs, int rowNumber) throws SQLException {
52          return _rowMapper.mapRow(rs, rowNumber);
53      }
54  
55      private RowMapper<T> _rowMapper;
56  
57  }