org.hibernate.dialect.pagination.LimitHandler Java Examples

The following examples show how to use org.hibernate.dialect.pagination.LimitHandler. 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: ReactiveLoader.java    From hibernate-reactive with GNU Lesser General Public License v2.1 6 votes vote down vote up
default CompletionStage<ResultSet> executeReactiveQueryStatement(
		String sqlStatement,
		QueryParameters queryParameters,
		List<AfterLoadAction> afterLoadActions,
		SessionImplementor session) {

	// Processing query filters.
	queryParameters.processFilters( sqlStatement, session );

	// Applying LIMIT clause.
	final LimitHandler limitHandler = limitHandler( queryParameters.getRowSelection(), session );
	String sql = limitHandler.processSql( queryParameters.getFilteredSQL(), queryParameters.getRowSelection() );

	// Adding locks and comments.
	sql = preprocessSQL( sql, queryParameters, session.getSessionFactory(), afterLoadActions );

	return session.unwrap(ReactiveSession.class)
			.getReactiveConnection()
			.selectJdbc( sql, toParameterArray(queryParameters, session) );
}
 
Example #2
Source File: Loader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute given <tt>PreparedStatement</tt>, advance to the first result and return SQL <tt>ResultSet</tt>.
 */
protected final ResultSet getResultSet(
		final PreparedStatement st,
		final RowSelection selection,
		final LimitHandler limitHandler,
		final boolean autodiscovertypes,
		final SharedSessionContractImplementor session) throws SQLException, HibernateException {
	try {
		ResultSet rs = session.getJdbcCoordinator().getResultSetReturn().extract( st );

		return processResultSet(rs, selection, limitHandler, autodiscovertypes, session);
	}
	catch (SQLException | HibernateException e) {
		session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( st );
		session.getJdbcCoordinator().afterStatementExecution();
		throw e;
	}
}
 
Example #3
Source File: Loader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute given <tt>CallableStatement</tt>, advance to the first result and return SQL <tt>ResultSet</tt>.
 */
protected final ResultSet getResultSet(
		final CallableStatement st,
		final RowSelection selection,
		final LimitHandler limitHandler,
		final boolean autodiscovertypes,
		final SharedSessionContractImplementor session) throws SQLException, HibernateException {
	try {
		ResultSet rs = session.getJdbcCoordinator().getResultSetReturn().extract( st );

		return processResultSet(rs, selection, limitHandler, autodiscovertypes, session);
	}
	catch (SQLException | HibernateException e) {
		session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( st );
		session.getJdbcCoordinator().afterStatementExecution();
		throw e;
	}
}
 
Example #4
Source File: Loader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private ResultSet processResultSet(
		ResultSet rs,
		final RowSelection selection,
		final LimitHandler limitHandler,
		final boolean autodiscovertypes,
		final SharedSessionContractImplementor session
) throws SQLException, HibernateException {
	rs = wrapResultSetIfEnabled( rs, session );

	if ( !limitHandler.supportsLimitOffset() || !LimitHelper.useLimit( limitHandler, selection ) ) {
		advance( rs, selection );
	}

	if ( autodiscovertypes ) {
		autoDiscoverTypes( rs );
	}
	return rs;
}
 
Example #5
Source File: AbstractLoadPlanBasedLoader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute given <tt>PreparedStatement</tt>, advance to the first result and return SQL <tt>ResultSet</tt>.
 */
protected final ResultSet getResultSet(
		final PreparedStatement st,
		final RowSelection selection,
		final LimitHandler limitHandler,
		final boolean autodiscovertypes,
		final SharedSessionContractImplementor session)
		throws SQLException, HibernateException {

	try {
		ResultSet rs = session.getJdbcCoordinator().getResultSetReturn().extract( st );
		rs = wrapResultSetIfEnabled( rs , session );

		if ( !limitHandler.supportsLimitOffset() || !LimitHelper.useLimit( limitHandler, selection ) ) {
			advance( rs, selection );
		}

		if ( autodiscovertypes ) {
			autoDiscoverTypes( rs );
		}
		return rs;
	}
	catch (SQLException | HibernateException ex) {
		session.getJdbcCoordinator().getResourceRegistry().release( st );
		session.getJdbcCoordinator().afterStatementExecution();
		throw ex;
	}
}
 
Example #6
Source File: IngresDialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
	if ( isLegacyLimitHandlerBehaviorEnabled() ) {
		return LegacyFirstLimitHandler.INSTANCE;
	}
	return getDefaultLimitHandler();
}
 
Example #7
Source File: InformixDialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
	if ( isLegacyLimitHandlerBehaviorEnabled() ) {
		return LegacyFirstLimitHandler.INSTANCE;
	}
	return FirstLimitHandler.INSTANCE;
}
 
