/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.ibatis.sqlmap.client.SqlMapClient
 *  com.ibatis.sqlmap.engine.execution.SqlExecutor
 *  com.ibatis.sqlmap.engine.impl.SqlMapClientImpl
 *  com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate
 *  org.apache.commons.logging.Log
 *  org.apache.commons.logging.LogFactory
 *  org.springframework.orm.ibatis.SqlMapClientFactoryBean
 */
package com.hst.framework.orm.ibatis.spring;

import com.hst.framework.orm.ibatis.sqlmap.HstSqlExecutor;
import com.hst.framework.util.HstReflectUtil;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.engine.execution.SqlExecutor;
import com.ibatis.sqlmap.engine.impl.SqlMapClientImpl;
import com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.ibatis.SqlMapClientFactoryBean;

public class HstSqlMapClientFactoryBean
extends SqlMapClientFactoryBean {
    private static final Log logger = LogFactory.getLog(HstSqlMapClientFactoryBean.class);
    private SqlExecutor sqlExecutor;

    public SqlExecutor getSqlExecutor() {
        return this.sqlExecutor;
    }

    public void setSqlExecutor(SqlExecutor sqlExecutor) {
        this.sqlExecutor = sqlExecutor;
    }

    public void setEnableLimit(boolean enableLimit) {
        if (this.sqlExecutor instanceof HstSqlExecutor) {
            ((HstSqlExecutor)this.sqlExecutor).setEnableLimit(enableLimit);
        }
    }

    public void afterPropertiesSet() throws Exception {
        super.afterPropertiesSet();
        SqlMapClient c = this.getObject();
        if (this.sqlExecutor != null && c instanceof SqlMapClientImpl) {
            SqlMapClientImpl client = (SqlMapClientImpl)c;
            SqlMapExecutorDelegate delegate = client.getDelegate();
            try {
                HstReflectUtil.setFieldValue(delegate, "sqlExecutor", SqlExecutor.class, this.sqlExecutor);
                logger.debug((Object)("[iBATIS] success set ibatis SqlMapClient.sqlExecutor = " + this.sqlExecutor.getClass().getName()));
            }
            catch (Exception e) {
                logger.warn((Object)("[iBATIS] error,cannot set ibatis SqlMapClient.sqlExecutor = " + this.sqlExecutor.getClass().getName() + " cause:" + e));
            }
        }
    }
}
