@@ -35,21 +35,22 @@ public static DataSource createSqlDataSource(DatabaseConfig.SqlConfig config) {
3535 }
3636
3737 if (config .getEndpoint () == null ) {
38- throw new IllegalArgumentException ("JdbcUrl is required" );
39- }
40-
41- if (config .getUsername () == null ) {
42- throw new IllegalArgumentException ("Database username is required" );
43- }
44-
45- if (config .getPassword () == null ) {
46- throw new IllegalArgumentException ("Database password is required" );
38+ throw new IllegalArgumentException ("Database endpoint is required" );
4739 }
4840
4941 if (config .getSqlDialect () == null ) {
5042 throw new IllegalArgumentException ("Sql dialect is required" );
5143 }
5244
45+ if (!SqlDialect .SQLITE .equals (config .getSqlDialect ())) {
46+ if (config .getUsername () == null ) {
47+ throw new IllegalArgumentException ("Database username is required" );
48+ }
49+ if (config .getPassword () == null ) {
50+ throw new IllegalArgumentException ("Database password is required" );
51+ }
52+ }
53+
5354 try {
5455 DataSource sqlDatasource ;
5556
@@ -66,31 +67,11 @@ public static DataSource createSqlDataSource(DatabaseConfig.SqlConfig config) {
6667 sqlDatasource = sqliteDatasource ;
6768 } else {
6869 HikariConfig datasourceConfig = new HikariConfig ();
70+ datasourceConfig .setJdbcUrl (config .getEndpoint ());
71+ datasourceConfig .setUsername (config .getUsername ());
72+ datasourceConfig .setPassword (config .getPassword ());
6973 datasourceConfig .setDriverClassName (config .getDriverClassName ());
7074
71- if (config .getSqlDialect ().equals (SqlDialect .H2 )) {
72- datasourceConfig .setJdbcUrl ("jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1" );
73- datasourceConfig .setUsername ("sa" );
74- datasourceConfig .setPassword ("" );
75- } else {
76- datasourceConfig .setJdbcUrl (config .getEndpoint ());
77- datasourceConfig .setUsername (config .getUsername ());
78- datasourceConfig .setPassword (config .getPassword ());
79- }
80-
81- if (config .getSqlDialect () == SqlDialect .INFORMIX ) {
82- datasourceConfig .setMaximumPoolSize (1 );
83- datasourceConfig .setMinimumIdle (0 );
84- datasourceConfig .setConnectionTimeout (30000 );
85- datasourceConfig .setIdleTimeout (600000 );
86- datasourceConfig .setMaxLifetime (1800000 );
87- datasourceConfig .setLeakDetectionThreshold (0 );
88- datasourceConfig .setValidationTimeout (5000 );
89- datasourceConfig .setConnectionTestQuery ("SELECT 1 FROM systables WHERE tabid=1" );
90- datasourceConfig .setInitializationFailTimeout (-1 );
91- datasourceConfig .setAutoCommit (true );
92- }
93-
9475 sqlDatasource = new HikariDataSource (datasourceConfig );
9576 }
9677
0 commit comments