org.hibernate.loader.custom.CustomQuery Java Examples

The following examples show how to use org.hibernate.loader.custom.CustomQuery. 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
private CompletionStage<List<Object>> listReactiveCustomQuery(CustomQuery customQuery, QueryParameters parameters) {
		checkOpenOrWaitingForAutoClose();
//		checkTransactionSynchStatus();

		ReactiveCustomLoader loader = new ReactiveCustomLoader( customQuery, getFactory() );

//		autoFlushIfRequired( loader.getQuerySpaces() );

//		dontFlushFromFind++;
//		boolean success = false;
			return loader.reactiveList( this, parameters )
					.whenComplete( (r, e) -> delayedAfterCompletion() );
//			success = true;
//			dontFlushFromFind--;
//			afterOperation( success );
	}
 
Example #2
Source File: StatelessSessionImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public List listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)
throws HibernateException {
	errorIfClosed();
	CustomLoader loader = new CustomLoader( customQuery, getFactory() );

	boolean success = false;
	List results;
	try {
		results = loader.list(this, queryParameters);
		success = true;
	}
	finally {
		afterOperation(success);
	}
	temporaryPersistenceContext.clear();
	return results;
}
 
Example #3
Source File: SessionImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public List listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) 
throws HibernateException {
	errorIfClosed();
	checkTransactionSynchStatus();

	if ( log.isTraceEnabled() ) {
		log.trace( "SQL query: " + customQuery.getSQL() );
	}
	
	CustomLoader loader = new CustomLoader( customQuery, getFactory() );

	autoFlushIfRequired( loader.getQuerySpaces() );

	dontFlushFromFind++;
	boolean success = false;
	try {
		List results = loader.list(this, queryParameters);
		success = true;
		return results;
	}
	finally {
		dontFlushFromFind--;
		afterOperation(success);
	}
}
 
Example #4
Source File: SessionImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public ScrollableResults scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) 
throws HibernateException {
	errorIfClosed();
	checkTransactionSynchStatus();

	if ( log.isTraceEnabled() ) {
		log.trace( "scroll SQL query: " + customQuery.getSQL() );
	}

	CustomLoader loader = new CustomLoader( customQuery, getFactory() );

	autoFlushIfRequired( loader.getQuerySpaces() );

	dontFlushFromFind++; //stops flush being called multiple times if this method is recursively called
	try {
		return loader.scroll(queryParameters, this);
	}
	finally {
		dontFlushFromFind--;
	}
}
 
Example #5
Source File: SessionImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
	public ScrollableResultsImplementor scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) {
		checkOpenOrWaitingForAutoClose();
//		checkTransactionSynchStatus();

		if ( log.isTraceEnabled() ) {
			log.tracev( "Scroll SQL query: {0}", customQuery.getSQL() );
		}

		CustomLoader loader = getFactory().getQueryPlanCache().getNativeQueryInterpreter().createCustomLoader( customQuery, getFactory() );

		autoFlushIfRequired( loader.getQuerySpaces() );

		dontFlushFromFind++; //stops flush being called multiple times if this method is recursively called
		try {
			return loader.scroll( queryParameters, this );
		}
		finally {
			delayedAfterCompletion();
			dontFlushFromFind--;
		}
	}
 
Example #6
Source File: SessionImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
	public List listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) {
		checkOpenOrWaitingForAutoClose();
//		checkTransactionSynchStatus();

		if ( log.isTraceEnabled() ) {
			log.tracev( "SQL query: {0}", customQuery.getSQL() );
		}

		CustomLoader loader = getFactory().getQueryPlanCache().getNativeQueryInterpreter().createCustomLoader( customQuery, getFactory() );

		autoFlushIfRequired( loader.getQuerySpaces() );

		dontFlushFromFind++;
		boolean success = false;
		try {
			List results = loader.list( this, queryParameters );
			success = true;
			return results;
		}
		finally {
			dontFlushFromFind--;
			delayedAfterCompletion();
			afterOperation( success );
		}
	}
 
Example #7
Source File: StatelessSessionImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public List listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)
		throws HibernateException {
	checkOpen();
	CustomLoader loader = new CustomLoader( customQuery, getFactory() );

	boolean success = false;
	List results;
	try {
		results = loader.list( this, queryParameters );
		success = true;
	}
	finally {
		afterOperation( success );
	}
	temporaryPersistenceContext.clear();
	return results;
}
 
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: OutputsImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public CustomLoaderExtension(
		CustomQuery customQuery,
		QueryParameters queryParameters,
		SharedSessionContractImplementor session) {
	super( customQuery, session.getFactory() );
	this.queryParameters = queryParameters;
	this.session = session;

	entityAliases = interpretEntityAliases( customQuery.getCustomQueryReturns() );
}
 
Example #10
Source File: OutputsImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static CustomLoaderExtension buildSpecializedCustomLoader(final ResultContext context) {
	// might be better to just manually construct the Return(s).. SQLQueryReturnProcessor does a lot of
	// work that is really unnecessary here.
	final SQLQueryReturnProcessor processor = new SQLQueryReturnProcessor(
			context.getQueryReturns(),
			context.getSession().getFactory()
	);
	processor.process();
	final List<org.hibernate.loader.custom.Return> customReturns = processor.generateCallableReturns();

	CustomQuery customQuery = new CustomQuery() {
		@Override
		public String getSQL() {
			return context.getSql();
		}

		@Override
		public Set<String> getQuerySpaces() {
			return context.getSynchronizedQuerySpaces();
		}

		@Override
		public List<ParameterBinder> getParameterValueBinders() {
			// no parameters in terms of embedded in the SQL string
			return Collections.emptyList();
		}

		@Override
		public List<org.hibernate.loader.custom.Return> getCustomQueryReturns() {
			return customReturns;
		}
	};

	return new CustomLoaderExtension(
			customQuery,
			context.getQueryParameters(),
			context.getSession()
	);
}
 
Example #11
Source File: StatelessSessionImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ScrollableResultsImplementor scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)
		throws HibernateException {
	checkOpen();
	CustomLoader loader = new CustomLoader( customQuery, getFactory() );
	return loader.scroll( queryParameters, this );
}
 
Example #12
Source File: AbstractProxySharedSessionContractImplementor.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public ScrollableResultsImplementor scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)
		throws HibernateException {
	return target.scrollCustomQuery(customQuery, queryParameters);
}
 
Example #13
Source File: ReactiveCustomLoader.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
public ReactiveCustomLoader(CustomQuery customQuery, SessionFactoryImplementor factory) {
	super(customQuery, factory);
	this.resultSetProcessor = new ReactiveLoaderBasedResultSetProcessor( this );
}
 
Example #14
Source File: AbstractProxySharedSessionContractImplementor.java    From jadira with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public List listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) throws HibernateException {
	return target.listCustomQuery(customQuery, queryParameters);
}
 
Example #15
Source File: StatelessSessionImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public ScrollableResults scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)
throws HibernateException {
	errorIfClosed();
	CustomLoader loader = new CustomLoader( customQuery, getFactory() );
	return loader.scroll(queryParameters, this);
}
 
Example #16
Source File: SessionDelegatorBaseImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ScrollableResultsImplementor scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) throws HibernateException {
	return delegate.scrollCustomQuery( customQuery, queryParameters );
}
 
Example #17
Source File: SessionDelegatorBaseImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public List listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) throws HibernateException {
	return delegate.listCustomQuery( customQuery, queryParameters );
}
 
Example #18
Source File: NativeSQLQueryPlan.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public CustomQuery getCustomQuery() {
	return customQuery;
}
 
Example #19
Source File: ReactiveNativeSQLQueryPlan.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
public ReactiveNativeSQLQueryPlan(String sourceQuery, CustomQuery customQuery) {
	super(sourceQuery, customQuery);
	this.sourceQuery = sourceQuery;
	this.customQuery = customQuery;
}
 
Example #20
Source File: SessionImplementor.java    From cacheonix-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Execute an SQL Query
 */
public List listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) 
throws HibernateException;
 
Example #21
Source File: SessionImplementor.java    From cacheonix-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Execute an SQL Query
 */
public ScrollableResults scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) 
throws HibernateException;
 
Example #22
Source File: SharedSessionContractImplementor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Execute an SQL Query
 */
ScrollableResultsImplementor scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)
		throws HibernateException;
 
Example #23
Source File: SharedSessionContractImplementor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Execute an SQL Query
 */
List listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)
		throws HibernateException;
 
Example #24
Source File: NativeSQLQueryPlan.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
  * Constructs a NativeSQLQueryPlan.
  *
  * @param sourceQuery The original native query to create a plan for
  * @param customQuery The query executed via this plan
  */
public NativeSQLQueryPlan(String sourceQuery, CustomQuery customQuery) {
	this.sourceQuery = sourceQuery;
	this.customQuery = customQuery;
}
 
Example #25
Source File: NativeQueryInterpreter.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Creates a {@link CustomLoader} for the given {@link CustomQuery}.
 *
 * @param customQuery The CustomQuery to create a loader for
 * @param sessionFactory The current session factory
 *
 * @deprecated This method will be removed in 6.
 */
@Deprecated
default CustomLoader createCustomLoader(CustomQuery customQuery, SessionFactoryImplementor sessionFactory) {
	return new CustomLoader( customQuery, sessionFactory );
}