Skip to content

Commit

Permalink
Remove HikariCP and added new Initializable OracleDataSource
Browse files Browse the repository at this point in the history
  • Loading branch information
pesse committed Jun 27, 2019
1 parent 7725326 commit 8c99900
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 28 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.3.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/org/utplsql/cli/LoggerConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.ConsoleAppender;
import com.zaxxer.hikari.HikariDataSource;
import org.slf4j.LoggerFactory;

public class LoggerConfiguration {
Expand Down Expand Up @@ -39,7 +38,6 @@ private static void configureSilent() {

private static void configureInfo() {
setRootLoggerLevel(Level.INFO);
muteHikariLogger();
setSingleConsoleAppenderWithLayout("%msg%n");
}

Expand All @@ -53,10 +51,6 @@ private static void setRootLoggerLevel(Level level) {
root.setLevel(level);
}

private static void muteHikariLogger() {
((Logger) LoggerFactory.getLogger(HikariDataSource.class)).setLevel(Level.OFF);
}

private static void setSingleConsoleAppenderWithLayout(String patternLayout) {
Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/org/utplsql/cli/RunAction.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.utplsql.cli;

import com.zaxxer.hikari.HikariDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.utplsql.api.*;
Expand Down Expand Up @@ -59,13 +58,13 @@ public int doRun() throws OracleCreateStatmenetStuckException {
init();
outputMainInformation();

HikariDataSource dataSource = null;
DataSource dataSource = null;
int returnCode = 0;
try {

final List<Reporter> reporterList;

dataSource = (HikariDataSource) DataSourceProvider.getDataSource(config.getConnectString(), getReporterManager().getNumberOfReporters() + 2);
dataSource = DataSourceProvider.getDataSource(config.getConnectString(), getReporterManager().getNumberOfReporters() + 2);

initDatabase(dataSource);
reporterList = initReporters(dataSource);
Expand Down Expand Up @@ -112,10 +111,6 @@ public int doRun() throws OracleCreateStatmenetStuckException {
} catch (Throwable e) {
e.printStackTrace();
returnCode = Cli.DEFAULT_ERROR_CODE;
} finally {
if (dataSource != null) {
dataSource.close();
}
}
return returnCode;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.utplsql.cli.datasource;

import oracle.jdbc.pool.OracleDataSource;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;

public class InitializableOracleDataSource extends OracleDataSource {

private String initSql;

public InitializableOracleDataSource() throws SQLException {
}

@Override
public Connection getConnection() throws SQLException {
Connection con = super.getConnection();

if ( initSql != null && !initSql.isEmpty() ) {
try (CallableStatement stmt = con.prepareCall(initSql)) {
stmt.execute();
}
}

return con;
}

public void setConnectionInitSql( String sql ) {
this.initSql = sql;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.utplsql.cli.datasource;

import com.zaxxer.hikari.HikariDataSource;
import oracle.jdbc.pool.OracleDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.utplsql.api.EnvironmentVariableUtil;
import org.utplsql.cli.ConnectionConfig;
import org.utplsql.cli.exception.DatabaseConnectionFailed;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
Expand Down Expand Up @@ -35,27 +36,25 @@ public TestedDataSourceProvider(ConnectionConfig config, int maxConnections) {
possibilities.add(new ThinConnectStringPossibility());
}

public HikariDataSource getDataSource() throws SQLException {
public DataSource getDataSource() throws SQLException {

HikariDataSource ds = new HikariDataSource();
ds.setAutoCommit(false);
ds.setMaximumPoolSize(maxConnections);
InitializableOracleDataSource ds = new InitializableOracleDataSource();

setInitSqlFrom_NLS_LANG(ds);
setThickOrThinJdbcUrl(ds);

return ds;
}

private void setThickOrThinJdbcUrl(HikariDataSource ds) throws SQLException {
private void setThickOrThinJdbcUrl(OracleDataSource ds) throws SQLException {
List<String> errors = new ArrayList<>();
Throwable lastException = null;

ds.setUsername(config.getUser());
ds.setUser(config.getUser());
ds.setPassword(config.getPassword());

for (ConnectStringPossibility possibility : possibilities) {
ds.setJdbcUrl(possibility.getConnectString(config));
ds.setURL(possibility.getConnectString(config));
try (Connection ignored = ds.getConnection()) {
logger.info("Use connection string {}", possibility.getMaskedConnectString(config));
return;
Expand All @@ -69,7 +68,7 @@ private void setThickOrThinJdbcUrl(HikariDataSource ds) throws SQLException {
throw new DatabaseConnectionFailed(lastException);
}

private void setInitSqlFrom_NLS_LANG(HikariDataSource ds) {
private void setInitSqlFrom_NLS_LANG(InitializableOracleDataSource ds) {
String nls_lang = EnvironmentVariableUtil.getEnvValue("NLS_LANG");

if (nls_lang != null) {
Expand Down

0 comments on commit 8c99900

Please sign in to comment.