Skip to content

Commit

Permalink
HHH-9340 - Streams API for query result processing.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed May 13, 2016
1 parent b990cf0 commit eb308a9
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 110 deletions.
21 changes: 11 additions & 10 deletions hibernate-core/src/main/java/org/hibernate/BasicQueryContract.java
Expand Up @@ -6,14 +6,15 @@
*/ */
package org.hibernate; package org.hibernate;


import org.hibernate.query.CommonQueryContract;
import org.hibernate.type.Type; import org.hibernate.type.Type;


/** /**
* Defines the aspects of query definition that apply to all forms of querying. * Defines the aspects of query definition that apply to all forms of querying.
* *
* @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 {
Expand All @@ -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;
} }


/** /**
Expand All @@ -54,7 +55,7 @@ default org.hibernate.query.BasicQueryContract setFlushMode(FlushMode flushMode)
* *
* @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
Expand All @@ -79,7 +80,7 @@ default org.hibernate.query.BasicQueryContract setFlushMode(FlushMode flushMode)
* *
* @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
Expand All @@ -104,7 +105,7 @@ default org.hibernate.query.BasicQueryContract setFlushMode(FlushMode flushMode)
* *
* @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
Expand All @@ -126,7 +127,7 @@ default org.hibernate.query.BasicQueryContract setFlushMode(FlushMode flushMode)
* *
* @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
Expand All @@ -151,7 +152,7 @@ default org.hibernate.query.BasicQueryContract setFlushMode(FlushMode flushMode)
* *
* @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
Expand All @@ -177,7 +178,7 @@ default org.hibernate.query.BasicQueryContract setFlushMode(FlushMode flushMode)
* *
* @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
Expand Down Expand Up @@ -223,7 +224,7 @@ default org.hibernate.query.BasicQueryContract setFlushMode(FlushMode flushMode)
* 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.
Expand Down
Expand Up @@ -18,7 +18,6 @@
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;
Expand Down
Expand Up @@ -19,7 +19,6 @@
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;
Expand All @@ -33,7 +32,6 @@
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;


Expand All @@ -52,7 +50,7 @@
* {@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
Expand Down
Expand Up @@ -18,7 +18,6 @@
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;
Expand Down
Expand Up @@ -29,7 +29,6 @@
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;
Expand Down
Expand Up @@ -15,7 +15,6 @@
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;
Expand Down
Expand Up @@ -26,7 +26,6 @@
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;
Expand Down
Expand Up @@ -21,7 +21,6 @@
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;
Expand Down Expand Up @@ -179,7 +178,7 @@ public Object get(String entityName, Serializable id) {
@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();
Expand Down Expand Up @@ -254,7 +253,7 @@ public Object instantiate(
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
Expand All @@ -264,7 +263,7 @@ public Object internalLoad(
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 ) {
Expand Down
49 changes: 19 additions & 30 deletions hibernate-core/src/main/java/org/hibernate/loader/Loader.java
Expand Up @@ -28,7 +28,6 @@
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;
Expand Down Expand Up @@ -385,7 +384,7 @@ public Object loadSingleRow(
); );
} }
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()
Expand Down Expand Up @@ -445,7 +444,7 @@ private Object sequentialLoad(
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()
Expand Down Expand Up @@ -524,7 +523,7 @@ public Object loadSequentialRowsForward(
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()
Expand Down Expand Up @@ -651,7 +650,7 @@ public Object loadSequentialRowsReverse(
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()
Expand Down Expand Up @@ -939,7 +938,7 @@ private List doQuery(
); );
} }
finally { finally {
session.getJdbcCoordinator().getResourceRegistry().release( st ); session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( st );
session.getJdbcCoordinator().afterStatementExecution(); session.getJdbcCoordinator().afterStatementExecution();
} }


Expand Down Expand Up @@ -1978,15 +1977,10 @@ else if ( dialect.isLockTimeoutParameterized() ) {
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();
throw sqle;
}
catch (HibernateException he) {
session.getJdbcCoordinator().getResourceRegistry().release( st );
session.getJdbcCoordinator().afterStatementExecution(); session.getJdbcCoordinator().afterStatementExecution();
throw he; throw e;
} }


return st; return st;
Expand Down Expand Up @@ -2125,15 +2119,10 @@ protected final ResultSet getResultSet(
} }
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();
throw sqle;
}
catch (HibernateException he) {
session.getJdbcCoordinator().getResourceRegistry().release( st );
session.getJdbcCoordinator().afterStatementExecution(); session.getJdbcCoordinator().afterStatementExecution();
throw he; throw e;
} }
} }


Expand Down Expand Up @@ -2204,7 +2193,7 @@ protected final List loadEntity(
} }
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(
Expand Down Expand Up @@ -2249,7 +2238,7 @@ protected final List loadEntity(
); );
} }
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()
Expand Down Expand Up @@ -2292,7 +2281,7 @@ public final List loadEntityBatch(
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() ),
Expand Down Expand Up @@ -2329,7 +2318,7 @@ public final void loadCollection(
); );
} }
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() ),
Expand Down Expand Up @@ -2364,7 +2353,7 @@ public final void loadCollectionBatch(
); );
} }
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() ),
Expand Down Expand Up @@ -2395,7 +2384,7 @@ protected final void loadCollectionSubselect(
); );
} }
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() ),
Expand Down Expand Up @@ -2613,7 +2602,7 @@ private List doList(
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()
Expand Down Expand Up @@ -2730,7 +2719,7 @@ protected ScrollableResultsImplementor scroll(


} }
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()
Expand Down
Expand Up @@ -19,7 +19,6 @@
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;
Expand Down Expand Up @@ -233,7 +232,7 @@ public void afterLoad(SharedSessionContractImplementor session, Object entity, L
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] );
Expand Down

0 comments on commit eb308a9

Please sign in to comment.