@@ -40,25 +40,23 @@ private MessageHelper() {
40
40
* @return An info string, in the form [FooBar#1].
41
41
*/
42
42
public static String infoString (@ Nullable String entityName , @ Nullable Object id ) {
43
- StringBuilder s = new StringBuilder ();
44
- s .append ( '[' );
43
+ final StringBuilder info = new StringBuilder ();
44
+ info .append ( '[' );
45
45
if ( entityName == null ) {
46
- s .append ( "<null entity name> " );
46
+ info .append ( "unknown entity name" );
47
47
}
48
48
else {
49
- s .append ( entityName );
49
+ info .append ( entityName );
50
50
}
51
- s .append ( '#' );
52
51
53
52
if ( id == null ) {
54
- s .append ( "< null> " );
53
+ info .append ( " with null id " );
55
54
}
56
55
else {
57
- s .append ( id );
56
+ info .append ( " with id '" ). append ( id ). append ( "'" );
58
57
}
59
- s .append ( ']' );
60
-
61
- return s .toString ();
58
+ info .append ( ']' );
59
+ return info .toString ();
62
60
}
63
61
64
62
/**
@@ -73,38 +71,39 @@ public static String infoString(
73
71
@ Nullable EntityPersister persister ,
74
72
@ Nullable Object id ,
75
73
@ Nullable SessionFactoryImplementor factory ) {
76
- StringBuilder s = new StringBuilder ();
77
- s .append ( '[' );
74
+ final StringBuilder info = new StringBuilder ();
75
+ info .append ( '[' );
78
76
Type idType ;
79
77
if ( persister == null ) {
80
- s .append ( "<null EntityPersister> " );
78
+ info .append ( "unknown entity " );
81
79
idType = null ;
82
80
}
83
81
else {
84
- s .append ( persister .getEntityName () );
82
+ info .append ( persister .getEntityName () );
85
83
idType = persister .getIdentifierType ();
86
84
}
87
- s .append ( '#' );
88
85
89
86
if ( id == null ) {
90
- s .append ( "< null> " );
87
+ info .append ( " with null id " );
91
88
}
92
89
else {
90
+ info .append ( " with id '" ).append ( id ).append ( "'" );
93
91
if ( idType == null ) {
94
- s .append ( id );
92
+ info .append ( id );
95
93
}
96
94
else {
97
95
if ( factory != null ) {
98
- s .append ( idType .toLoggableString ( id , factory ) );
96
+ info .append ( idType .toLoggableString ( id , factory ) );
99
97
}
100
98
else {
101
- s .append ( "<not loggable>" );
99
+ info .append ( "<not loggable>" );
102
100
}
103
101
}
102
+ info .append ( "'" );
104
103
}
105
- s .append ( ']' );
104
+ info .append ( ']' );
106
105
107
- return s .toString ();
106
+ return info .toString ();
108
107
109
108
}
110
109
@@ -122,25 +121,24 @@ public static String infoString(
122
121
@ Nullable Object id ,
123
122
Type identifierType ,
124
123
SessionFactoryImplementor factory ) {
125
- StringBuilder s = new StringBuilder ();
126
- s .append ( '[' );
124
+ final StringBuilder info = new StringBuilder ();
125
+ info .append ( '[' );
127
126
if ( persister == null ) {
128
- s .append ( "<null EntityPersister> " );
127
+ info .append ( "unknown entity " );
129
128
}
130
129
else {
131
- s .append ( persister .getEntityName () );
130
+ info .append ( persister .getEntityName () );
132
131
}
133
- s .append ( '#' );
134
132
135
133
if ( id == null ) {
136
- s .append ( "< null> " );
134
+ info .append ( " with null id " );
137
135
}
138
136
else {
139
- s .append ( identifierType .toLoggableString ( id , factory ) );
137
+ info .append ( " with id '" ). append ( identifierType .toLoggableString ( id , factory ) ). append ( "'" );
140
138
}
141
- s .append ( ']' );
139
+ info .append ( ']' );
142
140
143
- return s .toString ();
141
+ return info .toString ();
144
142
}
145
143
146
144
/**
@@ -155,25 +153,25 @@ public static String infoString(
155
153
@ Nullable EntityPersister persister ,
156
154
Object [] ids ,
157
155
SessionFactoryImplementor factory ) {
158
- StringBuilder s = new StringBuilder ();
159
- s .append ( '[' );
160
- if ( persister == null ) {
161
- s .append ( "<null EntityPersister> " );
156
+ final StringBuilder info = new StringBuilder ();
157
+ info .append ( '[' );
158
+ if ( persister == null ) {
159
+ info .append ( "unknown entity " );
162
160
}
163
161
else {
164
- s .append ( persister .getEntityName () );
165
- s .append ( "#< " );
162
+ info .append ( persister .getEntityName () );
163
+ info .append ( " with ids " );
166
164
for ( int i =0 ; i <ids .length ; i ++ ) {
167
- s .append ( persister .getIdentifierType ().toLoggableString ( ids [i ], factory ) );
165
+ info .append ( "'" )
166
+ .append ( persister .getIdentifierType ().toLoggableString ( ids [i ], factory ) )
167
+ .append ( "'" );
168
168
if ( i < ids .length -1 ) {
169
- s .append ( ", " );
169
+ info .append ( ", " );
170
170
}
171
171
}
172
- s .append ( '>' );
173
172
}
174
- s .append ( ']' );
175
-
176
- return s .toString ();
173
+ info .append ( ']' );
174
+ return info .toString ();
177
175
178
176
}
179
177
@@ -184,16 +182,16 @@ public static String infoString(
184
182
* @return An info string, in the form [FooBar]
185
183
*/
186
184
public static String infoString (@ Nullable EntityPersister persister ) {
187
- StringBuilder s = new StringBuilder ();
188
- s .append ( '[' );
185
+ final StringBuilder info = new StringBuilder ();
186
+ info .append ( '[' );
189
187
if ( persister == null ) {
190
- s .append ( "<null EntityPersister> " );
188
+ info .append ( "unknown entity " );
191
189
}
192
190
else {
193
- s .append ( persister .getEntityName () );
191
+ info .append ( persister .getEntityName () );
194
192
}
195
- s .append ( ']' );
196
- return s .toString ();
193
+ info .append ( ']' );
194
+ return info .toString ();
197
195
}
198
196
199
197
/**
@@ -206,21 +204,20 @@ public static String infoString(@Nullable EntityPersister persister) {
206
204
* @return An info string, in the form [Foo.bars#1]
207
205
*/
208
206
public static String infoString (String entityName , String propertyName , @ Nullable Object key ) {
209
- StringBuilder s = new StringBuilder ()
207
+ final StringBuilder info = new StringBuilder ()
210
208
.append ( '[' )
211
209
.append ( entityName )
212
210
.append ( '.' )
213
- .append ( propertyName )
214
- .append ( '#' );
211
+ .append ( propertyName );
215
212
216
213
if ( key == null ) {
217
- s .append ( "< null> " );
214
+ info .append ( " with null owner id " );
218
215
}
219
216
else {
220
- s .append ( key );
217
+ info .append ( " with owner id '" ). append ( key ). append ( "'" );
221
218
}
222
- s .append ( ']' );
223
- return s .toString ();
219
+ info .append ( ']' );
220
+ return info .toString ();
224
221
}
225
222
226
223
@@ -242,36 +239,35 @@ public static String collectionInfoString(
242
239
@ Nullable PersistentCollection <?> collection ,
243
240
Object collectionKey ,
244
241
SharedSessionContractImplementor session ) {
245
-
246
- StringBuilder s = new StringBuilder ();
247
- s .append ( '[' );
242
+ final StringBuilder info = new StringBuilder ();
243
+ info .append ( '[' );
248
244
if ( persister == null ) {
249
- s .append ( "< unreferenced> " );
245
+ info .append ( "unreferenced collection " );
250
246
}
251
247
else {
252
- s .append ( persister .getRole () );
253
- s .append ( '#' );
254
-
255
- Type ownerIdentifierType = persister .getOwnerEntityPersister ()
256
- .getIdentifierType ();
257
- Object ownerKey ;
248
+ info .append ( persister .getRole () );
249
+ final Type ownerIdentifierType =
250
+ persister .getOwnerEntityPersister ().getIdentifierType ();
251
+ final Object ownerKey ;
258
252
// TODO: Is it redundant to attempt to use the collectionKey,
259
253
// or is always using the owner id sufficient?
260
254
if ( collectionKey .getClass ().isAssignableFrom (
261
255
ownerIdentifierType .getReturnedClass () ) ) {
262
256
ownerKey = collectionKey ;
263
257
}
264
258
else {
265
- Object collectionOwner = collection == null ? null : collection .getOwner ();
266
- EntityEntry entry = collectionOwner == null ? null : session .getPersistenceContextInternal ().getEntry (collectionOwner );
259
+ final Object collectionOwner = collection == null ? null
260
+ : collection .getOwner ();
261
+ final EntityEntry entry = collectionOwner == null ? null
262
+ : session .getPersistenceContextInternal ().getEntry ( collectionOwner );
267
263
ownerKey = entry == null ? null : entry .getId ();
268
264
}
269
- s .append ( ownerIdentifierType .toLoggableString (
270
- ownerKey , session .getFactory () ) );
265
+ info .append ( " with owner id '" )
266
+ .append ( ownerIdentifierType .toLoggableString ( ownerKey , session .getFactory () ) )
267
+ .append ( "'" );
271
268
}
272
- s .append ( ']' );
273
-
274
- return s .toString ();
269
+ info .append ( ']' );
270
+ return info .toString ();
275
271
}
276
272
277
273
/**
@@ -287,24 +283,25 @@ public static String collectionInfoString(
287
283
@ Nullable CollectionPersister persister ,
288
284
Object [] ids ,
289
285
SessionFactoryImplementor factory ) {
290
- StringBuilder s = new StringBuilder ();
291
- s .append ( '[' );
286
+ final StringBuilder info = new StringBuilder ();
287
+ info .append ( '[' );
292
288
if ( persister == null ) {
293
- s .append ( "< unreferenced> " );
289
+ info .append ( "unreferenced collection " );
294
290
}
295
291
else {
296
- s .append ( persister .getRole () );
297
- s .append ( "#< " );
292
+ info .append ( persister .getRole () );
293
+ info .append ( " with owner ids " );
298
294
for ( int i = 0 ; i < ids .length ; i ++ ) {
299
- addIdToCollectionInfoString ( persister , ids [i ], factory , s );
295
+ info .append ( "'" );
296
+ addIdToCollectionInfoString ( persister , ids [i ], factory , info );
297
+ info .append ( "'" );
300
298
if ( i < ids .length -1 ) {
301
- s .append ( ", " );
299
+ info .append ( ", " );
302
300
}
303
301
}
304
- s .append ( '>' );
305
302
}
306
- s .append ( ']' );
307
- return s .toString ();
303
+ info .append ( ']' );
304
+ return info .toString ();
308
305
}
309
306
310
307
/**
@@ -320,25 +317,24 @@ public static String collectionInfoString(
320
317
@ Nullable CollectionPersister persister ,
321
318
@ Nullable Object id ,
322
319
SessionFactoryImplementor factory ) {
323
- StringBuilder s = new StringBuilder ();
324
- s .append ( '[' );
320
+ final StringBuilder info = new StringBuilder ();
321
+ info .append ( '[' );
325
322
if ( persister == null ) {
326
- s .append ( "< unreferenced> " );
323
+ info .append ( "unreferenced collection " );
327
324
}
328
325
else {
329
- s .append ( persister .getRole () );
330
- s .append ( '#' );
331
-
326
+ info .append ( persister .getRole () );
332
327
if ( id == null ) {
333
- s .append ( "< null> " );
328
+ info .append ( " with null owner id " );
334
329
}
335
330
else {
336
- addIdToCollectionInfoString ( persister , id , factory , s );
331
+ info .append ( " with owner id '" );
332
+ addIdToCollectionInfoString ( persister , id , factory , info );
333
+ info .append ( "'" );
337
334
}
338
335
}
339
- s .append ( ']' );
340
-
341
- return s .toString ();
336
+ info .append ( ']' );
337
+ return info .toString ();
342
338
}
343
339
344
340
private static void addIdToCollectionInfoString (
@@ -353,8 +349,8 @@ private static void addIdToCollectionInfoString(
353
349
// Also need to check that the expected identifier type matches
354
350
// the given ID. Due to property-ref keys, the collection key
355
351
// may not be the owner key.
356
- Type ownerIdentifierType = persister . getOwnerEntityPersister ()
357
- .getIdentifierType ();
352
+ final Type ownerIdentifierType =
353
+ persister . getOwnerEntityPersister () .getIdentifierType ();
358
354
if ( id .getClass ().isAssignableFrom (
359
355
ownerIdentifierType .getReturnedClass () ) ) {
360
356
s .append ( ownerIdentifierType .toLoggableString ( id , factory ) );
@@ -375,24 +371,22 @@ private static void addIdToCollectionInfoString(
375
371
* @return An info string, in the form [Foo.bars#1]
376
372
*/
377
373
public static String collectionInfoString (@ Nullable String role , @ Nullable Object id ) {
378
- StringBuilder s = new StringBuilder ();
379
- s .append ( '[' );
374
+ final StringBuilder info = new StringBuilder ();
375
+ info .append ( '[' );
380
376
if ( role == null ) {
381
- s .append ( "< unreferenced> " );
377
+ info .append ( "unreferenced collection " );
382
378
}
383
379
else {
384
- s .append ( role );
385
- s .append ( '#' );
386
-
380
+ info .append ( role );
387
381
if ( id == null ) {
388
- s .append ( "< null> " );
382
+ info .append ( " with null owner id " );
389
383
}
390
384
else {
391
- s .append ( id );
385
+ info .append ( " with owner id '" ). append ( id ). append ( "'" );
392
386
}
393
387
}
394
- s .append ( ']' );
395
- return s .toString ();
388
+ info .append ( ']' );
389
+ return info .toString ();
396
390
}
397
391
398
392
}
0 commit comments