-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip
- Loading branch information
Showing
25 changed files
with
268 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
src/main/java/stirling/software/SPDF/config/security/database/DataSourceConfig.java
This file was deleted.
Oops, something went wrong.
44 changes: 30 additions & 14 deletions
44
src/main/java/stirling/software/SPDF/config/security/database/DatabaseConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,51 @@ | ||
package stirling.software.SPDF.config.security.database; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.jdbc.DataSourceBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import lombok.Getter; | ||
import stirling.software.SPDF.model.ApplicationProperties; | ||
import stirling.software.SPDF.model.exception.UnsupportedDriverException; | ||
|
||
@Getter | ||
@Configuration | ||
public class DatabaseConfig { | ||
|
||
@Autowired private DataSourceConfig dataSourceConfig; | ||
|
||
@Autowired private JpaConfig jpaConfig; | ||
@Autowired private ApplicationProperties applicationProperties; | ||
|
||
@Bean | ||
public DataSource dataSource() { | ||
return dataSourceConfig.dataSource(); | ||
public Connection connection() throws SQLException { | ||
ApplicationProperties.Datasource datasource = | ||
applicationProperties.getSystem().getDatasource(); | ||
|
||
DataSourceBuilder<?> dataSourceBuilder = DataSourceBuilder.create(); | ||
dataSourceBuilder.driverClassName(getDriverClassName(datasource.getDriverClassName())); | ||
dataSourceBuilder.url(datasource.getUrl()); | ||
dataSourceBuilder.username(datasource.getUsername()); | ||
dataSourceBuilder.password(datasource.getPassword()); | ||
|
||
return dataSourceBuilder.build().getConnection(); | ||
} | ||
|
||
@Bean | ||
public Connection connection() throws SQLException { | ||
return DriverManager.getConnection( | ||
dataSourceConfig.getUrl(), | ||
dataSourceConfig.getUsername(), | ||
dataSourceConfig.getPassword()); | ||
private String getDriverClassName(ApplicationProperties.Driver driverName) { | ||
switch (driverName) { | ||
case POSTGRESQL -> { | ||
return "org.postgresql.Driver"; | ||
} | ||
case ORACLE -> { | ||
return "oracle.jdbc.OracleDriver"; | ||
} | ||
case MY_SQL -> { | ||
return "com.mysql.cj.jdbc.Driver"; | ||
} | ||
default -> | ||
throw new UnsupportedDriverException( | ||
"The database driver " + driverName + " is not supported."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.