6666import org .hibernate .tool .schema .spi .SchemaManagementToolCoordinator ;
6767import org .hibernate .type .spi .TypeConfiguration ;
6868
69+ import static java .lang .String .join ;
6970import static org .hibernate .cfg .AvailableSettings .EVENT_LISTENER_PREFIX ;
7071import static org .hibernate .internal .util .StringHelper .splitAtCommas ;
7172import static org .hibernate .internal .util .collections .CollectionHelper .mapOfSize ;
@@ -164,17 +165,26 @@ public SqmFunctionRegistry getFunctionRegistry() {
164165
165166 @ Override
166167 public SessionFactoryBuilder getSessionFactoryBuilder () {
167- final SessionFactoryBuilderService factoryBuilderService = metadataBuildingOptions .getServiceRegistry ().requireService ( SessionFactoryBuilderService .class );
168- final SessionFactoryBuilderImplementor defaultBuilder = factoryBuilderService .createSessionFactoryBuilder ( this , bootstrapContext );
168+ final SessionFactoryBuilderImplementor defaultBuilder =
169+ metadataBuildingOptions .getServiceRegistry ()
170+ .requireService ( SessionFactoryBuilderService .class )
171+ .createSessionFactoryBuilder ( this , bootstrapContext );
172+ final SessionFactoryBuilder builder = discoverBuilder ( defaultBuilder );
173+ return builder != null ? builder : defaultBuilder ;
169174
170- final ClassLoaderService cls = metadataBuildingOptions .getServiceRegistry ().requireService ( ClassLoaderService .class );
171- final java .util .Collection <SessionFactoryBuilderFactory > discoveredBuilderFactories = cls .loadJavaServices ( SessionFactoryBuilderFactory .class );
175+ }
176+
177+ private SessionFactoryBuilder discoverBuilder (SessionFactoryBuilderImplementor defaultBuilder ) {
178+ final java .util .Collection <SessionFactoryBuilderFactory > discoveredBuilderFactories =
179+ metadataBuildingOptions .getServiceRegistry ().requireService ( ClassLoaderService .class )
180+ .loadJavaServices ( SessionFactoryBuilderFactory .class );
172181
173182 SessionFactoryBuilder builder = null ;
174183 List <String > activeFactoryNames = null ;
175184
176185 for ( SessionFactoryBuilderFactory discoveredBuilderFactory : discoveredBuilderFactories ) {
177- final SessionFactoryBuilder returnedBuilder = discoveredBuilderFactory .getSessionFactoryBuilder ( this , defaultBuilder );
186+ final SessionFactoryBuilder returnedBuilder =
187+ discoveredBuilderFactory .getSessionFactoryBuilder ( this , defaultBuilder );
178188 if ( returnedBuilder != null ) {
179189 if ( activeFactoryNames == null ) {
180190 activeFactoryNames = new ArrayList <>();
@@ -186,16 +196,11 @@ public SessionFactoryBuilder getSessionFactoryBuilder() {
186196
187197 if ( activeFactoryNames != null && activeFactoryNames .size () > 1 ) {
188198 throw new HibernateException (
189- "Multiple active SessionFactoryBuilderFactory definitions were discovered : " +
190- String . join (", " , activeFactoryNames )
199+ "Multiple active SessionFactoryBuilderFactory definitions were discovered: " +
200+ join ( ", " , activeFactoryNames )
191201 );
192202 }
193-
194- if ( builder != null ) {
195- return builder ;
196- }
197-
198- return defaultBuilder ;
203+ return builder ;
199204 }
200205
201206 @ Override
@@ -423,8 +428,7 @@ public void orderColumns(boolean forceOrdering) {
423428 }
424429 }
425430 for ( UserDefinedType userDefinedType : namespace .getUserDefinedTypes () ) {
426- if ( userDefinedType instanceof UserDefinedObjectType ) {
427- final UserDefinedObjectType objectType = (UserDefinedObjectType ) userDefinedType ;
431+ if ( userDefinedType instanceof UserDefinedObjectType objectType ) {
428432 if ( objectType .getColumns ().size () > 1 ) {
429433 final List <Column > objectTypeColumns = columnOrderingStrategy .orderUserDefinedTypeColumns (
430434 objectType ,
@@ -440,32 +444,28 @@ public void orderColumns(boolean forceOrdering) {
440444 }
441445
442446 private boolean shouldOrderTableColumns () {
443- final ConfigurationService configurationService = metadataBuildingOptions .getServiceRegistry ()
444- .requireService ( ConfigurationService .class );
445- final Set <SchemaManagementToolCoordinator .ActionGrouping > groupings = SchemaManagementToolCoordinator .ActionGrouping .interpret (
446- this ,
447- configurationService .getSettings ()
448- );
447+ final ConfigurationService configurationService =
448+ metadataBuildingOptions .getServiceRegistry ().requireService ( ConfigurationService .class );
449+ final Set <SchemaManagementToolCoordinator .ActionGrouping > groupings =
450+ SchemaManagementToolCoordinator .ActionGrouping .interpret ( this ,
451+ configurationService .getSettings () );
449452 if ( groupings .isEmpty () ) {
450453 return false ;
451454 }
452455 for ( SchemaManagementToolCoordinator .ActionGrouping grouping : groupings ) {
453- if ( isColumnOrderingRelevant ( grouping .getScriptAction () ) || isColumnOrderingRelevant ( grouping .getDatabaseAction () ) ) {
456+ if ( isColumnOrderingRelevant ( grouping .getScriptAction () )
457+ || isColumnOrderingRelevant ( grouping .getDatabaseAction () ) ) {
454458 return true ;
455459 }
456460 }
457461 return false ;
458462 }
459463
460464 private static boolean isColumnOrderingRelevant (Action grouping ) {
461- switch ( grouping ) {
462- case CREATE :
463- case CREATE_DROP :
464- case CREATE_ONLY :
465- return true ;
466- default :
467- return false ;
468- }
465+ return switch ( grouping ) {
466+ case CREATE , CREATE_DROP , CREATE_ONLY -> true ;
467+ default -> false ;
468+ };
469469 }
470470
471471 @ Override
@@ -489,14 +489,15 @@ public Set<MappedSuperclass> getMappedSuperclassMappingsCopy() {
489489 @ Override
490490 public void initSessionFactory (SessionFactoryImplementor sessionFactory ) {
491491 final ServiceRegistryImplementor sessionFactoryServiceRegistry = sessionFactory .getServiceRegistry ();
492-
493492 assert sessionFactoryServiceRegistry != null ;
494-
495- final EventListenerRegistry eventListenerRegistry = sessionFactoryServiceRegistry .requireService ( EventListenerRegistry .class );
496- final ConfigurationService cfgService = sessionFactoryServiceRegistry .requireService ( ConfigurationService .class );
497- final ClassLoaderService classLoaderService = sessionFactoryServiceRegistry .requireService ( ClassLoaderService .class );
498-
499- for ( Map .Entry <String ,Object > entry : cfgService .getSettings ().entrySet () ) {
493+ final EventListenerRegistry eventListenerRegistry =
494+ sessionFactoryServiceRegistry .requireService ( EventListenerRegistry .class );
495+ final ConfigurationService configurationService =
496+ sessionFactoryServiceRegistry .requireService ( ConfigurationService .class );
497+ final ClassLoaderService classLoaderService =
498+ sessionFactoryServiceRegistry .requireService ( ClassLoaderService .class );
499+
500+ for ( Map .Entry <String ,Object > entry : configurationService .getSettings ().entrySet () ) {
500501 final String propertyName = entry .getKey ();
501502 if ( propertyName .startsWith ( EVENT_LISTENER_PREFIX ) ) {
502503 final String eventTypeName = propertyName .substring ( EVENT_LISTENER_PREFIX .length () + 1 );
@@ -517,8 +518,8 @@ private <T> void appendListeners(
517518 @ SuppressWarnings ("unchecked" )
518519 T listener = (T ) instantiate ( listenerImpl , classLoaderService );
519520 if ( !eventType .baseListenerInterface ().isInstance ( listener ) ) {
520- throw new HibernateException ( "Event listener '" + listenerImpl + "' must implement '"
521- + eventType .baseListenerInterface ().getName () + "'" );
521+ throw new HibernateException ( "Event listener '" + listenerImpl
522+ + "' must implement '" + eventType .baseListenerInterface ().getName () + "'" );
522523 }
523524 eventListenerGroup .appendListener ( listener );
524525 }
@@ -554,7 +555,7 @@ public DiscriminatorType<?> resolveEmbeddableDiscriminatorType(
554555 public org .hibernate .type .Type getIdentifierType (String entityName ) throws MappingException {
555556 final PersistentClass pc = entityBindingMap .get ( entityName );
556557 if ( pc == null ) {
557- throw new MappingException ( "persistent class not known: " + entityName );
558+ throw new MappingException ( "Persistent class not known: " + entityName );
558559 }
559560 return pc .getIdentifier ().getType ();
560561 }
@@ -563,7 +564,7 @@ public org.hibernate.type.Type getIdentifierType(String entityName) throws Mappi
563564 public String getIdentifierPropertyName (String entityName ) throws MappingException {
564565 final PersistentClass pc = entityBindingMap .get ( entityName );
565566 if ( pc == null ) {
566- throw new MappingException ( "persistent class not known: " + entityName );
567+ throw new MappingException ( "Persistent class not known: " + entityName );
567568 }
568569 if ( !pc .hasIdentifierProperty () ) {
569570 return null ;
@@ -575,14 +576,11 @@ public String getIdentifierPropertyName(String entityName) throws MappingExcepti
575576 public org .hibernate .type .Type getReferencedPropertyType (String entityName , String propertyName ) throws MappingException {
576577 final PersistentClass pc = entityBindingMap .get ( entityName );
577578 if ( pc == null ) {
578- throw new MappingException ( "persistent class not known: " + entityName );
579+ throw new MappingException ( "Persistent class not known: " + entityName );
579580 }
580- Property prop = pc .getReferencedProperty ( propertyName );
581+ final Property prop = pc .getReferencedProperty ( propertyName );
581582 if ( prop == null ) {
582- throw new MappingException (
583- "property not known: " +
584- entityName + '.' + propertyName
585- );
583+ throw new MappingException ( "Property not known: " + entityName + '.' + propertyName );
586584 }
587585 return prop .getType ();
588586 }
0 commit comments