Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConnectionString calculation refactoring #476

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading