Skip to content

Commit eb3feb6

Browse files
committed
Use L2CACHE_LOGGER from o.h.cache.spi.support
1 parent 7bcf234 commit eb3feb6

File tree

5 files changed

+62
-66
lines changed

5 files changed

+62
-66
lines changed

hibernate-core/src/main/java/org/hibernate/cache/spi/support/AbstractCachedDomainDataAccess.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
import org.hibernate.cache.spi.access.SoftLock;
1111
import org.hibernate.engine.spi.SharedSessionContractImplementor;
1212

13-
import org.jboss.logging.Logger;
13+
14+
import static org.hibernate.cache.spi.SecondLevelCacheLogger.L2CACHE_LOGGER;
1415

1516
/**
1617
* @author Steve Ebersole
1718
*/
1819
public abstract class AbstractCachedDomainDataAccess implements CachedDomainDataAccess, AbstractDomainDataRegion.Destructible {
19-
private static final Logger log = Logger.getLogger( AbstractCachedDomainDataAccess.class );
2020

2121
private final DomainDataRegion region;
2222
private final DomainDataStorageAccess storageAccess;
@@ -39,7 +39,7 @@ public DomainDataStorageAccess getStorageAccess() {
3939
}
4040

4141
protected void clearCache() {
42-
log.tracef( "Clearing cache data map [region=`%s`]", region.getName() );
42+
L2CACHE_LOGGER.tracef( "Clearing cache data map [region='%s']", region.getName() );
4343
getStorageAccess().evictData();
4444
}
4545

hibernate-core/src/main/java/org/hibernate/cache/spi/support/AbstractDomainDataRegion.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
import org.hibernate.internal.util.collections.CollectionHelper;
2626
import org.hibernate.metamodel.model.domain.NavigableRole;
2727

28-
import org.jboss.logging.Logger;
28+
29+
import static org.hibernate.cache.spi.SecondLevelCacheLogger.L2CACHE_LOGGER;
2930

3031
/**
3132
* @author Steve Ebersole
3233
*/
3334
public abstract class AbstractDomainDataRegion extends AbstractRegion implements DomainDataRegion {
34-
private static final Logger log = Logger.getLogger( AbstractDomainDataRegion.class );
3535

3636
private final SessionFactoryImplementor sessionFactory;
3737
private final CacheKeysFactory effectiveKeysFactory;
@@ -67,7 +67,8 @@ public AbstractDomainDataRegion(
6767
protected void completeInstantiation(
6868
DomainDataRegionConfig regionConfig,
6969
DomainDataRegionBuildingContext buildingContext) {
70-
log.tracef( "DomainDataRegion created [%s]; key-factory = %s", regionConfig.getRegionName(), effectiveKeysFactory );
70+
L2CACHE_LOGGER.tracef( "DomainDataRegion created [%s]; key-factory = %s",
71+
regionConfig.getRegionName(), effectiveKeysFactory );
7172

7273
this.entityDataAccessMap = generateEntityDataAccessMap( regionConfig );
7374
this.naturalIdDataAccessMap = generateNaturalIdDataAccessMap( regionConfig );
@@ -87,7 +88,7 @@ public CacheKeysFactory getEffectiveKeysFactory() {
8788
public EntityDataAccess getEntityDataAccess(NavigableRole rootEntityRole) {
8889
final EntityDataAccess access = entityDataAccessMap.get( rootEntityRole );
8990
if ( access == null ) {
90-
throw new IllegalArgumentException( "Caching was not configured for entity : " + rootEntityRole.getFullPath() );
91+
throw new IllegalArgumentException( "Caching was not configured for entity: " + rootEntityRole.getFullPath() );
9192
}
9293
return access;
9394
}
@@ -97,7 +98,7 @@ public EntityDataAccess getEntityDataAccess(NavigableRole rootEntityRole) {
9798
public NaturalIdDataAccess getNaturalIdDataAccess(NavigableRole rootEntityRole) {
9899
final NaturalIdDataAccess access = naturalIdDataAccessMap.get( rootEntityRole );
99100
if ( access == null ) {
100-
throw new IllegalArgumentException( "Caching was not configured for entity natural-id : " + rootEntityRole.getFullPath() );
101+
throw new IllegalArgumentException( "Caching was not configured for entity natural id: " + rootEntityRole.getFullPath() );
101102
}
102103
return access;
103104
}
@@ -106,7 +107,7 @@ public NaturalIdDataAccess getNaturalIdDataAccess(NavigableRole rootEntityRole)
106107
public CollectionDataAccess getCollectionDataAccess(NavigableRole collectionRole) {
107108
final CollectionDataAccess access = collectionDataAccessMap.get( collectionRole );
108109
if ( access == null ) {
109-
throw new IllegalArgumentException( "Caching was not configured for collection : " + collectionRole.getFullPath() );
110+
throw new IllegalArgumentException( "Caching was not configured for collection: " + collectionRole.getFullPath() );
110111
}
111112
return access;
112113
}

hibernate-core/src/main/java/org/hibernate/cache/spi/support/AbstractReadWriteAccess.java

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@
1717
import org.hibernate.cache.spi.access.SoftLock;
1818
import org.hibernate.engine.spi.SharedSessionContractImplementor;
1919

20-
import org.jboss.logging.Logger;
2120

2221
import static org.hibernate.cache.spi.SecondLevelCacheLogger.L2CACHE_LOGGER;
2322

2423
/**
2524
* @author Steve Ebersole
2625
*/
2726
public abstract class AbstractReadWriteAccess extends AbstractCachedDomainDataAccess {
28-
private static final Logger log = Logger.getLogger( AbstractReadWriteAccess.class );
2927

3028
private final UUID uuid = UUID.randomUUID();
3129
private final AtomicLong nextLockId = new AtomicLong();
@@ -63,31 +61,35 @@ protected Lock writeLock() {
6361
*/
6462
@Override
6563
public Object get(SharedSessionContractImplementor session, Object key) {
66-
final boolean traceEnabled = log.isTraceEnabled();
64+
final boolean traceEnabled = L2CACHE_LOGGER.isTraceEnabled();
6765
if ( traceEnabled ) {
68-
log.tracef( "Getting cached data from region [`%s` (%s)] by key [%s]", getRegion().getName(), getAccessType(), key );
66+
L2CACHE_LOGGER.tracef( "Getting cached data from region ['%s' (%s)] by key [%s]",
67+
getRegion().getName(), getAccessType(), key );
6968
}
7069
try {
7170
readLock.lock();
7271
final Lockable item = (Lockable) getStorageAccess().getFromCache( key, session );
7372

7473
if ( item == null ) {
7574
if ( traceEnabled ) {
76-
log.tracef( "Cache miss : region = `%s`, key = `%s`", getRegion().getName(), key );
75+
L2CACHE_LOGGER.tracef( "Cache miss: region = '%s', key = '%s'",
76+
getRegion().getName(), key );
7777
}
7878
return null;
7979
}
8080

8181
final boolean readable = item.isReadable( session.getCacheTransactionSynchronization().getCachingTimestamp() );
8282
if ( readable ) {
8383
if ( traceEnabled ) {
84-
log.tracef( "Cache hit : region = `%s`, key = `%s`", getRegion().getName(), key );
84+
L2CACHE_LOGGER.tracef( "Cache hit: region = '%s', key = '%s'",
85+
getRegion().getName(), key );
8586
}
8687
return item.getValue();
8788
}
8889
else {
8990
if ( traceEnabled ) {
90-
log.tracef( "Cache hit, but item is unreadable/invalid : region = `%s`, key = `%s`", getRegion().getName(), key );
91+
L2CACHE_LOGGER.tracef( "Cache hit, but item is unreadable/invalid: region = '%s', key = '%s'",
92+
getRegion().getName(), key );
9193
}
9294
return null;
9395
}
@@ -104,9 +106,10 @@ public boolean putFromLoad(
104106
Object value,
105107
Object version) {
106108
try {
107-
final boolean traceEnabled = log.isTraceEnabled();
109+
final boolean traceEnabled = L2CACHE_LOGGER.isTraceEnabled();
108110
if ( traceEnabled ) {
109-
log.tracef( "Caching data from load [region='%s' (%s)] : key[%s] -> value[%s]", getRegion().getName(), getAccessType(), key, value );
111+
L2CACHE_LOGGER.tracef( "Caching data from load [region='%s' (%s)] : key[%s] -> value[%s]",
112+
getRegion().getName(), getAccessType(), key, value );
110113
}
111114
writeLock.lock();
112115
Lockable item = (Lockable) getStorageAccess().getFromCache( key, session );
@@ -122,8 +125,8 @@ public boolean putFromLoad(
122125
}
123126
else {
124127
if ( traceEnabled ) {
125-
log.tracef(
126-
"Cache put-from-load [region=`%s` (%s), key=`%s`, value=`%s`] failed due to being non-writable",
128+
L2CACHE_LOGGER.tracef(
129+
"Cache put-from-load [region='%s' (%s), key='%s', value='%s'] failed due to being non-writable",
127130
getAccessType(),
128131
getRegion().getName(),
129132
key,
@@ -156,8 +159,9 @@ public SoftLock lockItem(SharedSessionContractImplementor session, Object key, O
156159
writeLock.lock();
157160

158161
long timeout = getRegion().getRegionFactory().nextTimestamp() + getRegion().getRegionFactory().getTimeout();
159-
if ( log.isTraceEnabled() ) {
160-
log.tracef( "Locking cache item [region=`%s` (%s)] : `%s` (timeout=%s, version=%s)", getRegion().getName(), getAccessType(), key, timeout, version );
162+
if ( L2CACHE_LOGGER.isTraceEnabled() ) {
163+
L2CACHE_LOGGER.tracef( "Locking cache item [region='%s' (%s)] : '%s' (timeout=%s, version=%s)",
164+
getRegion().getName(), getAccessType(), key, timeout, version );
161165
}
162166

163167
Lockable item = (Lockable) getStorageAccess().getFromCache( key, session );
@@ -175,18 +179,14 @@ public SoftLock lockItem(SharedSessionContractImplementor session, Object key, O
175179
@Override
176180
public void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock) {
177181
try {
178-
if ( log.isTraceEnabled() ) {
179-
log.tracef(
180-
"Unlocking cache item [region=`%s` (%s)] : %s",
181-
getRegion().getName(),
182-
getAccessType(),
183-
key
184-
);
182+
if ( L2CACHE_LOGGER.isTraceEnabled() ) {
183+
L2CACHE_LOGGER.tracef( "Unlocking cache item [region='%s' (%s)] : %s",
184+
getRegion().getName(), getAccessType(), key );
185185
}
186186
writeLock.lock();
187187
Lockable item = (Lockable) getStorageAccess().getFromCache( key, session );
188188

189-
if ( ( item != null ) && item.isUnlockable( lock ) ) {
189+
if ( item != null && item.isUnlockable( lock ) ) {
190190
decrementLock( session, key, (SoftLockImpl) item );
191191
}
192192
else {
@@ -205,7 +205,7 @@ protected void decrementLock(SharedSessionContractImplementor session, Object ke
205205

206206
protected void handleLockExpiry(SharedSessionContractImplementor session, Object key, Lockable lock) {
207207
L2CACHE_LOGGER.softLockedCacheExpired( getRegion().getName(), key );
208-
log.tracef( "Cached entry expired: %s", key );
208+
L2CACHE_LOGGER.tracef( "Cached entry expired: %s", key );
209209
final RegionFactory regionFactory = getRegion().getRegionFactory();
210210

211211
// create new lock that times out immediately
@@ -219,7 +219,9 @@ protected void handleLockExpiry(SharedSessionContractImplementor session, Object
219219
@Override
220220
public void remove(SharedSessionContractImplementor session, Object key) {
221221
if ( getStorageAccess().getFromCache( key, session ) instanceof SoftLock ) {
222-
log.debugf( "Skipping #remove call in read-write access to maintain SoftLock: %s", key );
222+
if ( L2CACHE_LOGGER.isDebugEnabled() ) {
223+
L2CACHE_LOGGER.debugf( "Skipping remove call in read-write access to maintain SoftLock: ", key );
224+
}
223225
// don't do anything... we want the SoftLock to remain in place
224226
}
225227
else {
@@ -285,9 +287,9 @@ public final static class Item implements Serializable, Lockable {
285287

286288
@Override
287289
public boolean isReadable(long txTimestamp) {
288-
if ( log.isTraceEnabled() ) {
289-
log.tracef(
290-
"Checking readability of read-write cache item [timestamp=`%s`, version=`%s`] : txTimestamp=`%s`",
290+
if ( L2CACHE_LOGGER.isTraceEnabled() ) {
291+
L2CACHE_LOGGER.tracef(
292+
"Checking readability of read-write cache item [timestamp='%s', version='%s'] : txTimestamp='%s'",
291293
(Object) timestamp,
292294
version,
293295
txTimestamp
@@ -299,9 +301,9 @@ public boolean isReadable(long txTimestamp) {
299301

300302
@Override
301303
public boolean isWriteable(long txTimestamp, Object newVersion, Comparator versionComparator) {
302-
if ( log.isTraceEnabled() ) {
303-
log.tracef(
304-
"Checking writeability of read-write cache item [timestamp=`%s`, version=`%s`] : txTimestamp=`%s`, newVersion=`%s`",
304+
if ( L2CACHE_LOGGER.isTraceEnabled() ) {
305+
L2CACHE_LOGGER.tracef(
306+
"Checking writeability of read-write cache item [timestamp='%s', version='%s'] : txTimestamp='%s', newVersion='%s'",
305307
timestamp,
306308
version,
307309
txTimestamp,
@@ -372,9 +374,9 @@ public boolean isReadable(long txTimestamp) {
372374

373375
@Override
374376
public boolean isWriteable(long txTimestamp, Object newVersion, Comparator versionComparator) {
375-
if ( log.isTraceEnabled() ) {
376-
log.tracef(
377-
"Checking writeability of read-write cache lock [timeout=`%s`, lockId=`%s`, version=`%s`, sourceUuid=%s, multiplicity=`%s`, unlockTimestamp=`%s`] : txTimestamp=`%s`, newVersion=`%s`",
377+
if ( L2CACHE_LOGGER.isTraceEnabled() ) {
378+
L2CACHE_LOGGER.tracef(
379+
"Checking writeability of read-write cache lock [timeout='%s', lockId='%s', version='%s', sourceUuid=%s, multiplicity='%s', unlockTimestamp='%s'] : txTimestamp='%s', newVersion='%s'",
378380
timeout,
379381
lockId,
380382
version,

hibernate-core/src/main/java/org/hibernate/cache/spi/support/DomainDataRegionTemplate.java

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
import org.hibernate.cache.spi.access.NaturalIdDataAccess;
1818
import org.hibernate.metamodel.model.domain.NavigableRole;
1919

20-
import org.jboss.logging.Logger;
20+
21+
import static org.hibernate.cache.spi.SecondLevelCacheLogger.L2CACHE_LOGGER;
2122

2223
/**
2324
* Abstract implementation of {@link org.hibernate.cache.spi.DomainDataRegion} based
@@ -37,7 +38,6 @@
3738
* @author Steve Ebersole
3839
*/
3940
public class DomainDataRegionTemplate extends AbstractDomainDataRegion {
40-
private static final Logger log = Logger.getLogger( DomainDataRegionTemplate.class );
4141

4242
private final DomainDataStorageAccess storageAccess;
4343

@@ -67,25 +67,15 @@ public EntityDataAccess generateEntityAccess(EntityDataCachingConfig entityAcces
6767
final NavigableRole namedEntityRole = entityAccessConfig.getNavigableRole();
6868
final AccessType accessType = entityAccessConfig.getAccessType();
6969

70-
log.tracef( "Generating entity cache access [%s] : %s", accessType.getExternalName(), namedEntityRole );
71-
72-
switch ( accessType ) {
73-
case READ_ONLY: {
74-
return generateReadOnlyEntityAccess( entityAccessConfig );
75-
}
76-
case READ_WRITE: {
77-
return generateReadWriteEntityAccess( entityAccessConfig );
78-
}
79-
case NONSTRICT_READ_WRITE: {
80-
return generateNonStrictReadWriteEntityAccess( entityAccessConfig );
81-
}
82-
case TRANSACTIONAL: {
83-
return generateTransactionalEntityDataAccess( entityAccessConfig );
84-
}
85-
default: {
86-
throw new IllegalArgumentException( "Unrecognized cache AccessType - " + accessType );
87-
}
88-
}
70+
L2CACHE_LOGGER.tracef( "Generating entity cache access [%s] : %s",
71+
accessType.getExternalName(), namedEntityRole );
72+
73+
return switch ( accessType ) {
74+
case READ_ONLY -> generateReadOnlyEntityAccess( entityAccessConfig );
75+
case READ_WRITE -> generateReadWriteEntityAccess( entityAccessConfig );
76+
case NONSTRICT_READ_WRITE -> generateNonStrictReadWriteEntityAccess( entityAccessConfig );
77+
case TRANSACTIONAL -> generateTransactionalEntityDataAccess( entityAccessConfig );
78+
};
8979
}
9080

9181
protected EntityDataAccess generateReadOnlyEntityAccess(EntityDataCachingConfig accessConfig) {
@@ -128,7 +118,8 @@ public NaturalIdDataAccess generateNaturalIdAccess(NaturalIdDataCachingConfig ac
128118
final NavigableRole namedEntityRole = accessConfig.getNavigableRole();
129119
final AccessType accessType = accessConfig.getAccessType();
130120

131-
log.tracef( "Generating entity natural-id access [%s] : %s", accessType.getExternalName(), namedEntityRole );
121+
L2CACHE_LOGGER.tracef( "Generating entity natural-id access [%s] : %s",
122+
accessType.getExternalName(), namedEntityRole );
132123

133124
return switch ( accessType ) {
134125
case READ_ONLY -> generateReadOnlyNaturalIdAccess( accessConfig );
@@ -173,7 +164,9 @@ protected NaturalIdDataAccess generateTransactionalNaturalIdDataAccess(NaturalId
173164
public CollectionDataAccess generateCollectionAccess(CollectionDataCachingConfig accessConfig) {
174165
final NavigableRole namedCollectionRole = accessConfig.getNavigableRole();
175166

176-
log.tracef( "Generating collection cache access: %s", namedCollectionRole );
167+
if ( L2CACHE_LOGGER.isTraceEnabled() ) {
168+
L2CACHE_LOGGER.trace( "Generating collection cache access: " + namedCollectionRole );
169+
}
177170

178171
return switch ( accessConfig.getAccessType() ) {
179172
case READ_ONLY -> generateReadOnlyCollectionAccess( accessConfig );

hibernate-core/src/main/java/org/hibernate/cache/spi/support/EntityReadOnlyAccess.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public boolean update(
6363
Object currentVersion,
6464
Object previousVersion) {
6565
// log.debugf( "Illegal attempt to update item cached as read-only [%s]", key );
66-
throw new UnsupportedOperationException( "Can't update readonly object" );
66+
throw new UnsupportedOperationException( "Can't update read-only object" );
6767
}
6868

6969
@Override
@@ -75,6 +75,6 @@ public boolean afterUpdate(
7575
Object previousVersion,
7676
SoftLock lock) {
7777
// log.debugf( "Illegal attempt to update item cached as read-only [%s]", key );
78-
throw new UnsupportedOperationException( "Can't write to a readonly object" );
78+
throw new UnsupportedOperationException( "Can't write to a read-only object" );
7979
}
8080
}

0 commit comments

Comments
 (0)