Java Code Examples for org.hibernate.engine.spi.QueryParameters#processFilters()

The following examples show how to use org.hibernate.engine.spi.QueryParameters#processFilters() . 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: ReactiveNativeSQLQueryPlan.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
public CompletionStage<Integer> performExecuteReactiveUpdate(QueryParameters queryParameters, ReactiveSession session) {
		SharedSessionContractImplementor sessionContract = session.getSharedContract();

		coordinateSharedCacheCleanup(sessionContract);

		if ( queryParameters.isCallable() ) {
			throw new IllegalArgumentException("callable not yet supported for native queries");
		}

		queryParameters.processFilters( customQuery.getSQL(), sessionContract );

		Object[] params = PreparedStatementAdaptor.bind( statement -> {
			int col = 1;
			for ( ParameterBinder binder : customQuery.getParameterValueBinders() ) {
				col += binder.bind( statement, queryParameters, sessionContract, col );
			}
		} );

//		RowSelection selection = queryParameters.getRowSelection();
//		if ( selection != null && selection.getTimeout() != null ) {
//			statement.setQueryTimeout( selection.getTimeout() );
//		}

		boolean commentsEnabled = session.getFactory().getSessionFactoryOptions().isCommentsEnabled();
		String sql = session.getDialect()
				.addSqlHintOrComment( queryParameters.getFilteredSQL(), queryParameters, commentsEnabled );

		return session.getReactiveConnection().update( sql, params );
	}
 
Example 2
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 3
Source File: Loader.java    From lams with GNU General Public License v2.0 4 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 = preprocessSQL( sql, queryParameters, getFactory(), afterLoadActions );

	final PreparedStatement st = prepareQueryStatement( sql, queryParameters, limitHandler, scroll, session );

	final ResultSet rs;

	if( queryParameters.isCallable() && isTypeOf( st, CallableStatement.class ) ) {
		final CallableStatement cs = st.unwrap( CallableStatement.class );

		rs = getResultSet(
				cs,
				queryParameters.getRowSelection(),
				limitHandler,
				queryParameters.hasAutoDiscoverScalarTypes(),
				session
		);
	}
	else {
		rs = getResultSet(
			st,
			queryParameters.getRowSelection(),
			limitHandler,
			queryParameters.hasAutoDiscoverScalarTypes(),
			session
		);
	}

	return new SqlStatementWrapper(
		st,
		rs
	);

}
 
Example 4
Source File: NativeSQLQueryPlan.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Performs the execute query
 *
 * @param queryParameters The query parameters
 * @param session The session
 *
 * @return The number of affected rows as returned by the JDBC driver
 *
 * @throws HibernateException Indicates a problem performing the query execution
 */
public int performExecuteUpdate(
		QueryParameters queryParameters,
		SharedSessionContractImplementor session) throws HibernateException {

	coordinateSharedCacheCleanup( session );

	if ( queryParameters.isCallable() ) {
		throw new IllegalArgumentException("callable not yet supported for native queries");
	}

	int result = 0;
	PreparedStatement ps;
	RowSelection selection = queryParameters.getRowSelection();
	try {
		queryParameters.processFilters( this.customQuery.getSQL(), session );
		final String sql = session.getJdbcServices().getDialect()
				.addSqlHintOrComment(
					queryParameters.getFilteredSQL(),
					queryParameters,
					session.getFactory().getSessionFactoryOptions().isCommentsEnabled()
				);

		ps = session.getJdbcCoordinator().getStatementPreparer().prepareStatement( sql, false );

		try {
			int col = 1;
			for ( ParameterBinder binder : this.customQuery.getParameterValueBinders() ) {
				col += binder.bind( ps, queryParameters, session, col );
			}
			if ( selection != null && selection.getTimeout() != null ) {
				ps.setQueryTimeout( selection.getTimeout() );
			}
			result = session.getJdbcCoordinator().getResultSetReturn().executeUpdate( ps );
		}
		finally {
			if ( ps != null ) {
				session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( ps );
				session.getJdbcCoordinator().afterStatementExecution();
			}
		}
	}
	catch (SQLException sqle) {
		throw session.getFactory().getSQLExceptionHelper().convert(
				sqle,
				"could not execute native bulk manipulation query",
				this.sourceQuery
		);
	}

	return result;
}