split out SessionFactoryRegistryMessageLogger
Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
f6ff6fa0f7
commit
049610b90d
|
@ -23,7 +23,7 @@ public class CoreLogging {
|
|||
private CoreLogging() {
|
||||
}
|
||||
|
||||
public static CoreMessageLogger messageLogger(Class classNeedingLogging) {
|
||||
public static CoreMessageLogger messageLogger(Class<?> classNeedingLogging) {
|
||||
return messageLogger( classNeedingLogging.getName() );
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public class CoreLogging {
|
|||
return Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, loggerName );
|
||||
}
|
||||
|
||||
public static Logger logger(Class classNeedingLogging) {
|
||||
public static Logger logger(Class<?> classNeedingLogging) {
|
||||
return Logger.getLogger( classNeedingLogging );
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ import java.sql.SQLWarning;
|
|||
import java.util.Properties;
|
||||
import java.util.ServiceConfigurationError;
|
||||
import java.util.Set;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.JDBCException;
|
||||
|
@ -22,8 +21,6 @@ import org.hibernate.LockMode;
|
|||
import org.hibernate.cache.CacheException;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.jdbc.env.internal.LobCreationLogging;
|
||||
import org.hibernate.engine.jndi.JndiException;
|
||||
import org.hibernate.engine.jndi.JndiNameException;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.id.IntegralDataTypeHolder;
|
||||
import org.hibernate.service.Service;
|
||||
|
@ -194,22 +191,6 @@ public interface CoreMessageLogger extends BasicLogger {
|
|||
void expectedType(String name,
|
||||
@Nullable String string);
|
||||
|
||||
@LogMessage(level = INFO)
|
||||
@Message(value = "Bound factory to JNDI name: %s", id = 94)
|
||||
void factoryBoundToJndiName(String name);
|
||||
|
||||
@LogMessage(level = INFO)
|
||||
@Message(value = "A factory was renamed from [%s] to [%s] in JNDI", id = 96)
|
||||
void factoryJndiRename(String oldName, String newName);
|
||||
|
||||
@LogMessage(level = INFO)
|
||||
@Message(value = "Unbound factory from JNDI name: %s", id = 97)
|
||||
void factoryUnboundFromJndiName(String name);
|
||||
|
||||
@LogMessage(level = INFO)
|
||||
@Message(value = "A factory was unbound from name: %s", id = 98)
|
||||
void factoryUnboundFromName(String name);
|
||||
|
||||
@LogMessage(level = ERROR)
|
||||
@Message(value = "an assertion failure occurred" + " (this may indicate a bug in Hibernate, but is more likely due"
|
||||
+ " to unsafe use of the session): %s", id = 99)
|
||||
|
@ -261,10 +242,6 @@ public interface CoreMessageLogger extends BasicLogger {
|
|||
@Message(value = "IllegalArgumentException in class: %s, setter method of property: %s", id = 123)
|
||||
void illegalPropertySetterArgument(String name, String propertyName);
|
||||
|
||||
@LogMessage(level = DEBUG)
|
||||
@Message(value = "Could not bind JNDI listener", id = 127)
|
||||
void couldNotBindJndiListener();
|
||||
|
||||
@LogMessage(level = INFO)
|
||||
@Message(value = "Instantiating explicit connection provider: %s", id = 130)
|
||||
void instantiatingExplicitConnectionProvider(String providerClassName);
|
||||
|
@ -273,10 +250,6 @@ public interface CoreMessageLogger extends BasicLogger {
|
|||
@Message(value = "Array element type error\n%s", id = 132)
|
||||
void invalidArrayElementType(String message);
|
||||
|
||||
@LogMessage(level = ERROR)
|
||||
@Message(value = "Invalid JNDI name: %s", id = 135)
|
||||
void invalidJndiName(String name, @Cause JndiNameException e);
|
||||
|
||||
@LogMessage(level = INFO)
|
||||
@Message(value = "java.sql.Types mapped the same code [%s] multiple times; was [%s]; now [%s]", id = 141)
|
||||
void JavaSqlTypesMappedSameCodeMultipleTimes(int code, String old, String name);
|
||||
|
@ -299,10 +272,6 @@ public interface CoreMessageLogger extends BasicLogger {
|
|||
int anticipatedNumberOfArguments,
|
||||
int numberOfArguments);
|
||||
|
||||
@LogMessage(level = WARN)
|
||||
@Message(value = "Naming exception occurred accessing factory: %s", id = 178)
|
||||
void namingExceptionAccessingFactory(NamingException exception);
|
||||
|
||||
@LogMessage(level = WARN)
|
||||
@Message(value = "Narrowing proxy to %s - this operation breaks ==", id = 179)
|
||||
void narrowingProxy(Class<?> concreteProxyClass);
|
||||
|
@ -471,10 +440,6 @@ public interface CoreMessageLogger extends BasicLogger {
|
|||
@Message(value = "Unable to apply constraints on DDL for %s", id = 274)
|
||||
void unableToApplyConstraints(String className, @Cause Exception e);
|
||||
|
||||
@LogMessage(level = WARN)
|
||||
@Message(value = "Could not bind factory to JNDI", id = 277)
|
||||
void unableToBindFactoryToJndi(@Cause JndiException e);
|
||||
|
||||
@LogMessage(level = WARN)
|
||||
@Message(value = "Unable to cleanup temporary id table after use [%s]", id = 283)
|
||||
void unableToCleanupTemporaryIdTable(Throwable t);
|
||||
|
@ -623,10 +588,6 @@ public interface CoreMessageLogger extends BasicLogger {
|
|||
@Message(value = "Error stopping service [%s]", id = 369)
|
||||
void unableToStopService(Class<? extends Service> class1, @Cause Exception e);
|
||||
|
||||
@LogMessage(level = WARN)
|
||||
@Message(value = "Could not unbind factory from JNDI", id = 374)
|
||||
void unableToUnbindFactoryFromJndi(@Cause JndiException e);
|
||||
|
||||
@LogMessage(level = ERROR)
|
||||
@Message(value = "Could not updateQuery hi value in: %s", id = 376)
|
||||
void unableToUpdateQueryHiValue(String tableName, @Cause SQLException e);
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.internal;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.jboss.logging.annotations.Cause;
|
||||
import org.jboss.logging.annotations.LogMessage;
|
||||
import org.jboss.logging.annotations.Message;
|
||||
import org.jboss.logging.annotations.MessageLogger;
|
||||
|
@ -17,7 +13,6 @@ import org.jboss.logging.annotations.ValidIdRange;
|
|||
|
||||
import static org.jboss.logging.Logger.Level.DEBUG;
|
||||
import static org.jboss.logging.Logger.Level.ERROR;
|
||||
import static org.jboss.logging.Logger.Level.INFO;
|
||||
import static org.jboss.logging.Logger.Level.WARN;
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,7 +21,8 @@ import org.hibernate.engine.jndi.JndiException;
|
|||
import org.hibernate.engine.jndi.JndiNameException;
|
||||
import org.hibernate.engine.jndi.spi.JndiService;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
|
||||
|
||||
/**
|
||||
* A registry of all {@link SessionFactory} instances for the same classloader as this class.
|
||||
|
@ -31,7 +32,7 @@ import org.hibernate.internal.util.StringHelper;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SessionFactoryRegistry {
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( SessionFactoryRegistry.class );
|
||||
private static final SessionFactoryRegistryMessageLogger LOG = SessionFactoryRegistryMessageLogger.INSTANCE;
|
||||
|
||||
/**
|
||||
* Singleton access
|
||||
|
@ -71,14 +72,14 @@ public class SessionFactoryRegistry {
|
|||
throw new IllegalArgumentException( "SessionFactory UUID cannot be null" );
|
||||
}
|
||||
|
||||
LOG.debugf( "Registering SessionFactory: %s (%s)", uuid, name == null ? "<unnamed>" : name );
|
||||
LOG.registeringSessionFactory( uuid, name == null ? "<unnamed>" : name );
|
||||
sessionFactoryMap.put( uuid, instance );
|
||||
if ( name != null ) {
|
||||
nameUuidXref.put( name, uuid );
|
||||
}
|
||||
|
||||
if ( jndiName == null ) {
|
||||
LOG.debug( "Not binding SessionFactory to JNDI, no JNDI name configured" );
|
||||
LOG.notBindingSessionFactory();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -87,7 +88,7 @@ public class SessionFactoryRegistry {
|
|||
|
||||
private void bindToJndi(String jndiName, SessionFactoryImplementor instance, JndiService jndiService) {
|
||||
try {
|
||||
LOG.debugf( "Attempting to bind SessionFactory [%s] to JNDI", jndiName );
|
||||
LOG.attemptingToBindFactoryToJndi( jndiName );
|
||||
jndiService.bind( jndiName, instance );
|
||||
LOG.factoryBoundToJndiName( jndiName );
|
||||
try {
|
||||
|
@ -124,7 +125,7 @@ public class SessionFactoryRegistry {
|
|||
|
||||
if ( jndiName != null ) {
|
||||
try {
|
||||
LOG.tracef( "Unbinding SessionFactory from JNDI : %s", jndiName );
|
||||
LOG.attemptingToUnbindFactoryFromJndi( jndiName );
|
||||
jndiService.unbind( jndiName );
|
||||
LOG.factoryUnboundFromJndiName( jndiName );
|
||||
}
|
||||
|
@ -164,17 +165,15 @@ public class SessionFactoryRegistry {
|
|||
}
|
||||
|
||||
public SessionFactoryImplementor findSessionFactory(String uuid, String name) {
|
||||
SessionFactoryImplementor sessionFactory = getSessionFactory( uuid );
|
||||
if ( sessionFactory == null && StringHelper.isNotEmpty( name ) ) {
|
||||
sessionFactory = getNamedSessionFactory( name );
|
||||
}
|
||||
return sessionFactory;
|
||||
final SessionFactoryImplementor sessionFactory = getSessionFactory( uuid );
|
||||
return sessionFactory == null && isNotEmpty( name )
|
||||
? getNamedSessionFactory( name )
|
||||
: sessionFactory;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this registry currently contain registrations?
|
||||
*
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean hasRegistrations() {
|
||||
return !sessionFactoryMap.isEmpty();
|
||||
|
@ -200,7 +199,7 @@ public class SessionFactoryRegistry {
|
|||
@Override
|
||||
public void objectAdded(NamingEvent evt) {
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
LOG.debugf( "A factory was successfully bound to name: %s", evt.getNewBinding().getName() );
|
||||
LOG.factoryBoundToJndi( evt.getNewBinding().getName() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,16 +222,13 @@ public class SessionFactoryRegistry {
|
|||
public void objectRenamed(NamingEvent evt) {
|
||||
final String oldJndiName = evt.getOldBinding().getName();
|
||||
final String newJndiName = evt.getNewBinding().getName();
|
||||
|
||||
LOG.factoryJndiRename( oldJndiName, newJndiName );
|
||||
|
||||
final String uuid = nameUuidXref.remove( oldJndiName );
|
||||
nameUuidXref.put( newJndiName, uuid );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void namingExceptionThrown(NamingExceptionEvent evt) {
|
||||
//noinspection ThrowableResultOfMethodCallIgnored
|
||||
LOG.namingExceptionAccessingFactory( evt.getException() );
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* 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 org.hibernate.engine.jndi.JndiException;
|
||||
import org.hibernate.engine.jndi.JndiNameException;
|
||||
import org.hibernate.internal.log.SubSystemLogging;
|
||||
import org.jboss.logging.BasicLogger;
|
||||
import org.jboss.logging.annotations.Cause;
|
||||
import org.jboss.logging.annotations.LogMessage;
|
||||
import org.jboss.logging.annotations.Message;
|
||||
import org.jboss.logging.annotations.MessageLogger;
|
||||
import org.jboss.logging.annotations.ValidIdRange;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
|
||||
import static org.jboss.logging.Logger.Level.DEBUG;
|
||||
import static org.jboss.logging.Logger.Level.ERROR;
|
||||
import static org.jboss.logging.Logger.Level.INFO;
|
||||
import static org.jboss.logging.Logger.Level.WARN;
|
||||
import static org.jboss.logging.Logger.getMessageLogger;
|
||||
|
||||
@MessageLogger(projectCode = "HHH")
|
||||
@ValidIdRange( min = 20100, max = 20400 )
|
||||
@SubSystemLogging(
|
||||
name = SessionFactoryRegistryMessageLogger.LOGGER_NAME,
|
||||
description = "Logging related to session factory registry"
|
||||
)
|
||||
public interface SessionFactoryRegistryMessageLogger extends BasicLogger {
|
||||
String LOGGER_NAME = SubSystemLogging.BASE + ".factoryRegistry";
|
||||
|
||||
SessionFactoryRegistryMessageLogger INSTANCE =
|
||||
getMessageLogger( MethodHandles.lookup(), SessionFactoryRegistryMessageLogger.class, LOGGER_NAME );
|
||||
|
||||
@LogMessage(level = WARN)
|
||||
@Message(value = "Naming exception occurred accessing factory: %s", id = 20178)
|
||||
void namingExceptionAccessingFactory(NamingException exception);
|
||||
|
||||
@LogMessage(level = INFO)
|
||||
@Message(value = "Bound factory to JNDI name: %s", id = 20194)
|
||||
void factoryBoundToJndiName(String name);
|
||||
|
||||
@LogMessage(level = INFO)
|
||||
@Message(value = "A factory was renamed from [%s] to [%s] in JNDI", id = 20196)
|
||||
void factoryJndiRename(String oldName, String newName);
|
||||
|
||||
@LogMessage(level = DEBUG)
|
||||
@Message(value = "Could not bind JNDI listener", id = 20127)
|
||||
void couldNotBindJndiListener();
|
||||
|
||||
@LogMessage(level = ERROR)
|
||||
@Message(value = "Invalid JNDI name: %s", id = 20135)
|
||||
void invalidJndiName(String name, @Cause JndiNameException e);
|
||||
|
||||
@LogMessage(level = WARN)
|
||||
@Message(value = "Could not bind factory to JNDI", id = 20277)
|
||||
void unableToBindFactoryToJndi(@Cause JndiException e);
|
||||
|
||||
@LogMessage(level = INFO)
|
||||
@Message(value = "Unbound factory from JNDI name: %s", id = 20197)
|
||||
void factoryUnboundFromJndiName(String name);
|
||||
|
||||
@LogMessage(level = INFO)
|
||||
@Message(value = "A factory was unbound from name: %s", id = 20198)
|
||||
void factoryUnboundFromName(String name);
|
||||
|
||||
@LogMessage(level = WARN)
|
||||
@Message(value = "Could not unbind factory from JNDI", id = 20374)
|
||||
void unableToUnbindFactoryFromJndi(@Cause JndiException e);
|
||||
|
||||
@LogMessage(level = DEBUG)
|
||||
@Message(value = "Registering SessionFactory: %s (%s)", id = 20384)
|
||||
void registeringSessionFactory(String uuid, String name);
|
||||
|
||||
@LogMessage(level = DEBUG)
|
||||
@Message(value = "Attempting to bind SessionFactory [%s] to JNDI", id = 20280)
|
||||
void attemptingToBindFactoryToJndi(String name);
|
||||
|
||||
@LogMessage(level = DEBUG)
|
||||
@Message(value = "Attempting to unbind SessionFactory [%s] from JNDI", id = 20281)
|
||||
void attemptingToUnbindFactoryFromJndi(String name);
|
||||
|
||||
@LogMessage(level = DEBUG)
|
||||
@Message(value = "A SessionFactory was successfully bound to name: %s", id = 20282)
|
||||
void factoryBoundToJndi(String name);
|
||||
|
||||
@LogMessage(level = DEBUG)
|
||||
@Message(value = "Not binding SessionFactory to JNDI, no JNDI name configured", id = 20385)
|
||||
void notBindingSessionFactory();
|
||||
}
|
|
@ -61,7 +61,6 @@ import org.hibernate.query.sqm.SqmExpressible;
|
|||
import org.hibernate.query.sqm.tree.SqmTypedNode;
|
||||
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
||||
import org.hibernate.resource.beans.internal.FallbackBeanInstanceProducer;
|
||||
import org.hibernate.resource.beans.spi.ManagedBean;
|
||||
import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.type.BasicType;
|
||||
|
@ -130,12 +129,11 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
|||
private final transient Map<Integer, Set<String>> jdbcToHibernateTypeContributionMap = new HashMap<>();
|
||||
|
||||
public TypeConfiguration() {
|
||||
this.scope = new Scope( this );
|
||||
|
||||
this.javaTypeRegistry = new JavaTypeRegistry( this );
|
||||
this.jdbcTypeRegistry = new JdbcTypeRegistry( this );
|
||||
this.ddlTypeRegistry = new DdlTypeRegistry( this );
|
||||
this.basicTypeRegistry = new BasicTypeRegistry( this );
|
||||
scope = new Scope( this );
|
||||
javaTypeRegistry = new JavaTypeRegistry( this );
|
||||
jdbcTypeRegistry = new JdbcTypeRegistry( this );
|
||||
ddlTypeRegistry = new DdlTypeRegistry( this );
|
||||
basicTypeRegistry = new BasicTypeRegistry( this );
|
||||
StandardBasicTypes.prime( this );
|
||||
}
|
||||
|
||||
|
@ -277,9 +275,7 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
|||
@Override
|
||||
public void sessionFactoryClosed(SessionFactory factory) {
|
||||
log.tracef( "Handling #sessionFactoryClosed from [%s] for TypeConfiguration", factory );
|
||||
|
||||
scope.unsetSessionFactory( factory );
|
||||
|
||||
// todo (6.0) : finish this
|
||||
// release Database, descriptor Maps, etc... things that are only
|
||||
// valid while the TypeConfiguration is scoped to SessionFactory
|
||||
|
@ -287,7 +283,7 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
|||
|
||||
public void addBasicTypeRegistrationContributions(List<BasicTypeRegistration> contributions) {
|
||||
for ( BasicTypeRegistration basicTypeRegistration : contributions ) {
|
||||
BasicType<?> basicType = basicTypeRegistration.getBasicType();
|
||||
final BasicType<?> basicType = basicTypeRegistration.getBasicType();
|
||||
|
||||
basicTypeRegistry.register(
|
||||
basicType,
|
||||
|
@ -365,9 +361,7 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
|||
}
|
||||
|
||||
try {
|
||||
final Class<?> javaTypeClass =
|
||||
scope.getServiceRegistry().requireService( ClassLoaderService.class )
|
||||
.classForName( name );
|
||||
final Class<?> javaTypeClass = getClassLoaderService().classForName( name );
|
||||
final JavaType<?> jtd = javaTypeRegistry.resolveDescriptor( javaTypeClass );
|
||||
final JdbcType jdbcType = jtd.getRecommendedJdbcType( getCurrentBaseSqlTypeIndicators() );
|
||||
return basicTypeRegistry.resolve( jtd, jdbcType );
|
||||
|
@ -504,7 +498,9 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
|||
else if ( sessionFactory != null ) {
|
||||
return sessionFactory.getServiceRegistry();
|
||||
}
|
||||
return null;
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private JpaCompliance getJpaCompliance() {
|
||||
|
@ -517,10 +513,10 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
|||
return null;
|
||||
}
|
||||
|
||||
private void setMetadataBuildingContext(MetadataBuildingContext metadataBuildingContext) {
|
||||
this.metadataBuildingContext = metadataBuildingContext;
|
||||
if ( metadataBuildingContext != null ) {
|
||||
this.allowExtensionsInCdi = metadataBuildingContext.getBuildingOptions().isAllowExtensionsInCdi();
|
||||
private void setMetadataBuildingContext(MetadataBuildingContext context) {
|
||||
metadataBuildingContext = context;
|
||||
if ( context != null ) {
|
||||
allowExtensionsInCdi = context.getBuildingOptions().isAllowExtensionsInCdi();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -529,18 +525,15 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
|||
if ( sessionFactoryName == null && sessionFactoryUuid == null ) {
|
||||
throw new HibernateException( "TypeConfiguration was not yet scoped to SessionFactory" );
|
||||
}
|
||||
sessionFactory = SessionFactoryRegistry.INSTANCE.findSessionFactory(
|
||||
sessionFactoryUuid,
|
||||
sessionFactoryName
|
||||
);
|
||||
sessionFactory =
|
||||
SessionFactoryRegistry.INSTANCE
|
||||
.findSessionFactory( sessionFactoryUuid, sessionFactoryName );
|
||||
if ( sessionFactory == null ) {
|
||||
throw new HibernateException(
|
||||
"Could not find a SessionFactory [uuid=" + sessionFactoryUuid + ",name=" + sessionFactoryName + "]"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return sessionFactory;
|
||||
}
|
||||
|
||||
|
@ -550,31 +543,32 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
|||
* @param factory The {@link SessionFactory} to which the {@link TypeConfiguration} is being bound
|
||||
*/
|
||||
private void setSessionFactory(SessionFactoryImplementor factory) {
|
||||
if ( this.sessionFactory != null ) {
|
||||
log.scopingTypesToSessionFactoryAfterAlreadyScoped( this.sessionFactory, factory );
|
||||
if ( sessionFactory != null ) {
|
||||
log.scopingTypesToSessionFactoryAfterAlreadyScoped( sessionFactory, factory );
|
||||
}
|
||||
else {
|
||||
this.sessionFactoryUuid = factory.getUuid();
|
||||
this.sessionFactoryName = getFactoryName( factory );
|
||||
sessionFactoryUuid = factory.getUuid();
|
||||
sessionFactoryName = getFactoryName( factory );
|
||||
}
|
||||
this.sessionFactory = factory;
|
||||
sessionFactory = factory;
|
||||
}
|
||||
|
||||
private static String getFactoryName(SessionFactoryImplementor factory) {
|
||||
final String factoryName = factory.getSessionFactoryOptions().getSessionFactoryName();
|
||||
if ( factoryName == null ) {
|
||||
final CfgXmlAccessService cfgXmlAccessService = factory.getServiceRegistry()
|
||||
.requireService( CfgXmlAccessService.class );
|
||||
if ( cfgXmlAccessService.getAggregatedConfig() != null ) {
|
||||
return cfgXmlAccessService.getAggregatedConfig().getSessionFactoryName();
|
||||
}
|
||||
final CfgXmlAccessService cfgXmlAccessService =
|
||||
factory.getServiceRegistry().requireService( CfgXmlAccessService.class );
|
||||
return cfgXmlAccessService.getAggregatedConfig() == null ? null
|
||||
: cfgXmlAccessService.getAggregatedConfig().getSessionFactoryName();
|
||||
}
|
||||
else {
|
||||
return factoryName;
|
||||
}
|
||||
return factoryName;
|
||||
}
|
||||
|
||||
private void unsetSessionFactory(SessionFactory factory) {
|
||||
log.debugf( "Un-scoping TypeConfiguration [%s] from SessionFactory [%s]", this, factory );
|
||||
this.sessionFactory = null;
|
||||
sessionFactory = null;
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -583,14 +577,12 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
|||
private Object readResolve() throws InvalidObjectException {
|
||||
if ( sessionFactory == null ) {
|
||||
if ( sessionFactoryName != null || sessionFactoryUuid != null ) {
|
||||
sessionFactory = SessionFactoryRegistry.INSTANCE.findSessionFactory(
|
||||
sessionFactoryUuid,
|
||||
sessionFactoryName
|
||||
);
|
||||
|
||||
sessionFactory =
|
||||
SessionFactoryRegistry.INSTANCE
|
||||
.findSessionFactory( sessionFactoryUuid, sessionFactoryName );
|
||||
if ( sessionFactory == null ) {
|
||||
throw new HibernateException(
|
||||
"Could not find a SessionFactory [uuid=" + sessionFactoryUuid + ",name=" + sessionFactoryName + "]"
|
||||
throw new HibernateException( "Could not find a SessionFactory [uuid="
|
||||
+ sessionFactoryUuid + ",name=" + sessionFactoryName + "]"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -617,7 +609,7 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
|||
SqmTypedNode<?> tupleElement = typedNodes.get(i);
|
||||
final SqmExpressible<?> sqmExpressible = tupleElement.getNodeType();
|
||||
// keep null value for Named Parameters
|
||||
if (tupleElement instanceof SqmParameter<?> && sqmExpressible == null) {
|
||||
if ( tupleElement instanceof SqmParameter<?> && sqmExpressible == null ) {
|
||||
components[i] = QueryParameterJavaObjectType.INSTANCE;
|
||||
}
|
||||
else {
|
||||
|
@ -736,42 +728,46 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
|||
//noinspection unchecked
|
||||
return (BasicType<J>) existing;
|
||||
}
|
||||
|
||||
final BasicType<J> registeredType = basicTypeRegistry.getRegisteredType( javaType );
|
||||
if ( registeredType != null ) {
|
||||
basicTypeByJavaType.put( javaType, registeredType );
|
||||
return registeredType;
|
||||
else {
|
||||
final BasicType<J> registeredType = basicTypeRegistry.getRegisteredType( javaType );
|
||||
if ( registeredType != null ) {
|
||||
basicTypeByJavaType.put( javaType, registeredType );
|
||||
return registeredType;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public <J> BasicType<J> standardBasicTypeForJavaType(Class<J> javaType) {
|
||||
if ( javaType == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return standardBasicTypeForJavaType(
|
||||
javaType,
|
||||
javaTypeDescriptor -> new BasicTypeImpl<>(
|
||||
javaTypeDescriptor,
|
||||
javaTypeDescriptor.getRecommendedJdbcType( getCurrentBaseSqlTypeIndicators() )
|
||||
)
|
||||
);
|
||||
else {
|
||||
return standardBasicTypeForJavaType(
|
||||
javaType,
|
||||
javaTypeDescriptor -> new BasicTypeImpl<>(
|
||||
javaTypeDescriptor,
|
||||
javaTypeDescriptor.getRecommendedJdbcType( getCurrentBaseSqlTypeIndicators() )
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public BasicType<?> standardBasicTypeForJavaType(Type javaType) {
|
||||
if ( javaType == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return standardBasicTypeForJavaType(
|
||||
javaType,
|
||||
javaTypeDescriptor -> new BasicTypeImpl<>(
|
||||
javaTypeDescriptor,
|
||||
javaTypeDescriptor.getRecommendedJdbcType( getCurrentBaseSqlTypeIndicators() )
|
||||
)
|
||||
);
|
||||
else {
|
||||
return standardBasicTypeForJavaType(
|
||||
javaType,
|
||||
javaTypeDescriptor -> new BasicTypeImpl<>(
|
||||
javaTypeDescriptor,
|
||||
javaTypeDescriptor.getRecommendedJdbcType( getCurrentBaseSqlTypeIndicators() )
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public <J> BasicType<J> standardBasicTypeForJavaType(
|
||||
|
@ -795,9 +791,10 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
|||
if ( registeredType != null ) {
|
||||
return registeredType;
|
||||
}
|
||||
|
||||
// otherwise, apply the creator
|
||||
return creator.apply( javaTypeRegistry.resolveDescriptor( javaType ) );
|
||||
else {
|
||||
// otherwise, apply the creator
|
||||
return creator.apply( javaTypeRegistry.resolveDescriptor( javaType ) );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -819,12 +816,12 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
|||
}
|
||||
|
||||
public static TemporalType getSqlTemporalType(MappingModelExpressible<?> type) {
|
||||
if ( type instanceof BasicValuedMapping ) {
|
||||
return getSqlTemporalType( ( (BasicValuedMapping) type ).getJdbcMapping().getJdbcType() );
|
||||
if ( type instanceof BasicValuedMapping basicValuedMapping ) {
|
||||
return getSqlTemporalType( basicValuedMapping.getJdbcMapping().getJdbcType() );
|
||||
}
|
||||
else if ( type instanceof EmbeddableValuedModelPart ) {
|
||||
else if ( type instanceof EmbeddableValuedModelPart embeddableValuedModelPart ) {
|
||||
// Handle the special embeddables for emulated offset/timezone handling
|
||||
final Class<?> javaTypeClass = ( (EmbeddableValuedModelPart) type ).getJavaType().getJavaTypeClass();
|
||||
final Class<?> javaTypeClass = embeddableValuedModelPart.getJavaType().getJavaTypeClass();
|
||||
if ( javaTypeClass == OffsetDateTime.class
|
||||
|| javaTypeClass == ZonedDateTime.class ) {
|
||||
return TemporalType.TIMESTAMP;
|
||||
|
@ -832,8 +829,13 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
|||
else if ( javaTypeClass == OffsetTime.class ) {
|
||||
return TemporalType.TIME;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static TemporalType getSqlTemporalType(JdbcType descriptor) {
|
||||
|
@ -852,8 +854,9 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
|||
return TemporalType.TIME;
|
||||
case SqlTypes.DATE:
|
||||
return TemporalType.DATE;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IntervalType getSqlIntervalType(JdbcMappingContainer jdbcMappings) {
|
||||
|
@ -869,8 +872,9 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
|||
switch ( jdbcTypeCode ) {
|
||||
case SqlTypes.INTERVAL_SECOND:
|
||||
return IntervalType.SECOND;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isJdbcTemporalType(SqmExpressible<?> type) {
|
||||
|
@ -883,14 +887,16 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
|||
|
||||
@Internal @SuppressWarnings("unchecked")
|
||||
public <J> MutabilityPlan<J> createMutabilityPlan(Class<? extends MutabilityPlan<?>> planClass) {
|
||||
if ( !scope.allowExtensionsInCdi ) {
|
||||
//noinspection rawtypes
|
||||
return (MutabilityPlan) FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( planClass );
|
||||
}
|
||||
return !scope.allowExtensionsInCdi
|
||||
? (MutabilityPlan<J>) FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( planClass )
|
||||
: (MutabilityPlan<J>) getManagedBeanRegistry().getBean( planClass ).getBeanInstance();
|
||||
}
|
||||
|
||||
final ManagedBean<? extends MutabilityPlan<?>> planBean =
|
||||
scope.getServiceRegistry().requireService( ManagedBeanRegistry.class )
|
||||
.getBean( planClass );
|
||||
return (MutabilityPlan<J>) planBean.getBeanInstance();
|
||||
private ClassLoaderService getClassLoaderService() {
|
||||
return scope.getServiceRegistry().requireService( ClassLoaderService.class );
|
||||
}
|
||||
|
||||
private ManagedBeanRegistry getManagedBeanRegistry() {
|
||||
return scope.getServiceRegistry().requireService( ManagedBeanRegistry.class );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,14 +6,12 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.boot;
|
||||
|
||||
import org.hibernate.boot.model.process.internal.ScanningCoordinator;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.PersistenceSettings;
|
||||
import org.hibernate.internal.SessionFactoryRegistry;
|
||||
|
||||
import org.hibernate.internal.SessionFactoryRegistryMessageLogger;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.Logger;
|
||||
import org.hibernate.testing.orm.junit.LoggingInspections;
|
||||
import org.hibernate.testing.orm.junit.MessageKeyInspection;
|
||||
import org.hibernate.testing.orm.junit.MessageKeyWatcher;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
|
@ -29,8 +27,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*/
|
||||
@SuppressWarnings("JUnitMalformedDeclaration")
|
||||
@MessageKeyInspection(
|
||||
messageKey = "HHH000277",
|
||||
logger = @Logger( loggerNameClass = SessionFactoryRegistry.class )
|
||||
messageKey = "HHH020277",
|
||||
logger = @Logger( loggerName = SessionFactoryRegistryMessageLogger.LOGGER_NAME )
|
||||
)
|
||||
public class SessionFactoryNamingTests {
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue