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

The following examples show how to use org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification. 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: ReactiveSessionImpl.java    From hibernate-reactive with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 File: StatelessSessionImpl.java    From lams with 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 #3
Source File: SessionImpl.java    From lams with 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 #4
Source File: ReactiveNativeQueryImpl.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
private NativeSQLQuerySpecification generateQuerySpecification() {
	return new NativeSQLQuerySpecification(
			getQueryParameterBindings().expandListValuedParameters( getQueryString(), getProducer() ),
			getQueryReturns().toArray( new NativeSQLQueryReturn[0] ),
			getSynchronizedQuerySpaces()
	);
}
 
Example #5
Source File: NativeQueryImpl.java    From lams with 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 File: NativeQueryImpl.java    From lams with 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 File: QueryPlanCache.java    From lams with 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
Source File: NativeQueryInterpreterStandardImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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
Source File: ReactiveSession.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
CompletionStage<Integer> executeReactiveUpdate(NativeSQLQuerySpecification specification,
QueryParameters parameters);
 
Example #10
Source File: AbstractProxySharedSessionContractImplementor.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters)
		throws HibernateException {
	return target.executeNativeUpdate(specification, queryParameters);
}
 
Example #11
Source File: AbstractProxySharedSessionContractImplementor.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public ScrollableResultsImplementor scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters) {
	return target.scroll(spec, queryParameters);
}
 
Example #12
Source File: AbstractProxySharedSessionContractImplementor.java    From jadira with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException {
	return target.list(spec, queryParameters);
}
 
Example #13
Source File: AbstractSharedSessionContract.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ScrollableResultsImplementor scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters) {
	return scrollCustomQuery( getNativeQueryPlan( spec ).getCustomQuery(), queryParameters );
}
 
Example #14
Source File: AbstractSharedSessionContract.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters) {
	return listCustomQuery( getNativeQueryPlan( spec ).getCustomQuery(), queryParameters );
}
 
Example #15
Source File: AbstractSharedSessionContract.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected NativeSQLQueryPlan getNativeQueryPlan(NativeSQLQuerySpecification spec) throws HibernateException {
	return getFactory().getQueryPlanCache().getNativeSQLQueryPlan( spec );
}
 
Example #16
Source File: SessionDelegatorBaseImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters) throws HibernateException {
	return delegate.executeNativeUpdate( specification, queryParameters );
}
 
Example #17
Source File: SessionDelegatorBaseImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ScrollableResultsImplementor scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException {
	return delegate.scroll( spec, queryParameters );
}
 
Example #18
Source File: SessionDelegatorBaseImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException {
	return delegate.list( spec, queryParameters );
}
 
Example #19
Source File: ReactiveSessionImpl.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
@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 #20
Source File: SharedSessionContractImplementor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Execute a native SQL update or delete query
 */
int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters)
		throws HibernateException;
 
Example #21
Source File: SharedSessionContractImplementor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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 #22
Source File: SharedSessionContractImplementor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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 #23
Source File: NativeQueryInterpreter.java    From lams with 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 #24
Source File: ReactiveSession.java    From hibernate-reactive with GNU Lesser General Public License v2.1 votes vote down vote up
<T> CompletionStage<List<T>> reactiveList(NativeSQLQuerySpecification spec, QueryParameters parameters);