Skip to content

Commit d8dae66

Browse files
committed
introduce ActionLogging + add some info to API doc
1 parent 38d1b03 commit d8dae66

File tree

5 files changed

+268
-70
lines changed

5 files changed

+268
-70
lines changed
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.action.internal;
6+
7+
import java.lang.invoke.MethodHandles;
8+
import java.util.Set;
9+
10+
import org.hibernate.Internal;
11+
import org.hibernate.internal.log.SubSystemLogging;
12+
13+
import org.jboss.logging.BasicLogger;
14+
import org.jboss.logging.Logger;
15+
import org.jboss.logging.annotations.LogMessage;
16+
import org.jboss.logging.annotations.Message;
17+
import org.jboss.logging.annotations.MessageLogger;
18+
import org.jboss.logging.annotations.ValidIdRange;
19+
20+
import static org.jboss.logging.Logger.Level.TRACE;
21+
import static org.jboss.logging.Logger.Level.WARN;
22+
23+
/**
24+
* Logging related to the action queue.
25+
*/
26+
@MessageLogger(projectCode = "HHH")
27+
@ValidIdRange(min = 90032001, max = 90033000)
28+
@SubSystemLogging(
29+
name = ActionLogging.NAME,
30+
description = "Logging related to the action queue"
31+
)
32+
@Internal
33+
public interface ActionLogging extends BasicLogger {
34+
String NAME = SubSystemLogging.BASE + ".action";
35+
36+
ActionLogging ACTION_LOGGER = Logger.getMessageLogger(
37+
MethodHandles.lookup(), ActionLogging.class, NAME
38+
);
39+
40+
int NAMESPACE = 90032000;
41+
42+
@LogMessage(level = TRACE)
43+
@Message(
44+
value = "Adding insert with non-nullable, transient entities; insert=[%s], dependencies=[%s]",
45+
id = NAMESPACE + 1
46+
)
47+
void addingInsertWithNonNullableTransientEntities(Object insert, String dependenciesLoggableString);
48+
49+
@LogMessage(level = TRACE)
50+
@Message(
51+
value = "No entity insert actions have non-nullable, transient entity dependencies",
52+
id = NAMESPACE + 2
53+
)
54+
void noEntityInsertActionsHaveNonNullableTransientDependencies();
55+
56+
@LogMessage(level = WARN)
57+
@Message(
58+
id = NAMESPACE + 3,
59+
value = """
60+
Attempting to save one or more entities that have a non-nullable association with an unsaved transient entity.
61+
The unsaved transient entity must be saved in an operation prior to saving these dependent entities.
62+
Unsaved transient entity: %s
63+
Dependent entities: %s
64+
Non-nullable associations: %s"""
65+
)
66+
void cannotResolveNonNullableTransientDependencies(
67+
String transientEntityString,
68+
Set<String> dependentEntityStrings,
69+
Set<String> nonNullableAssociationPaths);
70+
71+
72+
@LogMessage(level = TRACE)
73+
@Message(
74+
value = "No unresolved entity inserts that depended on [%s]",
75+
id = NAMESPACE + 4
76+
)
77+
void noUnresolvedEntityInsertsThatDependedOn(String entityInfoString);
78+
79+
@LogMessage(level = TRACE)
80+
@Message(
81+
value = "Unresolved inserts before resolving [%s]: [%s]",
82+
id = NAMESPACE + 5
83+
)
84+
void unresolvedInsertsBeforeResolving(String entityInfoString, String unresolvedState);
85+
86+
@LogMessage(level = TRACE)
87+
@Message(
88+
value = "Resolving insert [%s] dependency on [%s]",
89+
id = NAMESPACE + 6
90+
)
91+
void resolvingInsertDependencyOn(String dependentInfo, String entityInfo);
92+
93+
@LogMessage(level = TRACE)
94+
@Message(
95+
value = "Resolving insert [%s] (only depended on [%s])",
96+
id = NAMESPACE + 7
97+
)
98+
void resolvingInsertOnlyDependedOn(Object dependentAction, String entityInfo);
99+
100+
@LogMessage(level = TRACE)
101+
@Message(
102+
value = "Unresolved inserts after resolving [%s]: [%s]",
103+
id = NAMESPACE + 8
104+
)
105+
void unresolvedInsertsAfterResolving(String entityInfo, String unresolvedState);
106+
107+
@LogMessage(level = TRACE)
108+
@Message(
109+
value = "Starting serialization of [%s] unresolved insert entries",
110+
id = NAMESPACE + 9
111+
)
112+
void serializingUnresolvedInsertEntries(int queueSize);
113+
114+
@LogMessage(level = TRACE)
115+
@Message(
116+
value = "Starting deserialization of [%s] unresolved insert entries",
117+
id = NAMESPACE + 10
118+
)
119+
void deserializingUnresolvedInsertEntries(int queueSize);
120+
121+
// ActionQueue
122+
@LogMessage(level = TRACE)
123+
@Message(
124+
value = "Adding an EntityInsertAction for entity of type [%s]",
125+
id = NAMESPACE + 11
126+
)
127+
void addingEntityInsertAction(String entityName);
128+
129+
@LogMessage(level = TRACE)
130+
@Message(
131+
value = "Executing inserts before finding non-nullable transient entities for early insert: [%s]",
132+
id = NAMESPACE + 12
133+
)
134+
void executingInsertsBeforeFindingNonNullableTransientEntitiesForEarlyInsert(Object insertAction);
135+
136+
@LogMessage(level = TRACE)
137+
@Message(
138+
value = "Adding insert with no non-nullable, transient entities: [%s]",
139+
id = NAMESPACE + 13
140+
)
141+
void addingInsertWithNoNonNullableTransientEntities(Object insertAction);
142+
143+
@LogMessage(level = TRACE)
144+
@Message(
145+
value = "Executing insertions before resolved early insert",
146+
id = NAMESPACE + 14
147+
)
148+
void executingInsertionsBeforeResolvedEarlyInsert();
149+
150+
@LogMessage(level = TRACE)
151+
@Message(
152+
value = "Executing identity insert immediately",
153+
id = NAMESPACE + 15
154+
)
155+
void executingIdentityInsertImmediately();
156+
157+
@LogMessage(level = TRACE)
158+
@Message(
159+
value = "Adding resolved non-early insert action.",
160+
id = NAMESPACE + 16
161+
)
162+
void addingResolvedNonEarlyInsertAction();
163+
164+
@LogMessage(level = TRACE)
165+
@Message(
166+
value = "Adding an EntityIdentityInsertAction for entity of type [%s]",
167+
id = NAMESPACE + 17
168+
)
169+
void addingEntityIdentityInsertAction(String entityName);
170+
171+
@LogMessage(level = TRACE)
172+
@Message(
173+
value = "Changes must be flushed to space: %s",
174+
id = NAMESPACE + 18
175+
)
176+
void changesMustBeFlushedToSpace(Object space);
177+
178+
@LogMessage(level = TRACE)
179+
@Message(
180+
value = "Serializing action queue",
181+
id = NAMESPACE + 19
182+
)
183+
void serializingActionQueue();
184+
185+
@LogMessage(level = TRACE)
186+
@Message(
187+
value = "Deserializing action queue",
188+
id = NAMESPACE + 20
189+
)
190+
void deserializingActionQueue();
191+
192+
@LogMessage(level = TRACE)
193+
@Message(
194+
value = "Deserialized [%s] entries",
195+
id = NAMESPACE + 21
196+
)
197+
void deserializedEntries(int count);
198+
199+
@LogMessage(level = WARN)
200+
@Message(
201+
value = "Batch containing %s statements could not be sorted (might indicate a circular entity relationship)",
202+
id = NAMESPACE + 22
203+
)
204+
void batchCouldNotBeSorted(int count);
205+
}

