2323import org .hibernate .engine .jdbc .internal .Formatter ;
2424import org .hibernate .internal .CoreLogging ;
2525import org .hibernate .internal .CoreMessageLogger ;
26- import org .hibernate .internal .util .StringHelper ;
2726import org .hibernate .internal .util .config .ConfigurationHelper ;
2827import org .hibernate .resource .transaction .spi .DdlTransactionIsolator ;
2928import org .hibernate .service .ServiceRegistry ;
4544import org .hibernate .tool .schema .spi .ScriptTargetOutput ;
4645import org .hibernate .tool .schema .spi .SqlScriptCommandExtractor ;
4746
47+ import static org .hibernate .internal .util .StringHelper .isEmpty ;
4848import static org .hibernate .internal .util .StringHelper .splitAtCommas ;
4949
5050/**
@@ -92,13 +92,10 @@ private static AbstractScriptSourceInput interpretScriptSourceSetting(
9292 log .trace ( "Trying as URL..." );
9393 // ClassLoaderService.locateResource() first tries the given resource name as url form...
9494 final URL url = classLoaderService .locateResource ( scriptSourceSettingString );
95- if ( url != null ) {
96- return new ScriptSourceInputFromUrl ( url , charsetName );
97- }
98-
99- // assume it is a File path
100- final File file = new File ( scriptSourceSettingString );
101- return new ScriptSourceInputFromFile ( file , charsetName );
95+ return url != null
96+ ? new ScriptSourceInputFromUrl ( url , charsetName )
97+ // assume it is a File path
98+ : new ScriptSourceInputFromFile ( new File ( scriptSourceSettingString ), charsetName );
10299 }
103100
104101 public static ScriptTargetOutput interpretScriptTargetSetting (
@@ -109,8 +106,8 @@ public static ScriptTargetOutput interpretScriptTargetSetting(
109106 if ( scriptTargetSetting == null ) {
110107 return null ;
111108 }
112- else if ( scriptTargetSetting instanceof Writer ) {
113- return new ScriptTargetOutputToWriter ( ( Writer ) scriptTargetSetting );
109+ else if ( scriptTargetSetting instanceof Writer writer ) {
110+ return new ScriptTargetOutputToWriter ( writer );
114111 }
115112 else {
116113 final String scriptTargetSettingString = scriptTargetSetting .toString ();
@@ -124,31 +121,15 @@ else if ( scriptTargetSetting instanceof Writer ) {
124121 log .trace ( "Trying as URL..." );
125122 // ClassLoaderService.locateResource() first tries the given resource name as url form...
126123 final URL url = classLoaderService .locateResource ( scriptTargetSettingString );
127- if ( url != null ) {
128- return new ScriptTargetOutputToUrl ( url , charsetName );
129- }
130-
131- // assume it is a File path
132- final File file = new File ( scriptTargetSettingString );
133- return new ScriptTargetOutputToFile ( file , charsetName , append );
124+ return url != null
125+ ? new ScriptTargetOutputToUrl ( url , charsetName )
126+ // assume it is a File path
127+ : new ScriptTargetOutputToFile ( new File ( scriptTargetSettingString ), charsetName , append );
134128 }
135129 }
136130
137131 public static boolean interpretNamespaceHandling (Map <String ,Object > configurationValues ) {
138- //Print a warning if multiple conflicting properties are being set:
139- int count = 0 ;
140- if ( configurationValues .containsKey ( AvailableSettings .HBM2DDL_CREATE_SCHEMAS ) ) {
141- count ++;
142- }
143- if ( configurationValues .containsKey ( AvailableSettings .JAKARTA_HBM2DDL_CREATE_SCHEMAS ) ) {
144- count ++;
145- }
146- if ( configurationValues .containsKey ( AvailableSettings .HBM2DDL_CREATE_NAMESPACES ) ) {
147- count ++;
148- }
149- if ( count > 1 ) {
150- log .multipleSchemaCreationSettingsDefined ();
151- }
132+ warnIfConflictingPropertiesSet ( configurationValues );
152133 // prefer the JPA setting...
153134 return ConfigurationHelper .getBoolean (
154135 AvailableSettings .HBM2DDL_CREATE_SCHEMAS ,
@@ -166,19 +147,33 @@ public static boolean interpretNamespaceHandling(Map<String,Object> configuratio
166147 );
167148 }
168149
150+ private static void warnIfConflictingPropertiesSet (Map <String , Object > configurationValues ) {
151+ //Print a warning if multiple conflicting properties are being set:
152+ int count = 0 ;
153+ if ( configurationValues .containsKey ( AvailableSettings .HBM2DDL_CREATE_SCHEMAS ) ) {
154+ count ++;
155+ }
156+ if ( configurationValues .containsKey ( AvailableSettings .JAKARTA_HBM2DDL_CREATE_SCHEMAS ) ) {
157+ count ++;
158+ }
159+ if ( configurationValues .containsKey ( AvailableSettings .HBM2DDL_CREATE_NAMESPACES ) ) {
160+ count ++;
161+ }
162+ if ( count > 1 ) {
163+ log .multipleSchemaCreationSettingsDefined ();
164+ }
165+ }
166+
169167 public static boolean interpretFormattingEnabled (Map <String ,Object > configurationValues ) {
170- return ConfigurationHelper .getBoolean (
171- AvailableSettings .FORMAT_SQL ,
172- configurationValues
173- );
168+ return ConfigurationHelper .getBoolean ( AvailableSettings .FORMAT_SQL , configurationValues );
174169 }
175170
176171 public static DatabaseInformation buildDatabaseInformation (
177172 ServiceRegistry serviceRegistry ,
178173 DdlTransactionIsolator ddlTransactionIsolator ,
179174 SqlStringGenerationContext context ,
180175 SchemaManagementTool tool ) {
181- final JdbcEnvironment jdbcEnvironment = serviceRegistry .getService ( JdbcEnvironment .class );
176+ final JdbcEnvironment jdbcEnvironment = serviceRegistry .requireService ( JdbcEnvironment .class );
182177 try {
183178 return new DatabaseInformationImpl (
184179 serviceRegistry ,
@@ -207,12 +202,10 @@ public static void applySqlStrings(
207202 Formatter formatter ,
208203 ExecutionOptions options ,
209204 GenerationTarget ... targets ) {
210- if ( sqlStrings == null ) {
211- return ;
212- }
213-
214- for ( String sqlString : sqlStrings ) {
215- applySqlString ( sqlString , formatter , options , targets );
205+ if ( sqlStrings != null ) {
206+ for ( String sqlString : sqlStrings ) {
207+ applySqlString ( sqlString , formatter , options , targets );
208+ }
216209 }
217210 }
218211
@@ -221,17 +214,15 @@ public static void applySqlString(
221214 Formatter formatter ,
222215 ExecutionOptions options ,
223216 GenerationTarget ... targets ) {
224- if ( StringHelper .isEmpty ( sqlString ) ) {
225- return ;
226- }
227-
228- String sqlStringFormatted = formatter .format ( sqlString );
229- for ( GenerationTarget target : targets ) {
230- try {
231- target .accept ( sqlStringFormatted );
232- }
233- catch (CommandAcceptanceException e ) {
234- options .getExceptionHandler ().handleException ( e );
217+ if ( !isEmpty ( sqlString ) ) {
218+ final String sqlStringFormatted = formatter .format ( sqlString );
219+ for ( GenerationTarget target : targets ) {
220+ try {
221+ target .accept ( sqlStringFormatted );
222+ }
223+ catch (CommandAcceptanceException e ) {
224+ options .getExceptionHandler ().handleException ( e );
225+ }
235226 }
236227 }
237228 }
0 commit comments