HHH-9340 - Streams API for query result processing.

This commit is contained in:
Steve Ebersole 2016-05-13 08:38:06 -05:00
parent b990cf08ea
commit eb308a953a
17 changed files with 87 additions and 110 deletions

View File

@ -6,6 +6,7 @@
*/ */
package org.hibernate; package org.hibernate;
import org.hibernate.query.CommonQueryContract;
import org.hibernate.type.Type; import org.hibernate.type.Type;
/** /**
@ -13,7 +14,7 @@ import org.hibernate.type.Type;
* *
* @author Steve Ebersole * @author Steve Ebersole
* *
* @deprecated (since 5.2) use {@link org.hibernate.query.BasicQueryContract} instead. * @deprecated (since 5.2) use {@link CommonQueryContract} instead.
*/ */
@Deprecated @Deprecated
public interface BasicQueryContract { public interface BasicQueryContract {
@ -29,9 +30,9 @@ public interface BasicQueryContract {
* @deprecated (since 5.2) use {@link #setHibernateFlushMode} instead * @deprecated (since 5.2) use {@link #setHibernateFlushMode} instead
*/ */
@Deprecated @Deprecated
default org.hibernate.query.BasicQueryContract setFlushMode(FlushMode flushMode) { default CommonQueryContract setFlushMode(FlushMode flushMode) {
setHibernateFlushMode( flushMode ); setHibernateFlushMode( flushMode );
return (org.hibernate.query.BasicQueryContract) this; return (CommonQueryContract) this;
} }
/** /**
@ -54,7 +55,7 @@ public interface BasicQueryContract {
* *
* @see #getHibernateFlushMode() * @see #getHibernateFlushMode()
*/ */
org.hibernate.query.BasicQueryContract setHibernateFlushMode(FlushMode flushMode); CommonQueryContract setHibernateFlushMode(FlushMode flushMode);
/** /**
* Obtain the CacheMode in effect for this query. By default, the query inherits the CacheMode of the Session * Obtain the CacheMode in effect for this query. By default, the query inherits the CacheMode of the Session
@ -79,7 +80,7 @@ public interface BasicQueryContract {
* *
* @see #getCacheMode() * @see #getCacheMode()
*/ */
org.hibernate.query.BasicQueryContract setCacheMode(CacheMode cacheMode); CommonQueryContract setCacheMode(CacheMode cacheMode);
/** /**
* Are the results of this query eligible for second level query caching? This is different that second level * Are the results of this query eligible for second level query caching? This is different that second level
@ -104,7 +105,7 @@ public interface BasicQueryContract {
* *
* @see #isCacheable * @see #isCacheable
*/ */
org.hibernate.query.BasicQueryContract setCacheable(boolean cacheable); CommonQueryContract setCacheable(boolean cacheable);
/** /**
* Obtain the name of the second level query cache region in which query results will be stored (if they are * Obtain the name of the second level query cache region in which query results will be stored (if they are
@ -126,7 +127,7 @@ public interface BasicQueryContract {
* *
* @see #getCacheRegion() * @see #getCacheRegion()
*/ */
org.hibernate.query.BasicQueryContract setCacheRegion(String cacheRegion); CommonQueryContract setCacheRegion(String cacheRegion);
/** /**
* Obtain the query timeout <b>in seconds</b>. This value is eventually passed along to the JDBC query via * Obtain the query timeout <b>in seconds</b>. This value is eventually passed along to the JDBC query via
@ -151,7 +152,7 @@ public interface BasicQueryContract {
* *
* @see #getTimeout() * @see #getTimeout()
*/ */
org.hibernate.query.BasicQueryContract setTimeout(int timeout); CommonQueryContract setTimeout(int timeout);
/** /**
* Obtain the JDBC fetch size hint in effect for this query. This value is eventually passed along to the JDBC * Obtain the JDBC fetch size hint in effect for this query. This value is eventually passed along to the JDBC
@ -177,7 +178,7 @@ public interface BasicQueryContract {
* *
* @see #getFetchSize() * @see #getFetchSize()
*/ */
org.hibernate.query.BasicQueryContract setFetchSize(int fetchSize); CommonQueryContract setFetchSize(int fetchSize);
/** /**
* Should entities and proxies loaded by this Query be put in read-only mode? If the * Should entities and proxies loaded by this Query be put in read-only mode? If the
@ -223,7 +224,7 @@ public interface BasicQueryContract {
* are to be put in read-only mode; {@code false} indicates that entities and proxies * are to be put in read-only mode; {@code false} indicates that entities and proxies
* loaded by the query will be put in modifiable mode * loaded by the query will be put in modifiable mode
*/ */
org.hibernate.query.BasicQueryContract setReadOnly(boolean readOnly); CommonQueryContract setReadOnly(boolean readOnly);
/** /**
* Return the Hibernate types of the query results. * Return the Hibernate types of the query results.

View File

@ -18,7 +18,6 @@ import java.util.Set;
import org.hibernate.Filter; import org.hibernate.Filter;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.QueryException; import org.hibernate.QueryException;
import org.hibernate.ScrollableResults;
import org.hibernate.engine.spi.QueryParameters; import org.hibernate.engine.spi.QueryParameters;
import org.hibernate.engine.spi.RowSelection; import org.hibernate.engine.spi.RowSelection;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;

View File

@ -19,7 +19,6 @@ import org.hibernate.FlushMode;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Interceptor; import org.hibernate.Interceptor;
import org.hibernate.ScrollMode; import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.SharedSessionContract; import org.hibernate.SharedSessionContract;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.collection.spi.PersistentCollection;
@ -33,7 +32,6 @@ import org.hibernate.query.spi.QueryProducerImplementor;
import org.hibernate.query.spi.ScrollableResultsImplementor; import org.hibernate.query.spi.ScrollableResultsImplementor;
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner; import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
import org.hibernate.resource.transaction.spi.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder.Options; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder.Options;
import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.WrapperOptions;
@ -52,7 +50,7 @@ import org.hibernate.type.descriptor.WrapperOptions;
* {@link Options} * {@link Options}
* to drive the creation of the {@link TransactionCoordinator} delegate. * to drive the creation of the {@link TransactionCoordinator} delegate.
* This allows it to be passed along to * This allows it to be passed along to
* {@link TransactionCoordinatorBuilder#buildTransactionCoordinator} * {@link org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder#buildTransactionCoordinator}
* </li> * </li>
* <li> * <li>
* {@link org.hibernate.engine.jdbc.LobCreationContext} to act as the context for JDBC LOB instance creation * {@link org.hibernate.engine.jdbc.LobCreationContext} to act as the context for JDBC LOB instance creation

View File

@ -18,7 +18,6 @@ import java.util.Set;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.QueryException; import org.hibernate.QueryException;
import org.hibernate.ScrollableResults;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.query.spi.EntityGraphQueryHint; import org.hibernate.engine.query.spi.EntityGraphQueryHint;
import org.hibernate.engine.spi.QueryParameters; import org.hibernate.engine.spi.QueryParameters;

View File

@ -29,7 +29,6 @@ import org.hibernate.LockMode;
import org.hibernate.LockOptions; import org.hibernate.LockOptions;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.QueryException; import org.hibernate.QueryException;
import org.hibernate.ScrollableResults;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.internal.JoinSequence; import org.hibernate.engine.internal.JoinSequence;
import org.hibernate.engine.spi.QueryParameters; import org.hibernate.engine.spi.QueryParameters;

View File

@ -15,7 +15,6 @@ import java.util.Set;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.QueryException; import org.hibernate.QueryException;
import org.hibernate.ScrollableResults;
import org.hibernate.engine.spi.QueryParameters; import org.hibernate.engine.spi.QueryParameters;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.EventSource;

View File

@ -26,7 +26,6 @@ import org.hibernate.HibernateException;
import org.hibernate.Interceptor; import org.hibernate.Interceptor;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.MultiTenancyStrategy; import org.hibernate.MultiTenancyStrategy;
import org.hibernate.ScrollableResults;
import org.hibernate.SessionException; import org.hibernate.SessionException;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;

View File

@ -21,7 +21,6 @@ import org.hibernate.HibernateException;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.ScrollMode; import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.SessionException; import org.hibernate.SessionException;
import org.hibernate.StatelessSession; import org.hibernate.StatelessSession;
import org.hibernate.UnresolvableObjectException; import org.hibernate.UnresolvableObjectException;
@ -179,7 +178,7 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen
@Override @Override
public Object get(String entityName, Serializable id, LockMode lockMode) { public Object get(String entityName, Serializable id, LockMode lockMode) {
checkOpen(); checkOpen();
Object result = getFactory().getEntityPersister( entityName ) Object result = getFactory().getMetamodel().entityPersister( entityName )
.load( id, null, lockMode, this ); .load( id, null, lockMode, this );
if ( temporaryPersistenceContext.isLoadFinished() ) { if ( temporaryPersistenceContext.isLoadFinished() ) {
temporaryPersistenceContext.clear(); temporaryPersistenceContext.clear();
@ -254,7 +253,7 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen
String entityName, String entityName,
Serializable id) throws HibernateException { Serializable id) throws HibernateException {
checkOpen(); checkOpen();
return getFactory().getEntityPersister( entityName ).instantiate( id, this ); return getFactory().getMetamodel().entityPersister( entityName ).instantiate( id, this );
} }
@Override @Override
@ -264,7 +263,7 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen
boolean eager, boolean eager,
boolean nullable) throws HibernateException { boolean nullable) throws HibernateException {
checkOpen(); checkOpen();
EntityPersister persister = getFactory().getEntityPersister( entityName ); EntityPersister persister = getFactory().getMetamodel().entityPersister( entityName );
// first, try to load it from the temp PC associated to this SS // first, try to load it from the temp PC associated to this SS
Object loaded = temporaryPersistenceContext.getEntity( generateEntityKey( id, persister ) ); Object loaded = temporaryPersistenceContext.getEntity( generateEntityKey( id, persister ) );
if ( loaded != null ) { if ( loaded != null ) {

View File

@ -28,7 +28,6 @@ import org.hibernate.LockMode;
import org.hibernate.LockOptions; import org.hibernate.LockOptions;
import org.hibernate.QueryException; import org.hibernate.QueryException;
import org.hibernate.ScrollMode; import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.StaleObjectStateException; import org.hibernate.StaleObjectStateException;
import org.hibernate.WrongClassException; import org.hibernate.WrongClassException;
@ -385,7 +384,7 @@ public abstract class Loader {
); );
} }
catch (SQLException sqle) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getJdbcServices().getSqlExceptionHelper().convert(
sqle, sqle,
"could not read next row of results", "could not read next row of results",
getSQLString() getSQLString()
@ -445,7 +444,7 @@ public abstract class Loader {
isCurrentRowForSameEntity( keyToRead, 0, resultSet, session ) ); isCurrentRowForSameEntity( keyToRead, 0, resultSet, session ) );
} }
catch (SQLException sqle) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getJdbcServices().getSqlExceptionHelper().convert(
sqle, sqle,
"could not doAfterTransactionCompletion sequential read of results (forward)", "could not doAfterTransactionCompletion sequential read of results (forward)",
getSQLString() getSQLString()
@ -524,7 +523,7 @@ public abstract class Loader {
return sequentialLoad( resultSet, session, queryParameters, returnProxies, currentKey ); return sequentialLoad( resultSet, session, queryParameters, returnProxies, currentKey );
} }
catch (SQLException sqle) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getJdbcServices().getSqlExceptionHelper().convert(
sqle, sqle,
"could not perform sequential read of results (forward)", "could not perform sequential read of results (forward)",
getSQLString() getSQLString()
@ -651,7 +650,7 @@ public abstract class Loader {
return sequentialLoad( resultSet, session, queryParameters, returnProxies, keyToRead ); return sequentialLoad( resultSet, session, queryParameters, returnProxies, keyToRead );
} }
catch (SQLException sqle) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getJdbcServices().getSqlExceptionHelper().convert(
sqle, sqle,
"could not doAfterTransactionCompletion sequential read of results (forward)", "could not doAfterTransactionCompletion sequential read of results (forward)",
getSQLString() getSQLString()
@ -939,7 +938,7 @@ public abstract class Loader {
); );
} }
finally { finally {
session.getJdbcCoordinator().getResourceRegistry().release( st ); session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( st );
session.getJdbcCoordinator().afterStatementExecution(); session.getJdbcCoordinator().afterStatementExecution();
} }
@ -1978,15 +1977,10 @@ public abstract class Loader {
LOG.tracev( "Bound [{0}] parameters total", col ); LOG.tracev( "Bound [{0}] parameters total", col );
} }
} }
catch (SQLException sqle) { catch (SQLException | HibernateException e) {
session.getJdbcCoordinator().getResourceRegistry().release( st ); session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( st );
session.getJdbcCoordinator().afterStatementExecution(); session.getJdbcCoordinator().afterStatementExecution();
throw sqle; throw e;
}
catch (HibernateException he) {
session.getJdbcCoordinator().getResourceRegistry().release( st );
session.getJdbcCoordinator().afterStatementExecution();
throw he;
} }
return st; return st;
@ -2125,15 +2119,10 @@ public abstract class Loader {
} }
return rs; return rs;
} }
catch (SQLException sqle) { catch (SQLException | HibernateException e) {
session.getJdbcCoordinator().getResourceRegistry().release( st ); session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( st );
session.getJdbcCoordinator().afterStatementExecution(); session.getJdbcCoordinator().afterStatementExecution();
throw sqle; throw e;
}
catch (HibernateException he) {
session.getJdbcCoordinator().getResourceRegistry().release( st );
session.getJdbcCoordinator().afterStatementExecution();
throw he;
} }
} }
@ -2204,7 +2193,7 @@ public abstract class Loader {
} }
catch (SQLException sqle) { catch (SQLException sqle) {
final Loadable[] persisters = getEntityPersisters(); final Loadable[] persisters = getEntityPersisters();
throw factory.getSQLExceptionHelper().convert( throw factory.getJdbcServices().getSqlExceptionHelper().convert(
sqle, sqle,
"could not load an entity: " + "could not load an entity: " +
MessageHelper.infoString( MessageHelper.infoString(
@ -2249,7 +2238,7 @@ public abstract class Loader {
); );
} }
catch (SQLException sqle) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getJdbcServices().getSqlExceptionHelper().convert(
sqle, sqle,
"could not load collection element by index", "could not load collection element by index",
getSQLString() getSQLString()
@ -2292,7 +2281,7 @@ public abstract class Loader {
result = doQueryAndInitializeNonLazyCollections( session, qp, false ); result = doQueryAndInitializeNonLazyCollections( session, qp, false );
} }
catch (SQLException sqle) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getJdbcServices().getSqlExceptionHelper().convert(
sqle, sqle,
"could not load an entity batch: " + "could not load an entity batch: " +
MessageHelper.infoString( getEntityPersisters()[0], ids, getFactory() ), MessageHelper.infoString( getEntityPersisters()[0], ids, getFactory() ),
@ -2329,7 +2318,7 @@ public abstract class Loader {
); );
} }
catch (SQLException sqle) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getJdbcServices().getSqlExceptionHelper().convert(
sqle, sqle,
"could not initialize a collection: " + "could not initialize a collection: " +
MessageHelper.collectionInfoString( getCollectionPersisters()[0], id, getFactory() ), MessageHelper.collectionInfoString( getCollectionPersisters()[0], id, getFactory() ),
@ -2364,7 +2353,7 @@ public abstract class Loader {
); );
} }
catch (SQLException sqle) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getJdbcServices().getSqlExceptionHelper().convert(
sqle, sqle,
"could not initialize a collection batch: " + "could not initialize a collection batch: " +
MessageHelper.collectionInfoString( getCollectionPersisters()[0], ids, getFactory() ), MessageHelper.collectionInfoString( getCollectionPersisters()[0], ids, getFactory() ),
@ -2395,7 +2384,7 @@ public abstract class Loader {
); );
} }
catch (SQLException sqle) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getJdbcServices().getSqlExceptionHelper().convert(
sqle, sqle,
"could not load collection by subselect: " + "could not load collection by subselect: " +
MessageHelper.collectionInfoString( getCollectionPersisters()[0], ids, getFactory() ), MessageHelper.collectionInfoString( getCollectionPersisters()[0], ids, getFactory() ),
@ -2613,7 +2602,7 @@ public abstract class Loader {
result = doQueryAndInitializeNonLazyCollections( session, queryParameters, true, forcedResultTransformer ); result = doQueryAndInitializeNonLazyCollections( session, queryParameters, true, forcedResultTransformer );
} }
catch (SQLException sqle) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getJdbcServices().getSqlExceptionHelper().convert(
sqle, sqle,
"could not execute query", "could not execute query",
getSQLString() getSQLString()
@ -2730,7 +2719,7 @@ public abstract class Loader {
} }
catch (SQLException sqle) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getJdbcServices().getSqlExceptionHelper().convert(
sqle, sqle,
"could not execute query using scroll", "could not execute query using scroll",
getSQLString() getSQLString()

View File

@ -19,7 +19,6 @@ import org.hibernate.LockMode;
import org.hibernate.LockOptions; import org.hibernate.LockOptions;
import org.hibernate.QueryException; import org.hibernate.QueryException;
import org.hibernate.ScrollMode; import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.LoadQueryInfluencers; import org.hibernate.engine.spi.LoadQueryInfluencers;
@ -233,7 +232,7 @@ public class CriteriaLoader extends OuterJoinLoader {
locks.setScope( lockOptions.getScope() ); locks.setScope( lockOptions.getScope() );
locks.setTimeOut( lockOptions.getTimeOut() ); locks.setTimeOut( lockOptions.getTimeOut() );
final Map keyColumnNames = dialect.forUpdateOfColumns() ? new HashMap() : null; final Map<String,String[]> keyColumnNames = dialect.forUpdateOfColumns() ? new HashMap() : null;
final String[] drivingSqlAliases = getAliases(); final String[] drivingSqlAliases = getAliases();
for ( int i = 0; i < drivingSqlAliases.length; i++ ) { for ( int i = 0; i < drivingSqlAliases.length; i++ ) {
final LockMode lockMode = lockOptions.getAliasSpecificLockMode( drivingSqlAliases[i] ); final LockMode lockMode = lockOptions.getAliasSpecificLockMode( drivingSqlAliases[i] );

View File

@ -19,7 +19,6 @@ import org.hibernate.HibernateException;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.LockOptions; import org.hibernate.LockOptions;
import org.hibernate.QueryException; import org.hibernate.QueryException;
import org.hibernate.ScrollableResults;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.cache.spi.QueryCache; import org.hibernate.cache.spi.QueryCache;
import org.hibernate.cache.spi.QueryKey; import org.hibernate.cache.spi.QueryKey;
@ -44,7 +43,6 @@ import org.hibernate.type.CollectionType;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
/** /**
* Extension point for loaders which use a SQL result set with "unexpected" column aliases. * Extension point for loaders which use a SQL result set with "unexpected" column aliases.
* *
@ -56,7 +54,7 @@ public class CustomLoader extends Loader {
// Currently *not* cachable if autodiscover types is in effect (e.g. "select * ...") // Currently *not* cachable if autodiscover types is in effect (e.g. "select * ...")
private final String sql; private final String sql;
private final Set<Serializable> querySpaces = new HashSet<Serializable>(); private final Set<Serializable> querySpaces = new HashSet<>();
private final Map namedParameterBindPoints; private final Map namedParameterBindPoints;
private final Queryable[] entityPersisters; private final Queryable[] entityPersisters;
@ -89,24 +87,24 @@ public class CustomLoader extends Loader {
this.querySpaces.addAll( customQuery.getQuerySpaces() ); this.querySpaces.addAll( customQuery.getQuerySpaces() );
this.namedParameterBindPoints = customQuery.getNamedParameterBindPoints(); this.namedParameterBindPoints = customQuery.getNamedParameterBindPoints();
List<Queryable> entityPersisters = new ArrayList<Queryable>(); List<Queryable> entityPersisters = new ArrayList<>();
List<Integer> entityOwners = new ArrayList<Integer>(); List<Integer> entityOwners = new ArrayList<>();
List<EntityAliases> entityAliases = new ArrayList<EntityAliases>(); List<EntityAliases> entityAliases = new ArrayList<>();
List<QueryableCollection> collectionPersisters = new ArrayList<QueryableCollection>(); List<QueryableCollection> collectionPersisters = new ArrayList<>();
List<Integer> collectionOwners = new ArrayList<Integer>(); List<Integer> collectionOwners = new ArrayList<>();
List<CollectionAliases> collectionAliases = new ArrayList<CollectionAliases>(); List<CollectionAliases> collectionAliases = new ArrayList<>();
List<LockMode> lockModes = new ArrayList<LockMode>(); List<LockMode> lockModes = new ArrayList<>();
List<ResultColumnProcessor> resultColumnProcessors = new ArrayList<ResultColumnProcessor>(); List<ResultColumnProcessor> resultColumnProcessors = new ArrayList<>();
List<Return> nonScalarReturnList = new ArrayList<Return>(); List<Return> nonScalarReturnList = new ArrayList<>();
List<Type> resultTypes = new ArrayList<Type>(); List<Type> resultTypes = new ArrayList<>();
List<String> specifiedAliases = new ArrayList<String>(); List<String> specifiedAliases = new ArrayList<>();
int returnableCounter = 0; int returnableCounter = 0;
boolean hasScalars = false; boolean hasScalars = false;
List<Boolean> includeInResultRowList = new ArrayList<Boolean>(); List<Boolean> includeInResultRowList = new ArrayList<>();
for ( Return rtn : customQuery.getCustomQueryReturns() ) { for ( Return rtn : customQuery.getCustomQueryReturns() ) {
if ( rtn instanceof ScalarReturn ) { if ( rtn instanceof ScalarReturn ) {
@ -115,7 +113,7 @@ public class CustomLoader extends Loader {
specifiedAliases.add( scalarRtn.getColumnAlias() ); specifiedAliases.add( scalarRtn.getColumnAlias() );
resultColumnProcessors.add( resultColumnProcessors.add(
new ScalarResultColumnProcessor( new ScalarResultColumnProcessor(
StringHelper.unquote( scalarRtn.getColumnAlias(), factory.getDialect() ), StringHelper.unquote( scalarRtn.getColumnAlias(), factory.getJdbcServices().getDialect() ),
scalarRtn.getType() scalarRtn.getType()
) )
); );
@ -132,7 +130,7 @@ public class CustomLoader extends Loader {
int i = 0; int i = 0;
for ( ScalarReturn scalarReturn : constructorReturn.getScalars() ) { for ( ScalarReturn scalarReturn : constructorReturn.getScalars() ) {
scalarProcessors[i++] = new ScalarResultColumnProcessor( scalarProcessors[i++] = new ScalarResultColumnProcessor(
StringHelper.unquote( scalarReturn.getColumnAlias(), factory.getDialect() ), StringHelper.unquote( scalarReturn.getColumnAlias(), factory.getJdbcServices().getDialect() ),
scalarReturn.getType() scalarReturn.getType()
); );
} }
@ -143,7 +141,7 @@ public class CustomLoader extends Loader {
} }
else if ( rtn instanceof RootReturn ) { else if ( rtn instanceof RootReturn ) {
RootReturn rootRtn = (RootReturn) rtn; RootReturn rootRtn = (RootReturn) rtn;
Queryable persister = (Queryable) factory.getEntityPersister( rootRtn.getEntityName() ); Queryable persister = (Queryable) factory.getMetamodel().entityPersister( rootRtn.getEntityName() );
entityPersisters.add( persister ); entityPersisters.add( persister );
lockModes.add( ( rootRtn.getLockMode() ) ); lockModes.add( ( rootRtn.getLockMode() ) );
resultColumnProcessors.add( new NonScalarResultColumnProcessor( returnableCounter++ ) ); resultColumnProcessors.add( new NonScalarResultColumnProcessor( returnableCounter++ ) );
@ -158,7 +156,7 @@ public class CustomLoader extends Loader {
else if ( rtn instanceof CollectionReturn ) { else if ( rtn instanceof CollectionReturn ) {
CollectionReturn collRtn = (CollectionReturn) rtn; CollectionReturn collRtn = (CollectionReturn) rtn;
String role = collRtn.getOwnerEntityName() + "." + collRtn.getOwnerProperty(); String role = collRtn.getOwnerEntityName() + "." + collRtn.getOwnerProperty();
QueryableCollection persister = (QueryableCollection) factory.getCollectionPersister( role ); QueryableCollection persister = (QueryableCollection) factory.getMetamodel().collectionPersister( role );
collectionPersisters.add( persister ); collectionPersisters.add( persister );
lockModes.add( collRtn.getLockMode() ); lockModes.add( collRtn.getLockMode() );
resultColumnProcessors.add( new NonScalarResultColumnProcessor( returnableCounter++ ) ); resultColumnProcessors.add( new NonScalarResultColumnProcessor( returnableCounter++ ) );
@ -187,7 +185,7 @@ public class CustomLoader extends Loader {
Queryable ownerPersister = determineAppropriateOwnerPersister( ownerDescriptor ); Queryable ownerPersister = determineAppropriateOwnerPersister( ownerDescriptor );
EntityType fetchedType = (EntityType) ownerPersister.getPropertyType( fetchRtn.getOwnerProperty() ); EntityType fetchedType = (EntityType) ownerPersister.getPropertyType( fetchRtn.getOwnerProperty() );
String entityName = fetchedType.getAssociatedEntityName( getFactory() ); String entityName = fetchedType.getAssociatedEntityName( getFactory() );
Queryable persister = (Queryable) factory.getEntityPersister( entityName ); Queryable persister = (Queryable) factory.getMetamodel().entityPersister( entityName );
entityPersisters.add( persister ); entityPersisters.add( persister );
nonScalarReturnList.add( rtn ); nonScalarReturnList.add( rtn );
specifiedAliases.add( fetchRtn.getAlias() ); specifiedAliases.add( fetchRtn.getAlias() );
@ -203,7 +201,7 @@ public class CustomLoader extends Loader {
lockModes.add( fetchRtn.getLockMode() ); lockModes.add( fetchRtn.getLockMode() );
Queryable ownerPersister = determineAppropriateOwnerPersister( ownerDescriptor ); Queryable ownerPersister = determineAppropriateOwnerPersister( ownerDescriptor );
String role = ownerPersister.getEntityName() + '.' + fetchRtn.getOwnerProperty(); String role = ownerPersister.getEntityName() + '.' + fetchRtn.getOwnerProperty();
QueryableCollection persister = (QueryableCollection) factory.getCollectionPersister( role ); QueryableCollection persister = (QueryableCollection) factory.getMetamodel().collectionPersister( role );
collectionPersisters.add( persister ); collectionPersisters.add( persister );
nonScalarReturnList.add( rtn ); nonScalarReturnList.add( rtn );
specifiedAliases.add( fetchRtn.getAlias() ); specifiedAliases.add( fetchRtn.getAlias() );
@ -268,7 +266,7 @@ public class CustomLoader extends Loader {
else if ( ownerDescriptor instanceof CollectionReturn ) { else if ( ownerDescriptor instanceof CollectionReturn ) {
CollectionReturn collRtn = (CollectionReturn) ownerDescriptor; CollectionReturn collRtn = (CollectionReturn) ownerDescriptor;
String role = collRtn.getOwnerEntityName() + "." + collRtn.getOwnerProperty(); String role = collRtn.getOwnerEntityName() + "." + collRtn.getOwnerProperty();
CollectionPersister persister = getFactory().getCollectionPersister( role ); CollectionPersister persister = getFactory().getMetamodel().collectionPersister( role );
EntityType ownerType = (EntityType) persister.getElementType(); EntityType ownerType = (EntityType) persister.getElementType();
entityName = ownerType.getAssociatedEntityName( getFactory() ); entityName = ownerType.getAssociatedEntityName( getFactory() );
} }
@ -291,7 +289,7 @@ public class CustomLoader extends Loader {
throw new HibernateException( "Could not determine fetch owner : " + ownerDescriptor ); throw new HibernateException( "Could not determine fetch owner : " + ownerDescriptor );
} }
return (Queryable) getFactory().getEntityPersister( entityName ); return (Queryable) getFactory().getMetamodel().entityPersister( entityName );
} }
@Override @Override
@ -482,8 +480,8 @@ public class CustomLoader extends Loader {
JdbcResultMetadata metadata = new JdbcResultMetadata( getFactory(), rs ); JdbcResultMetadata metadata = new JdbcResultMetadata( getFactory(), rs );
rowProcessor.prepareForAutoDiscovery( metadata ); rowProcessor.prepareForAutoDiscovery( metadata );
List<String> aliases = new ArrayList<String>(); List<String> aliases = new ArrayList<>();
List<Type> types = new ArrayList<Type>(); List<Type> types = new ArrayList<>();
for ( ResultColumnProcessor resultProcessor : rowProcessor.getColumnProcessors() ) { for ( ResultColumnProcessor resultProcessor : rowProcessor.getColumnProcessors() ) {
resultProcessor.performDiscovery( metadata, types, aliases ); resultProcessor.performDiscovery( metadata, types, aliases );
} }
@ -527,9 +525,7 @@ public class CustomLoader extends Loader {
* *afterQuery* {@link #list(SharedSessionContractImplementor, QueryParameters)} has already been called. It's a bit of a * *afterQuery* {@link #list(SharedSessionContractImplementor, QueryParameters)} has already been called. It's a bit of a
* chicken-and-the-egg issue since {@link #autoDiscoverTypes(ResultSet)} needs the {@link ResultSet}. * chicken-and-the-egg issue since {@link #autoDiscoverTypes(ResultSet)} needs the {@link ResultSet}.
* <p/> * <p/>
* As a hacky workaround, override * As a hacky workaround, overriden here to provide the {@link #resultTypes}.
* {@link #putResultInQueryCache(SharedSessionContractImplementor, QueryParameters, Type[], QueryCache, QueryKey, List)} here
* and provide the {@link #resultTypes}.
* *
* see HHH-3051 * see HHH-3051
*/ */

View File

@ -21,7 +21,6 @@ import org.hibernate.HibernateException;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.LockOptions; import org.hibernate.LockOptions;
import org.hibernate.QueryException; import org.hibernate.QueryException;
import org.hibernate.ScrollableResults;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.QueryParameters; import org.hibernate.engine.spi.QueryParameters;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
@ -73,7 +72,7 @@ public class QueryLoader extends BasicLoader {
//private Type[] sqlResultTypes; //private Type[] sqlResultTypes;
private Type[] queryReturnTypes; private Type[] queryReturnTypes;
private final Map<String, String> sqlAliasByEntityAlias = new HashMap<String, String>( 8 ); private final Map<String, String> sqlAliasByEntityAlias = new HashMap<>( 8 );
private EntityType[] ownerAssociationTypes; private EntityType[] ownerAssociationTypes;
private int[] owners; private int[] owners;
@ -167,6 +166,7 @@ public class QueryLoader extends BasicLoader {
owners[i] = -1; //by default owners[i] = -1; //by default
if ( element.isFetch() ) { if ( element.isFetch() ) {
//noinspection StatementWithEmptyBody
if ( element.isCollectionJoin() || element.getQueryableCollection() != null ) { if ( element.isCollectionJoin() || element.getQueryableCollection() != null ) {
// This is now handled earlier in this method. // This is now handled earlier in this method.
} }

View File

@ -14,5 +14,5 @@ package org.hibernate.query;
* @author Steve Ebersole * @author Steve Ebersole
* @author Gavin King * @author Gavin King
*/ */
public interface BasicQueryContract extends org.hibernate.BasicQueryContract { public interface CommonQueryContract extends org.hibernate.BasicQueryContract {
} }

View File

@ -12,7 +12,6 @@ import java.time.OffsetDateTime;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Spliterator;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.persistence.FlushModeType; import javax.persistence.FlushModeType;
import javax.persistence.LockModeType; import javax.persistence.LockModeType;
@ -41,7 +40,7 @@ import org.hibernate.engine.spi.RowSelection;
*/ */
@Incubating @Incubating
@SuppressWarnings("UnusedDeclaration") @SuppressWarnings("UnusedDeclaration")
public interface Query<R> extends TypedQuery<R>, org.hibernate.Query<R>, BasicQueryContract { public interface Query<R> extends TypedQuery<R>, org.hibernate.Query<R>, CommonQueryContract {
/** /**
* Get the QueryProducer this Query originates from. * Get the QueryProducer this Query originates from.
*/ */

View File

@ -11,7 +11,6 @@ import java.util.List;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.ScrollMode; import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.query.Query; import org.hibernate.query.Query;
import org.hibernate.query.spi.ScrollableResultsImplementor; import org.hibernate.query.spi.ScrollableResultsImplementor;

View File

@ -26,7 +26,6 @@ import org.hibernate.LockOptions;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.QueryException; import org.hibernate.QueryException;
import org.hibernate.ScrollMode; import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.engine.ResultSetMappingDefinition; import org.hibernate.engine.ResultSetMappingDefinition;
import org.hibernate.engine.query.spi.sql.NativeSQLQueryConstructorReturn; import org.hibernate.engine.query.spi.sql.NativeSQLQueryConstructorReturn;
import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn; import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn;
@ -578,6 +577,7 @@ public class NativeQueryImpl<T> extends AbstractProducedQuery<T> implements Nati
} }
@Override @Override
@SuppressWarnings("unchecked")
public NativeQueryImplementor<T> setParameter(QueryParameter parameter, Object value, Type type) { public NativeQueryImplementor<T> setParameter(QueryParameter parameter, Object value, Type type) {
super.setParameter( parameter, value, type ); super.setParameter( parameter, value, type );
return this; return this;
@ -602,115 +602,117 @@ public class NativeQueryImpl<T> extends AbstractProducedQuery<T> implements Nati
} }
@Override @Override
public NativeQueryImplementor setParameter(String name, Object value, TemporalType temporalType) { public NativeQueryImplementor<T> setParameter(String name, Object value, TemporalType temporalType) {
super.setParameter( name, value, temporalType ); super.setParameter( name, value, temporalType );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setParameter(int position, Object value, TemporalType temporalType) { public NativeQueryImplementor<T> setParameter(int position, Object value, TemporalType temporalType) {
super.setParameter( position, value, temporalType ); super.setParameter( position, value, temporalType );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setParameterList(QueryParameter parameter, Collection values) { public NativeQueryImplementor<T> setParameterList(QueryParameter parameter, Collection values) {
super.setParameterList( parameter, values ); super.setParameterList( parameter, values );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setParameterList(String name, Collection values) { public NativeQueryImplementor<T> setParameterList(String name, Collection values) {
super.setParameterList( name, values ); super.setParameterList( name, values );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setParameterList(String name, Collection values, Type type) { public NativeQueryImplementor<T> setParameterList(String name, Collection values, Type type) {
super.setParameterList( name, values, type ); super.setParameterList( name, values, type );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setParameterList(String name, Object[] values, Type type) { public NativeQueryImplementor<T> setParameterList(String name, Object[] values, Type type) {
super.setParameterList( name, values, type ); super.setParameterList( name, values, type );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setParameterList(String name, Object[] values) { public NativeQueryImplementor<T> setParameterList(String name, Object[] values) {
super.setParameterList( name, values ); super.setParameterList( name, values );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setParameter(Parameter param, Calendar value, TemporalType temporalType) { @SuppressWarnings("unchecked")
public NativeQueryImplementor<T> setParameter(Parameter param, Calendar value, TemporalType temporalType) {
super.setParameter( param, value, temporalType ); super.setParameter( param, value, temporalType );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setParameter(Parameter param, Date value, TemporalType temporalType) { @SuppressWarnings("unchecked")
public NativeQueryImplementor<T> setParameter(Parameter param, Date value, TemporalType temporalType) {
super.setParameter( param, value, temporalType ); super.setParameter( param, value, temporalType );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setParameter(String name, Calendar value, TemporalType temporalType) { public NativeQueryImplementor<T> setParameter(String name, Calendar value, TemporalType temporalType) {
super.setParameter( name, value, temporalType ); super.setParameter( name, value, temporalType );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setParameter(String name, Date value, TemporalType temporalType) { public NativeQueryImplementor<T> setParameter(String name, Date value, TemporalType temporalType) {
super.setParameter( name, value, temporalType ); super.setParameter( name, value, temporalType );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setParameter(int position, Calendar value, TemporalType temporalType) { public NativeQueryImplementor<T> setParameter(int position, Calendar value, TemporalType temporalType) {
super.setParameter( position, value, temporalType ); super.setParameter( position, value, temporalType );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setParameter(int position, Date value, TemporalType temporalType) { public NativeQueryImplementor<T> setParameter(int position, Date value, TemporalType temporalType) {
super.setParameter( position, value, temporalType ); super.setParameter( position, value, temporalType );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setResultTransformer(ResultTransformer transformer) { public NativeQueryImplementor<T> setResultTransformer(ResultTransformer transformer) {
super.setResultTransformer( transformer ); super.setResultTransformer( transformer );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setProperties(Map map) { public NativeQueryImplementor<T> setProperties(Map map) {
super.setProperties( map ); super.setProperties( map );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setProperties(Object bean) { public NativeQueryImplementor<T> setProperties(Object bean) {
super.setProperties( bean ); super.setProperties( bean );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setMaxResults(int maxResult) { public NativeQueryImplementor<T> setMaxResults(int maxResult) {
super.setMaxResults( maxResult ); super.setMaxResults( maxResult );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setFirstResult(int startPosition) { public NativeQueryImplementor<T> setFirstResult(int startPosition) {
super.setFirstResult( startPosition ); super.setFirstResult( startPosition );
return this; return this;
} }
@Override @Override
public NativeQueryImplementor setHint(String hintName, Object value) { public NativeQueryImplementor<T> setHint(String hintName, Object value) {
super.setHint( hintName, value ); super.setHint( hintName, value );
return this; return this;
} }

View File

@ -16,10 +16,10 @@ import org.hibernate.query.spi.ScrollableResultsImplementor;
* @since 5.2 * @since 5.2
*/ */
@Incubating @Incubating
public class ScrollableResultsIterator<T> implements CloseableIterator { class ScrollableResultsIterator<T> implements CloseableIterator {
private final ScrollableResultsImplementor scrollableResults; private final ScrollableResultsImplementor scrollableResults;
public ScrollableResultsIterator(ScrollableResultsImplementor scrollableResults) { ScrollableResultsIterator(ScrollableResultsImplementor scrollableResults) {
this.scrollableResults = scrollableResults; this.scrollableResults = scrollableResults;
} }