HHH-13587 Review formatting and logging style of StatefulPersistenceContext

This commit is contained in:
Sanne Grinovero 2019-08-17 13:55:29 +01:00 committed by Sanne Grinovero
parent d065888140
commit eb675e1c7f
1 changed files with 22 additions and 22 deletions

View File

@ -58,6 +58,7 @@ import org.hibernate.event.spi.EventSource;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.collections.ConcurrentReferenceHashMap; import org.hibernate.internal.util.collections.ConcurrentReferenceHashMap;
import org.hibernate.internal.util.collections.IdentityMap; import org.hibernate.internal.util.collections.IdentityMap;
import org.hibernate.metamodel.spi.MetamodelImplementor;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper; import org.hibernate.pretty.MessageHelper;
@ -78,6 +79,7 @@ import org.jboss.logging.Logger;
* their processing. * their processing.
* *
* @author Steve Ebersole * @author Steve Ebersole
* @author Sanne Grinovero
*/ */
public class StatefulPersistenceContext implements PersistenceContext { public class StatefulPersistenceContext implements PersistenceContext {
private static final CoreMessageLogger LOG = Logger.getMessageLogger( private static final CoreMessageLogger LOG = Logger.getMessageLogger(
@ -199,7 +201,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
@Override @Override
public void addUnownedCollection(CollectionKey key, PersistentCollection collection) { public void addUnownedCollection(CollectionKey key, PersistentCollection collection) {
if (unownedCollections==null) { if ( unownedCollections == null ) {
unownedCollections = new HashMap<>( INIT_COLL_SIZE ); unownedCollections = new HashMap<>( INIT_COLL_SIZE );
} }
unownedCollections.put( key, collection ); unownedCollections.put( key, collection );
@ -212,8 +214,8 @@ public class StatefulPersistenceContext implements PersistenceContext {
@Override @Override
public BatchFetchQueue getBatchFetchQueue() { public BatchFetchQueue getBatchFetchQueue() {
if (batchFetchQueue==null) { if ( batchFetchQueue == null ) {
batchFetchQueue = new BatchFetchQueue(this); batchFetchQueue = new BatchFetchQueue( this );
} }
return batchFetchQueue; return batchFetchQueue;
} }
@ -417,8 +419,8 @@ public class StatefulPersistenceContext implements PersistenceContext {
entitySnapshotsByKey.remove( key ); entitySnapshotsByKey.remove( key );
nullifiableEntityKeys.remove( key ); nullifiableEntityKeys.remove( key );
if( batchFetchQueue != null ) { if( batchFetchQueue != null ) {
getBatchFetchQueue().removeBatchLoadableEntityKey(key); getBatchFetchQueue().removeBatchLoadableEntityKey( key );
getBatchFetchQueue().removeSubselect(key); getBatchFetchQueue().removeSubselect( key );
} }
return entity; return entity;
} }
@ -938,9 +940,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
@Override @Override
public void initializeNonLazyCollections() throws HibernateException { public void initializeNonLazyCollections() throws HibernateException {
if ( loadCounter == 0 ) { if ( loadCounter == 0 ) {
if ( LOG.isTraceEnabled() ) { LOG.trace( "Initializing non-lazy collections" );
LOG.trace( "Initializing non-lazy collections" );
}
//do this work only at the very highest level of the load //do this work only at the very highest level of the load
//don't let this method be called recursively //don't let this method be called recursively
@ -1278,8 +1278,9 @@ public class StatefulPersistenceContext implements PersistenceContext {
@Override @Override
public Object getIndexInOwner(String entity, String property, Object childEntity, Map mergeMap) { public Object getIndexInOwner(String entity, String property, Object childEntity, Map mergeMap) {
final EntityPersister persister = session.getFactory().getMetamodel().entityPersister( entity ); final MetamodelImplementor metamodel = session.getFactory().getMetamodel();
final CollectionPersister cp = session.getFactory().getMetamodel().collectionPersister( entity + '.' + property ); final EntityPersister persister = metamodel.entityPersister( entity );
final CollectionPersister cp = metamodel.collectionPersister( entity + '.' + property );
// try cache lookup first // try cache lookup first
final Object parent = parentsByChild.get( childEntity ); final Object parent = parentsByChild.get( childEntity );
@ -1289,7 +1290,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
if ( persister.isSubclassEntityName( entityEntry.getEntityName() ) ) { if ( persister.isSubclassEntityName( entityEntry.getEntityName() ) ) {
Object index = getIndexInParent( property, childEntity, persister, cp, parent ); Object index = getIndexInParent( property, childEntity, persister, cp, parent );
if (index==null && mergeMap!=null) { if ( index == null && mergeMap != null ) {
final Object unMergedInstance = mergeMap.get( parent ); final Object unMergedInstance = mergeMap.get( parent );
final Object unMergedChild = mergeMap.get( childEntity ); final Object unMergedChild = mergeMap.get( childEntity );
if ( unMergedInstance != null && unMergedChild != null ) { if ( unMergedInstance != null && unMergedChild != null ) {
@ -1378,7 +1379,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
else { else {
final EntityEntry ee = getEntry( entityOrProxy ); final EntityEntry ee = getEntry( entityOrProxy );
if ( ee == null ) { if ( ee == null ) {
throw new TransientObjectException("Instance was not associated with this persistence context" ); throw new TransientObjectException( "Instance was not associated with this persistence context" );
} }
isReadOnly = ee.isReadOnly(); isReadOnly = ee.isReadOnly();
} }
@ -1415,11 +1416,12 @@ public class StatefulPersistenceContext implements PersistenceContext {
} }
private void setProxyReadOnly(HibernateProxy proxy, boolean readOnly) { private void setProxyReadOnly(HibernateProxy proxy, boolean readOnly) {
if ( proxy.getHibernateLazyInitializer().getSession() != getSession() ) { final LazyInitializer hibernateLazyInitializer = proxy.getHibernateLazyInitializer();
if ( hibernateLazyInitializer.getSession() != getSession() ) {
throw new AssertionFailure( throw new AssertionFailure(
"Attempt to set a proxy to read-only that is associated with a different session" ); "Attempt to set a proxy to read-only that is associated with a different session" );
} }
proxy.getHibernateLazyInitializer().setReadOnly( readOnly ); hibernateLazyInitializer.setReadOnly( readOnly );
} }
private void setEntityReadOnly(Object entity, boolean readOnly) { private void setEntityReadOnly(Object entity, boolean readOnly) {
@ -1461,9 +1463,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
* @throws IOException serialization errors. * @throws IOException serialization errors.
*/ */
public void serialize(ObjectOutputStream oos) throws IOException { public void serialize(ObjectOutputStream oos) throws IOException {
if ( LOG.isTraceEnabled() ) { LOG.trace( "Serializing persistence-context" );
LOG.trace( "Serializing persistence-context" );
}
oos.writeBoolean( defaultReadOnly ); oos.writeBoolean( defaultReadOnly );
oos.writeBoolean( hasNonReadOnlyEntities ); oos.writeBoolean( hasNonReadOnlyEntities );
@ -1556,9 +1556,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
public static StatefulPersistenceContext deserialize( public static StatefulPersistenceContext deserialize(
ObjectInputStream ois, ObjectInputStream ois,
SessionImplementor session) throws IOException, ClassNotFoundException { SessionImplementor session) throws IOException, ClassNotFoundException {
if ( LOG.isTraceEnabled() ) { LOG.trace( "Deserializing persistence-context" );
LOG.trace( "Deserializing persistence-context" );
}
final StatefulPersistenceContext rtn = new StatefulPersistenceContext( session ); final StatefulPersistenceContext rtn = new StatefulPersistenceContext( session );
SessionFactoryImplementor sfi = session.getFactory(); SessionFactoryImplementor sfi = session.getFactory();
@ -1848,7 +1846,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
new AfterTransactionCompletionProcess() { new AfterTransactionCompletionProcess() {
@Override @Override
public void doAfterTransactionCompletion(boolean success, SharedSessionContractImplementor session) { public void doAfterTransactionCompletion(boolean success, SharedSessionContractImplementor session) {
if (success) { if ( success ) {
final boolean put = naturalIdCacheAccessStrategy.afterInsert( session, naturalIdCacheKey, id ); final boolean put = naturalIdCacheAccessStrategy.afterInsert( session, naturalIdCacheKey, id );
if ( put && statistics.isStatisticsEnabled() ) { if ( put && statistics.isStatisticsEnabled() ) {
statistics.naturalIdCachePut( statistics.naturalIdCachePut(
@ -1914,7 +1912,9 @@ public class StatefulPersistenceContext implements PersistenceContext {
break; break;
} }
default: { default: {
LOG.debug( "Unexpected CachedNaturalIdValueSource [" + source + "]" ); if ( LOG.isDebugEnabled() ) {
LOG.debug( "Unexpected CachedNaturalIdValueSource [" + source + "]" );
}
} }
} }
} }