Java Code Examples for org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification

The following examples show how to use org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification. These examples are extracted from open source projects. 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
@Override
public CompletionStage<Integer> executeReactiveUpdate(NativeSQLQuerySpecification specification,
													  QueryParameters parameters) {
	checkOpenOrWaitingForAutoClose();
	pulseTransactionCoordinator();
	parameters.validateParameters();

	ReactiveNativeSQLQueryPlan reactivePlan = //getNativeQueryPlan( specification );
			new ReactiveNativeSQLQueryPlan(
					specification.getQueryString(),
					new SQLCustomQuery(
							specification.getQueryString(),
							specification.getQueryReturns(),
							specification.getQuerySpaces(),
							getFactory()
					) );
	return reactiveAutoFlushIfRequired( reactivePlan.getCustomQuery().getQuerySpaces() )
			.thenCompose( v -> reactivePlan.performExecuteReactiveUpdate( parameters, this ) )
			.whenComplete( (count, x) -> {
				afterOperation( x == null );
				delayedAfterCompletion();
			} );
}
 
Example 2
Source Project: lams   Source File: SessionImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public int executeNativeUpdate(
		NativeSQLQuerySpecification nativeQuerySpecification,
		QueryParameters queryParameters) throws HibernateException {
	checkOpenOrWaitingForAutoClose();
	checkTransactionSynchStatus();
	queryParameters.validateParameters();
	NativeSQLQueryPlan plan = getNativeQueryPlan( nativeQuerySpecification );


	autoFlushIfRequired( plan.getCustomQuery().getQuerySpaces() );

	boolean success = false;
	int result = 0;
	try {
		result = plan.performExecuteUpdate( queryParameters, this );
		success = true;
	}
	finally {
		afterOperation( success );
		delayedAfterCompletion();
	}
	return result;
}
 
Example 3
Source Project: lams   Source File: StatelessSessionImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public int executeNativeUpdate(
		NativeSQLQuerySpecification nativeSQLQuerySpecification,
		QueryParameters queryParameters) throws HibernateException {
	checkOpen();
	queryParameters.validateParameters();
	NativeSQLQueryPlan plan = getNativeQueryPlan( nativeSQLQuerySpecification );

	boolean success = false;
	int result = 0;
	try {
		result = plan.performExecuteUpdate( queryParameters, this );
		success = true;
	}
	finally {
		afterOperation( success );
	}
	temporaryPersistenceContext.clear();
	return result;
}
 
Example 4
private NativeSQLQuerySpecification generateQuerySpecification() {
	return new NativeSQLQuerySpecification(
			getQueryParameterBindings().expandListValuedParameters( getQueryString(), getProducer() ),
			getQueryReturns().toArray( new NativeSQLQueryReturn[0] ),
			getSynchronizedQuerySpaces()
	);
}
 
Example 5
Source Project: lams   Source File: NativeQueryImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
private NativeSQLQuerySpecification generateQuerySpecification() {
	return new NativeSQLQuerySpecification(
			getQueryParameterBindings().expandListValuedParameters( getQueryString(), getProducer() ),
			queryReturns.toArray( new NativeSQLQueryReturn[queryReturns.size()] ),
			querySpaces
	);
}
 
Example 6
Source Project: lams   Source File: NativeQueryImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected ScrollableResultsImplementor doScroll(ScrollMode scrollMode) {
	final NativeSQLQuerySpecification nativeSQLQuerySpecification = generateQuerySpecification();
	final QueryParameters queryParameters = getQueryParameters();
	queryParameters.setScrollMode( scrollMode );
	return getProducer().scroll(
			nativeSQLQuerySpecification,
			queryParameters
	);
}
 
Example 7
Source Project: lams   Source File: QueryPlanCache.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the query plan for a native SQL query, creating it and caching it if not already cached
 *
 * @param spec The native SQL query specification
 *
 * @return The query plan
 *
 * @throws QueryException Indicates a problem translating the query
 * @throws MappingException Indicates a problem translating the query
 */
