Search in sources :

Example 11 with Limit

use of org.hibernate.query.spi.Limit in project hibernate-orm by hibernate.

the class Oracle12LimitHandlerTest method testSqlWithForUpdateInsideQuotedString.

@Test
public void testSqlWithForUpdateInsideQuotedString() {
    final String sql = "select a.prop from A a where a.name =  'this is for update '";
    final String expected = "select a.prop from A a where a.name =  'this is for update ' fetch first ? rows only";
    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 12 with Limit

use of org.hibernate.query.spi.Limit in project hibernate-orm by hibernate.

the class SQLServer2005DialectTestCase method testGetLimitStringUsingCTEQueryNoOffset.

@Test
@TestForIssue(jiraKey = "HHH-8916")
public void testGetLimitStringUsingCTEQueryNoOffset() {
    Limit selection = toRowSelection(0, 5);
    // test top-based CTE with single CTE query_ definition with no odd formatting
    final String query1 = "WITH a (c1, c2) AS (SELECT c1, c2 FROM t) SELECT c1, c2 FROM a";
    assertEquals("WITH a (c1, c2) AS (SELECT c1, c2 FROM t) SELECT top(?) c1, c2 FROM a", dialect.getLimitHandler().processSql(query1, selection));
    // test top-based CTE with single CTE query_ definition and various tab, newline spaces
    final String query2 = "  \n\tWITH a (c1\n\t,c2)\t\nAS (SELECT\n\tc1,c2 FROM t)\t\nSELECT c1, c2 FROM a";
    assertEquals("WITH a (c1\n\t,c2)\t\nAS (SELECT\n\tc1,c2 FROM t)\t\nSELECT top(?) c1, c2 FROM a", dialect.getLimitHandler().processSql(query2, selection));
    // test top-based CTE with multiple CTE query_ definitions with no odd formatting
    final String query3 = "WITH a (c1, c2) AS (SELECT c1, c2 FROM t1), b (b1, b2) AS (SELECT b1, b2 FROM t2) " + "SELECT c1, c2, b1, b2 FROM t1, t2 WHERE t1.c1 = t2.b1";
    assertEquals("WITH a (c1, c2) AS (SELECT c1, c2 FROM t1), b (b1, b2) AS (SELECT b1, b2 FROM t2) " + "SELECT top(?) c1, c2, b1, b2 FROM t1, t2 WHERE t1.c1 = t2.b1", dialect.getLimitHandler().processSql(query3, selection));
    // test top-based CTE with multiple CTE query_ definitions and various tab, newline spaces
    final String query4 = "  \n\r\tWITH a (c1, c2) AS\n\r (SELECT c1, c2 FROM t1)\n\r, b (b1, b2)\tAS\t" + "(SELECT b1, b2 FROM t2)    SELECT c1, c2, b1, b2 FROM t1, t2 WHERE t1.c1 = t2.b1";
    assertEquals("WITH a (c1, c2) AS\n\r (SELECT c1, c2 FROM t1)\n\r, b (b1, b2)\tAS\t(SELECT b1, b2 FROM t2)" + "    SELECT top(?) c1, c2, b1, b2 FROM t1, t2 WHERE t1.c1 = t2.b1", dialect.getLimitHandler().processSql(query4, selection));
}
Also used : Limit(org.hibernate.query.spi.Limit) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 13 with Limit

use of org.hibernate.query.spi.Limit in project hibernate-orm by hibernate.

the class SQLServer2012DialectTestCase method toRowSelection.

private Limit toRowSelection(int firstRow, int maxRows) {
    final Limit selection = new Limit();
    selection.setFirstRow(firstRow);
    selection.setMaxRows(maxRows);
    return selection;
}
Also used : Limit(org.hibernate.query.spi.Limit)

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