package wint.dal.ibatis;

import org.springframework.orm.ibatis.SqlMapClientTemplate;
import wint.dal.MasterForcer;

import java.util.List;

/**
 * User: pister
 * Date: 13-7-7
 * Time: 上午11:16
 */
public class SqlExecutor {

    private ReadWriteSqlMapClientSource readWriteSqlMapClientSource;

    public SqlExecutor(ReadWriteSqlMapClientSource readWriteSqlMapClientSource) {
        this.readWriteSqlMapClientSource = readWriteSqlMapClientSource;
    }

    protected SqlMapClientTemplate getWriteSqlMapClientTemplate() {
        SqlMapClientTemplate sqlMapClientTemplate = MasterForcer.getSqlMapClientTemplate();
        if (sqlMapClientTemplate != null) {
            return sqlMapClientTemplate;
        }
        return readWriteSqlMapClientSource.getSqlMapClient(SqlMapClientTarget.MASTER);
    }

    protected SqlMapClientTemplate getReadSqlMapClientTemplate() {
        SqlMapClientTemplate sqlMapClientTemplate = MasterForcer.getSqlMapClientTemplate();
        if (sqlMapClientTemplate != null) {
            return sqlMapClientTemplate;
        }
        return readWriteSqlMapClientSource.getSqlMapClient(SqlMapClientTarget.SLAVE);
    }

    public Object queryForObject(String statementName) {
        return getReadSqlMapClientTemplate().queryForObject(statementName);
    }

    public Object queryForObject(String statementName, Object parameterObject) {
        return getReadSqlMapClientTemplate().queryForObject(statementName, parameterObject);
    }

    public List queryForList(String statementName) {
        return getReadSqlMapClientTemplate().queryForList(statementName);
    }

    public List queryForList(String statementName, Object parameterObject) {
        return getReadSqlMapClientTemplate().queryForList(statementName, parameterObject);
    }

    public Object insert(String statementName) {
        return getWriteSqlMapClientTemplate().insert(statementName);
    }

    public Object insert(String statementName, Object parameterObject) {
        return getWriteSqlMapClientTemplate().insert(statementName, parameterObject);
    }

    public int update(String statementName) {
        return getWriteSqlMapClientTemplate().update(statementName);
    }

    public int update(String statementName, Object parameterObject) {
        return getWriteSqlMapClientTemplate().update(statementName, parameterObject);
    }

    public int delete(String statementName) {
        return getWriteSqlMapClientTemplate().delete(statementName);
    }

    public int delete(String statementName, Object parameterObject) {
        return getWriteSqlMapClientTemplate().delete(statementName, parameterObject);
    }

}

@@ -17,24 +17,85 @@
 .ibatis;%0D%0A%0D%0A
+import org.springframework.orm.ibatis.SqlMapClientCallback;%0D%0A
 import org.s
@@ -1235,32 +1235,163 @@
 AVE);%0D%0A    %7D%0D%0A%0D%0A
+    public Object execute(SqlMapClientCallback action) %7B%0D%0A        return getWriteSqlMapClientTemplate().execute(action);%0D%0A    %7D%0D%0A%0D%0A
     public Objec

add ibatis batch