package com.uas.account.dao;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;

import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.stereotype.Repository;

import com.uas.account.entity.Log;

@Repository
public class LogDaoImpl extends BaseDao implements LogDao {

	@Override
	public void save(final List<Log> logs) {
		jdbcTemplate.batchUpdate("insert into ac$log(name,logDate,logLevel,msg,detailMsg,key) values (?,?,?,?,?,?)",
				new BatchPreparedStatementSetter() {

					@Override
					public void setValues(PreparedStatement ps, int i) throws SQLException {
						Log log = logs.get(i);
						ps.setObject(1, log.getName());
						ps.setObject(2, new Timestamp(log.getLogDate().getTime()));
						ps.setObject(3, log.getLevel());
						ps.setObject(4, log.getMsg());
						ps.setObject(5, log.getDetailMsg());
						ps.setObject(6, log.getKey());
					}

					@Override
					public int getBatchSize() {
						return logs.size();
					}
				});
	}

}
