From b39d9d22bd57557111b80fda5245947012a32aed Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 10 Jul 2019 10:11:55 -0500 Subject: [PATCH] 6 - SQM based on JPA type system - focus on reducing compilation errors --- .../chapters/services/Services.adoc | 2 +- .../src/main/java/org/hibernate/Session.java | 2 +- .../hibernate/cache/spi/CacheImplementor.java | 2 +- .../org/hibernate/cfg/AvailableSettings.java | 24 +- .../hibernate/ejb/HibernateEntityManager.java | 2 +- .../engine/query/spi/FilterQueryPlan.java | 46 --- .../engine/spi/CacheImplementor.java | 266 ----------------- .../hibernate/engine/spi/QueryParameters.java | 10 - .../engine/spi/SessionDelegatorBaseImpl.java | 46 +-- .../engine/spi/SessionImplementor.java | 6 +- .../spi/SharedSessionContractImplementor.java | 11 - .../internal/AbstractScrollableResults.java | 276 +++--------------- .../FetchingScrollableResultsImpl.java | 154 +++++----- .../org/hibernate/internal/IteratorImpl.java | 159 ---------- .../internal/ScrollableResultsImpl.java | 87 +++--- .../org/hibernate/internal/SessionImpl.java | 98 +------ .../HibernateEntityManagerFactoryAware.java | 27 -- .../HibernateEntityManagerImplementor.java | 105 ------- .../java/org/hibernate/loader/Loader.java | 16 +- .../hibernate/loader/custom/CustomLoader.java | 16 +- .../model/domain/AllowableParameterType.java | 6 +- .../StandardCallableStatementSupport.java | 13 +- .../hibernate/query/spi/QueryPlanCache.java | 41 +++ .../sqm/tree/expression/SqmFieldLiteral.java | 4 + .../hibernate/sql/results/spi/RowReader.java | 49 ++++ .../cachemodes/SharedCacheModesTest.java | 2 +- ...EntityManagerFactorySerializationTest.java | 3 +- .../EntityManagerSerializationTest.java | 3 +- .../jpa/test/query/CachedQueryTest.java | 5 +- .../hibernate/test/cache/RegionNameTest.java | 32 -- .../test/jpa/EntityManagerUnwrapTest.java | 60 ++-- 31 files changed, 326 insertions(+), 1247 deletions(-) delete mode 100644 hibernate-core/src/main/java/org/hibernate/engine/query/spi/FilterQueryPlan.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/engine/spi/CacheImplementor.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/internal/IteratorImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/jpa/spi/HibernateEntityManagerFactoryAware.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/jpa/spi/HibernateEntityManagerImplementor.java create mode 100644 hibernate-core/src/main/java/org/hibernate/query/spi/QueryPlanCache.java create mode 100644 hibernate-core/src/main/java/org/hibernate/sql/results/spi/RowReader.java diff --git a/documentation/src/main/asciidoc/integrationguide/chapters/services/Services.adoc b/documentation/src/main/asciidoc/integrationguide/chapters/services/Services.adoc index a23200c173..b1728d366e 100644 --- a/documentation/src/main/asciidoc/integrationguide/chapters/services/Services.adoc +++ b/documentation/src/main/asciidoc/integrationguide/chapters/services/Services.adoc @@ -270,7 +270,7 @@ Exists as a `Service` mainly so that integrations such as OGM can override it. ===== `CacheImplementor` -`org.hibernate.engine.spi.CacheImplementor` provides a way to customize the way Hibernate interacts with the second-level caching implementation. +`org.hibernate.cache.spi.CacheImplementor` provides a way to customize the way Hibernate interacts with the second-level caching implementation. [[services-custom]] === Custom Services diff --git a/hibernate-core/src/main/java/org/hibernate/Session.java b/hibernate-core/src/main/java/org/hibernate/Session.java index 18c160d241..fd15b0eb5c 100644 --- a/hibernate-core/src/main/java/org/hibernate/Session.java +++ b/hibernate-core/src/main/java/org/hibernate/Session.java @@ -84,7 +84,7 @@ import org.hibernate.stat.SessionStatistics; * @author Gavin King * @author Steve Ebersole */ -public interface Session extends SharedSessionContract, EntityManager, HibernateEntityManager, AutoCloseable, Closeable { +public interface Session extends SharedSessionContract, EntityManager, AutoCloseable, Closeable { /** * Obtain a {@link Session} builder with the ability to grab certain information from this session. * diff --git a/hibernate-core/src/main/java/org/hibernate/cache/spi/CacheImplementor.java b/hibernate-core/src/main/java/org/hibernate/cache/spi/CacheImplementor.java index c77b13db7b..9c175b3d78 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/spi/CacheImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/spi/CacheImplementor.java @@ -30,7 +30,7 @@ import org.hibernate.service.Service; * @author Steve Ebersole */ @SuppressWarnings("unused") -public interface CacheImplementor extends Service, Cache, org.hibernate.engine.spi.CacheImplementor, Serializable { +public interface CacheImplementor extends Service, Cache, Serializable { @Override SessionFactoryImplementor getSessionFactory(); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java index a6aba7d1d7..78a1b01701 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java @@ -1259,28 +1259,10 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings { String QUERY_PLAN_CACHE_ENABLED = "hibernate.query.plan_cache_enabled"; /** - * The maximum number of strong references maintained by {@link QueryInterpretationCache}. Default is 128. - * @deprecated in favor of {@link #QUERY_PLAN_CACHE_PARAMETER_METADATA_MAX_SIZE} - */ - @Deprecated - String QUERY_PLAN_CACHE_MAX_STRONG_REFERENCES = "hibernate.query.plan_cache_max_strong_references"; - - /** - * The maximum number of soft references maintained by {@link QueryInterpretationCache}. Default is 2048. - * @deprecated in favor of {@link #QUERY_PLAN_CACHE_MAX_SIZE} - */ - @Deprecated - String QUERY_PLAN_CACHE_MAX_SOFT_REFERENCES = "hibernate.query.plan_cache_max_soft_references"; - - /** - * The maximum number of entries including: - * + * The maximum number of entries in the Hibernate "Query Plan Cache". The + * default size is 2048. * - * maintained by {@link QueryInterpretationCache}. Default is 2048. + * @see org.hibernate.query.spi.QueryPlanCache */ String QUERY_PLAN_CACHE_MAX_SIZE = "hibernate.query.plan_cache_max_size"; diff --git a/hibernate-core/src/main/java/org/hibernate/ejb/HibernateEntityManager.java b/hibernate-core/src/main/java/org/hibernate/ejb/HibernateEntityManager.java index ed6880a2b5..a54d6de9a6 100644 --- a/hibernate-core/src/main/java/org/hibernate/ejb/HibernateEntityManager.java +++ b/hibernate-core/src/main/java/org/hibernate/ejb/HibernateEntityManager.java @@ -10,5 +10,5 @@ package org.hibernate.ejb; * @deprecated Use {@link org.hibernate.jpa.HibernateEntityManager} instead */ @Deprecated -public interface HibernateEntityManager extends org.hibernate.jpa.HibernateEntityManager { +public interface HibernateEntityManager { } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/FilterQueryPlan.java b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/FilterQueryPlan.java deleted file mode 100644 index 57a1b31dfb..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/FilterQueryPlan.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.engine.query.spi; - -import java.io.Serializable; -import java.util.Map; - -import org.hibernate.engine.spi.SessionFactoryImplementor; - -/** - * Extends an HQLQueryPlan to maintain a reference to the collection-role name - * being filtered. - * - * @author Steve Ebersole - */ -public class FilterQueryPlan extends HQLQueryPlan implements Serializable { - - private final String collectionRole; - - /** - * Constructs a query plan for an HQL filter - * - * @param hql The HQL fragment - * @param collectionRole The collection role being filtered - * @param shallow Is the query shallow? - * @param enabledFilters All enabled filters from the Session - * @param factory The factory - */ - public FilterQueryPlan( - String hql, - String collectionRole, - boolean shallow, - Map enabledFilters, - SessionFactoryImplementor factory) { - super( hql, collectionRole, shallow, enabledFilters, factory, null ); - this.collectionRole = collectionRole; - } - - public String getCollectionRole() { - return collectionRole; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/CacheImplementor.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/CacheImplementor.java deleted file mode 100644 index 672c62e316..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/CacheImplementor.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.engine.spi; - -import java.io.Serializable; -import java.util.Locale; -import java.util.Set; - -import org.hibernate.Cache; -import org.hibernate.HibernateException; -import org.hibernate.cache.cfg.spi.DomainDataRegionConfig; -import org.hibernate.cache.spi.QueryCache; -import org.hibernate.cache.spi.QueryResultsCache; -import org.hibernate.cache.spi.Region; -import org.hibernate.cache.spi.RegionFactory; -import org.hibernate.cache.spi.TimestampsCache; -import org.hibernate.cache.spi.UpdateTimestampsCache; -import org.hibernate.cache.spi.access.CollectionDataAccess; -import org.hibernate.cache.spi.access.EntityDataAccess; -import org.hibernate.cache.spi.access.NaturalIdDataAccess; -import org.hibernate.metamodel.model.domain.NavigableRole; -import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.service.Service; - -/** - * SPI contract for Hibernate's second-level cache engine - * - * @since 4.1 - * - * @author Strong Liu - * @author Steve Ebersole - * - * @deprecated Moved to {@link org.hibernate.cache.spi.CacheImplementor} - */ -@Deprecated -@SuppressWarnings("unused") -public interface CacheImplementor extends Service, Cache, Serializable { - @Override - SessionFactoryImplementor getSessionFactory(); - - /** - * The underlying RegionFactory in use. - * - * @apiNote CacheImplementor acts partially as a wrapper for details - * of interacting with the configured RegionFactory. Care should - * be taken when accessing the RegionFactory directly. - */ - RegionFactory getRegionFactory(); - - /** - * An initialization phase allowing the caching provider to prime itself - * from the passed configs - * - * @since 5.3 - */ - void prime(Set cacheRegionConfigs); - - /** - * Get a cache Region by name - * - * @apiNote It is only valid to call this method after {@link #prime} has - * been performed - * - * @since 5.3 - */ - Region getRegion(String regionName); - - /** - * The unqualified name of all regions. Intended for use with {@link #getRegion} - * - * @since 5.3 - */ - Set getCacheRegionNames(); - - /** - * Find the cache data access strategy for Hibernate's timestamps cache. - * Will return {@code null} if Hibernate is not configured for query result caching - * - * @since 5.3 - */ - TimestampsCache getTimestampsCache(); - - /** - * Access to the "default" region used to store query results when caching - * was requested but no region was explicitly named. Will return {@code null} - * if Hibernate is not configured for query result caching - */ - QueryResultsCache getDefaultQueryResultsCache(); - - /** - * Get query cache by region name or create a new one if none exist. - * - * If the region name is null, then default query cache region will be returned. - * - * Will return {@code null} if Hibernate is not configured for query result caching - */ - QueryResultsCache getQueryResultsCache(String regionName); - - /** - * Get the named QueryResultRegionAccess but not creating one if it - * does not already exist. This is intended for use by statistics. - * - * Will return {@code null} if Hibernate is not configured for query result - * caching or if no such region (yet) exists - * - * @since 5.3 - */ - QueryResultsCache getQueryResultsCacheStrictly(String regionName); - - /** - * Clean up the default query cache - */ - default void evictQueries() throws HibernateException { - QueryResultsCache cache = getDefaultQueryResultsCache(); - if ( cache != null ) { - cache.clear(); - } - } - - /** - * Close this "cache", releasing all underlying resources. - */ - void close(); - - - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // Deprecations (5.3) - - /** - * Get the *qualified* names of all regions caching entity and collection data. - * - * @return All cache region names - * - * @deprecated (since 5.3) Use {@link CacheImplementor#getCacheRegionNames()} instead - */ - @Deprecated - String[] getSecondLevelCacheRegionNames(); - - /** - * Find the cache data access strategy for an entity. Will - * return {@code null} when the entity is not configured for caching. - * - * @param rootEntityName The NavigableRole representation of the root entity - * - * @apiNote It is only valid to call this method after {@link #prime} has - * been performed - * - * @deprecated Use {@link EntityPersister#getCacheAccessStrategy()} instead - */ - @Deprecated - EntityDataAccess getEntityRegionAccess(NavigableRole rootEntityName); - - /** - * Find the cache data access strategy for the given entity's natural-id cache. - * Will return {@code null} when the entity does not define a natural-id, or its - * natural-id is not configured for caching. - * - * @param rootEntityName The NavigableRole representation of the root entity - * - * @apiNote It is only valid to call this method after {@link #prime} has - * been performed - * - * @deprecated Use {@link EntityPersister#getNaturalIdCacheAccessStrategy()} ()} instead - */ - @Deprecated - NaturalIdDataAccess getNaturalIdCacheRegionAccessStrategy(NavigableRole rootEntityName); - - /** - * Find the cache data access strategy for the given collection. Will - * return {@code null} when the collection is not configured for caching. - * - * @apiNote It is only valid to call this method after {@link #prime} has - * been performed - * - * @deprecated Use {@link EntityPersister#getNaturalIdCacheAccessStrategy()} ()} instead - */ - @Deprecated - CollectionDataAccess getCollectionRegionAccess(NavigableRole collectionRole); - - - /** - * Get {@code UpdateTimestampsCache} instance managed by the {@code SessionFactory}. - * - * @deprecated Use {@link #getTimestampsCache} instead - */ - @Deprecated - default UpdateTimestampsCache getUpdateTimestampsCache() { - return getTimestampsCache(); - } - - /** - * Get the default {@code QueryCache}. - * - * @deprecated Use {@link #getDefaultQueryResultsCache} instead. - */ - @Deprecated - default QueryCache getQueryCache() { - return getDefaultQueryResultsCache(); - } - - /** - * Get the default {@code QueryCache}. - * - * @deprecated Use {@link #getDefaultQueryResultsCache} instead. - */ - @Deprecated - default QueryCache getDefaultQueryCache() { - return getDefaultQueryResultsCache(); - } - - /** - * @deprecated Use {@link #getQueryResultsCache(String)} instead, but using unqualified name - */ - @Deprecated - default QueryCache getQueryCache(String regionName) throws HibernateException { - return getQueryResultsCache( unqualifyRegionName( regionName ) ); - } - - - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // Some new (default) support methods for the above deprecations - // - themselves deprecated - - /** - * @deprecated (since 5.3) No replacement - added just to continue some backwards compatibility - * in supporting the newly deprecated methods expecting a qualified (prefix +) region name - */ - @Deprecated - default String unqualifyRegionName(String name) { - if ( getSessionFactory().getSessionFactoryOptions().getCacheRegionPrefix() == null ) { - return name; - } - - if ( !name.startsWith( getSessionFactory().getSessionFactoryOptions().getCacheRegionPrefix() ) ) { - throw new IllegalArgumentException( - String.format( - Locale.ROOT, - "Legacy methods for accessing cache information expect a qualified (prefix) region name - " + - "but passed name [%s] was not qualified by the configured prefix [%s]", - name, - getSessionFactory().getSessionFactoryOptions().getCacheRegionPrefix() - ) - ); - } - - return name.substring( getSessionFactory().getSessionFactoryOptions().getCacheRegionPrefix().length() + 1 ); - } - - /** - * @deprecated No replacement - added just for support of the newly deprecated methods expecting a qualified region name - */ - @Deprecated - default Region getRegionByLegacyName(String legacyName) { - return getRegion( unqualifyRegionName( legacyName ) ); - } - - /** - * @deprecated No replacement - added just for support of the newly deprecated methods expecting a qualified region name - */ - @Deprecated - Set getNaturalIdAccessesInRegion(String legacyQualifiedRegionName); -} diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/QueryParameters.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/QueryParameters.java index 8366c86145..f619547c04 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/QueryParameters.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/QueryParameters.java @@ -59,8 +59,6 @@ public final class QueryParameters { private Type[] processedPositionalParameterTypes; private Object[] processedPositionalParameterValues; - private HQLQueryPlan queryPlan; - public QueryParameters() { this( ArrayHelper.EMPTY_TYPE_ARRAY, ArrayHelper.EMPTY_OBJECT_ARRAY ); } @@ -644,14 +642,6 @@ public final class QueryParameters { return copy; } - public HQLQueryPlan getQueryPlan() { - return queryPlan; - } - - public void setQueryPlan(HQLQueryPlan queryPlan) { - this.queryPlan = queryPlan; - } - public void bindDynamicParameter(Type paramType, Object paramValue) { if(processedPositionalParameterTypes != null) { int length = processedPositionalParameterTypes.length; diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java index 7570b0382f..a78e397a1f 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java @@ -79,27 +79,8 @@ public class SessionDelegatorBaseImpl implements SessionImplementor { protected final SessionImplementor delegate; - /** - * @deprecated (since 5.3) SessionDelegatorBaseImpl should take just one argument, the SessionImplementor. - * Use the {@link #SessionDelegatorBaseImpl(SessionImplementor)} form instead - */ - @Deprecated - public SessionDelegatorBaseImpl(SessionImplementor delegate, Session session) { - if ( delegate == null ) { - throw new IllegalArgumentException( "Unable to create a SessionDelegatorBaseImpl from a null delegate object" ); - } - if ( session == null ) { - throw new IllegalArgumentException( "Unable to create a SessionDelegatorBaseImpl from a null Session" ); - } - if ( delegate != session ) { - throw new IllegalArgumentException( "Unable to create a SessionDelegatorBaseImpl from different Session/SessionImplementor references" ); - } - - this.delegate = delegate; - } - public SessionDelegatorBaseImpl(SessionImplementor delegate) { - this( delegate, delegate ); + this.delegate = delegate; } /** @@ -157,16 +138,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor { delegate.checkTransactionNeededForUpdateOperation( exceptionMessage ); } - @Override - public LockOptions getLockRequest(LockModeType lockModeType, Map properties) { - return delegate.getLockRequest( lockModeType, properties ); - } - - @Override - public LockOptions buildLockOptions(LockModeType lockModeType, Map properties) { - return delegate.buildLockOptions( lockModeType, properties ); - } - @Override public void initializeCollection(PersistentCollection collection, boolean writing) throws HibernateException { delegate.initializeCollection( collection, writing ); @@ -252,16 +223,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor { return delegate.getPersistenceContext(); } - @Override - public int executeUpdate(String query, QueryParameters queryParameters) throws HibernateException { - return delegate.executeUpdate( query, queryParameters ); - } - - @Override - public int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters) throws HibernateException { - return delegate.executeNativeUpdate( specification, queryParameters ); - } - @Override public CacheMode getCacheMode() { return delegate.getCacheMode(); @@ -621,11 +582,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor { return this; } - @Override - public NativeQueryImplementor createSQLQuery(String queryString) { - return delegate.createSQLQuery( queryString ); - } - @Override public ProcedureCall getNamedProcedureCall(String name) { return delegate.getNamedProcedureCall( name ); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionImplementor.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionImplementor.java index e9068a706f..596aaef214 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionImplementor.java @@ -12,13 +12,10 @@ import java.util.Set; import javax.persistence.criteria.CriteriaDelete; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaUpdate; -import javax.persistence.criteria.Selection; import org.hibernate.HibernateException; import org.hibernate.Session; -import org.hibernate.graph.RootGraph; import org.hibernate.graph.spi.RootGraphImplementor; -import org.hibernate.jpa.spi.HibernateEntityManagerImplementor; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.query.spi.QueryImplementor; import org.hibernate.query.sql.spi.NativeQueryImplementor; @@ -54,8 +51,7 @@ import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; * @author Gavin King * @author Steve Ebersole */ -public interface SessionImplementor - extends Session, SharedSessionContractImplementor, HibernateEntityManagerImplementor { +public interface SessionImplementor extends Session, SharedSessionContractImplementor { @Override default SessionImplementor getSession() { diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java index 5a7f05df8a..98e5079ffd 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java @@ -353,17 +353,6 @@ public interface SharedSessionContractImplementor int getDontFlushFromFind(); - /** - * Execute a HQL update or delete query - */ - int executeUpdate(String query, QueryParameters queryParameters) throws HibernateException; - - /** - * Execute a native SQL update or delete query - */ - int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters) - throws HibernateException; - boolean isDefaultReadOnly(); CacheMode getCacheMode(); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractScrollableResults.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractScrollableResults.java index cb3c0072cf..e311720515 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractScrollableResults.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractScrollableResults.java @@ -6,33 +6,23 @@ */ package org.hibernate.internal; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.sql.Blob; -import java.sql.Clob; import java.sql.PreparedStatement; import java.sql.ResultSet; -import java.util.Calendar; -import java.util.Date; -import java.util.Locale; -import java.util.TimeZone; import org.hibernate.HibernateException; import org.hibernate.engine.jdbc.spi.JdbcCoordinator; import org.hibernate.engine.spi.QueryParameters; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.hql.internal.HolderInstantiator; import org.hibernate.loader.Loader; import org.hibernate.query.spi.ScrollableResultsImplementor; -import org.hibernate.type.StandardBasicTypes; -import org.hibernate.type.Type; +import org.hibernate.sql.results.spi.RowReader; /** * Base implementation of the ScrollableResults interface. * * @author Steve Ebersole */ -public abstract class AbstractScrollableResults implements ScrollableResultsImplementor { +public abstract class AbstractScrollableResults implements ScrollableResultsImplementor { private static final CoreMessageLogger LOG = CoreLogging.messageLogger( AbstractScrollableResults.class ); private final ResultSet resultSet; @@ -40,30 +30,31 @@ public abstract class AbstractScrollableResults implements ScrollableResultsImpl private final SharedSessionContractImplementor session; private final Loader loader; private final QueryParameters queryParameters; - private final Type[] types; - private HolderInstantiator holderInstantiator; + + private final RowReader rowReader; + private boolean closed; + @SuppressWarnings("WeakerAccess") protected AbstractScrollableResults( ResultSet rs, PreparedStatement ps, SharedSessionContractImplementor sess, Loader loader, QueryParameters queryParameters, - Type[] types, - HolderInstantiator holderInstantiator) { + RowReader rowReader) { this.resultSet = rs; this.ps = ps; this.session = sess; this.loader = loader; this.queryParameters = queryParameters; - this.types = types; - this.holderInstantiator = holderInstantiator != null && holderInstantiator.isRequired() - ? holderInstantiator - : null; + this.rowReader = rowReader; } - protected abstract Object[] getCurrentRow(); + protected abstract R getCurrentRow(); + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Access to state fr sub-types protected ResultSet getResultSet() { return resultSet; @@ -85,12 +76,25 @@ public abstract class AbstractScrollableResults implements ScrollableResultsImpl return queryParameters; } - protected Type[] getTypes() { - return types; + protected RowReader getRowReader() { + return rowReader; } - protected HolderInstantiator getHolderInstantiator() { - return holderInstantiator; + @Override + public final R get() throws HibernateException { + if ( closed ) { + throw new IllegalStateException( "ScrollableResults is closed" ); + } + return getCurrentRow(); + } + + protected void afterScrollOperation() { + session.afterScrollOperation(); + } + + @Override + public boolean isClosed() { + return this.closed; } @Override @@ -100,213 +104,23 @@ public abstract class AbstractScrollableResults implements ScrollableResultsImpl return; } - // not absolutely necessary, but does help with aggressive release - //session.getJDBCContext().getConnectionManager().closeQueryStatement( ps, resultSet ); - final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator(); - jdbcCoordinator.getResourceRegistry().release( ps ); - jdbcCoordinator.afterStatementExecution(); - try { - session.getPersistenceContextInternal().getLoadContexts().cleanup( resultSet ); - } - catch (Throwable ignore) { - // ignore this error for now - if ( LOG.isTraceEnabled() ) { - LOG.tracev( "Exception trying to cleanup load context : {0}", ignore.getMessage() ); - } - } +// getJdbcValues().finishUp(); +// getPersistenceContext().getJdbcCoordinator().afterStatementExecution(); + +// // not absolutely necessary, but does help with aggressive release +// //session.getJDBCContext().getConnectionManager().closeQueryStatement( ps, resultSet ); +// session.getJdbcCoordinator().getResourceRegistry().release( ps ); +// session.getJdbcCoordinator().afterStatementExecution(); +// try { +// session.getPersistenceContext().getLoadContexts().cleanup( resultSet ); +// } +// catch (Throwable ignore) { +// // ignore this error for now +// if ( LOG.isTraceEnabled() ) { +// LOG.tracev( "Exception trying to cleanup load context : {0}", ignore.getMessage() ); +// } +// } this.closed = true; } - - @Override - public boolean isClosed() { - return this.closed; - } - - @Override - public int getNumberOfTypes() { - return this.types.length; - } - - @Override - public final Object[] get() throws HibernateException { - if ( closed ) { - throw new IllegalStateException( "ScrollableResults is closed" ); - } - return getCurrentRow(); - } - - @Override - public final Object get(int col) throws HibernateException { - if ( closed ) { - throw new IllegalStateException( "ScrollableResults is closed" ); - } - return getCurrentRow()[col]; - } - - /** - * Check that the requested type is compatible with the result type, and - * return the column value. This version makes sure the the classes - * are identical. - * - * @param col the column - * @param returnType a "final" type - */ - protected final Object getFinal(int col, Type returnType) throws HibernateException { - if ( closed ) { - throw new IllegalStateException( "ScrollableResults is closed" ); - } - - if ( holderInstantiator != null ) { - throw new HibernateException( "query specifies a holder class" ); - } - - if ( returnType.getReturnedClass() == types[col].getReturnedClass() ) { - return get( col ); - } - else { - return throwInvalidColumnTypeException( col, types[col], returnType ); - } - } - - /** - * Check that the requested type is compatible with the result type, and - * return the column value. This version makes sure the the classes - * are "assignable". - * - * @param col the column - * @param returnType any type - */ - protected final Object getNonFinal(int col, Type returnType) throws HibernateException { - if ( closed ) { - throw new IllegalStateException( "ScrollableResults is closed" ); - } - - if ( holderInstantiator != null ) { - throw new HibernateException( "query specifies a holder class" ); - } - - if ( returnType.getReturnedClass().isAssignableFrom( types[col].getReturnedClass() ) ) { - return get( col ); - } - else { - return throwInvalidColumnTypeException( col, types[col], returnType ); - } - } - - @Override - public final BigDecimal getBigDecimal(int col) throws HibernateException { - return (BigDecimal) getFinal( col, StandardBasicTypes.BIG_DECIMAL ); - } - - @Override - public final BigInteger getBigInteger(int col) throws HibernateException { - return (BigInteger) getFinal( col, StandardBasicTypes.BIG_INTEGER ); - } - - @Override - public final byte[] getBinary(int col) throws HibernateException { - return (byte[]) getFinal( col, StandardBasicTypes.BINARY ); - } - - @Override - public final String getText(int col) throws HibernateException { - return (String) getFinal( col, StandardBasicTypes.TEXT ); - } - - @Override - public final Blob getBlob(int col) throws HibernateException { - return (Blob) getNonFinal( col, StandardBasicTypes.BLOB ); - } - - @Override - public final Clob getClob(int col) throws HibernateException { - return (Clob) getNonFinal( col, StandardBasicTypes.CLOB ); - } - - @Override - public final Boolean getBoolean(int col) throws HibernateException { - return (Boolean) getFinal( col, StandardBasicTypes.BOOLEAN ); - } - - @Override - public final Byte getByte(int col) throws HibernateException { - return (Byte) getFinal( col, StandardBasicTypes.BYTE ); - } - - @Override - public final Character getCharacter(int col) throws HibernateException { - return (Character) getFinal( col, StandardBasicTypes.CHARACTER ); - } - - @Override - public final Date getDate(int col) throws HibernateException { - return (Date) getNonFinal( col, StandardBasicTypes.TIMESTAMP ); - } - - @Override - public final Calendar getCalendar(int col) throws HibernateException { - return (Calendar) getNonFinal( col, StandardBasicTypes.CALENDAR ); - } - - @Override - public final Double getDouble(int col) throws HibernateException { - return (Double) getFinal( col, StandardBasicTypes.DOUBLE ); - } - - @Override - public final Float getFloat(int col) throws HibernateException { - return (Float) getFinal( col, StandardBasicTypes.FLOAT ); - } - - @Override - public final Integer getInteger(int col) throws HibernateException { - return (Integer) getFinal( col, StandardBasicTypes.INTEGER ); - } - - @Override - public final Long getLong(int col) throws HibernateException { - return (Long) getFinal( col, StandardBasicTypes.LONG ); - } - - @Override - public final Short getShort(int col) throws HibernateException { - return (Short) getFinal( col, StandardBasicTypes.SHORT ); - } - - @Override - public final String getString(int col) throws HibernateException { - return (String) getFinal( col, StandardBasicTypes.STRING ); - } - - @Override - public final Locale getLocale(int col) throws HibernateException { - return (Locale) getFinal( col, StandardBasicTypes.LOCALE ); - } - - @Override - public final TimeZone getTimeZone(int col) throws HibernateException { - return (TimeZone) getNonFinal( col, StandardBasicTypes.TIMEZONE ); - } - - @Override - public final Type getType(int i) { - return types[i]; - } - - private Object throwInvalidColumnTypeException( - int i, - Type type, - Type returnType) throws HibernateException { - throw new HibernateException( - "incompatible column types: " + - type.getName() + - ", " + - returnType.getName() - ); - } - - protected void afterScrollOperation() { - session.afterScrollOperation(); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/FetchingScrollableResultsImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/FetchingScrollableResultsImpl.java index 182b80e854..7bb80bf74d 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/FetchingScrollableResultsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/FetchingScrollableResultsImpl.java @@ -11,119 +11,111 @@ import java.sql.ResultSet; import java.sql.SQLException; import org.hibernate.HibernateException; +import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.engine.spi.QueryParameters; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.hql.internal.HolderInstantiator; import org.hibernate.loader.Loader; -import org.hibernate.type.Type; +import org.hibernate.sql.results.spi.RowReader; /** * Implementation of ScrollableResults which can handle collection fetches. * * @author Steve Ebersole */ -public class FetchingScrollableResultsImpl extends AbstractScrollableResults { - private Object[] currentRow; +public class FetchingScrollableResultsImpl extends AbstractScrollableResults { + private R currentRow; private int currentPosition; private Integer maxPosition; - /** - * Constructs a FetchingScrollableResultsImpl. - * - * @param rs The scrollable result set - * @param ps The prepared statement used to obtain the result set - * @param sess The originating session - * @param loader The loader - * @param queryParameters query parameters - * @param types The result types - * @param holderInstantiator Ugh - */ public FetchingScrollableResultsImpl( ResultSet rs, PreparedStatement ps, SharedSessionContractImplementor sess, Loader loader, QueryParameters queryParameters, - Type[] types, - HolderInstantiator holderInstantiator) { - super( rs, ps, sess, loader, queryParameters, types, holderInstantiator ); + RowReader rowReader) { + super( rs, ps, sess, loader, queryParameters, rowReader ); } @Override - protected Object[] getCurrentRow() { + protected R getCurrentRow() { return currentRow; } @Override public boolean next() { - if ( maxPosition != null && maxPosition <= currentPosition ) { - currentRow = null; - currentPosition = maxPosition + 1; - return false; - } + throw new NotYetImplementedFor6Exception( getClass() ); - if ( isResultSetEmpty() ) { - currentRow = null; - currentPosition = 0; - return false; - } - - final Object row = getLoader().loadSequentialRowsForward( - getResultSet(), - getSession(), - getQueryParameters(), - true - ); - - - final boolean afterLast; - try { - afterLast = getResultSet().isAfterLast(); - } - catch (SQLException e) { - throw getSession().getFactory().getSQLExceptionHelper().convert( - e, - "exception calling isAfterLast()" - ); - } - - currentPosition++; - currentRow = new Object[] {row}; - - if ( afterLast ) { - if ( maxPosition == null ) { - // we just hit the last position - maxPosition = currentPosition; - } - } - - afterScrollOperation(); - - return true; +// if ( maxPosition != null && maxPosition <= currentPosition ) { +// currentRow = null; +// currentPosition = maxPosition + 1; +// return false; +// } +// +// if ( isResultSetEmpty() ) { +// currentRow = null; +// currentPosition = 0; +// return false; +// } +// +// final Object row = getLoader().loadSequentialRowsForward( +// getResultSet(), +// getSession(), +// getQueryParameters(), +// true +// ); +// +// +// final boolean afterLast; +// try { +// afterLast = getResultSet().isAfterLast(); +// } +// catch (SQLException e) { +// throw getSession().getFactory().getSQLExceptionHelper().convert( +// e, +// "exception calling isAfterLast()" +// ); +// } +// +// currentPosition++; +// currentRow = new Object[] {row}; +// +// if ( afterLast ) { +// if ( maxPosition == null ) { +// // we just hit the last position +// maxPosition = currentPosition; +// } +// } +// +// afterScrollOperation(); +// +// return true; } @Override public boolean previous() { - if ( currentPosition <= 1 ) { - currentPosition = 0; - currentRow = null; - return false; - } + throw new NotYetImplementedFor6Exception( getClass() ); - final Object loadResult = getLoader().loadSequentialRowsReverse( - getResultSet(), - getSession(), - getQueryParameters(), - false, - ( maxPosition != null && currentPosition > maxPosition ) - ); - - currentRow = new Object[] {loadResult}; - currentPosition--; - - afterScrollOperation(); - - return true; +// if ( currentPosition <= 1 ) { +// currentPosition = 0; +// currentRow = null; +// return false; +// } +// +// final Object loadResult = getLoader().loadSequentialRowsReverse( +// getResultSet(), +// getSession(), +// getQueryParameters(), +// false, +// ( maxPosition != null && currentPosition > maxPosition ) +// ); +// +// currentRow = new Object[] {loadResult}; +// currentPosition--; +// +// afterScrollOperation(); +// +// return true; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/internal/IteratorImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/IteratorImpl.java deleted file mode 100644 index 5e62e4a30c..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/IteratorImpl.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.internal; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.NoSuchElementException; - -import org.hibernate.HibernateException; -import org.hibernate.JDBCException; -import org.hibernate.engine.HibernateIterator; -import org.hibernate.engine.jdbc.spi.JdbcCoordinator; -import org.hibernate.event.spi.EventSource; -import org.hibernate.hql.internal.HolderInstantiator; -import org.hibernate.type.EntityType; -import org.hibernate.type.Type; - -/** - * An implementation of java.util.Iterator that is - * returned by iterate() query execution methods. - * - * @author Gavin King - */ -public final class IteratorImpl implements HibernateIterator { - private static final CoreMessageLogger LOG = CoreLogging.messageLogger( IteratorImpl.class ); - - private ResultSet rs; - private final EventSource session; - private boolean readOnly; - private final Type[] types; - private final boolean single; - private Object currentResult; - private boolean hasNext; - private final String[][] names; - private PreparedStatement ps; - private HolderInstantiator holderInstantiator; - - public IteratorImpl( - ResultSet rs, - PreparedStatement ps, - EventSource sess, - boolean readOnly, - Type[] types, - String[][] columnNames, - HolderInstantiator holderInstantiator) throws HibernateException, SQLException { - this.rs = rs; - this.ps = ps; - this.session = sess; - this.readOnly = readOnly; - this.types = types; - this.names = columnNames; - this.holderInstantiator = holderInstantiator; - - single = types.length == 1; - - postNext(); - } - - public void close() throws JDBCException { - if ( ps != null ) { - LOG.debug( "Closing iterator" ); - final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator(); - jdbcCoordinator.getResourceRegistry().release( ps ); - try { - session.getPersistenceContext().getLoadContexts().cleanup( rs ); - } - catch (Throwable ignore) { - // ignore this error for now - LOG.debugf( "Exception trying to cleanup load context : %s", ignore.getMessage() ); - } - jdbcCoordinator.afterStatementExecution(); - ps = null; - rs = null; - hasNext = false; - } - } - - private void postNext() throws SQLException { - LOG.debug( "Attempting to retrieve next results" ); - this.hasNext = rs.next(); - if ( !hasNext ) { - LOG.debug( "Exhausted results" ); - close(); - } - else { - LOG.debug( "Retrieved next results" ); - } - } - - public boolean hasNext() { - return hasNext; - } - - public Object next() throws HibernateException { - if ( !hasNext ) { - throw new NoSuchElementException( "No more results" ); - } - boolean sessionDefaultReadOnlyOrig = session.isDefaultReadOnly(); - session.setDefaultReadOnly( readOnly ); - try { - boolean isHolder = holderInstantiator.isRequired(); - - LOG.debug( "Assembling results" ); - if ( single && !isHolder ) { - currentResult = types[0].nullSafeGet( rs, names[0], session, null ); - } - else { - Object[] currentResults = new Object[types.length]; - for ( int i = 0; i < types.length; i++ ) { - currentResults[i] = types[i].nullSafeGet( rs, names[i], session, null ); - } - - if ( isHolder ) { - currentResult = holderInstantiator.instantiate( currentResults ); - } - else { - currentResult = currentResults; - } - } - - postNext(); - LOG.debug( "Returning current results" ); - return currentResult; - } - catch (SQLException sqle) { - throw session.getFactory().getSQLExceptionHelper().convert( - sqle, - "could not get next iterator result" - ); - } - finally { - session.setDefaultReadOnly( sessionDefaultReadOnlyOrig ); - } - } - - public void remove() { - if ( !single ) { - throw new UnsupportedOperationException( "Not a single column hibernate query result set" ); - } - if ( currentResult == null ) { - throw new IllegalStateException( "Called Iterator.remove() before next()" ); - } - if ( !( types[0] instanceof EntityType ) ) { - throw new UnsupportedOperationException( "Not an entity" ); - } - - session.delete( - ( (EntityType) types[0] ).getAssociatedEntityName(), - currentResult, - false, - null - ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/ScrollableResultsImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/ScrollableResultsImpl.java index 9a52b45aec..abc3c68153 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/ScrollableResultsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/ScrollableResultsImpl.java @@ -12,45 +12,33 @@ import java.sql.SQLException; import org.hibernate.HibernateException; import org.hibernate.JDBCException; -import org.hibernate.ScrollableResults; +import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.QueryParameters; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.loader.Loader; -import org.hibernate.type.Type; +import org.hibernate.sql.results.spi.RowReader; /** * Standard ScrollableResults implementation. * * @author Gavin King */ -public class ScrollableResultsImpl extends AbstractScrollableResults implements ScrollableResults { - private Object[] currentRow; +public class ScrollableResultsImpl extends AbstractScrollableResults { + private R currentRow; - /** - * Constructs a ScrollableResultsImpl using the specified information. - * - * @param rs The scrollable result set - * @param ps The prepared statement used to obtain the result set - * @param sess The originating session - * @param loader The loader - * @param queryParameters query parameters - * @param types The result types - * @param holderInstantiator Ugh - */ public ScrollableResultsImpl( ResultSet rs, PreparedStatement ps, SharedSessionContractImplementor sess, Loader loader, QueryParameters queryParameters, - Type[] types, - HolderInstantiator holderInstantiator) { - super( rs, ps, sess, loader, queryParameters, types, holderInstantiator ); + RowReader rowReader) { + super( rs, ps, sess, loader, queryParameters, rowReader ); } @Override - protected Object[] getCurrentRow() { + protected R getCurrentRow() { return currentRow; } @@ -185,36 +173,37 @@ public class ScrollableResultsImpl extends AbstractScrollableResults implements } private void prepareCurrentRow(boolean underlyingScrollSuccessful) { - if ( !underlyingScrollSuccessful ) { - currentRow = null; - return; - } - - final PersistenceContext persistenceContext = getSession().getPersistenceContextInternal(); - persistenceContext.beforeLoad(); - try { - final Object result = getLoader().loadSingleRow( - getResultSet(), - getSession(), - getQueryParameters(), - true - ); - if ( result != null && result.getClass().isArray() ) { - currentRow = (Object[]) result; - } - else { - currentRow = new Object[] {result}; - } - - if ( getHolderInstantiator() != null ) { - currentRow = new Object[] { getHolderInstantiator().instantiate( currentRow ) }; - } - } - finally { - persistenceContext.afterLoad(); - } - - afterScrollOperation(); + throw new NotYetImplementedFor6Exception( getClass() ); +// if ( !underlyingScrollSuccessful ) { +// currentRow = null; +// return; +// } +// +// final PersistenceContext persistenceContext = getSession().getPersistenceContextInternal(); +// persistenceContext.beforeLoad(); +// try { +// final Object result = getLoader().loadSingleRow( +// getResultSet(), +// getSession(), +// getQueryParameters(), +// true +// ); +// if ( result != null && result.getClass().isArray() ) { +// currentRow = (Object[]) result; +// } +// else { +// currentRow = new Object[] {result}; +// } +// +// if ( getHolderInstantiator() != null ) { +// currentRow = new Object[] { getHolderInstantiator().instantiate( currentRow ) }; +// } +// } +// finally { +// persistenceContext.afterLoad(); +// } +// +// afterScrollOperation(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java index 3de2ff8923..cce2d67f6d 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -136,7 +136,6 @@ import org.hibernate.jpa.internal.util.ConfigurationHelper; import org.hibernate.jpa.internal.util.FlushModeTypeHelper; import org.hibernate.jpa.internal.util.LockModeTypeHelper; import org.hibernate.jpa.internal.util.LockOptionsHelper; -import org.hibernate.jpa.spi.HibernateEntityManagerImplementor; import org.hibernate.loader.custom.CustomLoader; import org.hibernate.loader.custom.CustomQuery; import org.hibernate.metamodel.spi.MetamodelImplementor; @@ -187,7 +186,7 @@ import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_STORE_MODE; */ public final class SessionImpl extends AbstractSessionImpl - implements EventSource, SessionImplementor, HibernateEntityManagerImplementor { + implements SessionImplementor, EventSource { private static final EntityManagerMessageLogger log = HEMLogging.messageLogger( SessionImpl.class ); // Defaults to null which means the properties are the default - as defined in FastSessionServices#defaultSessionProperties @@ -1379,101 +1378,6 @@ public final class SessionImpl doFlush(); } - @Override - public int executeUpdate(String query, QueryParameters queryParameters) throws HibernateException { - checkOpenOrWaitingForAutoClose(); - pulseTransactionCoordinator(); - queryParameters.validateParameters(); - HQLQueryPlan plan = getQueryPlan( query, false ); - autoFlushIfRequired( plan.getQuerySpaces() ); - - verifyImmutableEntityUpdate( plan ); - - boolean success = false; - int result = 0; - try { - result = plan.performExecuteUpdate( queryParameters, this ); - success = true; - } - finally { - afterOperation( success ); - delayedAfterCompletion(); - } - return result; - } - - private void verifyImmutableEntityUpdate(HQLQueryPlan plan) { - if ( plan.isUpdate() ) { - List primaryFromClauseTables = new ArrayList<>(); - for ( QueryTranslator queryTranslator : plan.getTranslators() ) { - primaryFromClauseTables.addAll( queryTranslator.getPrimaryFromClauseTables() ); - } - for ( EntityPersister entityPersister : getSessionFactory().getMetamodel().entityPersisters().values() ) { - if ( !entityPersister.isMutable() ) { - List entityQuerySpaces = new ArrayList<>( - Arrays.asList( entityPersister.getQuerySpaces() ) - ); - boolean matching = false; - for ( Serializable entityQuerySpace : entityQuerySpaces ) { - if ( primaryFromClauseTables.contains( entityQuerySpace ) ) { - matching = true; - break; - } - } - - if ( matching ) { - ImmutableEntityUpdateQueryHandlingMode immutableEntityUpdateQueryHandlingMode = getSessionFactory() - .getSessionFactoryOptions() - .getImmutableEntityUpdateQueryHandlingMode(); - - String querySpaces = Arrays.toString( entityQuerySpaces.toArray() ); - - switch ( immutableEntityUpdateQueryHandlingMode ) { - case WARNING: - log.immutableEntityUpdateQuery( plan.getSourceQuery(), querySpaces ); - break; - case EXCEPTION: - throw new HibernateException( - "The query: [" + plan.getSourceQuery() + "] attempts to update an immutable entity: " + querySpaces - ); - default: - throw new UnsupportedOperationException( - "The " + immutableEntityUpdateQueryHandlingMode + " is not supported!" - ); - - } - } - } - } - } - } - - @Override - public int executeNativeUpdate( - NativeSQLQuerySpecification nativeQuerySpecification, - QueryParameters queryParameters) throws HibernateException { - checkOpenOrWaitingForAutoClose(); - pulseTransactionCoordinator(); - 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; - } - - @Override public Object instantiate(String entityName, Serializable id) throws HibernateException { return instantiate( getFactory().getMetamodel().entityPersister( entityName ), id ); diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/spi/HibernateEntityManagerFactoryAware.java b/hibernate-core/src/main/java/org/hibernate/jpa/spi/HibernateEntityManagerFactoryAware.java deleted file mode 100644 index a50aad84fd..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/jpa/spi/HibernateEntityManagerFactoryAware.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.jpa.spi; - -import org.hibernate.jpa.HibernateEntityManagerFactory; - -/** - * Internal contact for things that have {@link HibernateEntityManagerFactory} access. - * - * @author Strong Liu - * - * @deprecated (since 5.2) Why do we need an over-arching access to HibernateEntityManagerFactory across - * multiple contract hierarchies? - */ -@Deprecated -public interface HibernateEntityManagerFactoryAware { - /** - * Get access to the Hibernate extended EMF contract. - * - * @return The Hibernate EMF contract for this EM. - */ - HibernateEntityManagerFactory getFactory(); -} diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/spi/HibernateEntityManagerImplementor.java b/hibernate-core/src/main/java/org/hibernate/jpa/spi/HibernateEntityManagerImplementor.java deleted file mode 100644 index 2d60b40df9..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/jpa/spi/HibernateEntityManagerImplementor.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.jpa.spi; - -import java.util.List; -import java.util.Map; -import javax.persistence.LockModeType; - -import org.hibernate.LockOptions; -import org.hibernate.ejb.HibernateEntityManager; -import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.query.criteria.internal.ValueHandlerFactory; -import org.hibernate.type.Type; - -/** - * Additional internal contracts for the Hibernate {@link javax.persistence.EntityManager} implementation. - * - * @author Emmanuel Bernard - * @author Steve Ebersole - * - * @deprecated (since 5.2) move these methods to SessionImplementor - */ -@Deprecated -public interface HibernateEntityManagerImplementor extends HibernateEntityManager, HibernateEntityManagerFactoryAware { - @Override - SessionImplementor getSession(); - - /** - * Used to ensure the EntityManager is open, throwing IllegalStateException if it is closed. - * - * Depending on the value of {@code markForRollbackIfClosed}, may also rollback any enlisted-in transaction. This - * distinction is made across various sections of the spec. Most failed checks should rollback. Section - * 3.10.7 (per 2.1 spec) lists cases related to calls on related query objects that should not rollback. - * - * @param markForRollbackIfClosed If the EM is closed, should the transaction (if one) be marked for rollback? - * - * @throws IllegalStateException Thrown if the EM is closed - */ - void checkOpen(boolean markForRollbackIfClosed) throws IllegalStateException; - - /** - * Provides access to whether a transaction is currently in progress. - * - * @return True if a transaction is considered currently in progress; false otherwise. - */ - boolean isTransactionInProgress(); - - /** - * Used to mark a transaction for rollback only (when that is the JPA spec defined behavior). - */ - void markForRollbackOnly(); - - /** - * Convert from JPA 2 {@link javax.persistence.LockModeType} & properties into {@link org.hibernate.LockOptions} - * - * @param lockModeType is the requested lock type - * @param properties are the lock properties - * - * @return the LockOptions - * - * @deprecated (since 5.2) use {@link #buildLockOptions(LockModeType, Map)} instead - */ - @Deprecated - LockOptions getLockRequest(LockModeType lockModeType, Map properties); - - /** - * Given a JPA {@link javax.persistence.LockModeType} and properties, build a Hibernate - * {@link org.hibernate.LockOptions} - * - * @param lockModeType the requested LockModeType - * @param properties the lock properties - * - * @return the LockOptions - */ - default LockOptions buildLockOptions(LockModeType lockModeType, Map properties) { - return getLockRequest( lockModeType, properties ); - } - - interface QueryOptions { - interface ResultMetadataValidator { - void validate(Type[] returnTypes); - } - - ResultMetadataValidator getResultMetadataValidator(); - - /** - * Get the conversions for the individual tuples in the query results. - * - * @return Value conversions to be applied to the JPA QL results - */ - List getValueHandlers(); - - /** - * Get the explicit parameter types. Generally speaking these would apply to implicit named - * parameters. - * - * @return The - */ - Map getNamedParameterExplicitTypes(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/loader/Loader.java b/hibernate-core/src/main/java/org/hibernate/loader/Loader.java index 4f0066b402..dbba0bacd8 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/Loader.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/Loader.java @@ -46,10 +46,7 @@ import org.hibernate.dialect.pagination.NoopLimitHandler; import org.hibernate.engine.internal.CacheHelper; import org.hibernate.engine.internal.TwoPhaseLoad; import org.hibernate.engine.jdbc.ColumnNameCache; -import org.hibernate.engine.jdbc.spi.JdbcCoordinator; import org.hibernate.engine.jdbc.spi.JdbcServices; -import org.hibernate.engine.loading.internal.CollectionLoadContext; -import org.hibernate.engine.spi.BatchFetchQueue; import org.hibernate.engine.spi.EntityEntry; import org.hibernate.engine.spi.EntityKey; import org.hibernate.engine.spi.EntityUniqueKey; @@ -85,7 +82,6 @@ import org.hibernate.persister.entity.UniqueKeyLoadable; import org.hibernate.pretty.MessageHelper; import org.hibernate.proxy.HibernateProxy; import org.hibernate.query.spi.ScrollableResultsImplementor; -import org.hibernate.stat.spi.StatisticsImplementor; import org.hibernate.transform.CacheableResultTransformer; import org.hibernate.transform.ResultTransformer; import org.hibernate.type.AssociationType; @@ -2856,7 +2852,7 @@ public abstract class Loader { * * @param queryParameters The parameters with which the query should be executed. * @param returnTypes The expected return types of the query - * @param holderInstantiator If the return values are expected to be wrapped + * @param rowReader If the return values are expected to be wrapped * in a holder, this is the thing that knows how to wrap them. * @param session The session from which the scroll request originated. * @@ -2868,7 +2864,7 @@ public abstract class Loader { protected ScrollableResultsImplementor scroll( final QueryParameters queryParameters, final Type[] returnTypes, - final HolderInstantiator holderInstantiator, + final RowReader rowReader, final SharedSessionContractImplementor session) throws HibernateException { checkScrollability(); @@ -2903,25 +2899,25 @@ public abstract class Loader { } if ( needsFetchingScroll() ) { + //noinspection unchecked return new FetchingScrollableResultsImpl( rs, st, session, this, queryParameters, - returnTypes, - holderInstantiator + rowReader ); } else { + //noinspection unchecked return new ScrollableResultsImpl( rs, st, session, this, queryParameters, - returnTypes, - holderInstantiator + rowReader ); } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/custom/CustomLoader.java b/hibernate-core/src/main/java/org/hibernate/loader/custom/CustomLoader.java index cdde43aa9e..2303e25657 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/custom/CustomLoader.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/custom/CustomLoader.java @@ -18,6 +18,7 @@ import java.util.Set; import org.hibernate.HibernateException; import org.hibernate.LockMode; import org.hibernate.LockOptions; +import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.QueryException; import org.hibernate.Session; import org.hibernate.cache.spi.QueryKey; @@ -26,7 +27,6 @@ import org.hibernate.dialect.Dialect; import org.hibernate.engine.spi.QueryParameters; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.hql.internal.HolderInstantiator; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.loader.CollectionAliases; @@ -39,6 +39,7 @@ import org.hibernate.persister.collection.QueryableCollection; import org.hibernate.persister.entity.Loadable; import org.hibernate.persister.entity.Queryable; import org.hibernate.query.spi.ScrollableResultsImplementor; +import org.hibernate.sql.results.spi.RowReader; import org.hibernate.transform.ResultTransformer; import org.hibernate.type.CollectionType; import org.hibernate.type.EntityType; @@ -376,16 +377,11 @@ public class CustomLoader extends Loader { ResultTransformer resultTransformer = queryParameters.getResultTransformer(); - HolderInstantiator holderInstantiator = ( resultTransformer == null ) ? - HolderInstantiator.NOOP_INSTANTIATOR : - new HolderInstantiator( resultTransformer, this::getReturnAliasesForTransformer ); + throw new NotYetImplementedFor6Exception( getClass() ); - return scroll( - queryParameters, - resultTypes, - holderInstantiator, - session - ); +// final RowReader rowReader = ...; +// +// return scroll( queryParameters, resultTypes, rowReader, session ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AllowableParameterType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AllowableParameterType.java index 04db23db1e..3f88c1cf9e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AllowableParameterType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AllowableParameterType.java @@ -13,7 +13,11 @@ import org.hibernate.query.Query; /** * Specialization of DomainType for types that can be used as {@link Query} parameter bind values * - * todo (6.0) : extend Writeable (and therefore Readable too)? or composition? + * todo (6.0) : extend Writeable? or expose Writeable as "component"? + * i.e. + * ```` + * Writeable getWriteable(); + * ```` * * @author Steve Ebersole */ diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/StandardCallableStatementSupport.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/StandardCallableStatementSupport.java index 630c1ce700..22234a8d66 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/StandardCallableStatementSupport.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/StandardCallableStatementSupport.java @@ -19,6 +19,7 @@ import org.hibernate.procedure.spi.ParameterStrategy; import org.hibernate.procedure.spi.ProcedureParameterImplementor; import org.hibernate.query.spi.ParameterMetadataImplementor; import org.hibernate.query.spi.QueryParameterImplementor; +import org.hibernate.sql.ast.Clause; import org.hibernate.sql.exec.spi.JdbcCall; /** @@ -72,14 +73,14 @@ public class StandardCallableStatementSupport implements CallableStatementSuppor sep = ","; } else { - final int jdbcTypeCount = parameter.getHibernateType().getJdbcTypeCount( + parameter.getHibernateType().visitJdbcTypes( + sqlExpressableType -> { + buffer.append( sep ).append( "?" ); + sep = ","; + }, + Clause.IRRELEVANT, session.getFactory().getTypeConfiguration() ); - - for ( int i = 0; i < jdbcTypeCount; i++ ) { - buffer.append( sep ).append( "?" ); - sep = ","; - } } } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryPlanCache.java b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryPlanCache.java new file mode 100644 index 0000000000..70c2c71a97 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryPlanCache.java @@ -0,0 +1,41 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.query.spi; + +import org.hibernate.query.sqm.tree.SqmStatement; + +/** + * A cache for QueryPlans used (and produced) by the translation + * and execution of a query. + * + * @author Steve Ebersole + */ +public interface QueryPlanCache { + interface Key { + } + + SelectQueryPlan getSelectQueryPlan(Key key); + void cacheSelectQueryPlan(Key key, SelectQueryPlan plan); + + NonSelectQueryPlan getNonSelectQueryPlan(Key key); + void cacheNonSelectQueryPlan(Key key, NonSelectQueryPlan plan); + + // todo (6.0) : create a SqmStatementCache ? + SqmStatement getSqmStatement(String queryString); + void cacheSqmStatement(String key, SqmStatement sqmStatement); + + /** + * Close the cache when the SessionFactory is closed. + *

+ * Note that depending on the cache strategy implementation chosen, clearing the cache might not reclaim all the + * memory. + *

+ * Typically, when using LIRS, clearing the cache only invalidates the entries but the outdated entries are kept in + * memory until they are replaced by others. It is not considered a memory leak as the cache is bounded. + */ + void close(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmFieldLiteral.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmFieldLiteral.java index c5c31d52e4..5f3f0afe91 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmFieldLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmFieldLiteral.java @@ -78,6 +78,10 @@ public class SqmFieldLiteral implements SqmExpression, SqmExpressable, @Override public JavaTypeDescriptor getExpressableJavaTypeDescriptor() { + if ( expressable == this ) { + return fieldOwnerJavaTypeDescriptor; + } + return expressable.getExpressableJavaTypeDescriptor(); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/RowReader.java b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/RowReader.java new file mode 100644 index 0000000000..a5dbf1c1b0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/RowReader.java @@ -0,0 +1,49 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.sql.results.spi; + +import java.sql.SQLException; +import java.util.List; + +/** + * Coordinates the process of reading a single result values row + * + * @author Steve Ebersole + */ +public interface RowReader { + /** + * The overall row result Java type. Might be a scalar type, an + * entity type, etc. Might also be a `Object[].class` for multiple + * results (domain selections). + */ + Class getResultJavaType(); + + List getInitializers(); + + /** + * How many results (domain selections) are returned by this reader? + * + * @apiNote If this method returns `> 1` then {@link #getResultJavaType()} + * should return either `Object[].class` (or {@link javax.persistence.Tuple}?). + * + * todo (6.0) : determine this ^^ + */ + int getNumberOfResults(); + + /** + * The actual coordination of reading a row + * + * todo (6.0) : JdbcValuesSourceProcessingOptions is available through RowProcessingState - why pass it in separately + * should use one approach or the other + */ + R readRow(RowProcessingState processingState, JdbcValuesSourceProcessingOptions options) throws SQLException; + + /** + * Called at the end of processing all rows + */ + void finishUp(JdbcValuesSourceProcessingState context); +} diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/cacheable/cachemodes/SharedCacheModesTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/cacheable/cachemodes/SharedCacheModesTest.java index 3e791e2d2d..8792522a1f 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/cacheable/cachemodes/SharedCacheModesTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/cacheable/cachemodes/SharedCacheModesTest.java @@ -36,7 +36,7 @@ public class SharedCacheModesTest extends BaseEntityManagerFunctionalTestCase { Session session; em = getOrCreateEntityManager(); - session = ( (HibernateEntityManager) em ).getSession(); + session = em.unwrap( Session.class ); // defaults... assertEquals( CacheStoreMode.USE, em.getProperties().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) ); diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/ejb3configuration/EntityManagerFactorySerializationTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/ejb3configuration/EntityManagerFactorySerializationTest.java index d05947c635..1bbeb4e5a9 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/ejb3configuration/EntityManagerFactorySerializationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/ejb3configuration/EntityManagerFactorySerializationTest.java @@ -15,6 +15,7 @@ import java.util.Date; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; +import org.hibernate.Session; import org.hibernate.cfg.AvailableSettings; import org.hibernate.jpa.HibernateEntityManager; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; @@ -65,7 +66,7 @@ public class EntityManagerFactorySerializationTest extends BaseEntityManagerFunc //em.getTransaction().commit(); //fake the in container work - ( (HibernateEntityManager) em ).getSession().disconnect(); + em.unwrap( Session.class ).disconnect(); stream = new ByteArrayOutputStream(); out = new ObjectOutputStream( stream ); out.writeObject( em ); diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/ejb3configuration/EntityManagerSerializationTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/ejb3configuration/EntityManagerSerializationTest.java index fda9ee733a..ec1e743029 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/ejb3configuration/EntityManagerSerializationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/ejb3configuration/EntityManagerSerializationTest.java @@ -15,6 +15,7 @@ import java.util.Date; import java.util.Map; import javax.persistence.EntityManager; +import org.hibernate.Session; import org.hibernate.jpa.HibernateEntityManager; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.jpa.test.Cat; @@ -52,7 +53,7 @@ public class EntityManagerSerializationTest extends BaseEntityManagerFunctionalT //em.getTransaction().commit(); //fake the in container work - ( (HibernateEntityManager) em ).getSession().disconnect(); + em.unwrap( Session.class ).disconnect(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream( stream ); out.writeObject( em ); diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/query/CachedQueryTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/query/CachedQueryTest.java index 083efefe93..ceeeed97d4 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/query/CachedQueryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/query/CachedQueryTest.java @@ -13,10 +13,10 @@ import javax.persistence.SharedCacheMode; import javax.persistence.TypedQuery; import org.hibernate.cfg.Environment; +import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.jpa.AvailableSettings; import org.hibernate.jpa.HibernateEntityManagerFactory; import org.hibernate.jpa.QueryHints; -import org.hibernate.jpa.spi.HibernateEntityManagerImplementor; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.stat.Statistics; @@ -130,9 +130,8 @@ public class CachedQueryTest extends BaseEntityManagerFunctionalTestCase { em = getOrCreateEntityManager(); em.getEntityManagerFactory().getCache().evictAll(); - em.unwrap( HibernateEntityManagerImplementor.class ) + em.unwrap( SessionImplementor.class ) .getFactory() - .getSessionFactory() .getCache() .evictQueryRegions(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/cache/RegionNameTest.java b/hibernate-core/src/test/java/org/hibernate/test/cache/RegionNameTest.java index 98f12c2e37..e936cfae84 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/cache/RegionNameTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/cache/RegionNameTest.java @@ -20,7 +20,6 @@ import org.hibernate.annotations.NaturalId; import org.hibernate.annotations.NaturalIdCache; import org.hibernate.boot.MetadataSources; import org.hibernate.cfg.AvailableSettings; -import org.hibernate.engine.spi.CacheImplementor; import org.hibernate.metamodel.model.domain.NavigableRole; import org.hibernate.stat.NaturalIdCacheStatistics; import org.hibernate.stat.SecondLevelCacheStatistics; @@ -31,7 +30,6 @@ import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.junit.Test; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; /** * Test API and SPI expectation wrt region names - whether they expect the @@ -136,36 +134,6 @@ public class RegionNameTest extends BaseNonConfigCoreFunctionalTestCase { // sessionFactory().getCache().evictQueryRegions(); } - @Test - public void testLegacyCacheSpi() { - // these need to be the prefixed name - final String regionName = cachePrefix + '.' + localName; - - final CacheImplementor cache = sessionFactory().getCache(); - - // just like stats, the cache for queries cannot be accessed second level cache regions map - assertEquals( 2, cache.getSecondLevelCacheRegionNames().length ); - - boolean foundRegion = false; - for ( String name : cache.getSecondLevelCacheRegionNames() ) { - if ( regionName.equals( name ) ) { - foundRegion = true; - break; - } - } - if ( !foundRegion ) { - fail( "Could not find region [" + regionName + "] in reported list of region names" ); - } - - final NavigableRole personEntityName = new NavigableRole( Person.class.getName() ); - final NavigableRole nickNamesRole = personEntityName.append( "nickNames"); - - assert cache.getEntityRegionAccess( personEntityName ) != null; - assert cache.getNaturalIdCacheRegionAccessStrategy( personEntityName ) != null; - assert cache.getCollectionRegionAccess( nickNamesRole ) != null; - } - - @Entity( name = "Person" ) @Table( name = "persons" ) diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/EntityManagerUnwrapTest.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/EntityManagerUnwrapTest.java index 9f54b78590..2c2781f51e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jpa/EntityManagerUnwrapTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/EntityManagerUnwrapTest.java @@ -6,45 +6,55 @@ */ package org.hibernate.test.jpa; +import javax.persistence.metamodel.Metamodel; + import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.engine.jdbc.spi.JdbcServices; +import org.hibernate.engine.spi.PersistenceContext; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; -import org.junit.Test; +import org.hibernate.metamodel.spi.DomainMetamodel; +import org.hibernate.metamodel.spi.MetamodelImplementor; +import org.hibernate.query.spi.QueryEngine; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.service.spi.SessionFactoryServiceRegistry; -import org.hibernate.testing.TestForIssue; +import org.junit.Test; /** * @author Chris Cranford */ public class EntityManagerUnwrapTest extends BaseEntityManagerFunctionalTestCase { @Test - @TestForIssue(jiraKey = "HHH-13281") - public void testUnwrapEjbHibernateEntityManagerInterface() { - org.hibernate.ejb.HibernateEntityManager em = getOrCreateEntityManager().unwrap( org.hibernate.ejb.HibernateEntityManager.class ); - } - - @Test - @TestForIssue(jiraKey = "HHH-13281") - public void testUnwrapJpaHibernateEntityManagerInterface() { - org.hibernate.jpa.HibernateEntityManager em = getOrCreateEntityManager().unwrap( org.hibernate.jpa.HibernateEntityManager.class ); - } - - @Test - @TestForIssue(jiraKey = "HHH-13281") - public void testUnwrapSessionImplementor() { - SessionImplementor session = getOrCreateEntityManager().unwrap( SessionImplementor.class ); - } - - @Test - @TestForIssue(jiraKey = "HHH-13281") public void testUnwrapSession() { - Session session = getOrCreateEntityManager().unwrap( Session.class ); + getOrCreateEntityManager().unwrap( Session.class ); + getOrCreateEntityManager().unwrap( SessionImplementor.class ); + getOrCreateEntityManager().unwrap( SharedSessionContractImplementor.class ); + + getOrCreateEntityManager().unwrap( PersistenceContext.class ); } @Test - @TestForIssue(jiraKey = "HHH-13281") - public void testUnwrapSharedSessionContractImplementor() { - SharedSessionContractImplementor session = getOrCreateEntityManager().unwrap( SharedSessionContractImplementor.class ); + public void testUnwrapSessionFactory() { + entityManagerFactory().unwrap( SessionFactory.class ); + entityManagerFactory().unwrap( SessionFactoryImplementor.class ); + + entityManagerFactory().unwrap( SessionFactoryServiceRegistry.class ); + entityManagerFactory().unwrap( ServiceRegistry.class ); + + entityManagerFactory().unwrap( JdbcServices.class ); + + entityManagerFactory().unwrap( javax.persistence.Cache.class ); + entityManagerFactory().unwrap( org.hibernate.Cache.class ); + + entityManagerFactory().unwrap( javax.persistence.metamodel.Metamodel.class ); + entityManagerFactory().unwrap( Metamodel.class ); + entityManagerFactory().unwrap( MetamodelImplementor.class ); + entityManagerFactory().unwrap( DomainMetamodel.class ); + + entityManagerFactory().unwrap( QueryEngine.class ); } }