package com.ejie.ad74a.dao;

import java.util.List;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.ejie.ad74a.annotation.HistoricoAnnotation;

@Component
public class Ad74aJdbcTemplate {

	private static final Logger logger = LoggerFactory.getLogger(Ad74aJdbcTemplate.class);

	private JdbcTemplate jdbcTemplate;

	@Resource
	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}

	@HistoricoAnnotation
	@Transactional(readOnly = true)
	public <T> List<T> queryHist(String sql, RowMapper<T> rowMapper, Object[] array, boolean b)
			throws DataAccessException {
		Ad74aJdbcTemplate.logger.info("SQL: " + sql);
		return this.jdbcTemplate.query(sql, rowMapper, array);
	}

}
