use of org.hibernate.query.spi.Limit in project hibernate-orm by hibernate.
the class JdbcSelect method isCompatibleWith.
@Override
public boolean isCompatibleWith(JdbcParameterBindings jdbcParameterBindings, QueryOptions queryOptions) {
if (!appliedParameters.isEmpty()) {
if (jdbcParameterBindings == null) {
return false;
}
for (Map.Entry<JdbcParameter, JdbcParameterBinding> entry : appliedParameters.entrySet()) {
final JdbcParameter parameter = entry.getKey();
final JdbcParameterBinding appliedBinding = entry.getValue();
// we must treat the absence of Limit parameters, when they were considered for locking, as incompatible
if (appliedBinding == null) {
if (parameter == offsetParameter) {
if (queryOptions.getLimit() == null || queryOptions.getLimit().getFirstRowJpa() == 0) {
return false;
}
} else if (parameter == limitParameter) {
if (queryOptions.getLimit() == null || queryOptions.getLimit().getMaxRowsJpa() == Integer.MAX_VALUE) {
return false;
}
} else if (jdbcParameterBindings.getBinding(parameter) == null) {
return false;
}
}
// We handle limit and offset parameters below
if (parameter != offsetParameter && parameter != limitParameter) {
final JdbcParameterBinding binding = jdbcParameterBindings.getBinding(parameter);
if (binding == null || !appliedBinding.getBindType().getJavaTypeDescriptor().areEqual(binding.getBindValue(), appliedBinding.getBindValue())) {
return false;
}
}
}
}
final Limit limit = queryOptions.getLimit();
if (offsetParameter == null && limitParameter == null) {
if (limit != null && !limit.isEmpty()) {
return false;
}
}
if (!isCompatible(offsetParameter, limit == null ? null : limit.getFirstRow(), 0)) {
return false;
}
if (!isCompatible(limitParameter, limit == null ? null : limit.getMaxRows(), Integer.MAX_VALUE)) {
return false;
}
return true;
}
use of org.hibernate.query.spi.Limit in project hibernate-orm by hibernate.
the class SQLServer2005DialectTestCase method toRowSelection.
private Limit toRowSelection(int firstRow, int maxRows) {
Limit selection = new Limit();
selection.setFirstRow(firstRow);
selection.setMaxRows(maxRows);
return selection;
}
use of org.hibernate.query.spi.Limit in project hibernate-orm by hibernate.
the class Oracle12LimitHandlerTest method testSqlWithSpace.
@Test
public void testSqlWithSpace() {
final String sql = "select p.name from Person p where p.id = 1 for update";
final String expected = "select * from (select p.name from Person p where p.id = 1) where rownum<=? for update";
final String processedSql = Oracle12LimitHandler.INSTANCE.processSql(sql, new Limit(0, 5), QueryOptions.NONE);
assertEquals(expected, processedSql);
}
use of org.hibernate.query.spi.Limit in project hibernate-orm by hibernate.
the class Oracle12LimitHandlerTest method testSqlWithForUpdateInsideAndOutsideQuotedStringA.
@Test
public void testSqlWithForUpdateInsideAndOutsideQuotedStringA() {
final String sql = "select a.prop from A a where a.name = 'this is for update ' for update";
final String expected = "select * from (select a.prop from A a where a.name = 'this is for update ') where rownum<=? for update";
final String processedSql = Oracle12LimitHandler.INSTANCE.processSql(sql, new Limit(0, 5), QueryOptions.NONE);
assertEquals(expected, processedSql);
}
use of org.hibernate.query.spi.Limit in project hibernate-orm by hibernate.
the class Oracle12LimitHandlerTest method testSqlWithSpaceInsideQuotedString.
@Test
public void testSqlWithSpaceInsideQuotedString() {
final String sql = "select p.name from Person p where p.name = ' this is a string with spaces ' for update";
final String expected = "select * from (select p.name from Person p where p.name = ' this is a string with spaces ') where rownum<=? for update";
final String processedSql = Oracle12LimitHandler.INSTANCE.processSql(sql, new Limit(0, 5), QueryOptions.NONE);
assertEquals(expected, processedSql);
}
Aggregations