Skip to content

Commit

Permalink
ConnectionString calculation refactoring (data-integrations#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRahulSharma authored and bharatgulati committed Feb 1, 2024
1 parent 5025423 commit cfb1a3b
Show file tree
Hide file tree
Showing 6 changed files with 33 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 @@ -16,6 +16,8 @@

package io.cdap.plugin.oracle;

import javax.annotation.Nullable;

/**
* Oracle Constants.
*/
Expand All @@ -36,4 +38,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 TNS/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,
@Nullable String host,
@Nullable int port,
String database) {
if (OracleConstants.TNS_CONNECTION_TYPE.equalsIgnoreCase(connectionType)) {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_TNS_FORMAT, database);
}
if (OracleConstants.SERVICE_CONNECTION_TYPE.equalsIgnoreCase(connectionType)) {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SERVICE_NAME_FORMAT,
host, port, database);
}
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 cfb1a3b

Please sign in to comment.