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

The following examples show how to use org.hibernate.engine.spi.QueryParameters#traceParameters() . 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: ReactiveHQLQueryPlan.java    From hibernate-reactive with GNU Lesser General Public License v2.1 6 votes vote down vote up
public CompletionStage<Integer> performExecuteReactiveUpdate(QueryParameters queryParameters, ReactiveSession session) {
	if ( log.isTraceEnabled() ) {
		log.tracev( "Execute update: {0}", getSourceQuery() );
		queryParameters.traceParameters( session.getFactory() );
	}
	QueryTranslator[] translators = getTranslators();
	if ( translators.length != 1 ) {
		log.splitQueries( getSourceQuery(), translators.length );
	}

	CompletionStage<Integer> combinedStage = CompletionStages.completedFuture(0);
	for ( QueryTranslator translator : translators ) {
		ReactiveQueryTranslatorImpl reactiveTranslator = (ReactiveQueryTranslatorImpl) translator;
		combinedStage = combinedStage
				.thenCompose(
						count -> reactiveTranslator.executeReactiveUpdate( queryParameters, session )
								.thenApply( updateCount -> count + updateCount )
				);
	}
	return combinedStage;
}
 
Example 2
Source File: HQLQueryPlan.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Coordinates the efforts to perform a scroll across all the included query translators.
 *
 * @param queryParameters The query parameters
 * @param session The session
 *
 * @return The query result iterator
 *
 * @throws HibernateException Indicates a problem performing the query
 */
public ScrollableResultsImplementor performScroll(
		QueryParameters queryParameters,
		SharedSessionContractImplementor session) throws HibernateException {
	if ( traceEnabled ) {
		LOG.tracev( "Iterate: {0}", getSourceQuery() );
		queryParameters.traceParameters( session.getFactory() );
	}
	if ( translators.length != 1 ) {
		throw new QueryException( "implicit polymorphism not supported for scroll() queries" );
	}
	if ( queryParameters.getRowSelection().definesLimits() && translators[0].containsCollectionFetches() ) {
		throw new QueryException( "firstResult/maxResults not supported in conjunction with scroll() of a query containing collection fetches" );
	}

	return translators[0].scroll( queryParameters, session );
}
 
Example 3
Source File: HQLQueryPlan.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Coordinates the efforts to perform an execution across all the included query translators.
 *
 * @param queryParameters The query parameters
 * @param session The session
 *
 * @return The aggregated "affected row" count
 *
 * @throws HibernateException Indicates a problem performing the execution
 */
public int performExecuteUpdate(QueryParameters queryParameters, SharedSessionContractImplementor session)
		throws HibernateException {
	if ( traceEnabled ) {
		LOG.tracev( "Execute update: {0}", getSourceQuery() );
		queryParameters.traceParameters( session.getFactory() );
	}
	if ( translators.length != 1 ) {
		LOG.splitQueries( getSourceQuery(), translators.length );
	}
	int result = 0;
	for ( QueryTranslator translator : translators ) {
		result += translator.executeUpdate( queryParameters, session );
	}
	return result;
}
 
Example 4
Source File: HQLQueryPlan.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Coordinates the efforts to perform an iterate across all the included query translators.
 *
 * @param queryParameters The query parameters
 * @param session The session
 *
 * @return The query result iterator
 *
 * @throws HibernateException Indicates a problem performing the query
 */
@SuppressWarnings("unchecked")
public Iterator performIterate(
		QueryParameters queryParameters,
		EventSource session) throws HibernateException {
	if ( traceEnabled ) {
		LOG.tracev( "Iterate: {0}", getSourceQuery() );
		queryParameters.traceParameters( session.getFactory() );
	}
	if ( translators.length == 0 ) {
		return Collections.emptyIterator();
	}

	final boolean many = translators.length > 1;
	Iterator[] results = null;
	if ( many ) {
		results = new Iterator[translators.length];
	}

	Iterator result = null;
	for ( int i = 0; i < translators.length; i++ ) {
		result = translators[i].iterate( queryParameters, session );
		if ( many ) {
			results[i] = result;
		}
	}

	return many ? new JoinedIterator( results ) : result;
}
 
Example 5
Source File: HQLQueryPlan.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Coordinates the efforts to perform a list across all the included query translators.
 *
 * @param queryParameters The query parameters
 * @param session The session
 *
 * @return The query result list
 *
 * @throws HibernateException Indicates a problem performing the query
 */
@SuppressWarnings("unchecked")
public List performList(
		QueryParameters queryParameters,
		SharedSessionContractImplementor session) throws HibernateException {
	if ( traceEnabled ) {
		LOG.tracev( "Find: {0}", getSourceQuery() );
		queryParameters.traceParameters( session.getFactory() );
	}

	final RowSelection rowSelection = queryParameters.getRowSelection();
	final boolean hasLimit = rowSelection != null
			&& rowSelection.definesLimits();
	final boolean needsLimit = hasLimit && translators.length > 1;

	final QueryParameters queryParametersToUse;
	if ( needsLimit ) {
		LOG.needsLimit();
		final RowSelection selection = new RowSelection();
		selection.setFetchSize( queryParameters.getRowSelection().getFetchSize() );
		selection.setTimeout( queryParameters.getRowSelection().getTimeout() );
		queryParametersToUse = queryParameters.createCopyUsing( selection );
	}
	else {
		queryParametersToUse = queryParameters;
	}

	//fast path to avoid unnecessary allocation and copying
	if ( translators.length == 1 ) {
		return translators[0].list( session, queryParametersToUse );
	}
	final int guessedResultSize = guessResultSize( rowSelection );
	final List combinedResults = new ArrayList( guessedResultSize );
	final IdentitySet distinction;
	if ( needsLimit ) {
		distinction = new IdentitySet( guessedResultSize );
	}
	else {
		distinction = null;
	}
	int includedCount = -1;
	translator_loop:
	for ( QueryTranslator translator : translators ) {
		final List tmp = translator.list( session, queryParametersToUse );
		if ( needsLimit ) {
			// NOTE : firstRow is zero-based
			final int first = queryParameters.getRowSelection().getFirstRow() == null
					? 0
					: queryParameters.getRowSelection().getFirstRow();
			final int max = queryParameters.getRowSelection().getMaxRows() == null
					? -1
					: queryParameters.getRowSelection().getMaxRows();
			for ( final Object result : tmp ) {
				if ( !distinction.add( result ) ) {
					continue;
				}
				includedCount++;
				if ( includedCount < first ) {
					continue;
				}
				combinedResults.add( result );
				if ( max >= 0 && includedCount > max ) {
					// break the outer loop !!!
					break translator_loop;
				}
			}
		}
		else {
			combinedResults.addAll( tmp );
		}
	}
	return combinedResults;
}