SQLServer2005Dialect: modifications in order to support variable limit

This commit is contained in:
Yoryos Valotasios 2010-11-23 00:19:22 +02:00 committed by Strong Liu
parent 7df41185c5
commit 480ae72db6
1 changed files with 15 additions and 4 deletions

View File

@ -56,6 +56,17 @@ public class SQLServer2005Dialect extends SQLServerDialect {
registerFunction("row_number", new NoArgSQLFunction("row_number", StandardBasicTypes.INTEGER, true)); registerFunction("row_number", new NoArgSQLFunction("row_number", StandardBasicTypes.INTEGER, true));
} }
@Override
public int convertToFirstRowValue(int zeroBasedFirstResult) {
return zeroBasedFirstResult + 1;
}
@Override
public String getLimitString(String query, int offset, int limit) {
if (offset > 1 || limit > 1) return getLimitString(query, true);
return query;
}
/** /**
* Add a LIMIT clause to the given SQL SELECT (HHH-2655: ROW_NUMBER for Paging) * Add a LIMIT clause to the given SQL SELECT (HHH-2655: ROW_NUMBER for Paging)
@ -81,7 +92,7 @@ public class SQLServer2005Dialect extends SQLServerDialect {
* @return A new SQL statement with the LIMIT clause applied. * @return A new SQL statement with the LIMIT clause applied.
*/ */
@Override @Override
public String getLimitString(String querySqlString, int offset, int limit) { public String getLimitString(String querySqlString, boolean hasOffset) {
StringBuilder sb = new StringBuilder(querySqlString.trim().toLowerCase()); StringBuilder sb = new StringBuilder(querySqlString.trim().toLowerCase());
int orderByIndex = sb.indexOf("order by"); int orderByIndex = sb.indexOf("order by");
@ -100,7 +111,8 @@ public class SQLServer2005Dialect extends SQLServerDialect {
// Wrap the query within a with statement: // Wrap the query within a with statement:
sb.insert(0, "WITH query AS (").append(") SELECT * FROM query "); sb.insert(0, "WITH query AS (").append(") SELECT * FROM query ");
sb.append("WHERE __hibernate_row_nr__ BETWEEN ").append(offset + 1).append(" AND ").append(limit); //sb.append("WHERE __hibernate_row_nr__ BETWEEN ").append(offset + 1).append(" AND ").append(limit);
sb.append("WHERE __hibernate_row_nr__ BETWEEN ? AND ?");
return sb.toString(); return sb.toString();
} }
@ -185,7 +197,6 @@ public class SQLServer2005Dialect extends SQLServerDialect {
@Override @Override
public boolean supportsVariableLimit() { public boolean supportsVariableLimit() {
return false; return true;
} }
} }