@Override @SuppressWarnings("unchecked") public QueryImplementor setMaxResults(int maxResult) { getProducer().checkOpen(); if ( maxResult < 0 ) { throw new IllegalArgumentException( "max-results cannot be negative" ); } else { queryOptions.setMaxRows( maxResult ); } return this; }
/** * Set the maximum number of query results to be retrieved. A value less than * or equal to 0 is considered uninitialized, resulting in no limit on the number * of results. * * @param maxResults - the maximum number of query results * @return {@code this}, for method chaining * * @deprecated {@link #setMaxResults(int)} should be used instead. */ @Deprecated default Query setHibernateMaxResults(int maxResults) { // maxResults <= 0 is the same as uninitialized (with no limit), if ( maxResults <= 0 ) { // treat zero and negatives specifically as meaning no limit... getQueryOptions().setMaxRows( null ); } else { getQueryOptions().setMaxRows( maxResults ); } return this; }
public QueryParameters getQueryParameters() { final RowSelection selection = new RowSelection(); selection.setFirstRow( rootCriteria.getFirstResult() ); selection.setMaxRows( rootCriteria.getMaxResults() ); selection.setTimeout( rootCriteria.getTimeout() ); selection.setFetchSize( rootCriteria.getFetchSize() );
public Query setMaxResults(int maxResults) { if ( maxResults < 0 ) { // treat negatives specically as meaning no limit... selection.setMaxRows( null ); } else { selection.setMaxRows( maxResults); } return this; }
public Query setMaxResults(int maxResults) { if ( maxResults < 0 ) { // treat negatives specically as meaning no limit... selection.setMaxRows( null ); } else { selection.setMaxRows( maxResults); } return this; }
private int selectRecordsByMaxAge(Session session, String tempTable, Date minValue, Dialect dialect) { // fill temporary table, we don't need to join task on object on // container, oid and id is already in task table StringBuilder selectSB = new StringBuilder(); selectSB.append("select a.id as id from ").append(RAuditEventRecord.TABLE_NAME).append(" a"); selectSB.append(" where a.").append(RAuditEventRecord.COLUMN_TIMESTAMP).append(" < ###TIME###"); String selectString = selectSB.toString(); // batch size RowSelection rowSelection = new RowSelection(); rowSelection.setMaxRows(CLEANUP_AUDIT_BATCH_SIZE); LimitHandler limitHandler = dialect.getLimitHandler(); selectString = limitHandler.processSql(selectString, rowSelection); // replace ? -> batch size, $ -> ? // Sorry for that .... I just don't know how to write this query in HQL, // nor I'm not sure if limiting max size in // compound insert into ... select ... query via query.setMaxSize() // would work - TODO write more nicely if anybody knows how) selectString = selectString.replace("?", String.valueOf(CLEANUP_AUDIT_BATCH_SIZE)); selectString = selectString.replace("###TIME###", "?"); String queryString = "insert into " + tempTable + " " + selectString; LOGGER.trace("Query string = {}", queryString); NativeQuery query = session.createNativeQuery(queryString); query.setParameter(1, new Timestamp(minValue.getTime())); return query.executeUpdate(); }
rowSelection.setMaxRows(recordsToDelete); LimitHandler limitHandler = dialect.getLimitHandler(); selectString = limitHandler.processSql(selectString, rowSelection);
@Test public void testLimit() { RowSelection rowSelection = new RowSelection(); rowSelection.setMaxRows(getMaxRows()); long startNanos = System.nanoTime(); doInJDBC(connection -> { try (PreparedStatement statement = connection.prepareStatement(SELECT_POST_COMMENT); PreparedStatement noFixStatement = connection.prepareStatement(SELECT_POST_COMMENT_WITH_NO_FIX); ) { pocessResultSet(statement); try { pocessResultSet(noFixStatement); } catch (SQLException e) { LOGGER.error("Possible bug:", e); } } catch (SQLException e) { fail(e.getMessage()); } }); LOGGER.info("{} Result Set with limit took {} millis", dataSourceProvider().database(), TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos)); }
RowSelection selection = new RowSelection(); selection.setFirstRow( rootCriteria.getFirstResult() ); selection.setMaxRows( rootCriteria.getMaxResults() ); selection.setTimeout( rootCriteria.getTimeout() ); selection.setFetchSize( rootCriteria.getFetchSize() );
RowSelection selection = new RowSelection(); selection.setFirstRow( rootCriteria.getFirstResult() ); selection.setMaxRows( rootCriteria.getMaxResults() ); selection.setTimeout( rootCriteria.getTimeout() ); selection.setFetchSize( rootCriteria.getFetchSize() );
@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)); }
@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)); }
rowSelection.setMaxRows(original.getMaxRows()); } else if (original.getMaxRows() != null && original.getMaxRows() != Integer.MAX_VALUE && !original.getMaxRows().equals(rowSelection.getMaxRows())) { throw new IllegalStateException("Multiple row selections not allowed!");
@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)); }