package jp.ac.osaka_u.ist.sel.similarity.csv.database;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import jp.ac.osaka_u.ist.sel.similarity.database.AbstractDAO;
import jp.ac.osaka_u.ist.sel.similarity.database.ColumnName;
import jp.ac.osaka_u.ist.sel.similarity.database.SQLGenerator;
import jp.ac.osaka_u.ist.sel.similarity.database.TableType;
import jp.ac.osaka_u.ist.sel.similarity.database.TransactionManager;

/**
 * DAO class for CloneInfo table.
 * Insert clone data into CloneInfo table.
 * 
 * @author ysk-ssk
 *
 */
public class SelectionCloneDAO extends AbstractDAO {
	
	public SelectionCloneDAO(TransactionManager transactionManager)
			throws SQLException {
		super(transactionManager);
	}
	
	public Map<Integer,Integer> getMappedData() throws SQLException {
	    Map<Integer,Integer> mappedData = new HashMap<Integer,Integer>();
	    
        // create sql
        ColumnName[] columns = {ColumnName.ID,ColumnName.GROUP_ID};
        String sql = SQLGenerator.getSelectStatement(TableType.CLONE_INFO, columns);
        // prepare the statement
        PreparedStatement pstmt = prepareStatement(sql);
        // execute
        ResultSet results = executeQuery(pstmt);
        while (results.next()) {
            int fileId = results.getInt(1);
            int groupId = results.getInt(2);
            mappedData.put(fileId,groupId);
        }
        
        return mappedData;
	}

}
