Skip to content

Commit

Permalink
ConnectionString calculation refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRahulSharma committed Jan 2, 2024
1 parent 2657283 commit 3a53fc9
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,9 @@ public static class OracleActionConfig extends DBSpecificQueryConfig {

@Override
public String getConnectionString() {
if (OracleConstants.TNS_CONNECTION_TYPE.equals(this.connectionType)) {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_TNS_FORMAT, database);
} else if (OracleConstants.SERVICE_CONNECTION_TYPE.equals(this.connectionType)) {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SERVICE_NAME_FORMAT, host, port, database);
} else {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SID_FORMAT, host, port, database);
}
return OracleConstants.getConnectionString(this.connectionType, host, port, database);
}


@Override
protected Map<String, String> getDBSpecificArguments() {
return ImmutableMap.of(OracleConstants.DEFAULT_BATCH_VALUE, String.valueOf(defaultBatchValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,8 @@ protected String getConnectionString(@Nullable String database) {
if (database == null) {
return config.getConnectionString();
}
if (OracleConstants.TNS_CONNECTION_TYPE.equals(config.getConnectionType())) {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_TNS_FORMAT, database);
} else if (OracleConstants.SERVICE_CONNECTION_TYPE.equals(config.getConnectionType())) {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SERVICE_NAME_FORMAT, config.getHost(),
config.getPort(), database);
} else {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SID_FORMAT,
config.getHost(), config.getPort(), database);
}
return OracleConstants.getConnectionString(config.getConnectionType(),
config.getHost(), config.getPort(), database);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,7 @@ public OracleConnectorConfig(String host, int port, String user, String password

@Override
public String getConnectionString() {
if (OracleConstants.TNS_CONNECTION_TYPE.equals(getConnectionType())) {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_TNS_FORMAT, database);
} else if (OracleConstants.SERVICE_CONNECTION_TYPE.equals(getConnectionType())) {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SERVICE_NAME_FORMAT, host, getPort(), database);
} else {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SID_FORMAT, host, getPort(), database);
}
return OracleConstants.getConnectionString(database, host, getPort(), database);
}

@Name(OracleConstants.CONNECTION_TYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,28 @@ private OracleConstants() {
public static final String NAME_DATABASE = "database";
public static final String TNS_CONNECTION_TYPE = "TNS";
public static final String TRANSACTION_ISOLATION_LEVEL = "transactionIsolationLevel";

/**
* Returns the Connection String for the given ConnectionType.
*
* @param connectionType SID/Service/SID
* @param host Host name of the oracle server
* @param port Port of the oracle server
* @param database Database to connect to
* @return Connection String based on the given ConnectionType
*/
public static String getConnectionString(String connectionType,
String host,
int port,
String database) {
if (OracleConstants.TNS_CONNECTION_TYPE.equalsIgnoreCase(connectionType)) {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_TNS_FORMAT, database);
} else if (OracleConstants.SERVICE_CONNECTION_TYPE.equalsIgnoreCase(connectionType)) {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SERVICE_NAME_FORMAT,
host, port, database);
} else {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SID_FORMAT,
host, port, database);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,7 @@ public static class OracleQueryActionConfig extends DBSpecificQueryActionConfig

@Override
public String getConnectionString() {
if (OracleConstants.TNS_CONNECTION_TYPE.equals(this.connectionType)) {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_TNS_FORMAT, database);
} else if (OracleConstants.SERVICE_CONNECTION_TYPE.equals(this.connectionType)) {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SERVICE_NAME_FORMAT, host, port, database);
} else {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SID_FORMAT, host, port, database);
}
return OracleConstants.getConnectionString(this.connectionType, host, port, database);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,8 @@ public OracleSourceConfig(String host, int port, String user, String password, S

@Override
public String getConnectionString() {
if (OracleConstants.TNS_CONNECTION_TYPE.equals(connection.getConnectionType())) {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_TNS_FORMAT, connection.getDatabase());
} else if (OracleConstants.SERVICE_CONNECTION_TYPE.equals(connection.getConnectionType())) {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SERVICE_NAME_FORMAT, connection.getHost(),
connection.getPort(), connection.getDatabase());
} else {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SID_FORMAT,
connection.getHost(), connection.getPort(), connection.getDatabase());
}
return OracleConstants.getConnectionString(connection.getConnectionType(), connection.getHost(),
connection.getPort(), connection.getDatabase());
}

@Override
Expand Down

0 comments on commit 3a53fc9

Please sign in to comment.