/*
 * Decompiled with CFR 0.152.
 */
package com.hst.framework.orm.ibatis.dialect;

import com.hst.framework.orm.ibatis.dialect.HstDialect;

public class HstOracleDialect
implements HstDialect {
    protected static final String SQL_END_DELIMITER = ";";

    @Override
    public String getLimitString(String sql, int offset, int limit) {
        if (offset == 1) {
            offset = 0;
        }
        StringBuffer pageStr = new StringBuffer();
        pageStr.append("select * from ( select row_limit.*, rownum rownum_ from (");
        pageStr.append(this.trim(sql));
        pageStr.append(" ) row_limit where rownum <= ");
        pageStr.append(limit + offset);
        pageStr.append(" ) where rownum_ >");
        pageStr.append(offset);
        return pageStr.toString();
    }

    private String trim(String sql) {
        if ((sql = sql.trim()).endsWith(SQL_END_DELIMITER)) {
            sql = sql.substring(0, sql.length() - 1 - SQL_END_DELIMITER.length());
        }
        return sql;
    }

    @Override
    public boolean isSupportLimit(String sql) {
        if (sql.toLowerCase().indexOf("select") >= 0) {
            return sql.toLowerCase().indexOf("rownum") < 0;
        }
        return false;
    }
}
