Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Apr 18, 2024
1 parent 79ea114 commit 8da5685
Showing 1 changed file with 7 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void createTable(String dataBase, String schema, String table, String typ
Statement stmt = null;

// get a connection to the given destination
Connection con = driver.getConnection(dataBase, this.sqlHost);
Connection con = driver.getConnection(dataBase, this.sqlHost);
String query = "";
if (sqlInstance == SQLInstance.MYSQL) {
query = "create table if not exists `" + tableName + "`" + typedFieldNames;
Expand Down Expand Up @@ -276,7 +276,7 @@ public void insertContextData(String dataBase, String schema, String table, Stri
String tableName = table;

// get a connection to the given destination
Connection con = driver.getConnection(dataBase, this.sqlHost);
Connection con = driver.getConnection(dataBase, this.sqlHost);
String query = "";
if (sqlInstance == SQLInstance.MYSQL) {
query = "insert into `" + tableName + "` " + fieldNames + " values " + fieldValues;
Expand Down Expand Up @@ -606,7 +606,7 @@ public void createErrorTable(String dataBase, String schema)

Statement stmt = null;
// get a connection to the given destination
Connection con = driver.getConnection(dataBase, this.sqlHost);
Connection con = driver.getConnection(dataBase, this.sqlHost);

String query = "";
if (sqlInstance == SQLInstance.MYSQL) {
Expand Down Expand Up @@ -674,7 +674,7 @@ public void upsertTransaction (LinkedHashMap<String, ArrayList<JsonElement>> agg

try {

connection = driver.getConnection(dataBase, this.sqlHost);
connection = driver.getConnection(dataBase, this.sqlHost);
connection.setAutoCommit(false);

ArrayList<StringBuffer> upsertQuerysList = SQLQueryUtils.sqlUpsertQuery(aggregation,
Expand Down Expand Up @@ -760,7 +760,7 @@ public void insertTransaction (LinkedHashMap<String, ArrayList<JsonElement>> agg

try {

connection = driver.getConnection(dataBase, this.sqlHost);
connection = driver.getConnection(dataBase, this.sqlHost);
connection.setAutoCommit(false);

insertQuery = SQLQueryUtils.sqlInsertQuery(aggregation,
Expand Down Expand Up @@ -843,7 +843,7 @@ public void purgeErrorTable(String dataBase, String schema)

Statement stmt = null;
// get a connection to the given destination
Connection con = driver.getConnection(dataBase, this.sqlHost);
Connection con = driver.getConnection(dataBase, this.sqlHost);

String query = "";
if (sqlInstance == SQLInstance.MYSQL) {
Expand Down Expand Up @@ -887,7 +887,7 @@ private void insertErrorLog(String dataBase, String schema, String errorQuery, E
", query)";

// get a connection to the given destination
Connection con = driver.getConnection(dataBase, this.sqlHost);
Connection con = driver.getConnection(dataBase, this.sqlHost);

String query = "";
if (sqlInstance == SQLInstance.MYSQL) {
Expand Down Expand Up @@ -997,17 +997,13 @@ public Connection getConnection(String destination, String sqlHost) throws Cygnu
// number, if a new connection is needed, the oldest one is closed
Connection connection = null;

//if (datasources.containsKey(destination)) {
if (datasources.containsKey(sqlHost)) {
//connection = datasources.get(destination).getConnection();
connection = datasources.get(sqlHost).getConnection();
//LOGGER.debug(sqlInstance.toString().toUpperCase() + " Recovered destination connection from cache (" + destination + ")");
LOGGER.debug(sqlInstance.toString().toUpperCase() + " Recovered destination connection from cache (" + sqlHost + ")");
}

if (connection == null || !connection.isValid(0)) {
if (connection != null) {
//LOGGER.debug(sqlInstance.toString().toUpperCase() + " Closing invalid sql connection for destination " + destination);
LOGGER.debug(sqlInstance.toString().toUpperCase() + " Closing invalid sql connection for destination " + sqlHost);
try {
connection.close();
Expand All @@ -1016,9 +1012,7 @@ public Connection getConnection(String destination, String sqlHost) throws Cygnu
}
} // if

//DataSource datasource = createConnectionPool(destination);
DataSource datasource = createConnectionPool(destination, sqlHost);
//datasources.put(destination, datasource);
datasources.put(sqlHost, datasource);
connection = datasource.getConnection();
if (sqlInstance == SQLInstance.ORACLE) {
Expand All @@ -1033,15 +1027,11 @@ public Connection getConnection(String destination, String sqlHost) throws Cygnu
} // if

// Check Pool cache and log status
//if (pools.containsKey(destination)){
if (pools.containsKey(sqlHost)){
//GenericObjectPool pool = pools.get(destination);
GenericObjectPool pool = pools.get(sqlHost);
//LOGGER.debug(sqlInstance.toString().toUpperCase() + " Pool status (" + destination + ") Max.: " + pool.getMaxActive() + "; Active: "
LOGGER.debug(sqlInstance.toString().toUpperCase() + " Pool status (" + sqlHost + ") Max.: " + pool.getMaxActive() + "; Active: "
+ pool.getNumActive() + "; Idle: " + pool.getNumIdle());
}else{
//LOGGER.error(sqlInstance.toString().toUpperCase() + " Can't find dabase in pool cache (" + destination + ")");
LOGGER.error(sqlInstance.toString().toUpperCase() + " Can't find dabase in pool cache (" + sqlHost + ")");
}
return connection;
Expand Down Expand Up @@ -1116,11 +1106,8 @@ protected int numConnectionsCreated() {
@SuppressWarnings("unused")
private DataSource createConnectionPool(String destination, String sqlHost) throws Exception {
GenericObjectPool gPool = null;
//if (pools.containsKey(destination)){
if (pools.containsKey(sqlHost)){
//LOGGER.debug(sqlInstance.toString().toUpperCase() + " Pool recovered from Cache (" + destination + ")");
LOGGER.debug(sqlInstance.toString().toUpperCase() + " Pool recovered from Cache (" + sqlHost + ")");
//gPool = pools.get(destination);
gPool = pools.get(sqlHost);
}else{
String jdbcUrl = generateJDBCUrl(destination);
Expand Down

0 comments on commit 8da5685

Please sign in to comment.