001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.dao.jdbc.spring;
016    
017    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
018    import com.liferay.portal.kernel.dao.jdbc.RowMapper;
019    
020    import java.sql.ResultSet;
021    import java.sql.SQLException;
022    
023    import javax.sql.DataSource;
024    
025    import org.springframework.jdbc.core.SqlParameter;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class MappingSqlQueryImpl<T>
031            extends org.springframework.jdbc.object.MappingSqlQuery<T>
032            implements MappingSqlQuery<T> {
033    
034            public MappingSqlQueryImpl(
035                    DataSource dataSource, String sql, int[] types,
036                    RowMapper<T> rowMapper) {
037    
038                    super(dataSource, sql);
039    
040                    for (int type : types) {
041                            declareParameter(new SqlParameter(type));
042                    }
043    
044                    _rowMapper = rowMapper;
045    
046                    compile();
047            }
048    
049            protected T mapRow(ResultSet rs, int rowNumber) throws SQLException {
050                    return _rowMapper.mapRow(rs, rowNumber);
051            }
052    
053            private RowMapper<T> _rowMapper;
054    
055    }