Skip to content

Commit

Permalink
Use switch case instead of if else for connectionType.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vipinofficial11 committed Oct 10, 2024
1 parent ae059c4 commit 6c60d2d
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private OracleConstants() {
public static final String CONNECTION_TYPE = "connectionType";
public static final String ROLE = "role";
public static final String NAME_DATABASE = "database";
public static final String TNS_CONNECTION_TYPE = "TNS";
public static final String TNS_CONNECTION_TYPE = "tns";
public static final String TRANSACTION_ISOLATION_LEVEL = "transactionIsolationLevel";
public static final String USE_SSL = "useSSL";
public static final String DEFAULT_CONNECTION_PROTOCOL = "tcp";
Expand Down Expand Up @@ -90,15 +90,18 @@ public static String getConnectionString(String connectionType,
connectionProtocol = "tcp";
}

// For TNS Descriptor we can't specify the protocol in connection string.
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,
connectionProtocol, host, port, database);
switch (connectionType.toLowerCase()) {
case OracleConstants.TNS_CONNECTION_TYPE:
// TNS connection doesn't require protocol
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_TNS_FORMAT, database);
case OracleConstants.SERVICE_CONNECTION_TYPE:
// Service connection uses protocol, host, port, and database
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SERVICE_NAME_FORMAT,
connectionProtocol, host, port, database);
default:
// Default to SID format if no matching case is found
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SID_FORMAT,
connectionProtocol, host, port, database);
}
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SID_FORMAT,
connectionProtocol, host, port, database);
}
}

0 comments on commit 6c60d2d

Please sign in to comment.