1919import org .hibernate .generator .GeneratorCreationContext ;
2020import org .hibernate .id .Configurable ;
2121import org .hibernate .id .OptimizableGenerator ;
22- import org .hibernate .id .PersistentIdentifierGenerator ;
2322import org .hibernate .id .enhanced .LegacyNamingStrategy ;
2423import org .hibernate .id .enhanced .SequenceStyleGenerator ;
2524import org .hibernate .id .enhanced .SingleNamingStrategy ;
2625import org .hibernate .mapping .Column ;
2726import org .hibernate .mapping .RootClass ;
28- import org .hibernate .mapping .Table ;
2927
3028import jakarta .persistence .SequenceGenerator ;
3129import jakarta .persistence .TableGenerator ;
4038import static org .hibernate .id .OptimizableGenerator .IMPLICIT_NAME_BASE ;
4139import static org .hibernate .id .OptimizableGenerator .INCREMENT_PARAM ;
4240import static org .hibernate .id .OptimizableGenerator .INITIAL_PARAM ;
41+ import static org .hibernate .id .PersistentIdentifierGenerator .CATALOG ;
42+ import static org .hibernate .id .PersistentIdentifierGenerator .OPTIONS ;
4343import static org .hibernate .id .PersistentIdentifierGenerator .PK ;
44+ import static org .hibernate .id .PersistentIdentifierGenerator .SCHEMA ;
4445import static org .hibernate .id .PersistentIdentifierGenerator .TABLE ;
4546import static org .hibernate .id .PersistentIdentifierGenerator .TABLES ;
4647import 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 ;
4754import static org .hibernate .internal .util .StringHelper .isNotBlank ;
4855import static org .hibernate .internal .util .collections .CollectionHelper .isNotEmpty ;
4956
@@ -111,16 +118,14 @@ static void collectBaselineProperties(
111118 BiConsumer <String ,String > parameterCollector ,
112119 ConfigurationService configService ) {
113120 //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 ) );
118124
119125 //pass the column name (a generated id almost always has a single column)
120126 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 ) );
124129 }
125130
126131 //pass the entity-name, if not a collection-id
@@ -139,25 +144,35 @@ static void collectBaselineProperties(
139144 parameterCollector .accept ( TABLES , identityTablesString ( dialect , rootClass ) );
140145 }
141146 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 ) );
144149 }
145150
146151 parameterCollector .accept ( CONTRIBUTOR_NAME ,
147152 identifierValue .getBuildingContext ().getCurrentContributorName () );
148153
149- final Map < String , Object > settings = configService .getSettings ();
154+ final var settings = configService .getSettings ();
150155 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 ();
155170 }
156171 }
157172
158173 public static String identityTablesString (Dialect dialect , RootClass rootClass ) {
159174 final var tables = new StringBuilder ();
160- for ( Table table : rootClass .getIdentityTables () ) {
175+ for ( var table : rootClass .getIdentityTables () ) {
161176 tables .append ( table .getQuotedName ( dialect ) );
162177 if ( !tables .isEmpty () ) {
163178 tables .append ( ", " );
@@ -188,67 +203,51 @@ public static void interpretTableGenerator(
188203 IdentifierGeneratorDefinition .Builder definitionBuilder ) {
189204 definitionBuilder .setName ( tableGeneratorAnnotation .name () );
190205 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" );
192207
193208 final String catalog = tableGeneratorAnnotation .catalog ();
194209 if ( isNotBlank ( catalog ) ) {
195- definitionBuilder .addParam ( PersistentIdentifierGenerator . CATALOG , catalog );
210+ definitionBuilder .addParam ( CATALOG , catalog );
196211 }
197212
198213 final String schema = tableGeneratorAnnotation .schema ();
199214 if ( isNotBlank ( schema ) ) {
200- definitionBuilder .addParam ( PersistentIdentifierGenerator . SCHEMA , schema );
215+ definitionBuilder .addParam ( SCHEMA , schema );
201216 }
202217
203218 final String table = tableGeneratorAnnotation .table ();
204219 if ( isNotBlank ( table ) ) {
205- definitionBuilder .addParam ( org . hibernate . id . enhanced . TableGenerator . TABLE_PARAM , table );
220+ definitionBuilder .addParam ( TABLE_PARAM , table );
206221 }
207222
208223 final String pkColumnName = tableGeneratorAnnotation .pkColumnName ();
209224 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 );
214226 }
215227
216228 final String pkColumnValue = tableGeneratorAnnotation .pkColumnValue ();
217229 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 );
222231 }
223232
224233 final String valueColumnName = tableGeneratorAnnotation .valueColumnName ();
225234 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 );
230236 }
231237
232238 final String options = tableGeneratorAnnotation .options ();
233239 if ( isNotBlank ( options ) ) {
234- definitionBuilder .addParam (
235- PersistentIdentifierGenerator .OPTIONS ,
236- options
237- );
240+ definitionBuilder .addParam ( OPTIONS , options );
238241 }
239242
240- definitionBuilder .addParam (
241- INCREMENT_PARAM ,
242- String .valueOf ( tableGeneratorAnnotation .allocationSize () )
243- );
243+ definitionBuilder .addParam ( INCREMENT_PARAM ,
244+ String .valueOf ( tableGeneratorAnnotation .allocationSize () ) );
244245
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 ) );
250249
251- // TODO : implement unique- constraint support
250+ // TODO: implement unique constraint support
252251 if ( isNotEmpty ( tableGeneratorAnnotation .uniqueConstraints () ) ) {
253252 BOOT_LOGGER .ignoringTableGeneratorConstraints ( tableGeneratorAnnotation .name () );
254253 }
@@ -263,31 +262,27 @@ public static void interpretSequenceGenerator(
263262
264263 final String catalog = sequenceGeneratorAnnotation .catalog ();
265264 if ( isNotBlank ( catalog ) ) {
266- definitionBuilder .addParam ( PersistentIdentifierGenerator . CATALOG , catalog );
265+ definitionBuilder .addParam ( CATALOG , catalog );
267266 }
268267
269268 final String schema = sequenceGeneratorAnnotation .schema ();
270269 if ( isNotBlank ( schema ) ) {
271- definitionBuilder .addParam ( PersistentIdentifierGenerator . SCHEMA , schema );
270+ definitionBuilder .addParam ( SCHEMA , schema );
272271 }
273272
274273 final String sequenceName = sequenceGeneratorAnnotation .sequenceName ();
275274 if ( isNotBlank ( sequenceName ) ) {
276- definitionBuilder .addParam ( SequenceStyleGenerator . SEQUENCE_PARAM , sequenceName );
275+ definitionBuilder .addParam ( SEQUENCE_PARAM , sequenceName );
277276 }
278277
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 () ) );
287282
288283 final String options = sequenceGeneratorAnnotation .options ();
289284 if ( isNotBlank ( options ) ) {
290- definitionBuilder .addParam ( PersistentIdentifierGenerator . OPTIONS , options );
285+ definitionBuilder .addParam ( OPTIONS , options );
291286 }
292287 }
293288}
0 commit comments