/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.ibatis.sqlmap.engine.execution.SqlExecutor
 *  com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback
 *  com.ibatis.sqlmap.engine.scope.StatementScope
 */
package com.hst.framework.orm.ibatis.sqlmap;

import com.hst.framework.orm.ibatis.dialect.HstDialect;
import com.ibatis.sqlmap.engine.execution.SqlExecutor;
import com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback;
import com.ibatis.sqlmap.engine.scope.StatementScope;
import java.sql.Connection;
import java.sql.SQLException;

public class HstSqlExecutor
extends SqlExecutor {
    private HstDialect dialect;
    private boolean enableLimit = true;

    public HstDialect getDialect() {
        return this.dialect;
    }

    public void setDialect(HstDialect dialect) {
        this.dialect = dialect;
    }

    public boolean isEnableLimit() {
        return this.enableLimit;
    }

    public void setEnableLimit(boolean enableLimit) {
        this.enableLimit = enableLimit;
    }

    public void executeQuery(StatementScope request, Connection conn, String sql, Object[] parameters, int skipResults, int maxResults, RowHandlerCallback callback) throws SQLException {
        if (this.isLimit(sql, skipResults, maxResults)) {
            sql = this.dialect.getLimitString(sql, skipResults, maxResults);
            skipResults = 0;
            maxResults = -999999;
        }
        super.executeQuery(request, conn, sql, parameters, skipResults, maxResults, callback);
    }

    private boolean isLimit(String sql, int skipResults, int maxResults) {
        return (skipResults != 0 || maxResults != -999999) && this.enableLimit && this.dialect.isSupportLimit(sql);
    }
}
