Search in sources :

Example 6 with Limit

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;
}
Also used : JdbcParameter(org.hibernate.sql.ast.tree.expression.JdbcParameter) FilterJdbcParameter(org.hibernate.internal.FilterJdbcParameter) Limit(org.hibernate.query.spi.Limit) Map(java.util.Map)

Example 7 with Limit

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;
}
Also used : Limit(org.hibernate.query.spi.Limit)

Example 8 with Limit

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);
}
Also used : Limit(org.hibernate.query.spi.Limit) Test(org.junit.jupiter.api.Test)

Example 9 with Limit

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);
}
Also used : Limit(org.hibernate.query.spi.Limit) Test(org.junit.jupiter.api.Test)

Example 10 with Limit

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);
}
Also used : Limit(org.hibernate.query.spi.Limit) Test(org.junit.jupiter.api.Test)

Aggregations

Limit (org.hibernate.query.spi.Limit)13 Test (org.junit.jupiter.api.Test)4 TestForIssue (org.hibernate.testing.TestForIssue)3 Test (org.junit.Test)3 CacheRetrieveMode (jakarta.persistence.CacheRetrieveMode)1 CacheStoreMode (jakarta.persistence.CacheStoreMode)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 FlushMode (org.hibernate.FlushMode)1 LockOptions (org.hibernate.LockOptions)1 AppliedGraph (org.hibernate.graph.spi.AppliedGraph)1 FilterJdbcParameter (org.hibernate.internal.FilterJdbcParameter)1 QueryOptions (org.hibernate.query.spi.QueryOptions)1 JdbcParameter (org.hibernate.sql.ast.tree.expression.JdbcParameter)1 ExecutionContext (org.hibernate.sql.exec.spi.ExecutionContext)1