Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.collection.internal;

import org.hibernate.Internal;
import org.hibernate.internal.log.SubSystemLogging;

import org.jboss.logging.BasicLogger;
import org.jboss.logging.Logger;
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 java.lang.invoke.MethodHandles;

import static org.jboss.logging.Logger.Level.DEBUG;
import static org.jboss.logging.Logger.Level.INFO;
import static org.jboss.logging.Logger.Level.WARN;

/**
* Subsystem logging related to PersistentCollection runtime events
*/
@SubSystemLogging(
name = CollectionLogger.NAME,
description = "Logging related to persistent collection lifecycle and operations"
)
@MessageLogger(projectCode = "HHH")
@ValidIdRange(min = 90030001, max = 90031000)
@Internal
public interface CollectionLogger extends BasicLogger {
String NAME = SubSystemLogging.BASE + ".collection";

CollectionLogger COLLECTION_LOGGER = Logger.getMessageLogger( MethodHandles.lookup(), CollectionLogger.class, NAME );

@LogMessage(level = WARN)
@Message(id = 90030001, value = "Unable to close temporary session used to load lazy collection associated to no session")
void unableToCloseTemporarySession();

@LogMessage(level = WARN)
@Message(id = 90030002, value = "Detaching an uninitialized collection with enabled filters from a session: %s")
void enabledFiltersWhenDetachFromSession(String collectionInfoString);

@LogMessage(level = WARN)
@Message(id = 90030004, value = "Attaching an uninitialized collection with queued operations to a session: %s")
void queuedOperationWhenAttachToSession(String collectionInfoString);

@LogMessage(level = INFO)
@Message(id = 90030005, value = "Detaching an uninitialized collection with queued operations from a session: %s")
void queuedOperationWhenDetachFromSession(String collectionInfoString);

@LogMessage(level = DEBUG)
@Message(id = 90030006, value = "Detaching an uninitialized collection with queued operations from a session due to rollback: %s")
void queuedOperationWhenDetachFromSessionOnRollback(String collectionInfoString);

@LogMessage(level = WARN)
@Message(id = 90030007, value = "Cannot unset session in a collection because an unexpected session is defined."
+ " A persistent collection may only be associated with one session at a time. %s")
void logCannotUnsetUnexpectedSessionInCollection(String msg);

@LogMessage(level = WARN)
@Message(id = 90030008, value = "An unexpected session is defined for a collection, but the collection is not connected to that session."
+ " A persistent collection may only be associated with one session at a time. Overwriting session. %s")
void logUnexpectedSessionInCollectionNotConnected(String msg);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.Status;
import org.hibernate.engine.spi.TypedValue;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.SessionFactoryRegistry;
import org.hibernate.internal.util.MarkerObject;
import org.hibernate.internal.util.collections.IdentitySet;
Expand All @@ -40,6 +38,7 @@
import org.checkerframework.checker.nullness.qual.Nullable;

import static java.util.Collections.emptyList;
import static org.hibernate.collection.internal.CollectionLogger.COLLECTION_LOGGER;
import static org.hibernate.engine.internal.ForeignKeys.getEntityIdentifier;
import static org.hibernate.engine.internal.ForeignKeys.getEntityIdentifierIfNotUnsaved;
import static org.hibernate.engine.internal.ForeignKeys.isNotTransient;
Expand All @@ -57,8 +56,6 @@
*/
public abstract class AbstractPersistentCollection<E> implements Serializable, PersistentCollection<E> {

private static final CoreMessageLogger LOG = CoreLogging.messageLogger( AbstractPersistentCollection.class );

private transient SharedSessionContractImplementor session;
private boolean isTempSession = false;

Expand Down Expand Up @@ -298,7 +295,7 @@ else if ( !session.isConnected() ) {
tempSession.close();
}
catch (Exception e) {
LOG.unableToCloseTemporarySession();
COLLECTION_LOGGER.unableToCloseTemporarySession();
}
}
else {
Expand Down Expand Up @@ -706,15 +703,15 @@ public final boolean unsetSession(SharedSessionContractImplementor currentSessio
if ( allowLoadOutsideTransaction
&& !initialized
&& session.getLoadQueryInfluencers().hasEnabledFilters() ) {
LOG.enabledFiltersWhenDetachFromSession( collectionInfoString( getRole(), getKey() ) );
COLLECTION_LOGGER.enabledFiltersWhenDetachFromSession( collectionInfoString( getRole(), getKey() ) );
}
session = null;
}
return true;
}
else {
if ( session != null ) {
LOG.logCannotUnsetUnexpectedSessionInCollection( unexpectedSessionStateMessage( currentSession ) );
COLLECTION_LOGGER.logCannotUnsetUnexpectedSessionInCollection( unexpectedSessionStateMessage( currentSession ) );
}
return false;
}
Expand All @@ -724,20 +721,20 @@ private void logDiscardedQueuedOperations() {
try {
if ( wasTransactionRolledBack() ) {
// It was due to a rollback.
if ( LOG.isDebugEnabled()) {
LOG.queuedOperationWhenDetachFromSessionOnRollback( collectionInfoString( getRole(), getKey() ) );
if ( COLLECTION_LOGGER.isDebugEnabled()) {
COLLECTION_LOGGER.queuedOperationWhenDetachFromSessionOnRollback( collectionInfoString( getRole(), getKey() ) );
}
}
else {
// We don't know why the collection is being detached.
// Just log the info.
LOG.queuedOperationWhenDetachFromSession( collectionInfoString( getRole(), getKey() ) );
COLLECTION_LOGGER.queuedOperationWhenDetachFromSession( collectionInfoString( getRole(), getKey() ) );
}
}
catch (Exception e) {
// We don't know why the collection is being detached.
// Just log the info.
LOG.queuedOperationWhenDetachFromSession( collectionInfoString( getRole(), getKey() ) );
COLLECTION_LOGGER.queuedOperationWhenDetachFromSession( collectionInfoString( getRole(), getKey() ) );
}
}

Expand Down Expand Up @@ -772,11 +769,11 @@ else if ( this.session != null ) {
);
}
else {
LOG.logUnexpectedSessionInCollectionNotConnected( message );
COLLECTION_LOGGER.logUnexpectedSessionInCollectionNotConnected( message );
}
}
if ( hasQueuedOperations() ) {
LOG.queuedOperationWhenAttachToSession( collectionInfoString( getRole(), getKey() ) );
COLLECTION_LOGGER.queuedOperationWhenAttachToSession( collectionInfoString( getRole(), getKey() ) );
}
this.session = session;
return true;
Expand Down Expand Up @@ -808,7 +805,7 @@ private String unexpectedSessionStateMessage(SharedSessionContractImplementor se
}
}
// only include the collection contents if debug logging
if ( LOG.isDebugEnabled() ) {
if ( COLLECTION_LOGGER.isDebugEnabled() ) {
final String collectionContents = wasInitialized() ? toString() : "<uninitialized>";
message.append( "\nCollection contents: [" ).append( collectionContents ).append( "]" );
}
Expand Down
Loading
Loading