File tree Expand file tree Collapse file tree 3 files changed +18
-12
lines changed
cli/flamingock-cli/src/main/java/io/flamingock/cli
utils/sql-util/src/main/java/io/flamingock/internal/common/sql Expand file tree Collapse file tree 3 files changed +18
-12
lines changed Original file line number Diff line number Diff line change @@ -271,7 +271,7 @@ public void setPassword(String password) {
271271 }
272272
273273 public Optional <SqlDialect > getSqlDialect () {
274- return sqlDialect == null ? Optional .empty () : Optional . of (sqlDialect );
274+ return Optional .ofNullable (sqlDialect );
275275 }
276276
277277 public void setSqlDialect (String sqlDialect ) {
@@ -286,14 +286,7 @@ public SqlDialect getEffectiveSqlDialect() {
286286 if (parts .length < 2 || parts [1 ].isEmpty ()) {
287287 throw new IllegalStateException ("Cannot determine SQL dialect from endpoint: " + this .endpoint );
288288 }
289- String dialect = parts [1 ].toLowerCase ();
290- if ("firebirdsql" .equals (dialect )) dialect = "firebird" ;
291- if ("informix-sqli" .equals (dialect )) dialect = "informix" ;
292- try {
293- return SqlDialect .valueOf (dialect .toUpperCase ());
294- } catch (IllegalArgumentException e ) {
295- throw new IllegalArgumentException ("Unsupported SQL Dialect: " + dialect , e );
296- }
289+ return SqlDialect .fromString (parts [1 ].toLowerCase ());
297290 }
298291
299292 public String getDriverClassName () {
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ public static DataSource createSqlDataSource(DatabaseConfig.SqlConfig config) {
3838 throw new IllegalArgumentException ("Database endpoint is required" );
3939 }
4040
41- if (! SqlDialect . SQLITE . equals ( config .getEffectiveSqlDialect ()) ) {
41+ if (config .getEffectiveSqlDialect () != SqlDialect . SQLITE ) {
4242 if (config .getUsername () == null ) {
4343 throw new IllegalArgumentException ("Database username is required" );
4444 }
@@ -50,7 +50,7 @@ public static DataSource createSqlDataSource(DatabaseConfig.SqlConfig config) {
5050 try {
5151 DataSource sqlDatasource ;
5252
53- if (config .getEffectiveSqlDialect (). equals (SqlDialect .SQLITE )) {
53+ if (config .getEffectiveSqlDialect () == (SqlDialect .SQLITE )) {
5454 SQLiteDataSource sqliteDatasource = new SQLiteDataSource ();
5555 sqliteDatasource .setUrl (config .getEndpoint ());
5656
Original file line number Diff line number Diff line change 1515 */
1616package io .flamingock .internal .common .sql ;
1717
18+ import java .util .Locale ;
19+ import java .util .Optional ;
20+
1821public enum SqlDialect {
1922 MYSQL ,
2023 MARIADB ,
@@ -28,5 +31,15 @@ public enum SqlDialect {
2831 FIREBIRD ,
2932 INFORMIX ,
3033 ORACLE ,
31- DB2 ,
34+ DB2 ;
35+
36+ public static SqlDialect fromString (String dialect ) {
37+ if ("firebirdsql" .equals (dialect .toLowerCase ())) return FIREBIRD ;
38+ if ("informix-sqli" .equals (dialect .toLowerCase ())) return INFORMIX ;
39+ try {
40+ return SqlDialect .valueOf (dialect .toUpperCase ());
41+ } catch (IllegalArgumentException e ) {
42+ throw new IllegalArgumentException ("Unsupported SQL Dialect: " + dialect , e );
43+ }
44+ }
3245}
You can’t perform that action at this time.
0 commit comments