Skip to content

Commit

Permalink
Improve java doc and remove warnings of the driver manager (#1825) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
speckyspooky authored Aug 4, 2024
1 parent 674da27 commit 3ad1b86
Show file tree
Hide file tree
Showing 2 changed files with 206 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.sql.Connection;
import java.sql.SQLException;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.Properties;

Expand All @@ -24,21 +25,61 @@
import org.eclipse.datatools.connectivity.oda.OdaException;
import org.eclipse.ui.PlatformUI;

/**
* Driver load class
*
* @since 3.3
*
*/
public final class DriverLoader {
private DriverLoader() {
}

/**
* Get a JDBC connection
*
* @param driverClassName driver class name
* @param connectionString connection string
* @param userId login user name
* @param password login password
* @return new JDBC connection
* @throws SQLException
* @throws OdaException
*/
public static Connection getConnection(String driverClassName, String connectionString, String userId,
String password) throws SQLException, OdaException {
return getConnection(driverClassName, connectionString, userId, password, null);
}

/**
* Get a JDBC connection
*
* @param driverClassName driver class name
* @param connectionString connection string
* @param userId login user name
* @param password login password
* @param props connection properties
* @return new JDBC connection
* @throws SQLException
* @throws OdaException
*/
public static Connection getConnection(String driverClassName, String connectionString, String userId,
String password, Properties props) throws SQLException, OdaException {
return JDBCDriverManager.getInstance().getConnection(driverClassName, connectionString, userId, password, null,
props);
}

/**
* Get a JDBC connection
*
* @param driverClassName driver class name
* @param connectionString connection string
* @param userId login user name
* @param password login password
* @param props connection properties
* @return new JDBC connection
* @throws SQLException
*/
public static Connection getConnectionWithExceptionTip(String driverClassName, String connectionString,
String userId, String password, Properties props) throws SQLException {
try {
Expand All @@ -56,7 +97,7 @@ static String escapeCharacters(String value) {
char character = iterator.current();
final StringBuilder result = new StringBuilder();

while (character != StringCharacterIterator.DONE) {
while (character != CharacterIterator.DONE) {
if (character == '\\') {
result.append("\\"); //$NON-NLS-1$
} else {
Expand Down Expand Up @@ -86,6 +127,19 @@ public static boolean testConnection(String driverClassName, String connectionSt
return testConnection(driverClassName, connectionString, null, userId, password, new Properties());
}

/**
* Tests whether the given connection properties can be used to obtain a
* connection.
*
* @param driverClassName the name of driver class
* @param connectionString the JDBC driver connection URL
* @param userId the login user id
* @param password the login password
* @param props connection properties
* @return true if the the specified properties are valid to obtain a
* connection; false otherwise
* @throws OdaException
*/
public static boolean testConnection(String driverClassName, String connectionString, String userId,
String password, Properties props) throws OdaException {
return testConnection(driverClassName, connectionString, null, userId, password, props);
Expand All @@ -110,6 +164,21 @@ public static boolean testConnection(String driverClassName, String connectionSt
return testConnection(driverClassName, connectionString, jndiNameUrl, userId, password, new Properties());
}

/**
* Tests whether the given connection properties can be used to obtain a
* connection.
*
* @param driverClassName the name of driver class
* @param connectionString the JDBC driver connection URL
* @param jndiNameUrl the JNDI name to look up a Data Source name service;
* may be null or empty
* @param userId the login user id
* @param password the login password
* @param props connection properties
* @return true if the the specified properties are valid to obtain a
* connection; false otherwise
* @throws OdaException
*/
public static boolean testConnection(String driverClassName, String connectionString, String jndiNameUrl,
String userId, String password, Properties props) throws OdaException {
return JDBCDriverManager.getInstance().testConnection(driverClassName, connectionString, jndiNameUrl, userId,
Expand All @@ -118,13 +187,44 @@ public static boolean testConnection(String driverClassName, String connectionSt

// bidi_hcg: if Bidi format is defined - perform required Bidi transformations
// on connection properties before testing the connection
/**
* Tests whether the given connection properties can be used to obtain a
* connection.
*
* @param driverClassName the name of driver class
* @param connectionString the JDBC driver connection URL
* @param jndiNameUrl the JNDI name to look up a Data Source name service;
* may be null or empty
* @param userId the login user id
* @param password the login password
* @param bidiFormatStr BIDI format string
* @return true if the the specified properties are valid to obtain a
* connection; false otherwise
* @throws OdaException
*/
public static boolean testConnection(String driverClassName, String connectionString, String jndiNameUrl,
String userId, String password, String bidiFormatStr) throws OdaException {

return testConnection(driverClassName, connectionString, jndiNameUrl, userId, password, bidiFormatStr,
new Properties());
}

/**
* Tests whether the given connection properties can be used to obtain a
* connection.
*
* @param driverClassName the name of driver class
* @param connectionString the JDBC driver connection URL
* @param jndiNameUrl the JNDI name to look up a Data Source name service;
* may be null or empty
* @param userId the login user id
* @param password the login password
* @param bidiFormatStr BIDI format string
* @param props
* @return true if the the specified properties are valid to obtain a
* connection; false otherwise
* @throws OdaException
*/
public static boolean testConnection(String driverClassName, String connectionString, String jndiNameUrl,
String userId, String password, String bidiFormatStr, Properties props) throws OdaException {

Expand Down
Loading

0 comments on commit 3ad1b86

Please sign in to comment.