@SuppressWarnings("unchecked")
public NativeSQLQueryPlan getNativeSQLQueryPlan(final NativeSQLQuerySpecification spec) {
	NativeSQLQueryPlan value = (NativeSQLQueryPlan) queryPlanCache.get( spec );
	if ( value == null ) {
		LOG.tracev( "Unable to locate native-sql query plan in cache; generating ({0})", spec.getQueryString() );
		value = nativeQueryInterpreter.createQueryPlan( spec, factory );
		queryPlanCache.putIfAbsent( spec, value );
	}
	else {
		LOG.tracev( "Located native-sql query plan in cache ({0})", spec.getQueryString() );
	}
	return value;
}
 
Example 8
@Override
public NativeSQLQueryPlan createQueryPlan(
		NativeSQLQuerySpecification specification,
		SessionFactoryImplementor sessionFactory) {
	CustomQuery customQuery = new SQLCustomQuery(
			specification.getQueryString(),
			specification.getQueryReturns(),
			specification.getQuerySpaces(),
			sessionFactory
	);

	return new NativeSQLQueryPlan( specification.getQueryString(), customQuery );
}
 
Example 9
CompletionStage<Integer> executeReactiveUpdate(NativeSQLQuerySpecification specification,
QueryParameters parameters);
 
Example 10
@Override
public <T> CompletionStage<List<T>> reactiveList(NativeSQLQuerySpecification spec, QueryParameters parameters) {
	return listReactiveCustomQuery( getNativeQueryPlan( spec ).getCustomQuery(), parameters)
			//TODO: this typecast is rubbish
			.thenApply( list -> (List<T>) list );
}
 
Example 11
@Override
public List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException {
	return delegate.list( spec, queryParameters );
}
 
Example 12
@Override
public ScrollableResultsImplementor scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException {
	return delegate.scroll( spec, queryParameters );
}
 
Example 13
@Override
public int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters) throws HibernateException {
	return delegate.executeNativeUpdate( specification, queryParameters );
}
 
Example 14
protected NativeSQLQueryPlan getNativeQueryPlan(NativeSQLQuerySpecification spec) throws HibernateException {
	return getFactory().getQueryPlanCache().getNativeSQLQueryPlan( spec );
}
 
Example 15
@Override
public List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters) {
	return listCustomQuery( getNativeQueryPlan( spec ).getCustomQuery(), queryParameters );
}
 
Example 16
@Override
public ScrollableResultsImplementor scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters) {
	return scrollCustomQuery( getNativeQueryPlan( spec ).getCustomQuery(), queryParameters );
}
 
Example 17
@SuppressWarnings("rawtypes")
@Override
public List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException {
	return target.list(spec, queryParameters);
}
 
Example 18
@Override
public ScrollableResultsImplementor scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters) {
	return target.scroll(spec, queryParameters);
}
 
Example 19
@Override
public int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters)
		throws HibernateException {
	return target.executeNativeUpdate(specification, queryParameters);
}
 
Example 20
Source Project: lams   Source File: NativeQueryInterpreter.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Creates a new query plan for the specified native query.
 *
 * @param specification Describes the query to create a plan for
 * @param sessionFactory The current session factory
 *
 * @return A query plan for the specified native query.
 */
NativeSQLQueryPlan createQueryPlan(NativeSQLQuerySpecification specification, SessionFactoryImplementor sessionFactory);
 
Example 21
/**
 * Execute a native SQL query, and return the results as a fully built list.
 *
 * @param spec The specification of the native SQL query to execute.
 * @param queryParameters The parameters by which to perform the execution.
 *
 * @return The result list.
 *
 * @throws HibernateException
 */
List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters)
		throws HibernateException;
 
Example 22
/**
 * Execute a native SQL query, and return the results as a scrollable result.
 *
 * @param spec The specification of the native SQL query to execute.
 * @param queryParameters The parameters by which to perform the execution.
 *
 * @return The resulting scrollable result.
 *
 * @throws HibernateException
 */
ScrollableResultsImplementor scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters);
 
Example 23
/**
 * Execute a native SQL update or delete query
 */
int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters)
		throws HibernateException;
 
Example 24
<T> CompletionStage<List<T>> reactiveList(NativeSQLQuerySpecification spec, QueryParameters parameters);