Skip to content

Commit 049610b

Browse files
committed
split out SessionFactoryRegistryMessageLogger
Signed-off-by: Gavin King <[email protected]>
1 parent f6ff6fa commit 049610b

File tree

7 files changed

+204
-153
lines changed

7 files changed

+204
-153
lines changed

hibernate-core/src/main/java/org/hibernate/internal/CoreLogging.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ public class CoreLogging {
2323
private CoreLogging() {
2424
}
2525

26-
public static CoreMessageLogger messageLogger(Class classNeedingLogging) {
26+
public static CoreMessageLogger messageLogger(Class<?> classNeedingLogging) {
2727
return messageLogger( classNeedingLogging.getName() );
2828
}
2929

3030
public static CoreMessageLogger messageLogger(String loggerName) {
3131
return Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, loggerName );
3232
}
3333

34-
public static Logger logger(Class classNeedingLogging) {
34+
public static Logger logger(Class<?> classNeedingLogging) {
3535
return Logger.getLogger( classNeedingLogging );
3636
}
3737

hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@
1414
import java.util.Properties;
1515
import java.util.ServiceConfigurationError;
1616
import java.util.Set;
17-
import javax.naming.NamingException;
1817

1918
import org.hibernate.HibernateException;
2019
import org.hibernate.JDBCException;
2120
import org.hibernate.LockMode;
2221
import org.hibernate.cache.CacheException;
2322
import org.hibernate.dialect.Dialect;
2423
import org.hibernate.engine.jdbc.env.internal.LobCreationLogging;
25-
import org.hibernate.engine.jndi.JndiException;
26-
import org.hibernate.engine.jndi.JndiNameException;
2724
import org.hibernate.engine.spi.SessionFactoryImplementor;
2825
import org.hibernate.id.IntegralDataTypeHolder;
2926
import org.hibernate.service.Service;
@@ -194,22 +191,6 @@ public interface CoreMessageLogger extends BasicLogger {
194191
void expectedType(String name,
195192
@Nullable String string);
196193

197-
@LogMessage(level = INFO)
198-
@Message(value = "Bound factory to JNDI name: %s", id = 94)
199-
void factoryBoundToJndiName(String name);
200-
201-
@LogMessage(level = INFO)
202-
@Message(value = "A factory was renamed from [%s] to [%s] in JNDI", id = 96)
203-
void factoryJndiRename(String oldName, String newName);
204-
205-
@LogMessage(level = INFO)
206-
@Message(value = "Unbound factory from JNDI name: %s", id = 97)
207-
void factoryUnboundFromJndiName(String name);
208-
209-
@LogMessage(level = INFO)
210-
@Message(value = "A factory was unbound from name: %s", id = 98)
211-
void factoryUnboundFromName(String name);
212-
213194
@LogMessage(level = ERROR)
214195
@Message(value = "an assertion failure occurred" + " (this may indicate a bug in Hibernate, but is more likely due"
215196
+ " to unsafe use of the session): %s", id = 99)
@@ -261,10 +242,6 @@ void honoringOptimizerSetting(
261242
@Message(value = "IllegalArgumentException in class: %s, setter method of property: %s", id = 123)
262243
void illegalPropertySetterArgument(String name, String propertyName);
263244

264-
@LogMessage(level = DEBUG)
265-
@Message(value = "Could not bind JNDI listener", id = 127)
266-
void couldNotBindJndiListener();
267-
268245
@LogMessage(level = INFO)
269246
@Message(value = "Instantiating explicit connection provider: %s", id = 130)
270247
void instantiatingExplicitConnectionProvider(String providerClassName);
@@ -273,10 +250,6 @@ void honoringOptimizerSetting(
273250
@Message(value = "Array element type error\n%s", id = 132)
274251
void invalidArrayElementType(String message);
275252

276-
@LogMessage(level = ERROR)
277-
@Message(value = "Invalid JNDI name: %s", id = 135)
278-
void invalidJndiName(String name, @Cause JndiNameException e);
279-
280253
@LogMessage(level = INFO)
281254
@Message(value = "java.sql.Types mapped the same code [%s] multiple times; was [%s]; now [%s]", id = 141)
282255
void JavaSqlTypesMappedSameCodeMultipleTimes(int code, String old, String name);
@@ -299,10 +272,6 @@ void missingArguments(
299272
int anticipatedNumberOfArguments,
300273
int numberOfArguments);
301274

302-
@LogMessage(level = WARN)
303-
@Message(value = "Naming exception occurred accessing factory: %s", id = 178)
304-
void namingExceptionAccessingFactory(NamingException exception);
305-
306275
@LogMessage(level = WARN)
307276
@Message(value = "Narrowing proxy to %s - this operation breaks ==", id = 179)
308277
void narrowingProxy(Class<?> concreteProxyClass);
@@ -471,10 +440,6 @@ void synchronizationFailed(
471440
@Message(value = "Unable to apply constraints on DDL for %s", id = 274)
472441
void unableToApplyConstraints(String className, @Cause Exception e);
473442

474-
@LogMessage(level = WARN)
475-
@Message(value = "Could not bind factory to JNDI", id = 277)
476-
void unableToBindFactoryToJndi(@Cause JndiException e);
477-
478443
@LogMessage(level = WARN)
479444
@Message(value = "Unable to cleanup temporary id table after use [%s]", id = 283)
480445
void unableToCleanupTemporaryIdTable(Throwable t);
@@ -623,10 +588,6 @@ void synchronizationFailed(
623588
@Message(value = "Error stopping service [%s]", id = 369)
624589
void unableToStopService(Class<? extends Service> class1, @Cause Exception e);
625590

626-
@LogMessage(level = WARN)
627-
@Message(value = "Could not unbind factory from JNDI", id = 374)
628-
void unableToUnbindFactoryFromJndi(@Cause JndiException e);
629-
630591
@LogMessage(level = ERROR)
631592
@Message(value = "Could not updateQuery hi value in: %s", id = 376)
632593
void unableToUpdateQueryHiValue(String tableName, @Cause SQLException e);

hibernate-core/src/main/java/org/hibernate/internal/EntityManagerMessageLogger.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@
66
*/
77
package org.hibernate.internal;
88

9-
import java.net.URISyntaxException;
10-
import java.net.URL;
11-
12-
import org.jboss.logging.annotations.Cause;
139
import org.jboss.logging.annotations.LogMessage;
1410
import org.jboss.logging.annotations.Message;
1511
import org.jboss.logging.annotations.MessageLogger;
1612
import org.jboss.logging.annotations.ValidIdRange;
1713

1814
import static org.jboss.logging.Logger.Level.DEBUG;
1915
import static org.jboss.logging.Logger.Level.ERROR;
20-
import static org.jboss.logging.Logger.Level.INFO;
2116
import static org.jboss.logging.Logger.Level.WARN;
2217

2318
/**

hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryRegistry.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import org.hibernate.engine.jndi.JndiNameException;
2222
import org.hibernate.engine.jndi.spi.JndiService;
2323
import org.hibernate.engine.spi.SessionFactoryImplementor;
24-
import org.hibernate.internal.util.StringHelper;
24+
25+
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
2526

2627
/**
2728
* A registry of all {@link SessionFactory} instances for the same classloader as this class.
@@ -31,7 +32,7 @@
3132
* @author Steve Ebersole
3233
*/
3334
public class SessionFactoryRegistry {
34-
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( SessionFactoryRegistry.class );
35+
private static final SessionFactoryRegistryMessageLogger LOG = SessionFactoryRegistryMessageLogger.INSTANCE;
3536

3637
/**
3738
* Singleton access
@@ -71,14 +72,14 @@ public void addSessionFactory(
7172
throw new IllegalArgumentException( "SessionFactory UUID cannot be null" );
7273
}
7374

74-
LOG.debugf( "Registering SessionFactory: %s (%s)", uuid, name == null ? "<unnamed>" : name );
75+
LOG.registeringSessionFactory( uuid, name == null ? "<unnamed>" : name );
7576
sessionFactoryMap.put( uuid, instance );
7677
if ( name != null ) {
7778
nameUuidXref.put( name, uuid );
7879
}
7980

8081
if ( jndiName == null ) {
81-
LOG.debug( "Not binding SessionFactory to JNDI, no JNDI name configured" );
82+
LOG.notBindingSessionFactory();
8283
return;
8384
}
8485

@@ -87,7 +88,7 @@ public void addSessionFactory(
8788

8889
private void bindToJndi(String jndiName, SessionFactoryImplementor instance, JndiService jndiService) {
8990
try {
90-
LOG.debugf( "Attempting to bind SessionFactory [%s] to JNDI", jndiName );
91+
LOG.attemptingToBindFactoryToJndi( jndiName );
9192
jndiService.bind( jndiName, instance );
9293
LOG.factoryBoundToJndiName( jndiName );
9394
try {
@@ -124,7 +125,7 @@ public void removeSessionFactory(
124125

125126
if ( jndiName != null ) {
126127
try {
127-
LOG.tracef( "Unbinding SessionFactory from JNDI : %s", jndiName );
128+
LOG.attemptingToUnbindFactoryFromJndi( jndiName );
128129
jndiService.unbind( jndiName );
129130
LOG.factoryUnboundFromJndiName( jndiName );
130131
}
@@ -164,17 +165,15 @@ public SessionFactoryImplementor getSessionFactory(String uuid) {
164165
}
165166

166167
public SessionFactoryImplementor findSessionFactory(String uuid, String name) {
167-
SessionFactoryImplementor sessionFactory = getSessionFactory( uuid );
168-
if ( sessionFactory == null && StringHelper.isNotEmpty( name ) ) {
169-
sessionFactory = getNamedSessionFactory( name );
170-
}
171-
return sessionFactory;
168+
final SessionFactoryImplementor sessionFactory = getSessionFactory( uuid );
169+
return sessionFactory == null && isNotEmpty( name )
170+
? getNamedSessionFactory( name )
171+
: sessionFactory;
172+
172173
}
173174

174175
/**
175176
* Does this registry currently contain registrations?
176-
*
177-
* @return true/false
178177
*/
179178
public boolean hasRegistrations() {
180179
return !sessionFactoryMap.isEmpty();
@@ -200,7 +199,7 @@ public void clearRegistrations() {
200199
@Override
201200
public void objectAdded(NamingEvent evt) {
202201
if ( LOG.isDebugEnabled() ) {
203-
LOG.debugf( "A factory was successfully bound to name: %s", evt.getNewBinding().getName() );
202+
LOG.factoryBoundToJndi( evt.getNewBinding().getName() );
204203
}
205204
}
206205

@@ -223,16 +222,13 @@ public void objectRemoved(NamingEvent evt) {
223222
public void objectRenamed(NamingEvent evt) {
224223
final String oldJndiName = evt.getOldBinding().getName();
225224
final String newJndiName = evt.getNewBinding().getName();
226-
227225
LOG.factoryJndiRename( oldJndiName, newJndiName );
228-
229226
final String uuid = nameUuidXref.remove( oldJndiName );
230227
nameUuidXref.put( newJndiName, uuid );
231228
}
232229

233230
@Override
234231
public void namingExceptionThrown(NamingExceptionEvent evt) {
235-
//noinspection ThrowableResultOfMethodCallIgnored
236232
LOG.namingExceptionAccessingFactory( evt.getException() );
237233
}
238234
};
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
6+
*/
7+
package org.hibernate.internal;
8+
9+
import org.hibernate.engine.jndi.JndiException;
10+
import org.hibernate.engine.jndi.JndiNameException;
11+
import org.hibernate.internal.log.SubSystemLogging;
12+
import org.jboss.logging.BasicLogger;
13+
import org.jboss.logging.annotations.Cause;
14+
import org.jboss.logging.annotations.LogMessage;
15+
import org.jboss.logging.annotations.Message;
16+
import org.jboss.logging.annotations.MessageLogger;
17+
import org.jboss.logging.annotations.ValidIdRange;
18+
19+
import javax.naming.NamingException;
20+
import java.lang.invoke.MethodHandles;
21+
22+
import static org.jboss.logging.Logger.Level.DEBUG;
23+
import static org.jboss.logging.Logger.Level.ERROR;
24+
import static org.jboss.logging.Logger.Level.INFO;
25+
import static org.jboss.logging.Logger.Level.WARN;
26+
import static org.jboss.logging.Logger.getMessageLogger;
27+
28+
@MessageLogger(projectCode = "HHH")
29+
@ValidIdRange( min = 20100, max = 20400 )
30+
@SubSystemLogging(
31+
name = SessionFactoryRegistryMessageLogger.LOGGER_NAME,
32+
description = "Logging related to session factory registry"
33+
)
34+
public interface SessionFactoryRegistryMessageLogger extends BasicLogger {
35+
String LOGGER_NAME = SubSystemLogging.BASE + ".factoryRegistry";
36+
37+
SessionFactoryRegistryMessageLogger INSTANCE =
38+
getMessageLogger( MethodHandles.lookup(), SessionFactoryRegistryMessageLogger.class, LOGGER_NAME );
39+
40+
@LogMessage(level = WARN)
41+
@Message(value = "Naming exception occurred accessing factory: %s", id = 20178)
42+
void namingExceptionAccessingFactory(NamingException exception);
43+
44+
@LogMessage(level = INFO)
45+
@Message(value = "Bound factory to JNDI name: %s", id = 20194)
46+
void factoryBoundToJndiName(String name);
47+
48+
@LogMessage(level = INFO)
49+
@Message(value = "A factory was renamed from [%s] to [%s] in JNDI", id = 20196)
50+
void factoryJndiRename(String oldName, String newName);
51+
52+
@LogMessage(level = DEBUG)
53+
@Message(value = "Could not bind JNDI listener", id = 20127)
54+
void couldNotBindJndiListener();
55+
56+
@LogMessage(level = ERROR)
57+
@Message(value = "Invalid JNDI name: %s", id = 20135)
58+
void invalidJndiName(String name, @Cause JndiNameException e);
59+
60+
@LogMessage(level = WARN)
61+
@Message(value = "Could not bind factory to JNDI", id = 20277)
62+
void unableToBindFactoryToJndi(@Cause JndiException e);
63+
64+
@LogMessage(level = INFO)
65+
@Message(value = "Unbound factory from JNDI name: %s", id = 20197)
66+
void factoryUnboundFromJndiName(String name);
67+
68+
@LogMessage(level = INFO)
69+
@Message(value = "A factory was unbound from name: %s", id = 20198)
70+
void factoryUnboundFromName(String name);
71+
72+
@LogMessage(level = WARN)
73+
@Message(value = "Could not unbind factory from JNDI", id = 20374)
74+
void unableToUnbindFactoryFromJndi(@Cause JndiException e);
75+
76+
@LogMessage(level = DEBUG)
77+
@Message(value = "Registering SessionFactory: %s (%s)", id = 20384)
78+
void registeringSessionFactory(String uuid, String name);
79+
80+
@LogMessage(level = DEBUG)
81+
@Message(value = "Attempting to bind SessionFactory [%s] to JNDI", id = 20280)
82+
void attemptingToBindFactoryToJndi(String name);
83+
84+
@LogMessage(level = DEBUG)
85+
@Message(value = "Attempting to unbind SessionFactory [%s] from JNDI", id = 20281)
86+
void attemptingToUnbindFactoryFromJndi(String name);
87+
88+
@LogMessage(level = DEBUG)
89+
@Message(value = "A SessionFactory was successfully bound to name: %s", id = 20282)
90+
void factoryBoundToJndi(String name);
91+
92+
@LogMessage(level = DEBUG)
93+
@Message(value = "Not binding SessionFactory to JNDI, no JNDI name configured", id = 20385)
94+
void notBindingSessionFactory();
95+
}

0 commit comments

Comments
 (0)