org.hibernate.query.internal.AbstractProducedQuery Java Examples

The following examples show how to use org.hibernate.query.internal.AbstractProducedQuery. 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: NamedQueryLoader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object load(Serializable id, Object optionalObject, SharedSessionContractImplementor session) {
	LOG.debugf( "Loading entity: %s using named query: %s", persister.getEntityName(), queryName );

	// IMPL NOTE: essentially we perform the named query (which loads the entity into the PC), and then
	// do an internal lookup of the entity from the PC.

	final AbstractProducedQuery query = (AbstractProducedQuery) session.getNamedQuery( queryName );
	if ( query.getParameterMetadata().hasNamedParameters() ) {
		query.setParameter( query.getNamedParameters()[0], id, persister.getIdentifierType() );
	}
	else {
		query.setParameter( position, id, persister.getIdentifierType() );
	}

	query.setOptionalId( id );
	query.setOptionalEntityName( persister.getEntityName() );
	query.setOptionalObject( optionalObject );
	query.setFlushMode( FlushMode.MANUAL );
	query.list();

	// now look up the object we are really interested in!
	// (this lets us correctly handle proxies and multi-row or multi-column queries)
	return session.getPersistenceContext().getEntity( session.generateEntityKey( id, persister ) );

}
 
Example #2
Source File: ReactiveQuery.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
static <T> T convertQueryException(T result, Throwable e,
								   AbstractProducedQuery<?> query) {
	if ( e instanceof QueryExecutionRequestException) {
		throw new IllegalStateException( e );
	}
	if ( e instanceof TypeMismatchException) {
		throw new IllegalStateException( e );
	}
	if ( e instanceof HibernateException) {
		throw query.getProducer().getExceptionConverter()
				.convert( (HibernateException) e, query.getLockOptions() );
	}
	return CompletionStages.returnOrRethrow( e, result );
}
 
Example #3
Source File: ReactiveQuery.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
static <R> R extractUniqueResult(List<R> list, AbstractProducedQuery<R> query) {
	try {
		if ( list.size() == 0 ) {
			throw new NoResultException( "No entity found for query" );
		}
		return AbstractProducedQuery.uniqueElement( list );
	}
	catch (HibernateException e) {
		throw query.getProducer().getExceptionConverter()
				.convert( e, query.getLockOptions() );
	}
}
 
Example #4
Source File: SQLExtractor.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
/**
 * Get the underlying SQL generated by the provided JPA query.
 *
 * @param query JPA query
 * @return the underlying SQL generated by the provided JPA query
 */
public static String from(Query query) {
    AbstractProducedQuery abstractProducedQuery = query.unwrap(AbstractProducedQuery.class);
    String[] sqls = abstractProducedQuery
        .getProducer()
        .getFactory()
        .getQueryPlanCache()
        .getHQLQueryPlan(abstractProducedQuery.getQueryString(), false, Collections.emptyMap())
        .getSqlStrings();

    return sqls.length > 0 ? sqls[0] : null;
}
 
Example #5
Source File: CriteriaImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Object uniqueResult() throws HibernateException {
	return AbstractProducedQuery.uniqueElement( list() );
}