6 - SQM based on JPA type system
- focus on reducing compilation errors
This commit is contained in:
parent
c6a11d99fd
commit
b39d9d22bd
|
@ -270,7 +270,7 @@ Exists as a `Service` mainly so that integrations such as OGM can override it.
|
||||||
|
|
||||||
===== `CacheImplementor`
|
===== `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]]
|
[[services-custom]]
|
||||||
=== Custom Services
|
=== Custom Services
|
||||||
|
|
|
@ -84,7 +84,7 @@ import org.hibernate.stat.SessionStatistics;
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
* @author Steve Ebersole
|
* @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.
|
* Obtain a {@link Session} builder with the ability to grab certain information from this session.
|
||||||
*
|
*
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.hibernate.service.Service;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public interface CacheImplementor extends Service, Cache, org.hibernate.engine.spi.CacheImplementor, Serializable {
|
public interface CacheImplementor extends Service, Cache, Serializable {
|
||||||
@Override
|
@Override
|
||||||
SessionFactoryImplementor getSessionFactory();
|
SessionFactoryImplementor getSessionFactory();
|
||||||
|
|
||||||
|
|
|
@ -1259,28 +1259,10 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings {
|
||||||
String QUERY_PLAN_CACHE_ENABLED = "hibernate.query.plan_cache_enabled";
|
String QUERY_PLAN_CACHE_ENABLED = "hibernate.query.plan_cache_enabled";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum number of strong references maintained by {@link QueryInterpretationCache}. Default is 128.
|
* The maximum number of entries in the Hibernate "Query Plan Cache". The
|
||||||
* @deprecated in favor of {@link #QUERY_PLAN_CACHE_PARAMETER_METADATA_MAX_SIZE}
|
* default size is 2048.
|
||||||
*/
|
|
||||||
@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:
|
|
||||||
* <ul>
|
|
||||||
* <li>{@link org.hibernate.engine.query.spi.HQLQueryPlan}</li>
|
|
||||||
* <li>{@link org.hibernate.engine.query.spi.FilterQueryPlan}</li>
|
|
||||||
* <li>{@link org.hibernate.engine.query.spi.NativeSQLQueryPlan}</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
*
|
||||||
* 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";
|
String QUERY_PLAN_CACHE_MAX_SIZE = "hibernate.query.plan_cache_max_size";
|
||||||
|
|
||||||
|
|
|
@ -10,5 +10,5 @@ package org.hibernate.ejb;
|
||||||
* @deprecated Use {@link org.hibernate.jpa.HibernateEntityManager} instead
|
* @deprecated Use {@link org.hibernate.jpa.HibernateEntityManager} instead
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public interface HibernateEntityManager extends org.hibernate.jpa.HibernateEntityManager {
|
public interface HibernateEntityManager {
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
|
||||||
*/
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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<DomainDataRegionConfig> 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<String> 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 <tt>region name</tt> 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<NaturalIdDataAccess> getNaturalIdAccessesInRegion(String legacyQualifiedRegionName);
|
|
||||||
}
|
|
|
@ -59,8 +59,6 @@ public final class QueryParameters {
|
||||||
private Type[] processedPositionalParameterTypes;
|
private Type[] processedPositionalParameterTypes;
|
||||||
private Object[] processedPositionalParameterValues;
|
private Object[] processedPositionalParameterValues;
|
||||||
|
|
||||||
private HQLQueryPlan queryPlan;
|
|
||||||
|
|
||||||
public QueryParameters() {
|
public QueryParameters() {
|
||||||
this( ArrayHelper.EMPTY_TYPE_ARRAY, ArrayHelper.EMPTY_OBJECT_ARRAY );
|
this( ArrayHelper.EMPTY_TYPE_ARRAY, ArrayHelper.EMPTY_OBJECT_ARRAY );
|
||||||
}
|
}
|
||||||
|
@ -644,14 +642,6 @@ public final class QueryParameters {
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HQLQueryPlan getQueryPlan() {
|
|
||||||
return queryPlan;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setQueryPlan(HQLQueryPlan queryPlan) {
|
|
||||||
this.queryPlan = queryPlan;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void bindDynamicParameter(Type paramType, Object paramValue) {
|
public void bindDynamicParameter(Type paramType, Object paramValue) {
|
||||||
if(processedPositionalParameterTypes != null) {
|
if(processedPositionalParameterTypes != null) {
|
||||||
int length = processedPositionalParameterTypes.length;
|
int length = processedPositionalParameterTypes.length;
|
||||||
|
|
|
@ -79,27 +79,8 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
|
||||||
|
|
||||||
protected final SessionImplementor delegate;
|
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) {
|
public SessionDelegatorBaseImpl(SessionImplementor delegate) {
|
||||||
this( delegate, delegate );
|
this.delegate = delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -157,16 +138,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
|
||||||
delegate.checkTransactionNeededForUpdateOperation( exceptionMessage );
|
delegate.checkTransactionNeededForUpdateOperation( exceptionMessage );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public LockOptions getLockRequest(LockModeType lockModeType, Map<String, Object> properties) {
|
|
||||||
return delegate.getLockRequest( lockModeType, properties );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LockOptions buildLockOptions(LockModeType lockModeType, Map<String, Object> properties) {
|
|
||||||
return delegate.buildLockOptions( lockModeType, properties );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initializeCollection(PersistentCollection collection, boolean writing) throws HibernateException {
|
public void initializeCollection(PersistentCollection collection, boolean writing) throws HibernateException {
|
||||||
delegate.initializeCollection( collection, writing );
|
delegate.initializeCollection( collection, writing );
|
||||||
|
@ -252,16 +223,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
|
||||||
return delegate.getPersistenceContext();
|
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
|
@Override
|
||||||
public CacheMode getCacheMode() {
|
public CacheMode getCacheMode() {
|
||||||
return delegate.getCacheMode();
|
return delegate.getCacheMode();
|
||||||
|
@ -621,11 +582,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public NativeQueryImplementor createSQLQuery(String queryString) {
|
|
||||||
return delegate.createSQLQuery( queryString );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProcedureCall getNamedProcedureCall(String name) {
|
public ProcedureCall getNamedProcedureCall(String name) {
|
||||||
return delegate.getNamedProcedureCall( name );
|
return delegate.getNamedProcedureCall( name );
|
||||||
|
|
|
@ -12,13 +12,10 @@ import java.util.Set;
|
||||||
import javax.persistence.criteria.CriteriaDelete;
|
import javax.persistence.criteria.CriteriaDelete;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.CriteriaUpdate;
|
import javax.persistence.criteria.CriteriaUpdate;
|
||||||
import javax.persistence.criteria.Selection;
|
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.graph.RootGraph;
|
|
||||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||||
import org.hibernate.jpa.spi.HibernateEntityManagerImplementor;
|
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.query.spi.QueryImplementor;
|
import org.hibernate.query.spi.QueryImplementor;
|
||||||
import org.hibernate.query.sql.spi.NativeQueryImplementor;
|
import org.hibernate.query.sql.spi.NativeQueryImplementor;
|
||||||
|
@ -54,8 +51,7 @@ import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface SessionImplementor
|
public interface SessionImplementor extends Session, SharedSessionContractImplementor {
|
||||||
extends Session, SharedSessionContractImplementor, HibernateEntityManagerImplementor {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default SessionImplementor getSession() {
|
default SessionImplementor getSession() {
|
||||||
|
|
|
@ -353,17 +353,6 @@ public interface SharedSessionContractImplementor
|
||||||
|
|
||||||
int getDontFlushFromFind();
|
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();
|
boolean isDefaultReadOnly();
|
||||||
|
|
||||||
CacheMode getCacheMode();
|
CacheMode getCacheMode();
|
||||||
|
|
|
@ -6,33 +6,23 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.internal;
|
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.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
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.HibernateException;
|
||||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
||||||
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.hql.internal.HolderInstantiator;
|
|
||||||
import org.hibernate.loader.Loader;
|
import org.hibernate.loader.Loader;
|
||||||
import org.hibernate.query.spi.ScrollableResultsImplementor;
|
import org.hibernate.query.spi.ScrollableResultsImplementor;
|
||||||
import org.hibernate.type.StandardBasicTypes;
|
import org.hibernate.sql.results.spi.RowReader;
|
||||||
import org.hibernate.type.Type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base implementation of the ScrollableResults interface.
|
* Base implementation of the ScrollableResults interface.
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractScrollableResults implements ScrollableResultsImplementor {
|
public abstract class AbstractScrollableResults<R> implements ScrollableResultsImplementor<R> {
|
||||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( AbstractScrollableResults.class );
|
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( AbstractScrollableResults.class );
|
||||||
|
|
||||||
private final ResultSet resultSet;
|
private final ResultSet resultSet;
|
||||||
|
@ -40,30 +30,31 @@ public abstract class AbstractScrollableResults implements ScrollableResultsImpl
|
||||||
private final SharedSessionContractImplementor session;
|
private final SharedSessionContractImplementor session;
|
||||||
private final Loader loader;
|
private final Loader loader;
|
||||||
private final QueryParameters queryParameters;
|
private final QueryParameters queryParameters;
|
||||||
private final Type[] types;
|
|
||||||
private HolderInstantiator holderInstantiator;
|
private final RowReader<R> rowReader;
|
||||||
|
|
||||||
private boolean closed;
|
private boolean closed;
|
||||||
|
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
protected AbstractScrollableResults(
|
protected AbstractScrollableResults(
|
||||||
ResultSet rs,
|
ResultSet rs,
|
||||||
PreparedStatement ps,
|
PreparedStatement ps,
|
||||||
SharedSessionContractImplementor sess,
|
SharedSessionContractImplementor sess,
|
||||||
Loader loader,
|
Loader loader,
|
||||||
QueryParameters queryParameters,
|
QueryParameters queryParameters,
|
||||||
Type[] types,
|
RowReader<R> rowReader) {
|
||||||
HolderInstantiator holderInstantiator) {
|
|
||||||
this.resultSet = rs;
|
this.resultSet = rs;
|
||||||
this.ps = ps;
|
this.ps = ps;
|
||||||
this.session = sess;
|
this.session = sess;
|
||||||
this.loader = loader;
|
this.loader = loader;
|
||||||
this.queryParameters = queryParameters;
|
this.queryParameters = queryParameters;
|
||||||
this.types = types;
|
this.rowReader = rowReader;
|
||||||
this.holderInstantiator = holderInstantiator != null && holderInstantiator.isRequired()
|
|
||||||
? holderInstantiator
|
|
||||||
: null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Object[] getCurrentRow();
|
protected abstract R getCurrentRow();
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
// Access to state fr sub-types
|
||||||
|
|
||||||
protected ResultSet getResultSet() {
|
protected ResultSet getResultSet() {
|
||||||
return resultSet;
|
return resultSet;
|
||||||
|
@ -85,12 +76,25 @@ public abstract class AbstractScrollableResults implements ScrollableResultsImpl
|
||||||
return queryParameters;
|
return queryParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Type[] getTypes() {
|
protected RowReader<R> getRowReader() {
|
||||||
return types;
|
return rowReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HolderInstantiator getHolderInstantiator() {
|
@Override
|
||||||
return holderInstantiator;
|
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
|
@Override
|
||||||
|
@ -100,213 +104,23 @@ public abstract class AbstractScrollableResults implements ScrollableResultsImpl
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// not absolutely necessary, but does help with aggressive release
|
// getJdbcValues().finishUp();
|
||||||
//session.getJDBCContext().getConnectionManager().closeQueryStatement( ps, resultSet );
|
// getPersistenceContext().getJdbcCoordinator().afterStatementExecution();
|
||||||
final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator();
|
|
||||||
jdbcCoordinator.getResourceRegistry().release( ps );
|
// // not absolutely necessary, but does help with aggressive release
|
||||||
jdbcCoordinator.afterStatementExecution();
|
// //session.getJDBCContext().getConnectionManager().closeQueryStatement( ps, resultSet );
|
||||||
try {
|
// session.getJdbcCoordinator().getResourceRegistry().release( ps );
|
||||||
session.getPersistenceContextInternal().getLoadContexts().cleanup( resultSet );
|
// session.getJdbcCoordinator().afterStatementExecution();
|
||||||
}
|
// try {
|
||||||
catch (Throwable ignore) {
|
// session.getPersistenceContext().getLoadContexts().cleanup( resultSet );
|
||||||
// ignore this error for now
|
// }
|
||||||
if ( LOG.isTraceEnabled() ) {
|
// catch (Throwable ignore) {
|
||||||
LOG.tracev( "Exception trying to cleanup load context : {0}", ignore.getMessage() );
|
// // ignore this error for now
|
||||||
}
|
// if ( LOG.isTraceEnabled() ) {
|
||||||
}
|
// LOG.tracev( "Exception trying to cleanup load context : {0}", ignore.getMessage() );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
this.closed = true;
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,119 +11,111 @@ import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.NotYetImplementedFor6Exception;
|
||||||
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.hql.internal.HolderInstantiator;
|
|
||||||
import org.hibernate.loader.Loader;
|
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.
|
* Implementation of ScrollableResults which can handle collection fetches.
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class FetchingScrollableResultsImpl extends AbstractScrollableResults {
|
public class FetchingScrollableResultsImpl<R> extends AbstractScrollableResults<R> {
|
||||||
private Object[] currentRow;
|
private R currentRow;
|
||||||
private int currentPosition;
|
private int currentPosition;
|
||||||
private Integer maxPosition;
|
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(
|
public FetchingScrollableResultsImpl(
|
||||||
ResultSet rs,
|
ResultSet rs,
|
||||||
PreparedStatement ps,
|
PreparedStatement ps,
|
||||||
SharedSessionContractImplementor sess,
|
SharedSessionContractImplementor sess,
|
||||||
Loader loader,
|
Loader loader,
|
||||||
QueryParameters queryParameters,
|
QueryParameters queryParameters,
|
||||||
Type[] types,
|
RowReader<R> rowReader) {
|
||||||
HolderInstantiator holderInstantiator) {
|
super( rs, ps, sess, loader, queryParameters, rowReader );
|
||||||
super( rs, ps, sess, loader, queryParameters, types, holderInstantiator );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object[] getCurrentRow() {
|
protected R getCurrentRow() {
|
||||||
return currentRow;
|
return currentRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean next() {
|
public boolean next() {
|
||||||
if ( maxPosition != null && maxPosition <= currentPosition ) {
|
throw new NotYetImplementedFor6Exception( getClass() );
|
||||||
currentRow = null;
|
|
||||||
currentPosition = maxPosition + 1;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( isResultSetEmpty() ) {
|
// if ( maxPosition != null && maxPosition <= currentPosition ) {
|
||||||
currentRow = null;
|
// currentRow = null;
|
||||||
currentPosition = 0;
|
// currentPosition = maxPosition + 1;
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
final Object row = getLoader().loadSequentialRowsForward(
|
// if ( isResultSetEmpty() ) {
|
||||||
getResultSet(),
|
// currentRow = null;
|
||||||
getSession(),
|
// currentPosition = 0;
|
||||||
getQueryParameters(),
|
// return false;
|
||||||
true
|
// }
|
||||||
);
|
//
|
||||||
|
// final Object row = getLoader().loadSequentialRowsForward(
|
||||||
|
// getResultSet(),
|
||||||
final boolean afterLast;
|
// getSession(),
|
||||||
try {
|
// getQueryParameters(),
|
||||||
afterLast = getResultSet().isAfterLast();
|
// true
|
||||||
}
|
// );
|
||||||
catch (SQLException e) {
|
//
|
||||||
throw getSession().getFactory().getSQLExceptionHelper().convert(
|
//
|
||||||
e,
|
// final boolean afterLast;
|
||||||
"exception calling isAfterLast()"
|
// try {
|
||||||
);
|
// afterLast = getResultSet().isAfterLast();
|
||||||
}
|
// }
|
||||||
|
// catch (SQLException e) {
|
||||||
currentPosition++;
|
// throw getSession().getFactory().getSQLExceptionHelper().convert(
|
||||||
currentRow = new Object[] {row};
|
// e,
|
||||||
|
// "exception calling isAfterLast()"
|
||||||
if ( afterLast ) {
|
// );
|
||||||
if ( maxPosition == null ) {
|
// }
|
||||||
// we just hit the last position
|
//
|
||||||
maxPosition = currentPosition;
|
// currentPosition++;
|
||||||
}
|
// currentRow = new Object[] {row};
|
||||||
}
|
//
|
||||||
|
// if ( afterLast ) {
|
||||||
afterScrollOperation();
|
// if ( maxPosition == null ) {
|
||||||
|
// // we just hit the last position
|
||||||
return true;
|
// maxPosition = currentPosition;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// afterScrollOperation();
|
||||||
|
//
|
||||||
|
// return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean previous() {
|
public boolean previous() {
|
||||||
if ( currentPosition <= 1 ) {
|
throw new NotYetImplementedFor6Exception( getClass() );
|
||||||
currentPosition = 0;
|
|
||||||
currentRow = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Object loadResult = getLoader().loadSequentialRowsReverse(
|
// if ( currentPosition <= 1 ) {
|
||||||
getResultSet(),
|
// currentPosition = 0;
|
||||||
getSession(),
|
// currentRow = null;
|
||||||
getQueryParameters(),
|
// return false;
|
||||||
false,
|
// }
|
||||||
( maxPosition != null && currentPosition > maxPosition )
|
//
|
||||||
);
|
// final Object loadResult = getLoader().loadSequentialRowsReverse(
|
||||||
|
// getResultSet(),
|
||||||
currentRow = new Object[] {loadResult};
|
// getSession(),
|
||||||
currentPosition--;
|
// getQueryParameters(),
|
||||||
|
// false,
|
||||||
afterScrollOperation();
|
// ( maxPosition != null && currentPosition > maxPosition )
|
||||||
|
// );
|
||||||
return true;
|
//
|
||||||
|
// currentRow = new Object[] {loadResult};
|
||||||
|
// currentPosition--;
|
||||||
|
//
|
||||||
|
// afterScrollOperation();
|
||||||
|
//
|
||||||
|
// return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
|
||||||
*/
|
|
||||||
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 <tt>java.util.Iterator</tt> that is
|
|
||||||
* returned by <tt>iterate()</tt> 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
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,45 +12,33 @@ import java.sql.SQLException;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.JDBCException;
|
import org.hibernate.JDBCException;
|
||||||
import org.hibernate.ScrollableResults;
|
import org.hibernate.NotYetImplementedFor6Exception;
|
||||||
import org.hibernate.engine.spi.PersistenceContext;
|
import org.hibernate.engine.spi.PersistenceContext;
|
||||||
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.loader.Loader;
|
import org.hibernate.loader.Loader;
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.sql.results.spi.RowReader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard ScrollableResults implementation.
|
* Standard ScrollableResults implementation.
|
||||||
*
|
*
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
*/
|
*/
|
||||||
public class ScrollableResultsImpl extends AbstractScrollableResults implements ScrollableResults {
|
public class ScrollableResultsImpl<R> extends AbstractScrollableResults<R> {
|
||||||
private Object[] currentRow;
|
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(
|
public ScrollableResultsImpl(
|
||||||
ResultSet rs,
|
ResultSet rs,
|
||||||
PreparedStatement ps,
|
PreparedStatement ps,
|
||||||
SharedSessionContractImplementor sess,
|
SharedSessionContractImplementor sess,
|
||||||
Loader loader,
|
Loader loader,
|
||||||
QueryParameters queryParameters,
|
QueryParameters queryParameters,
|
||||||
Type[] types,
|
RowReader<R> rowReader) {
|
||||||
HolderInstantiator holderInstantiator) {
|
super( rs, ps, sess, loader, queryParameters, rowReader );
|
||||||
super( rs, ps, sess, loader, queryParameters, types, holderInstantiator );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object[] getCurrentRow() {
|
protected R getCurrentRow() {
|
||||||
return currentRow;
|
return currentRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,36 +173,37 @@ public class ScrollableResultsImpl extends AbstractScrollableResults implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareCurrentRow(boolean underlyingScrollSuccessful) {
|
private void prepareCurrentRow(boolean underlyingScrollSuccessful) {
|
||||||
if ( !underlyingScrollSuccessful ) {
|
throw new NotYetImplementedFor6Exception( getClass() );
|
||||||
currentRow = null;
|
// if ( !underlyingScrollSuccessful ) {
|
||||||
return;
|
// currentRow = null;
|
||||||
}
|
// return;
|
||||||
|
// }
|
||||||
final PersistenceContext persistenceContext = getSession().getPersistenceContextInternal();
|
//
|
||||||
persistenceContext.beforeLoad();
|
// final PersistenceContext persistenceContext = getSession().getPersistenceContextInternal();
|
||||||
try {
|
// persistenceContext.beforeLoad();
|
||||||
final Object result = getLoader().loadSingleRow(
|
// try {
|
||||||
getResultSet(),
|
// final Object result = getLoader().loadSingleRow(
|
||||||
getSession(),
|
// getResultSet(),
|
||||||
getQueryParameters(),
|
// getSession(),
|
||||||
true
|
// getQueryParameters(),
|
||||||
);
|
// true
|
||||||
if ( result != null && result.getClass().isArray() ) {
|
// );
|
||||||
currentRow = (Object[]) result;
|
// if ( result != null && result.getClass().isArray() ) {
|
||||||
}
|
// currentRow = (Object[]) result;
|
||||||
else {
|
// }
|
||||||
currentRow = new Object[] {result};
|
// else {
|
||||||
}
|
// currentRow = new Object[] {result};
|
||||||
|
// }
|
||||||
if ( getHolderInstantiator() != null ) {
|
//
|
||||||
currentRow = new Object[] { getHolderInstantiator().instantiate( currentRow ) };
|
// if ( getHolderInstantiator() != null ) {
|
||||||
}
|
// currentRow = new Object[] { getHolderInstantiator().instantiate( currentRow ) };
|
||||||
}
|
// }
|
||||||
finally {
|
// }
|
||||||
persistenceContext.afterLoad();
|
// finally {
|
||||||
}
|
// persistenceContext.afterLoad();
|
||||||
|
// }
|
||||||
afterScrollOperation();
|
//
|
||||||
|
// afterScrollOperation();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,7 +136,6 @@ import org.hibernate.jpa.internal.util.ConfigurationHelper;
|
||||||
import org.hibernate.jpa.internal.util.FlushModeTypeHelper;
|
import org.hibernate.jpa.internal.util.FlushModeTypeHelper;
|
||||||
import org.hibernate.jpa.internal.util.LockModeTypeHelper;
|
import org.hibernate.jpa.internal.util.LockModeTypeHelper;
|
||||||
import org.hibernate.jpa.internal.util.LockOptionsHelper;
|
import org.hibernate.jpa.internal.util.LockOptionsHelper;
|
||||||
import org.hibernate.jpa.spi.HibernateEntityManagerImplementor;
|
|
||||||
import org.hibernate.loader.custom.CustomLoader;
|
import org.hibernate.loader.custom.CustomLoader;
|
||||||
import org.hibernate.loader.custom.CustomQuery;
|
import org.hibernate.loader.custom.CustomQuery;
|
||||||
import org.hibernate.metamodel.spi.MetamodelImplementor;
|
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
|
public final class SessionImpl
|
||||||
extends AbstractSessionImpl
|
extends AbstractSessionImpl
|
||||||
implements EventSource, SessionImplementor, HibernateEntityManagerImplementor {
|
implements SessionImplementor, EventSource {
|
||||||
private static final EntityManagerMessageLogger log = HEMLogging.messageLogger( SessionImpl.class );
|
private static final EntityManagerMessageLogger log = HEMLogging.messageLogger( SessionImpl.class );
|
||||||
|
|
||||||
// Defaults to null which means the properties are the default - as defined in FastSessionServices#defaultSessionProperties
|
// Defaults to null which means the properties are the default - as defined in FastSessionServices#defaultSessionProperties
|
||||||
|
@ -1379,101 +1378,6 @@ public final class SessionImpl
|
||||||
doFlush();
|
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<String> primaryFromClauseTables = new ArrayList<>();
|
|
||||||
for ( QueryTranslator queryTranslator : plan.getTranslators() ) {
|
|
||||||
primaryFromClauseTables.addAll( queryTranslator.getPrimaryFromClauseTables() );
|
|
||||||
}
|
|
||||||
for ( EntityPersister entityPersister : getSessionFactory().getMetamodel().entityPersisters().values() ) {
|
|
||||||
if ( !entityPersister.isMutable() ) {
|
|
||||||
List<Serializable> 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
|
@Override
|
||||||
public Object instantiate(String entityName, Serializable id) throws HibernateException {
|
public Object instantiate(String entityName, Serializable id) throws HibernateException {
|
||||||
return instantiate( getFactory().getMetamodel().entityPersister( entityName ), id );
|
return instantiate( getFactory().getMetamodel().entityPersister( entityName ), id );
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
|
||||||
*/
|
|
||||||
package org.hibernate.jpa.spi;
|
|
||||||
|
|
||||||
import org.hibernate.jpa.HibernateEntityManagerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal contact for things that have {@link HibernateEntityManagerFactory} access.
|
|
||||||
*
|
|
||||||
* @author Strong Liu <stliu@hibernate.org>
|
|
||||||
*
|
|
||||||
* @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();
|
|
||||||
}
|
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
|
||||||
*/
|
|
||||||
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<String, Object> 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<String, Object> 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<ValueHandlerFactory.ValueHandler> getValueHandlers();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the explicit parameter types. Generally speaking these would apply to implicit named
|
|
||||||
* parameters.
|
|
||||||
*
|
|
||||||
* @return The
|
|
||||||
*/
|
|
||||||
Map<String, Class> getNamedParameterExplicitTypes();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -46,10 +46,7 @@ import org.hibernate.dialect.pagination.NoopLimitHandler;
|
||||||
import org.hibernate.engine.internal.CacheHelper;
|
import org.hibernate.engine.internal.CacheHelper;
|
||||||
import org.hibernate.engine.internal.TwoPhaseLoad;
|
import org.hibernate.engine.internal.TwoPhaseLoad;
|
||||||
import org.hibernate.engine.jdbc.ColumnNameCache;
|
import org.hibernate.engine.jdbc.ColumnNameCache;
|
||||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
|
||||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
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.EntityEntry;
|
||||||
import org.hibernate.engine.spi.EntityKey;
|
import org.hibernate.engine.spi.EntityKey;
|
||||||
import org.hibernate.engine.spi.EntityUniqueKey;
|
import org.hibernate.engine.spi.EntityUniqueKey;
|
||||||
|
@ -85,7 +82,6 @@ import org.hibernate.persister.entity.UniqueKeyLoadable;
|
||||||
import org.hibernate.pretty.MessageHelper;
|
import org.hibernate.pretty.MessageHelper;
|
||||||
import org.hibernate.proxy.HibernateProxy;
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
import org.hibernate.query.spi.ScrollableResultsImplementor;
|
import org.hibernate.query.spi.ScrollableResultsImplementor;
|
||||||
import org.hibernate.stat.spi.StatisticsImplementor;
|
|
||||||
import org.hibernate.transform.CacheableResultTransformer;
|
import org.hibernate.transform.CacheableResultTransformer;
|
||||||
import org.hibernate.transform.ResultTransformer;
|
import org.hibernate.transform.ResultTransformer;
|
||||||
import org.hibernate.type.AssociationType;
|
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 queryParameters The parameters with which the query should be executed.
|
||||||
* @param returnTypes The expected return types of the query
|
* @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.
|
* in a holder, this is the thing that knows how to wrap them.
|
||||||
* @param session The session from which the scroll request originated.
|
* @param session The session from which the scroll request originated.
|
||||||
*
|
*
|
||||||
|
@ -2868,7 +2864,7 @@ public abstract class Loader {
|
||||||
protected ScrollableResultsImplementor scroll(
|
protected ScrollableResultsImplementor scroll(
|
||||||
final QueryParameters queryParameters,
|
final QueryParameters queryParameters,
|
||||||
final Type[] returnTypes,
|
final Type[] returnTypes,
|
||||||
final HolderInstantiator holderInstantiator,
|
final RowReader rowReader,
|
||||||
final SharedSessionContractImplementor session) throws HibernateException {
|
final SharedSessionContractImplementor session) throws HibernateException {
|
||||||
checkScrollability();
|
checkScrollability();
|
||||||
|
|
||||||
|
@ -2903,25 +2899,25 @@ public abstract class Loader {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( needsFetchingScroll() ) {
|
if ( needsFetchingScroll() ) {
|
||||||
|
//noinspection unchecked
|
||||||
return new FetchingScrollableResultsImpl(
|
return new FetchingScrollableResultsImpl(
|
||||||
rs,
|
rs,
|
||||||
st,
|
st,
|
||||||
session,
|
session,
|
||||||
this,
|
this,
|
||||||
queryParameters,
|
queryParameters,
|
||||||
returnTypes,
|
rowReader
|
||||||
holderInstantiator
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
//noinspection unchecked
|
||||||
return new ScrollableResultsImpl(
|
return new ScrollableResultsImpl(
|
||||||
rs,
|
rs,
|
||||||
st,
|
st,
|
||||||
session,
|
session,
|
||||||
this,
|
this,
|
||||||
queryParameters,
|
queryParameters,
|
||||||
returnTypes,
|
rowReader
|
||||||
holderInstantiator
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import java.util.Set;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.LockMode;
|
import org.hibernate.LockMode;
|
||||||
import org.hibernate.LockOptions;
|
import org.hibernate.LockOptions;
|
||||||
|
import org.hibernate.NotYetImplementedFor6Exception;
|
||||||
import org.hibernate.QueryException;
|
import org.hibernate.QueryException;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.cache.spi.QueryKey;
|
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.QueryParameters;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
import org.hibernate.hql.internal.HolderInstantiator;
|
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||||
import org.hibernate.loader.CollectionAliases;
|
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.Loadable;
|
||||||
import org.hibernate.persister.entity.Queryable;
|
import org.hibernate.persister.entity.Queryable;
|
||||||
import org.hibernate.query.spi.ScrollableResultsImplementor;
|
import org.hibernate.query.spi.ScrollableResultsImplementor;
|
||||||
|
import org.hibernate.sql.results.spi.RowReader;
|
||||||
import org.hibernate.transform.ResultTransformer;
|
import org.hibernate.transform.ResultTransformer;
|
||||||
import org.hibernate.type.CollectionType;
|
import org.hibernate.type.CollectionType;
|
||||||
import org.hibernate.type.EntityType;
|
import org.hibernate.type.EntityType;
|
||||||
|
@ -376,16 +377,11 @@ public class CustomLoader extends Loader {
|
||||||
|
|
||||||
ResultTransformer resultTransformer = queryParameters.getResultTransformer();
|
ResultTransformer resultTransformer = queryParameters.getResultTransformer();
|
||||||
|
|
||||||
HolderInstantiator holderInstantiator = ( resultTransformer == null ) ?
|
throw new NotYetImplementedFor6Exception( getClass() );
|
||||||
HolderInstantiator.NOOP_INSTANTIATOR :
|
|
||||||
new HolderInstantiator( resultTransformer, this::getReturnAliasesForTransformer );
|
|
||||||
|
|
||||||
return scroll(
|
// final RowReader rowReader = ...;
|
||||||
queryParameters,
|
//
|
||||||
resultTypes,
|
// return scroll( queryParameters, resultTypes, rowReader, session );
|
||||||
holderInstantiator,
|
|
||||||
session
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,7 +13,11 @@ import org.hibernate.query.Query;
|
||||||
/**
|
/**
|
||||||
* Specialization of DomainType for types that can be used as {@link Query} parameter bind values
|
* 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
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.hibernate.procedure.spi.ParameterStrategy;
|
||||||
import org.hibernate.procedure.spi.ProcedureParameterImplementor;
|
import org.hibernate.procedure.spi.ProcedureParameterImplementor;
|
||||||
import org.hibernate.query.spi.ParameterMetadataImplementor;
|
import org.hibernate.query.spi.ParameterMetadataImplementor;
|
||||||
import org.hibernate.query.spi.QueryParameterImplementor;
|
import org.hibernate.query.spi.QueryParameterImplementor;
|
||||||
|
import org.hibernate.sql.ast.Clause;
|
||||||
import org.hibernate.sql.exec.spi.JdbcCall;
|
import org.hibernate.sql.exec.spi.JdbcCall;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,14 +73,14 @@ public class StandardCallableStatementSupport implements CallableStatementSuppor
|
||||||
sep = ",";
|
sep = ",";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final int jdbcTypeCount = parameter.getHibernateType().getJdbcTypeCount(
|
parameter.getHibernateType().visitJdbcTypes(
|
||||||
|
sqlExpressableType -> {
|
||||||
|
buffer.append( sep ).append( "?" );
|
||||||
|
sep = ",";
|
||||||
|
},
|
||||||
|
Clause.IRRELEVANT,
|
||||||
session.getFactory().getTypeConfiguration()
|
session.getFactory().getTypeConfiguration()
|
||||||
);
|
);
|
||||||
|
|
||||||
for ( int i = 0; i < jdbcTypeCount; i++ ) {
|
|
||||||
buffer.append( sep ).append( "?" );
|
|
||||||
sep = ",";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
||||||
|
* <p>
|
||||||
|
* Note that depending on the cache strategy implementation chosen, clearing the cache might not reclaim all the
|
||||||
|
* memory.
|
||||||
|
* <p>
|
||||||
|
* 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();
|
||||||
|
}
|
|
@ -78,6 +78,10 @@ public class SqmFieldLiteral<T> implements SqmExpression<T>, SqmExpressable<T>,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JavaTypeDescriptor<T> getExpressableJavaTypeDescriptor() {
|
public JavaTypeDescriptor<T> getExpressableJavaTypeDescriptor() {
|
||||||
|
if ( expressable == this ) {
|
||||||
|
return fieldOwnerJavaTypeDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
return expressable.getExpressableJavaTypeDescriptor();
|
return expressable.getExpressableJavaTypeDescriptor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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<R> {
|
||||||
|
/**
|
||||||
|
* 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<R> getResultJavaType();
|
||||||
|
|
||||||
|
List<Initializer> 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);
|
||||||
|
}
|
|
@ -36,7 +36,7 @@ public class SharedCacheModesTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
Session session;
|
Session session;
|
||||||
|
|
||||||
em = getOrCreateEntityManager();
|
em = getOrCreateEntityManager();
|
||||||
session = ( (HibernateEntityManager) em ).getSession();
|
session = em.unwrap( Session.class );
|
||||||
|
|
||||||
// defaults...
|
// defaults...
|
||||||
assertEquals( CacheStoreMode.USE, em.getProperties().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
|
assertEquals( CacheStoreMode.USE, em.getProperties().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
|
||||||
|
|
|
@ -15,6 +15,7 @@ import java.util.Date;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.jpa.HibernateEntityManager;
|
import org.hibernate.jpa.HibernateEntityManager;
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
@ -65,7 +66,7 @@ public class EntityManagerFactorySerializationTest extends BaseEntityManagerFunc
|
||||||
//em.getTransaction().commit();
|
//em.getTransaction().commit();
|
||||||
|
|
||||||
//fake the in container work
|
//fake the in container work
|
||||||
( (HibernateEntityManager) em ).getSession().disconnect();
|
em.unwrap( Session.class ).disconnect();
|
||||||
stream = new ByteArrayOutputStream();
|
stream = new ByteArrayOutputStream();
|
||||||
out = new ObjectOutputStream( stream );
|
out = new ObjectOutputStream( stream );
|
||||||
out.writeObject( em );
|
out.writeObject( em );
|
||||||
|
|
|
@ -15,6 +15,7 @@ import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
import org.hibernate.jpa.HibernateEntityManager;
|
import org.hibernate.jpa.HibernateEntityManager;
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.jpa.test.Cat;
|
import org.hibernate.jpa.test.Cat;
|
||||||
|
@ -52,7 +53,7 @@ public class EntityManagerSerializationTest extends BaseEntityManagerFunctionalT
|
||||||
//em.getTransaction().commit();
|
//em.getTransaction().commit();
|
||||||
|
|
||||||
//fake the in container work
|
//fake the in container work
|
||||||
( (HibernateEntityManager) em ).getSession().disconnect();
|
em.unwrap( Session.class ).disconnect();
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
ObjectOutput out = new ObjectOutputStream( stream );
|
ObjectOutput out = new ObjectOutputStream( stream );
|
||||||
out.writeObject( em );
|
out.writeObject( em );
|
||||||
|
|
|
@ -13,10 +13,10 @@ import javax.persistence.SharedCacheMode;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
|
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.jpa.AvailableSettings;
|
import org.hibernate.jpa.AvailableSettings;
|
||||||
import org.hibernate.jpa.HibernateEntityManagerFactory;
|
import org.hibernate.jpa.HibernateEntityManagerFactory;
|
||||||
import org.hibernate.jpa.QueryHints;
|
import org.hibernate.jpa.QueryHints;
|
||||||
import org.hibernate.jpa.spi.HibernateEntityManagerImplementor;
|
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.stat.Statistics;
|
import org.hibernate.stat.Statistics;
|
||||||
|
|
||||||
|
@ -130,9 +130,8 @@ public class CachedQueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em = getOrCreateEntityManager();
|
em = getOrCreateEntityManager();
|
||||||
|
|
||||||
em.getEntityManagerFactory().getCache().evictAll();
|
em.getEntityManagerFactory().getCache().evictAll();
|
||||||
em.unwrap( HibernateEntityManagerImplementor.class )
|
em.unwrap( SessionImplementor.class )
|
||||||
.getFactory()
|
.getFactory()
|
||||||
.getSessionFactory()
|
|
||||||
.getCache()
|
.getCache()
|
||||||
.evictQueryRegions();
|
.evictQueryRegions();
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ import org.hibernate.annotations.NaturalId;
|
||||||
import org.hibernate.annotations.NaturalIdCache;
|
import org.hibernate.annotations.NaturalIdCache;
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.engine.spi.CacheImplementor;
|
|
||||||
import org.hibernate.metamodel.model.domain.NavigableRole;
|
import org.hibernate.metamodel.model.domain.NavigableRole;
|
||||||
import org.hibernate.stat.NaturalIdCacheStatistics;
|
import org.hibernate.stat.NaturalIdCacheStatistics;
|
||||||
import org.hibernate.stat.SecondLevelCacheStatistics;
|
import org.hibernate.stat.SecondLevelCacheStatistics;
|
||||||
|
@ -31,7 +30,6 @@ import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test API and SPI expectation wrt region names - whether they expect the
|
* Test API and SPI expectation wrt region names - whether they expect the
|
||||||
|
@ -136,36 +134,6 @@ public class RegionNameTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
// sessionFactory().getCache().evictQueryRegions();
|
// 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" )
|
@Entity( name = "Person" )
|
||||||
@Table( name = "persons" )
|
@Table( name = "persons" )
|
||||||
|
|
|
@ -6,45 +6,55 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.jpa;
|
package org.hibernate.test.jpa;
|
||||||
|
|
||||||
|
import javax.persistence.metamodel.Metamodel;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
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.SessionImplementor;
|
||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
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
|
* @author Chris Cranford
|
||||||
*/
|
*/
|
||||||
public class EntityManagerUnwrapTest extends BaseEntityManagerFunctionalTestCase {
|
public class EntityManagerUnwrapTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
@Test
|
@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() {
|
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
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-13281")
|
public void testUnwrapSessionFactory() {
|
||||||
public void testUnwrapSharedSessionContractImplementor() {
|
entityManagerFactory().unwrap( SessionFactory.class );
|
||||||
SharedSessionContractImplementor session = getOrCreateEntityManager().unwrap( SharedSessionContractImplementor.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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue