Skip to content

Commit 80ae0e9

Browse files
committed
minor cleanups to SessionFactory logging
1 parent 9032a61 commit 80ae0e9

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.io.IOException;
1010
import java.sql.SQLException;
1111
import java.sql.SQLWarning;
12+
import java.util.Map;
1213
import java.util.Properties;
1314
import java.util.ServiceConfigurationError;
1415
import java.util.Set;
@@ -73,8 +74,20 @@ public interface CoreMessageLogger extends BasicLogger {
7374
void callingJoinTransactionOnNonJtaEntityManager();
7475

7576
@LogMessage(level = DEBUG)
76-
@Message(value = "Closing", id = 31)
77-
void closing();
77+
@Message(value = "Instantiating factory with settings: %s", id = 30)
78+
void instantiatingFactory(Map<String, Object> settings);
79+
80+
@LogMessage(level = DEBUG)
81+
@Message(value = "Closing factory", id = 31)
82+
void closingFactory();
83+
84+
@LogMessage(level = DEBUG)
85+
@Message(value = "Serializing factory: %s", id = 32)
86+
void serializingFactory(String uuid);
87+
88+
@LogMessage(level = DEBUG)
89+
@Message(value = "Deserialized factory: %s", id = 33)
90+
void deserializedFactory(String uuid);
7891

7992
@LogMessage(level = WARN)
8093
@Message(value = "Composite-id class does not override equals(): %s", id = 38)

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

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,10 @@ public class SessionFactoryImpl implements SessionFactoryImplementor, BindingCon
182182
private final transient Map<String,Object> settings;
183183

184184
private final transient SessionFactoryServiceRegistry serviceRegistry;
185-
private final transient EventEngine eventEngine;//Needs to be closed!
185+
private final transient EventEngine eventEngine;
186186
private final transient JdbcServices jdbcServices;
187187
private final transient SqlStringGenerationContext sqlStringGenerationContext;
188188

189-
// todo : org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor too?
190-
191189
private final transient RuntimeMetamodelsImplementor runtimeMetamodels;
192190
private final PersistenceUnitUtil jpaPersistenceUnitUtil;
193191
private final transient CacheImplementor cacheAccess;
@@ -245,7 +243,7 @@ public SessionFactoryImpl(
245243
settings = getSettings( options, serviceRegistry );
246244
maskOutSensitiveInformation( settings );
247245
deprecationCheck( settings );
248-
LOG.debugf( "Instantiating SessionFactory with settings: %s", settings );
246+
LOG.instantiatingFactory( settings );
249247

250248
sqlStringGenerationContext = createSqlStringGenerationContext( bootMetamodel, options, jdbcServices );
251249

@@ -258,7 +256,6 @@ public SessionFactoryImpl(
258256
}
259257

260258
filters = new HashMap<>( bootMetamodel.getFilterDefinitions() );
261-
LOG.debugf( "Session factory constructed with filter configurations : %s", filters );
262259

263260
final FilterDefinition tenantFilter = filters.get( TenantIdBinder.FILTER_NAME );
264261
if ( tenantFilter == null ) {
@@ -359,12 +356,12 @@ public SessionFactoryImpl(
359356
close();
360357
}
361358
catch (Exception closeException) {
362-
LOG.debug( "Eating error closing the SessionFactory after a failed attempt to start it" );
359+
LOG.trace( "Eating error closing factory after failed instantiation" );
363360
}
364361
throw e;
365362
}
366363

367-
LOG.debug( "Instantiated SessionFactory" );
364+
LOG.debug( "Instantiated factory" );
368365
}
369366

370367
private EventMonitor loadEventMonitor() {
@@ -770,7 +767,7 @@ public Interceptor getInterceptor() {
770767
@Override
771768
public Reference getReference() {
772769
// from javax.naming.Referenceable
773-
LOG.debug( "Returning a Reference to the SessionFactory" );
770+
LOG.debug( "Returning a Reference to the factory" );
774771
return new Reference(
775772
SessionFactoryImpl.class.getName(),
776773
new StringRefAddr( "uuid", getUuid() ),
@@ -809,7 +806,7 @@ public void close() throws HibernateException {
809806
}
810807

811808
try {
812-
LOG.closing();
809+
LOG.closingFactory();
813810
observer.sessionFactoryClosing( this );
814811

815812
// NOTE : the null checks below handle cases where close is called from
@@ -1543,11 +1540,9 @@ public JavaType<Object> getTenantIdentifierJavaType() {
15431540
*/
15441541
@Serial
15451542
private void writeObject(ObjectOutputStream out) throws IOException {
1546-
if ( LOG.isDebugEnabled() ) {
1547-
LOG.debugf( "Serializing: %s", getUuid() );
1548-
}
1543+
LOG.serializingFactory( getUuid() );
15491544
out.defaultWriteObject();
1550-
LOG.trace( "Serialized" );
1545+
LOG.trace( "Serialized factory" );
15511546
}
15521547

15531548
/**
@@ -1560,11 +1555,9 @@ private void writeObject(ObjectOutputStream out) throws IOException {
15601555
*/
15611556
@Serial
15621557
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
1563-
LOG.trace( "Deserializing" );
1558+
LOG.trace( "Deserializing factory" );
15641559
in.defaultReadObject();
1565-
if ( LOG.isDebugEnabled() ) {
1566-
LOG.debugf( "Deserialized: %s", getUuid() );
1567-
}
1560+
LOG.deserializedFactory( getUuid() );
15681561
}
15691562

15701563
/**
@@ -1580,15 +1573,15 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE
15801573
*/
15811574
@Serial
15821575
private Object readResolve() throws InvalidObjectException {
1583-
LOG.trace( "Resolving serialized SessionFactory" );
1576+
LOG.trace( "Resolving serialized factory" );
15841577
return locateSessionFactoryOnDeserialization( getUuid(), name );
15851578
}
15861579

15871580
private static SessionFactory locateSessionFactoryOnDeserialization(String uuid, String name)
15881581
throws InvalidObjectException{
15891582
final SessionFactory uuidResult = SessionFactoryRegistry.INSTANCE.getSessionFactory( uuid );
15901583
if ( uuidResult != null ) {
1591-
LOG.debugf( "Resolved SessionFactory by UUID [%s]", uuid );
1584+
LOG.debug( "Resolved factory by UUID: " + uuid );
15921585
return uuidResult;
15931586
}
15941587

@@ -1597,12 +1590,12 @@ private static SessionFactory locateSessionFactoryOnDeserialization(String uuid,
15971590
if ( name != null ) {
15981591
final SessionFactory namedResult = SessionFactoryRegistry.INSTANCE.getNamedSessionFactory( name );
15991592
if ( namedResult != null ) {
1600-
LOG.debugf( "Resolved SessionFactory by name [%s]", name );
1593+
LOG.debug( "Resolved factory by name: " + name );
16011594
return namedResult;
16021595
}
16031596
}
16041597

1605-
throw new InvalidObjectException( "Could not find a SessionFactory [uuid=" + uuid + ",name=" + name + "]" );
1598+
throw new InvalidObjectException( "No SessionFactory with uuid [" + uuid + "] and name [" + name + "]" );
16061599
}
16071600

16081601
/**
@@ -1627,7 +1620,7 @@ void serialize(ObjectOutputStream oos) throws IOException {
16271620
* @throws IOException indicates problems reading back serial data stream
16281621
*/
16291622
static SessionFactoryImpl deserialize(ObjectInputStream ois) throws IOException {
1630-
LOG.trace( "Deserializing SessionFactory from Session" );
1623+
LOG.trace( "Resolving factory from deserialized session" );
16311624
final String uuid = ois.readUTF();
16321625
boolean isNamed = ois.readBoolean();
16331626
final String name = isNamed ? ois.readUTF() : null;

0 commit comments

Comments
 (0)