Java Code Examples for org.hibernate.engine.spi.RowSelection#setMaxRows()

The following examples show how to use org.hibernate.engine.spi.RowSelection#setMaxRows() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommonPanacheQueryImpl.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private Query createQuery() {
    Query jpaQuery = createBaseQuery();

    if (range != null) {
        jpaQuery.setFirstResult(range.getStartIndex());
        // range is 0 based, so we add 1
        jpaQuery.setMaxResults(range.getLastIndex() - range.getStartIndex() + 1);
    } else if (page != null) {
        jpaQuery.setFirstResult(page.index * page.size);
        jpaQuery.setMaxResults(page.size);
    } else {
        // Use deprecated API in org.hibernate.Query that will be moved to org.hibernate.query.Query on Hibernate 6.0
        @SuppressWarnings("deprecation")
        RowSelection options = jpaQuery.unwrap(org.hibernate.query.Query.class).getQueryOptions();
        options.setFirstRow(null);
        options.setMaxRows(null);
    }

    return jpaQuery;
}
 
Example 2
Source File: OracleResultSetLimitTest.java    From high-performance-java-persistence with Apache License 2.0 6 votes vote down vote up
@Test
public void testLimit() {
    RowSelection rowSelection = new RowSelection();
    rowSelection.setMaxRows(getMaxRows());
    long startNanos = System.nanoTime();
    doInJDBC(connection -> {
        try (PreparedStatement statement = connection.prepareStatement(SELECT_POST)
        ) {
            statement.setMaxRows(getMaxRows());
            assertEquals(getMaxRows(), processResultSet(statement));
        } catch (SQLException e) {
            fail(e.getMessage());
        }

    });
    LOGGER.info("{} Result Set with limit took {} millis",
            dataSourceProvider().database(),
            TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos));
}
 
Example 3
Source File: SQLServerResultSetLimitTest.java    From high-performance-java-persistence with Apache License 2.0 6 votes vote down vote up
@Test
public void testLimit() {
    RowSelection rowSelection = new RowSelection();
    rowSelection.setMaxRows(getMaxRows());
    long startNanos = System.nanoTime();
    doInJDBC(connection -> {
        try (PreparedStatement statement1 = connection.prepareStatement(SELECT_POST_COMMENT_1);
             PreparedStatement statement11 = connection.prepareStatement(SELECT_POST_COMMENT_1);
             PreparedStatement statement2 = connection.prepareStatement(SELECT_POST_COMMENT_2);
        ) {
            statement1.setMaxRows(getMaxRows());
            assertEquals(getMaxRows(), processResultSet(statement1));
            assertEquals(getPostCommentCount() * getPostCount(), processResultSet(statement11));
            assertEquals(getPostCommentCount() * getPostCount(), processResultSet(statement2));
        } catch (SQLException e) {
            fail(e.getMessage());
        }

    });
    LOGGER.info("{} Result Set with limit took {} millis",
            dataSourceProvider().database(),
            TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos));
}
 
Example 4
Source File: ResultSetLimitTest.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Test
public void testLimit() {
    final RowSelection rowSelection = new RowSelection();
    rowSelection.setMaxRows(getMaxRows());
    LimitHandler limitHandler = ((SessionFactoryImpl) sessionFactory()).getDialect().getLimitHandler();
    String limitStatement = limitHandler.processSql(SELECT_POST_COMMENT, rowSelection);
    long startNanos = System.nanoTime();
    doInJDBC(connection -> {
        try (PreparedStatement statement = connection.prepareStatement(limitStatement)) {
            limitHandler.bindLimitParametersAtEndOfQuery(rowSelection, statement, 1);
            statement.setInt(1, getMaxRows());
            statement.execute();
            int count = 0;
            ResultSet resultSet = statement.getResultSet();
            while (resultSet.next()) {
                resultSet.getLong(1);
                count++;
            }
            assertEquals(getMaxRows(), count);
        } catch (SQLException e) {
            fail(e.getMessage());
        }

    });
    LOGGER.info("{} Result Set with limit took {} millis",
            dataSourceProvider().database(),
            TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos));
}