19
19
import org .hibernate .generator .GeneratorCreationContext ;
20
20
import org .hibernate .id .Configurable ;
21
21
import org .hibernate .id .OptimizableGenerator ;
22
- import org .hibernate .id .PersistentIdentifierGenerator ;
23
22
import org .hibernate .id .enhanced .LegacyNamingStrategy ;
24
23
import org .hibernate .id .enhanced .SequenceStyleGenerator ;
25
24
import org .hibernate .id .enhanced .SingleNamingStrategy ;
26
25
import org .hibernate .mapping .Column ;
27
26
import org .hibernate .mapping .RootClass ;
28
- import org .hibernate .mapping .Table ;
29
27
30
28
import jakarta .persistence .SequenceGenerator ;
31
29
import jakarta .persistence .TableGenerator ;
40
38
import static org .hibernate .id .OptimizableGenerator .IMPLICIT_NAME_BASE ;
41
39
import static org .hibernate .id .OptimizableGenerator .INCREMENT_PARAM ;
42
40
import static org .hibernate .id .OptimizableGenerator .INITIAL_PARAM ;
41
+ import static org .hibernate .id .PersistentIdentifierGenerator .CATALOG ;
42
+ import static org .hibernate .id .PersistentIdentifierGenerator .OPTIONS ;
43
43
import static org .hibernate .id .PersistentIdentifierGenerator .PK ;
44
+ import static org .hibernate .id .PersistentIdentifierGenerator .SCHEMA ;
44
45
import static org .hibernate .id .PersistentIdentifierGenerator .TABLE ;
45
46
import static org .hibernate .id .PersistentIdentifierGenerator .TABLES ;
46
47
import static org .hibernate .boot .BootLogging .BOOT_LOGGER ;
48
+ import static org .hibernate .id .enhanced .SequenceStyleGenerator .SEQUENCE_PARAM ;
49
+ import static org .hibernate .id .enhanced .TableGenerator .CONFIG_PREFER_SEGMENT_PER_ENTITY ;
50
+ import static org .hibernate .id .enhanced .TableGenerator .SEGMENT_COLUMN_PARAM ;
51
+ import static org .hibernate .id .enhanced .TableGenerator .SEGMENT_VALUE_PARAM ;
52
+ import static org .hibernate .id .enhanced .TableGenerator .TABLE_PARAM ;
53
+ import static org .hibernate .id .enhanced .TableGenerator .VALUE_COLUMN_PARAM ;
47
54
import static org .hibernate .internal .util .StringHelper .isNotBlank ;
48
55
import static org .hibernate .internal .util .collections .CollectionHelper .isNotEmpty ;
49
56
@@ -111,16 +118,14 @@ static void collectBaselineProperties(
111
118
BiConsumer <String ,String > parameterCollector ,
112
119
ConfigurationService configService ) {
113
120
//init the table here instead of earlier, so that we can get a quoted table name
114
- //TODO: would it be better to simply pass the qualified table name, instead of
115
- // splitting it up into schema/catalog/table names
116
- final String tableName = identifierValue .getTable ().getQuotedName ( dialect );
117
- parameterCollector .accept ( TABLE , tableName );
121
+ //TODO: would it be better to simply pass the qualified table name,
122
+ // instead of splitting it up into schema/catalog/table names
123
+ parameterCollector .accept ( TABLE , identifierValue .getTable ().getQuotedName ( dialect ) );
118
124
119
125
//pass the column name (a generated id almost always has a single column)
120
126
if ( identifierValue .getColumnSpan () == 1 ) {
121
- final Column column = (Column ) identifierValue .getSelectables ().get ( 0 );
122
- final String columnName = column .getQuotedName ( dialect );
123
- parameterCollector .accept ( PK , columnName );
127
+ final var column = (Column ) identifierValue .getSelectables ().get ( 0 );
128
+ parameterCollector .accept ( PK , column .getQuotedName ( dialect ) );
124
129
}
125
130
126
131
//pass the entity-name, if not a collection-id
@@ -139,25 +144,35 @@ static void collectBaselineProperties(
139
144
parameterCollector .accept ( TABLES , identityTablesString ( dialect , rootClass ) );
140
145
}
141
146
else {
142
- parameterCollector .accept ( TABLES , tableName );
143
- parameterCollector .accept ( IMPLICIT_NAME_BASE , tableName );
147
+ parameterCollector .accept ( TABLES , identifierValue . getTable (). getQuotedName ( dialect ) );
148
+ parameterCollector .accept ( IMPLICIT_NAME_BASE , identifierValue . getTable (). getQuotedName ( dialect ) );
144
149
}
145
150
146
151
parameterCollector .accept ( CONTRIBUTOR_NAME ,
147
152
identifierValue .getBuildingContext ().getCurrentContributorName () );
148
153
149
- final Map < String , Object > settings = configService .getSettings ();
154
+ final var settings = configService .getSettings ();
150
155
if ( settings .containsKey ( PREFERRED_POOLED_OPTIMIZER ) ) {
151
- parameterCollector .accept (
152
- PREFERRED_POOLED_OPTIMIZER ,
153
- (String ) settings .get ( PREFERRED_POOLED_OPTIMIZER )
154
- );
156
+ parameterCollector .accept ( PREFERRED_POOLED_OPTIMIZER ,
157
+ optimizerClassName ( settings .get ( PREFERRED_POOLED_OPTIMIZER ) ) );
158
+ }
159
+ }
160
+
161
+ private static String optimizerClassName (Object optimizerSetting ) {
162
+ if ( optimizerSetting instanceof String string ) {
163
+ return string ;
164
+ }
165
+ else if ( optimizerSetting instanceof Class <?> clazz ) {
166
+ return clazz .getName ();
167
+ }
168
+ else {
169
+ return optimizerSetting .toString ();
155
170
}
156
171
}
157
172
158
173
public static String identityTablesString (Dialect dialect , RootClass rootClass ) {
159
174
final var tables = new StringBuilder ();
160
- for ( Table table : rootClass .getIdentityTables () ) {
175
+ for ( var table : rootClass .getIdentityTables () ) {
161
176
tables .append ( table .getQuotedName ( dialect ) );
162
177
if ( !tables .isEmpty () ) {
163
178
tables .append ( ", " );
@@ -188,67 +203,51 @@ public static void interpretTableGenerator(
188
203
IdentifierGeneratorDefinition .Builder definitionBuilder ) {
189
204
definitionBuilder .setName ( tableGeneratorAnnotation .name () );
190
205
definitionBuilder .setStrategy ( org .hibernate .id .enhanced .TableGenerator .class .getName () );
191
- definitionBuilder .addParam ( org . hibernate . id . enhanced . TableGenerator . CONFIG_PREFER_SEGMENT_PER_ENTITY , "true" );
206
+ definitionBuilder .addParam ( CONFIG_PREFER_SEGMENT_PER_ENTITY , "true" );
192
207
193
208
final String catalog = tableGeneratorAnnotation .catalog ();
194
209
if ( isNotBlank ( catalog ) ) {
195
- definitionBuilder .addParam ( PersistentIdentifierGenerator . CATALOG , catalog );
210
+ definitionBuilder .addParam ( CATALOG , catalog );
196
211
}
197
212
198
213
final String schema = tableGeneratorAnnotation .schema ();
199
214
if ( isNotBlank ( schema ) ) {
200
- definitionBuilder .addParam ( PersistentIdentifierGenerator . SCHEMA , schema );
215
+ definitionBuilder .addParam ( SCHEMA , schema );
201
216
}
202
217
203
218
final String table = tableGeneratorAnnotation .table ();
204
219
if ( isNotBlank ( table ) ) {
205
- definitionBuilder .addParam ( org . hibernate . id . enhanced . TableGenerator . TABLE_PARAM , table );
220
+ definitionBuilder .addParam ( TABLE_PARAM , table );
206
221
}
207
222
208
223
final String pkColumnName = tableGeneratorAnnotation .pkColumnName ();
209
224
if ( isNotBlank ( pkColumnName ) ) {
210
- definitionBuilder .addParam (
211
- org .hibernate .id .enhanced .TableGenerator .SEGMENT_COLUMN_PARAM ,
212
- pkColumnName
213
- );
225
+ definitionBuilder .addParam ( SEGMENT_COLUMN_PARAM , pkColumnName );
214
226
}
215
227
216
228
final String pkColumnValue = tableGeneratorAnnotation .pkColumnValue ();
217
229
if ( isNotBlank ( pkColumnValue ) ) {
218
- definitionBuilder .addParam (
219
- org .hibernate .id .enhanced .TableGenerator .SEGMENT_VALUE_PARAM ,
220
- pkColumnValue
221
- );
230
+ definitionBuilder .addParam ( SEGMENT_VALUE_PARAM , pkColumnValue );
222
231
}
223
232
224
233
final String valueColumnName = tableGeneratorAnnotation .valueColumnName ();
225
234
if ( isNotBlank ( valueColumnName ) ) {
226
- definitionBuilder .addParam (
227
- org .hibernate .id .enhanced .TableGenerator .VALUE_COLUMN_PARAM ,
228
- valueColumnName
229
- );
235
+ definitionBuilder .addParam ( VALUE_COLUMN_PARAM , valueColumnName );
230
236
}
231
237
232
238
final String options = tableGeneratorAnnotation .options ();
233
239
if ( isNotBlank ( options ) ) {
234
- definitionBuilder .addParam (
235
- PersistentIdentifierGenerator .OPTIONS ,
236
- options
237
- );
240
+ definitionBuilder .addParam ( OPTIONS , options );
238
241
}
239
242
240
- definitionBuilder .addParam (
241
- INCREMENT_PARAM ,
242
- String .valueOf ( tableGeneratorAnnotation .allocationSize () )
243
- );
243
+ definitionBuilder .addParam ( INCREMENT_PARAM ,
244
+ String .valueOf ( tableGeneratorAnnotation .allocationSize () ) );
244
245
245
- // See comment on HHH-4884 wrt initialValue. Basically initialValue is really the stated value + 1
246
- definitionBuilder .addParam (
247
- INITIAL_PARAM ,
248
- String .valueOf ( tableGeneratorAnnotation .initialValue () + 1 )
249
- );
246
+ // See comment on HHH-4884 wrt initialValue. Basically initialValue is really the stated value + 1
247
+ definitionBuilder .addParam ( INITIAL_PARAM ,
248
+ String .valueOf ( tableGeneratorAnnotation .initialValue () + 1 ) );
250
249
251
- // TODO : implement unique- constraint support
250
+ // TODO: implement unique constraint support
252
251
if ( isNotEmpty ( tableGeneratorAnnotation .uniqueConstraints () ) ) {
253
252
BOOT_LOGGER .ignoringTableGeneratorConstraints ( tableGeneratorAnnotation .name () );
254
253
}
@@ -263,31 +262,27 @@ public static void interpretSequenceGenerator(
263
262
264
263
final String catalog = sequenceGeneratorAnnotation .catalog ();
265
264
if ( isNotBlank ( catalog ) ) {
266
- definitionBuilder .addParam ( PersistentIdentifierGenerator . CATALOG , catalog );
265
+ definitionBuilder .addParam ( CATALOG , catalog );
267
266
}
268
267
269
268
final String schema = sequenceGeneratorAnnotation .schema ();
270
269
if ( isNotBlank ( schema ) ) {
271
- definitionBuilder .addParam ( PersistentIdentifierGenerator . SCHEMA , schema );
270
+ definitionBuilder .addParam ( SCHEMA , schema );
272
271
}
273
272
274
273
final String sequenceName = sequenceGeneratorAnnotation .sequenceName ();
275
274
if ( isNotBlank ( sequenceName ) ) {
276
- definitionBuilder .addParam ( SequenceStyleGenerator . SEQUENCE_PARAM , sequenceName );
275
+ definitionBuilder .addParam ( SEQUENCE_PARAM , sequenceName );
277
276
}
278
277
279
- definitionBuilder .addParam (
280
- INCREMENT_PARAM ,
281
- String .valueOf ( sequenceGeneratorAnnotation .allocationSize () )
282
- );
283
- definitionBuilder .addParam (
284
- INITIAL_PARAM ,
285
- String .valueOf ( sequenceGeneratorAnnotation .initialValue () )
286
- );
278
+ definitionBuilder .addParam ( INCREMENT_PARAM ,
279
+ String .valueOf ( sequenceGeneratorAnnotation .allocationSize () ) );
280
+ definitionBuilder .addParam ( INITIAL_PARAM ,
281
+ String .valueOf ( sequenceGeneratorAnnotation .initialValue () ) );
287
282
288
283
final String options = sequenceGeneratorAnnotation .options ();
289
284
if ( isNotBlank ( options ) ) {
290
- definitionBuilder .addParam ( PersistentIdentifierGenerator . OPTIONS , options );
285
+ definitionBuilder .addParam ( OPTIONS , options );
291
286
}
292
287
}
293
288
}
0 commit comments