All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.jrouter.paging.jdbc.dialect.OracleDialect Maven / Gradle / Ivy

package net.jrouter.paging.jdbc.dialect;

/**
 * Dialect for Oracle.
 */
public class OracleDialect extends Dialect {

    @Override
    public String getLimitString(String query, int offset, int limit) {
        final StringBuilder pagingSelect = new StringBuilder(query.length() + 108);
        boolean hasOffset = offset > 0;
        if (hasOffset) {
            pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");
        } else {
            pagingSelect.append("select * from ( ");
        }
        pagingSelect.append(query);
        if (hasOffset) {
            pagingSelect.append(" ) row_ where rownum <= ").append(offset + limit).
                    append(") where rownum_ > ").append(offset);
        } else {
            pagingSelect.append(" ) where rownum <= ").append(limit);
        }
        return pagingSelect.toString();
    }

    @Override
    public String getCountString(String query, int countLimit) {
        if (hasLimit(countLimit)) {
            final StringBuilder pagingSelect = new StringBuilder(query.length() + 50);
            pagingSelect.append("select count(*) from ( ");
            pagingSelect.append(query);
            pagingSelect.append(" ) where rownum <= ").append(countLimit);
        }
        return getSimpleCountLimitSQL(query);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy