001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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            @Override
050            protected T mapRow(ResultSet rs, int rowNumber) throws SQLException {
051                    return _rowMapper.mapRow(rs, rowNumber);
052            }
053    
054            private RowMapper<T> _rowMapper;
055    
056    }