package org.imirsel.nema.meandre.util;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import org.imirsel.nema.dao.MirexSubmission;
import org.imirsel.nema.model.Job;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;

public class MeandreConsoleDaoJdbc implements MeandreConsoleDao {

	private SimpleJdbcTemplate simpleJdbcTemplate;

	public void setDataSource(DataSource dataSource) {
		this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
	}

	@Override
	public void clearConsole(Job job) {
		// TODO Auto-generated method stub

	}

	@Override
	public List<ConsoleEntry> getEntry(final Job job) {
		final String sqlGetList = "select print,ts from meandre_job_console where job_ID = ?";
		RowMapper<ConsoleEntry> mapper = new RowMapper<ConsoleEntry>() {
			public ConsoleEntry mapRow(ResultSet rs, int rowNum)
					throws SQLException {
				ConsoleEntry entry = new ConsoleEntry();
				entry.setLine(rs.getString("print"));
				entry.setTimeStamp(rs.getTimestamp("ts"));
				return entry;
			}
		};

		return this.simpleJdbcTemplate.query(sqlGetList, mapper,job.getExecutionInstanceId());
	}

	@Override
	public List<ConsoleEntry> getEntry(Job job, int maxCount) {
		List<ConsoleEntry> list = getEntry(job);
		if ((list != null) && (list.size() > maxCount)) {
			return list.subList(list.size() - maxCount, list.size() - 1);
		} else
			return list;
	}

}

@@ -144,16 +144,101 @@
 ource;%0A%0A
+import org.apache.commons.logging.Log;%0Aimport org.apache.commons.logging.LogFactory;%0A
 import o
@@ -270,24 +270,24 @@
 Submission;%0A
-
 import org.i
@@ -555,16 +555,91 @@
 eDao %7B%0A%0A
+%09static protected Log logger = LogFactory.getLog(MeandreConsoleDao.class);%0A
 %09private
@@ -851,45 +851,272 @@
 ) %7B%0A
-%09%09// TODO Auto-generated method stub%0A
+//%09%09final String deleteSql=%22delete from meandre_job_console where job_ID= ?%22;%0A//%09%09int count=this.simpleJdbcTemplate.update(deleteSql, job.getExecutionInstanceId());%0A//%09%09logger.info(%22Console entries of job (%22+job.getName()+%22) has been deleted. Total count:%22+count);
 %0A%09%7D%0A

modify the clear database part