hibernate-core/src/main/java/org/hibernate/action/internal/UnresolvedEntityInsertActions.java

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
import static java.util.Collections.emptySet;
26-
import static org.hibernate.internal.CoreMessageLogger.CORE_LOGGER;
26+
import static org.hibernate.action.internal.ActionLogging.ACTION_LOGGER;
2727
import static org.hibernate.pretty.MessageHelper.infoString;
2828

2929
/**
@@ -61,9 +61,8 @@ public void addUnresolvedEntityInsertAction(AbstractEntityInsertAction insert, N
6161
"Attempt to add an unresolved insert action that has no non-nullable transient entities."
6262
);
6363
}
64-
if ( CORE_LOGGER.isTraceEnabled() ) {
65-
CORE_LOGGER.tracev(
66-
"Adding insert with non-nullable, transient entities; insert=[{0}], dependencies=[{1}]",
64+
if ( ACTION_LOGGER.isTraceEnabled() ) {
65+
ACTION_LOGGER.addingInsertWithNonNullableTransientEntities(
6766
insert,
6867
dependencies.toLoggableString( insert.getSession() )
6968
);
@@ -94,7 +93,7 @@ public Iterable<AbstractEntityInsertAction> getDependentEntityInsertActions() {
9493
*/
9594
public void checkNoUnresolvedActionsAfterOperation() throws PropertyValueException {
9695
if ( isEmpty() ) {
97-
CORE_LOGGER.trace( "No entity insert actions have non-nullable, transient entity dependencies." );
96+
ACTION_LOGGER.noEntityInsertActionsHaveNonNullableTransientDependencies();
9897
}
9998
else {
10099
final var firstDependentAction = dependenciesByAction.keySet().iterator().next();
@@ -134,13 +133,15 @@ private void logCannotResolveNonNullableTransientDependencies(SharedSessionContr
134133
final Set<String> nonNullableTransientPropertyPaths = new TreeSet<>();
135134
for ( var dependentAction : entry.getValue() ) {
136135
dependentEntityStrings.add( infoString( dependentAction.getEntityName(), dependentAction.getId() ) );
137-
for ( String path : dependenciesByAction.get( dependentAction ).getNonNullableTransientPropertyPaths( transientEntity ) ) {
136+
for ( String path :
137+
dependenciesByAction.get( dependentAction )
138+
.getNonNullableTransientPropertyPaths( transientEntity ) ) {
138139
final String fullPath = dependentAction.getEntityName() + '.' + path;
139140
nonNullableTransientPropertyPaths.add( fullPath );
140141
}
141142
}
142143

143-
CORE_LOGGER.cannotResolveNonNullableTransientDependencies(
144+
ACTION_LOGGER.cannotResolveNonNullableTransientDependencies(
144145
transientEntityString,
145146
dependentEntityStrings,
146147
nonNullableTransientPropertyPaths
@@ -184,14 +185,13 @@ public Set<AbstractEntityInsertAction> resolveDependentActions(Object managedEnt
184185
throw new IllegalArgumentException( "EntityEntry did not have status MANAGED or READ_ONLY: " + entityEntry );
185186
}
186187

187-
final boolean traceEnabled = CORE_LOGGER.isTraceEnabled();
188+
final boolean traceEnabled = ACTION_LOGGER.isTraceEnabled();
188189
// Find out if there are any unresolved insertions that are waiting for the
189190
// specified entity to be resolved.
190191
final var dependentActions = dependentActionsByTransientEntity.remove( managedEntity );
191192
if ( dependentActions == null ) {
192193
if ( traceEnabled ) {
193-
CORE_LOGGER.tracev(
194-
"No unresolved entity inserts that depended on [{0}]",
194+
ACTION_LOGGER.noUnresolvedEntityInsertsThatDependedOn(
195195
infoString( entityEntry.getEntityName(), entityEntry.getId() )
196196
);
197197
}
@@ -200,16 +200,14 @@ public Set<AbstractEntityInsertAction> resolveDependentActions(Object managedEnt
200200
else {
201201
final Set<AbstractEntityInsertAction> resolvedActions = new IdentitySet<>();
202202
if ( traceEnabled ) {
203-
CORE_LOGGER.tracev(
204-
"Unresolved inserts before resolving [{0}]: [{1}]",
203+
ACTION_LOGGER.unresolvedInsertsBeforeResolving(
205204
infoString( entityEntry.getEntityName(), entityEntry.getId() ),
206205
toString()
207206
);
208207
}
209208
for ( var dependentAction : dependentActions ) {
210209
if ( traceEnabled ) {
211-
CORE_LOGGER.tracev(
212-
"Resolving insert [{0}] dependency on [{1}]",
210+
ACTION_LOGGER.resolvingInsertDependencyOn(
213211
infoString( dependentAction.getEntityName(), dependentAction.getId() ),
214212
infoString( entityEntry.getEntityName(), entityEntry.getId() )
215213
);
@@ -218,8 +216,7 @@ public Set<AbstractEntityInsertAction> resolveDependentActions(Object managedEnt
218216
dependencies.resolveNonNullableTransientEntity( managedEntity );
219217
if ( dependencies.isEmpty() ) {
220218
if ( traceEnabled ) {
221-
CORE_LOGGER.tracev(
222-
"Resolving insert [{0}] (only depended on [{1}])",
219+
ACTION_LOGGER.resolvingInsertOnlyDependedOn(
223220
dependentAction,
224221
infoString( entityEntry.getEntityName(), entityEntry.getId() )
225222
);
@@ -230,8 +227,7 @@ public Set<AbstractEntityInsertAction> resolveDependentActions(Object managedEnt
230227
}
231228
}
232229
if ( traceEnabled ) {
233-
CORE_LOGGER.tracev(
234-
"Unresolved inserts after resolving [{0}]: [{1}]",
230+
ACTION_LOGGER.unresolvedInsertsAfterResolving(
235231
infoString( entityEntry.getEntityName(), entityEntry.getId() ),
236232
toString()
237233
);
@@ -271,7 +267,7 @@ public String toString() {
271267
*/
272268
public void serialize(ObjectOutputStream oos) throws IOException {
273269
final int queueSize = dependenciesByAction.size();
274-
CORE_LOGGER.tracev( "Starting serialization of [{0}] unresolved insert entries", queueSize );
270+
ACTION_LOGGER.serializingUnresolvedInsertEntries(queueSize);
275271
oos.writeInt( queueSize );
276272
for ( AbstractEntityInsertAction unresolvedAction : dependenciesByAction.keySet() ) {
277273
oos.writeObject( unresolvedAction );
@@ -295,7 +291,7 @@ public static UnresolvedEntityInsertActions deserialize(
295291
final var rtn = new UnresolvedEntityInsertActions();
296292

297293
final int queueSize = ois.readInt();
298-
CORE_LOGGER.tracev( "Starting deserialization of [{0}] unresolved insert entries", queueSize );
294+
ACTION_LOGGER.deserializingUnresolvedInsertEntries(queueSize);
299295
for ( int i = 0; i < queueSize; i++ ) {
300296
final var unresolvedAction = (AbstractEntityInsertAction) ois.readObject();
301297
unresolvedAction.afterDeserialize( session );

0 commit comments

Comments
 (0)