Example #8
Source File: Cache71Dialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
	if ( isLegacyLimitHandlerBehaviorEnabled() ) {
		return super.getLimitHandler();
	}
	return limitHandler;
}
 
Example #9
Source File: TimesTenDialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
	if ( isLegacyLimitHandlerBehaviorEnabled() ) {
		return LegacyFirstLimitHandler.INSTANCE;
	}
	return FirstLimitHandler.INSTANCE;
}
 
Example #10
Source File: SQLServerDialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
	if ( isLegacyLimitHandlerBehaviorEnabled() ) {
		return new LegacyLimitHandler( this );
	}
	return getDefaultLimitHandler();
}
 
Example #11
Source File: RDMSOS2200Dialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
	if ( isLegacyLimitHandlerBehaviorEnabled() ) {
		return LEGACY_LIMIT_HANDLER;
	}
	return LIMIT_HANDLER;
}
 
Example #12
Source File: DB2390Dialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
	if ( isLegacyLimitHandlerBehaviorEnabled() ) {
		return LEGACY_LIMIT_HANDLER;
	}
	else {
		return LIMIT_HANDLER;
	}
}
 
Example #13
Source File: ReactiveCustomLoader.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void bindToPreparedStatement(PreparedStatement adaptor,
									QueryParameters queryParameters,
									LimitHandler limitHandler,
									SharedSessionContractImplementor session) throws SQLException {
	super.bindPreparedStatement(adaptor, queryParameters, limitHandler, session);
}
 
Example #14
Source File: ReactiveQueryLoader.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void bindToPreparedStatement(PreparedStatement adaptor,
									QueryParameters queryParameters,
									LimitHandler limitHandler,
									SharedSessionContractImplementor session) throws SQLException {
	super.bindPreparedStatement(adaptor, queryParameters, limitHandler, session);
}
 
Example #15
Source File: AbstractLoadPlanBasedLoader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected SqlStatementWrapper executeQueryStatement(
		String sqlStatement,
		QueryParameters queryParameters,
		boolean scroll,
		List<AfterLoadAction> afterLoadActions,
		SharedSessionContractImplementor session) throws SQLException {

	// Processing query filters.
	queryParameters.processFilters( sqlStatement, session );

	// Applying LIMIT clause.
	final LimitHandler limitHandler = getLimitHandler(
			queryParameters.getRowSelection()
	);
	String sql = limitHandler.processSql( queryParameters.getFilteredSQL(), queryParameters.getRowSelection() );

	// Adding locks and comments.
	sql = session.getJdbcServices().getJdbcEnvironment().getDialect()
			.addSqlHintOrComment(
				sql,
				queryParameters,
				session.getFactory().getSessionFactoryOptions().isCommentsEnabled()
			);

	final PreparedStatement st = prepareQueryStatement( sql, queryParameters, limitHandler, scroll, session );
	return new SqlStatementWrapper( st, getResultSet( st, queryParameters.getRowSelection(), limitHandler, queryParameters.hasAutoDiscoverScalarTypes(), session ) );
}
 
Example #16
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));
}
 
Example #17
Source File: SQLServerDialect.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected LimitHandler getDefaultLimitHandler() {
	return limitHandler;
}
 
Example #18
Source File: DB2Dialect.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
	return LIMIT_HANDLER;
}
 
Example #19
Source File: Oracle12CustomDialect.java    From high-performance-java-persistence with Apache License 2.0 4 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
    return SQL2008StandardLimitHandler.INSTANCE;
}
 
Example #20
Source File: FollowOnLockingTest.java    From high-performance-java-persistence with Apache License 2.0 4 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
    return new Oracle9iDialect().getLimitHandler();
}
 
Example #21
Source File: Informix10Dialect.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
	return Informix10LimitHandler.INSTANCE;
}
 
Example #22
Source File: AbstractHANADialect.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
	return LIMIT_HANDLER;
}
 
Example #23
Source File: OracleDataSourceProvider.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
    return SQL2008StandardLimitHandler.INSTANCE;
}
 
Example #24
Source File: SQLServer2012Dialect.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected LimitHandler getDefaultLimitHandler() {
	return new SQLServer2012LimitHandler();
}
 
Example #25
Source File: OracleDataSourceProvider.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
    return SQL2008StandardLimitHandler.INSTANCE;
}
 
Example #26
Source File: SQLServer2005Dialect.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected LimitHandler getDefaultLimitHandler() {
	return new SQLServer2005LimitHandler();
}
 
Example #27
Source File: PostgreSQL81Dialect.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
	return LIMIT_HANDLER;
}
 
Example #28
Source File: DelegatingDialect.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
    return getInstance().getLimitHandler();
}
 
Example #29
Source File: Oracle9iDialect.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
	return LIMIT_HANDLER;
}
 
Example #30
Source File: InterbaseDialect.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public LimitHandler getLimitHandler() {
	return LIMIT_HANDLER;
}