some cleanup around SessionFactoryImplementor
Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
67bd785add
commit
519ffb7c78
|
@ -39,7 +39,6 @@ import org.hibernate.engine.jdbc.spi.JdbcServices;
|
|||
import org.hibernate.engine.profile.FetchProfile;
|
||||
import org.hibernate.event.spi.EventEngine;
|
||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.internal.FastSessionServices;
|
||||
import org.hibernate.metamodel.model.domain.spi.JpaMetamodelImplementor;
|
||||
import org.hibernate.metamodel.spi.MetamodelImplementor;
|
||||
|
@ -205,12 +204,7 @@ public class SessionFactoryDelegatingImpl implements SessionFactoryImplementor,
|
|||
return delegate.getDefinedFetchProfileNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierGenerator getIdentifierGenerator(String rootEntityName) {
|
||||
return delegate.getIdentifierGenerator( rootEntityName );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override @Deprecated
|
||||
public Generator getGenerator(String rootEntityName) {
|
||||
return delegate.getGenerator( rootEntityName );
|
||||
}
|
||||
|
|
|
@ -20,14 +20,11 @@ import org.hibernate.engine.jdbc.spi.JdbcServices;
|
|||
import org.hibernate.engine.profile.FetchProfile;
|
||||
import org.hibernate.event.spi.EventEngine;
|
||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.internal.FastSessionServices;
|
||||
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
|
||||
import org.hibernate.metamodel.spi.MetamodelImplementor;
|
||||
import org.hibernate.metamodel.spi.RuntimeMetamodelsImplementor;
|
||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||
import org.hibernate.query.BindableType;
|
||||
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
|
||||
import org.hibernate.query.spi.QueryEngine;
|
||||
import org.hibernate.query.spi.QueryParameterBindingTypeResolver;
|
||||
import org.hibernate.query.sqm.spi.SqmCreationContext;
|
||||
|
@ -53,34 +50,38 @@ public interface SessionFactoryImplementor
|
|||
extends Mapping, SessionFactory, SqmCreationContext, SqlAstCreationContext,
|
||||
QueryParameterBindingTypeResolver { //deprecated extension, use MappingMetamodel
|
||||
/**
|
||||
* Get the UUID for this SessionFactory.
|
||||
* Get the UUID for this {@code SessionFactory}.
|
||||
* <p>
|
||||
* The value is generated as a {@link java.util.UUID}, but kept as a String.
|
||||
*
|
||||
* @return The UUID for this SessionFactory.
|
||||
* @return The UUID for this {@code SessionFactory}.
|
||||
*
|
||||
* @see org.hibernate.internal.SessionFactoryRegistry#getSessionFactory
|
||||
*/
|
||||
String getUuid();
|
||||
|
||||
/**
|
||||
* Access to the name (if one) assigned to the SessionFactory
|
||||
* Access to the name (if one) assigned to the {@code SessionFactory}
|
||||
*
|
||||
* @return The name for the SessionFactory
|
||||
* @return The name for the {@code SessionFactory}
|
||||
*/
|
||||
@Override
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Overrides {@link SessionFactory#openSession()} to widen the return type:
|
||||
* this is useful for internal code depending on {@link SessionFactoryImplementor}
|
||||
* as it would otherwise need to frequently resort to casting to the internal contract.
|
||||
* @return the opened Session.
|
||||
*
|
||||
* @return the opened {@code Session}.
|
||||
*/
|
||||
@Override
|
||||
SessionImplementor openSession();
|
||||
|
||||
@Override
|
||||
TypeConfiguration getTypeConfiguration();
|
||||
|
||||
@Override
|
||||
default SessionFactoryImplementor getSessionFactory() {
|
||||
return this;
|
||||
}
|
||||
|
@ -90,10 +91,8 @@ public interface SessionFactoryImplementor
|
|||
return getRuntimeMetamodels().getMappingMetamodel();
|
||||
}
|
||||
|
||||
QueryEngine getQueryEngine();
|
||||
|
||||
@Override
|
||||
HibernateCriteriaBuilder getCriteriaBuilder();
|
||||
QueryEngine getQueryEngine();
|
||||
|
||||
@Override
|
||||
SessionBuilderImplementor withOptions();
|
||||
|
@ -112,10 +111,11 @@ public interface SessionFactoryImplementor
|
|||
RuntimeMetamodelsImplementor getRuntimeMetamodels();
|
||||
|
||||
/**
|
||||
* Access to the ServiceRegistry for this SessionFactory.
|
||||
* Access to the {@code ServiceRegistry} for this {@code SessionFactory}.
|
||||
*
|
||||
* @return The factory's ServiceRegistry
|
||||
*/
|
||||
@Override
|
||||
ServiceRegistryImplementor getServiceRegistry();
|
||||
|
||||
/**
|
||||
|
@ -133,7 +133,10 @@ public interface SessionFactoryImplementor
|
|||
|
||||
/**
|
||||
* Get the identifier generator for the hierarchy
|
||||
*
|
||||
* @deprecated Only used in one place, will be removed
|
||||
*/
|
||||
@Deprecated(since = "7", forRemoval = true)
|
||||
Generator getGenerator(String rootEntityName);
|
||||
|
||||
EntityNotFoundDelegate getEntityNotFoundDelegate();
|
||||
|
@ -154,35 +157,28 @@ public interface SessionFactoryImplementor
|
|||
JavaType<Object> getTenantIdentifierJavaType();
|
||||
|
||||
/**
|
||||
* @return the FastSessionServices instance associated with this SessionFactory
|
||||
* @return the {@link FastSessionServices} instance associated with this SessionFactory
|
||||
*/
|
||||
FastSessionServices getFastSessionServices();
|
||||
|
||||
WrapperOptions getWrapperOptions();
|
||||
|
||||
@Override
|
||||
SessionFactoryOptions getSessionFactoryOptions();
|
||||
|
||||
@Override
|
||||
FilterDefinition getFilterDefinition(String filterName);
|
||||
|
||||
Collection<FilterDefinition> getAutoEnabledFilters();
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the JdbcServices.
|
||||
*
|
||||
* @return the JdbcServices
|
||||
*/
|
||||
JdbcServices getJdbcServices();
|
||||
|
||||
SqlStringGenerationContext getSqlStringGenerationContext();
|
||||
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// map these to Metamodel
|
||||
|
||||
@Override
|
||||
RootGraphImplementor<?> findEntityGraphByName(String name);
|
||||
|
||||
/**
|
||||
|
@ -193,30 +189,9 @@ public interface SessionFactoryImplementor
|
|||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Deprecations
|
||||
|
||||
/**
|
||||
* Get the identifier generator for the hierarchy
|
||||
*
|
||||
* @deprecated use {@link #getGenerator(String)}
|
||||
*/
|
||||
@Deprecated(since = "6.2")
|
||||
IdentifierGenerator getIdentifierGenerator(String rootEntityName);
|
||||
|
||||
/**
|
||||
* @deprecated no longer for internal use, use {@link #getMappingMetamodel()} or {@link #getJpaMetamodel()}
|
||||
*/
|
||||
@Override @Deprecated
|
||||
MetamodelImplementor getMetamodel();
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getMappingMetamodel()}.{@link MappingMetamodelImplementor#resolveParameterBindType(Object)}
|
||||
*/
|
||||
@Override @Deprecated(since = "6.2", forRemoval = true)
|
||||
<T> BindableType<? super T> resolveParameterBindType(T bindValue);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getMappingMetamodel()}.{@link MappingMetamodelImplementor#resolveParameterBindType(Class)}
|
||||
*/
|
||||
@Override @Deprecated(since = "6.2", forRemoval = true)
|
||||
<T> BindableType<T> resolveParameterBindType(Class<T> clazz);
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import org.hibernate.Interceptor;
|
|||
import org.hibernate.StatelessSession;
|
||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.graph.GraphSemantic;
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.SharedSessionContract;
|
||||
import org.hibernate.Transaction;
|
||||
|
|
|
@ -73,7 +73,6 @@ import org.hibernate.event.spi.EventEngine;
|
|||
import org.hibernate.generator.Generator;
|
||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||
import org.hibernate.id.Configurable;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.integrator.spi.IntegratorService;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
@ -657,6 +656,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
|||
getCache().prime( regionConfigs );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SessionImplementor openSession() throws HibernateException {
|
||||
//The defaultSessionOpenOptions can't be used in some cases; for example when using a TenantIdentifierResolver.
|
||||
if ( defaultSessionOpenOptions != null ) {
|
||||
|
@ -678,6 +678,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Session getCurrentSession() throws HibernateException {
|
||||
if ( currentSessionContext == null ) {
|
||||
throw new HibernateException( "No CurrentSessionContext configured" );
|
||||
|
@ -695,6 +696,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
|||
return new StatelessSessionBuilderImpl( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatelessSession openStatelessSession() {
|
||||
if ( this.defaultStatelessOptions != null ) {
|
||||
return this.defaultStatelessOptions.openStatelessSession();
|
||||
|
@ -704,6 +706,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatelessSession openStatelessSession(Connection connection) {
|
||||
return withStatelessOptions().connection( connection ).openStatelessSession();
|
||||
}
|
||||
|
@ -897,13 +900,17 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getIdentifierType(String className) throws MappingException {
|
||||
return runtimeMetamodels.getMappingMetamodel().getEntityDescriptor( className ).getIdentifierType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifierPropertyName(String className) throws MappingException {
|
||||
return runtimeMetamodels.getMappingMetamodel().getEntityDescriptor( className ).getIdentifierPropertyName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getReferencedPropertyType(String className, String propertyName) throws MappingException {
|
||||
return runtimeMetamodels.getMappingMetamodel().getEntityDescriptor( className ).getPropertyType( propertyName );
|
||||
}
|
||||
|
@ -984,6 +991,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
|||
serviceRegistry.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheImplementor getCache() {
|
||||
validateNotClosed();
|
||||
return cacheAccess;
|
||||
|
@ -1150,10 +1158,12 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
|||
return autoEnabledFilters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsFetchProfileDefinition(String name) {
|
||||
return fetchProfiles.containsKey( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getDefinedFilterNames() {
|
||||
return unmodifiableSet( filters.keySet() );
|
||||
}
|
||||
|
@ -1163,12 +1173,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
|||
return unmodifiableSet( fetchProfiles.keySet() );
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public IdentifierGenerator getIdentifierGenerator(String rootEntityName) {
|
||||
return (IdentifierGenerator) getGenerator( rootEntityName );
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override @Deprecated
|
||||
public Generator getGenerator(String rootEntityName) {
|
||||
return identifierGenerators.get( rootEntityName );
|
||||
}
|
||||
|
@ -1250,6 +1255,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
|||
return sessionFactoryOptions.getEntityNotFoundDelegate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchProfile getFetchProfile(String name) {
|
||||
return fetchProfiles.get( name );
|
||||
}
|
||||
|
|
|
@ -1651,12 +1651,9 @@ public class SessionImpl
|
|||
object = lazyInitializer.getImplementation();
|
||||
}
|
||||
final EntityEntry entry = persistenceContext.getEntry( object );
|
||||
if ( entry == null ) {
|
||||
return guessEntityName( object );
|
||||
}
|
||||
else {
|
||||
return entry.getPersister().getEntityName();
|
||||
}
|
||||
return entry == null
|
||||
? guessEntityName( object )
|
||||
: entry.getPersister().getEntityName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1670,12 +1667,9 @@ public class SessionImpl
|
|||
}
|
||||
object = lazyInitializer.getImplementation();
|
||||
}
|
||||
if ( entry == null ) {
|
||||
return guessEntityName( object );
|
||||
}
|
||||
else {
|
||||
return entry.getPersister().getEntityName();
|
||||
}
|
||||
return entry == null
|
||||
? guessEntityName( object )
|
||||
: entry.getPersister().getEntityName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1690,7 +1684,7 @@ public class SessionImpl
|
|||
object = lazyInitializer.getImplementation();
|
||||
}
|
||||
|
||||
EntityEntry entry = persistenceContext.getEntry( object );
|
||||
final EntityEntry entry = persistenceContext.getEntry( object );
|
||||
if ( entry == null ) {
|
||||
throwTransientObjectException( object );
|
||||
}
|
||||
|
@ -1705,7 +1699,7 @@ public class SessionImpl
|
|||
return (T) getReference( lazyInitializer.getPersistentClass(), lazyInitializer.getIdentifier() );
|
||||
}
|
||||
else {
|
||||
EntityPersister persister = getEntityPersister( null, object );
|
||||
final EntityPersister persister = getEntityPersister( null, object );
|
||||
return (T) getReference( persister.getMappedClass(), persister.getIdentifier(object, this) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -269,13 +269,9 @@ public class DiscriminatedAssociationAttributeMapping
|
|||
}
|
||||
|
||||
private EntityMappingType determineConcreteType(Object entity, SharedSessionContractImplementor session) {
|
||||
final String entityName;
|
||||
if ( session == null ) {
|
||||
entityName = sessionFactory.bestGuessEntityName( entity );
|
||||
}
|
||||
else {
|
||||
entityName = session.bestGuessEntityName( entity );
|
||||
}
|
||||
final String entityName = session == null
|
||||
? sessionFactory.bestGuessEntityName( entity )
|
||||
: session.bestGuessEntityName( entity );
|
||||
return sessionFactory
|
||||
.getRuntimeMetamodels()
|
||||
.getEntityMappingType( entityName );
|
||||
|
|
|
@ -230,13 +230,9 @@ public class DiscriminatedAssociationMapping implements MappingType, FetchOption
|
|||
}
|
||||
|
||||
private EntityMappingType determineConcreteType(Object entity, SharedSessionContractImplementor session) {
|
||||
final String entityName;
|
||||
if ( session == null ) {
|
||||
entityName = sessionFactory.bestGuessEntityName( entity );
|
||||
}
|
||||
else {
|
||||
entityName = session.bestGuessEntityName( entity );
|
||||
}
|
||||
final String entityName = session == null
|
||||
? sessionFactory.bestGuessEntityName( entity )
|
||||
: session.bestGuessEntityName( entity );
|
||||
return sessionFactory
|
||||
.getRuntimeMetamodels()
|
||||
.getEntityMappingType( entityName );
|
||||
|
|
|
@ -35,6 +35,8 @@ import org.hibernate.annotations.GenericGenerator;
|
|||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
|
||||
import org.hibernate.generator.BeforeExecutionGenerator;
|
||||
import org.hibernate.generator.EventType;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
|
@ -125,8 +127,8 @@ public class PooledHiLoSequenceIdentifierTest {
|
|||
statement = connection.prepareStatement( "INSERT INTO sequenceIdentifier VALUES (?,?)" );
|
||||
statement.setObject(
|
||||
1,
|
||||
sfi.getIdentifierGenerator( SequenceIdentifier.class.getName() )
|
||||
.generate( si, null )
|
||||
((BeforeExecutionGenerator) sfi.getGenerator( SequenceIdentifier.class.getName() ))
|
||||
.generate( si, null, null, EventType.INSERT )
|
||||
);
|
||||
statement.setString( 2,"name" );
|
||||
statement.executeUpdate();
|
||||
|
|
Loading…
Reference in New Issue