Java Code Examples for org.springframework.util.ReflectionUtils#invokeJdbcMethod()

The following examples show how to use org.springframework.util.ReflectionUtils#invokeJdbcMethod() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Create a WebSphere {@code JDBCConnectionSpec} object for the given characteristics.
 * <p>The default implementation uses reflection to apply the given settings.
 * Can be overridden in subclasses to customize the JDBCConnectionSpec object
 * (<a href="http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/topic/com.ibm.websphere.javadoc.doc/public_html/api/com/ibm/websphere/rsadapter/JDBCConnectionSpec.html">JDBCConnectionSpec javadoc</a>;
 * <a href="http://www.ibm.com/developerworks/websphere/library/techarticles/0404_tang/0404_tang.html">IBM developerWorks article</a>).
 * @param isolationLevel the isolation level to apply (or {@code null} if none)
 * @param readOnlyFlag the read-only flag to apply (or {@code null} if none)
 * @param username the username to apply ({@code null} or empty indicates the default)
 * @param password the password to apply (may be {@code null} or empty)
 * @throws SQLException if thrown by JDBCConnectionSpec API methods
 * @see com.ibm.websphere.rsadapter.JDBCConnectionSpec
 */
protected Object createConnectionSpec(
		Integer isolationLevel, Boolean readOnlyFlag, String username, String password) throws SQLException {

	Object connSpec = ReflectionUtils.invokeJdbcMethod(this.newJdbcConnSpecMethod, null);
	if (isolationLevel != null) {
		ReflectionUtils.invokeJdbcMethod(this.setTransactionIsolationMethod, connSpec, isolationLevel);
	}
	if (readOnlyFlag != null) {
		ReflectionUtils.invokeJdbcMethod(this.setReadOnlyMethod, connSpec, readOnlyFlag);
	}
	// If the username is empty, we'll simply let the target DataSource
	// use its default credentials.
	if (StringUtils.hasLength(username)) {
		ReflectionUtils.invokeJdbcMethod(this.setUserNameMethod, connSpec, username);
		ReflectionUtils.invokeJdbcMethod(this.setPasswordMethod, connSpec, password);
	}
	return connSpec;
}
 
Example 2
/**
 * Create a WebSphere {@code JDBCConnectionSpec} object for the given charateristics.
 * <p>The default implementation uses reflection to apply the given settings.
 * Can be overridden in subclasses to customize the JDBCConnectionSpec object
 * (<a href="http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/topic/com.ibm.websphere.javadoc.doc/public_html/api/com/ibm/websphere/rsadapter/JDBCConnectionSpec.html">JDBCConnectionSpec javadoc</a>;
 * <a href="http://www.ibm.com/developerworks/websphere/library/techarticles/0404_tang/0404_tang.html">IBM developerWorks article</a>).
 * @param isolationLevel the isolation level to apply (or {@code null} if none)
 * @param readOnlyFlag the read-only flag to apply (or {@code null} if none)
 * @param username the username to apply ({@code null} or empty indicates the default)
 * @param password the password to apply (may be {@code null} or empty)
 * @throws SQLException if thrown by JDBCConnectionSpec API methods
 * @see com.ibm.websphere.rsadapter.JDBCConnectionSpec
 */
protected Object createConnectionSpec(
		Integer isolationLevel, Boolean readOnlyFlag, String username, String password) throws SQLException {

	Object connSpec = ReflectionUtils.invokeJdbcMethod(this.newJdbcConnSpecMethod, null);
	if (isolationLevel != null) {
		ReflectionUtils.invokeJdbcMethod(this.setTransactionIsolationMethod, connSpec, isolationLevel);
	}
	if (readOnlyFlag != null) {
		ReflectionUtils.invokeJdbcMethod(this.setReadOnlyMethod, connSpec, readOnlyFlag);
	}
	// If the username is empty, we'll simply let the target DataSource
	// use its default credentials.
	if (StringUtils.hasLength(username)) {
		ReflectionUtils.invokeJdbcMethod(this.setUserNameMethod, connSpec, username);
		ReflectionUtils.invokeJdbcMethod(this.setPasswordMethod, connSpec, password);
	}
	return connSpec;
}
 
Example 3
/**
 * Create a WebSphere {@code JDBCConnectionSpec} object for the given charateristics.
 * <p>The default implementation uses reflection to apply the given settings.
 * Can be overridden in subclasses to customize the JDBCConnectionSpec object
 * (<a href="http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/topic/com.ibm.websphere.javadoc.doc/public_html/api/com/ibm/websphere/rsadapter/JDBCConnectionSpec.html">JDBCConnectionSpec javadoc</a>;
 * <a href="http://www.ibm.com/developerworks/websphere/library/techarticles/0404_tang/0404_tang.html">IBM developerWorks article</a>).
 * @param isolationLevel the isolation level to apply (or {@code null} if none)
 * @param readOnlyFlag the read-only flag to apply (or {@code null} if none)
 * @param username the username to apply ({@code null} or empty indicates the default)
 * @param password the password to apply (may be {@code null} or empty)
 * @throws SQLException if thrown by JDBCConnectionSpec API methods
 * @see com.ibm.websphere.rsadapter.JDBCConnectionSpec
 */
protected Object createConnectionSpec(
		Integer isolationLevel, Boolean readOnlyFlag, String username, String password) throws SQLException {

	Object connSpec = ReflectionUtils.invokeJdbcMethod(this.newJdbcConnSpecMethod, null);
	if (isolationLevel != null) {
		ReflectionUtils.invokeJdbcMethod(this.setTransactionIsolationMethod, connSpec, isolationLevel);
	}
	if (readOnlyFlag != null) {
		ReflectionUtils.invokeJdbcMethod(this.setReadOnlyMethod, connSpec, readOnlyFlag);
	}
	// If the username is empty, we'll simply let the target DataSource
	// use its default credentials.
	if (StringUtils.hasLength(username)) {
		ReflectionUtils.invokeJdbcMethod(this.setUserNameMethod, connSpec, username);
		ReflectionUtils.invokeJdbcMethod(this.setPasswordMethod, connSpec, password);
	}
	return connSpec;
}
 
Example 4
/**
 * Builds a WebSphere JDBCConnectionSpec object for the current settings
 * and calls {@code WSDataSource.getConnection(JDBCConnectionSpec)}.
 * @see #createConnectionSpec
 * @see com.ibm.websphere.rsadapter.WSDataSource#getConnection(com.ibm.websphere.rsadapter.JDBCConnectionSpec)
 */
@Override
protected Connection doGetConnection(String username, String password) throws SQLException {
	// Create JDBCConnectionSpec using current isolation level value and read-only flag.
	Object connSpec = createConnectionSpec(
			getCurrentIsolationLevel(), getCurrentReadOnlyFlag(), username, password);
	if (logger.isDebugEnabled()) {
		logger.debug("Obtaining JDBC Connection from WebSphere DataSource [" +
				getTargetDataSource() + "], using ConnectionSpec [" + connSpec + "]");
	}
	// Create Connection through invoking WSDataSource.getConnection(JDBCConnectionSpec)
	return (Connection) ReflectionUtils.invokeJdbcMethod(
			this.wsDataSourceGetConnectionMethod, getTargetDataSource(), connSpec);
}
 
Example 5
/**
 * Retrieve the Connection via WebSphere's {@code getNativeConnection} method.
 */
@Override
protected Connection doGetNativeConnection(Connection con) throws SQLException {
	if (this.webSphereConnectionClass.isAssignableFrom(con.getClass())) {
		return (Connection) ReflectionUtils.invokeJdbcMethod(this.webSphereNativeConnectionMethod, null, con);
	}
	return con;
}
 
Example 6
/**
 * Retrieve the Connection via WebLogic's {@code getVendorConnection} method.
 */
@Override
protected Connection doGetNativeConnection(Connection con) throws SQLException {
	if (this.jdbcExtensionClass.isAssignableFrom(con.getClass())) {
		return (Connection) ReflectionUtils.invokeJdbcMethod(this.getVendorConnectionMethod, con);
	}
	return con;
}
 
Example 7
/**
 * Retrieve the Connection via JBoss' {@code getUnderlyingConnection} method.
 */
@Override
protected Connection doGetNativeConnection(Connection con) throws SQLException {
	if (this.wrappedConnectionClass.isAssignableFrom(con.getClass())) {
		return (Connection) ReflectionUtils.invokeJdbcMethod(this.getUnderlyingConnectionMethod, con);
	}
	return con;
}
 
Example 8
/**
 * Retrieve the Connection via JBoss' {@code getUnderlyingStatement} method.
 */
@Override
public Statement getNativeStatement(Statement stmt) throws SQLException {
	if (this.wrappedStatementClass.isAssignableFrom(stmt.getClass())) {
		return (Statement) ReflectionUtils.invokeJdbcMethod(this.getUnderlyingStatementMethod, stmt);
	}
	return stmt;
}
 
Example 9
/**
 * Retrieve the Connection via JBoss' {@code getUnderlyingResultSet} method.
 */
@Override
public ResultSet getNativeResultSet(ResultSet rs) throws SQLException {
	if (this.wrappedResultSetClass.isAssignableFrom(rs.getClass())) {
		return (ResultSet) ReflectionUtils.invokeJdbcMethod(this.getUnderlyingResultSetMethod, rs);
	}
	return rs;
}
 
Example 10
/**
 * Builds a WebSphere JDBCConnectionSpec object for the current settings
 * and calls {@code WSDataSource.getConnection(JDBCConnectionSpec)}.
 * @see #createConnectionSpec
 * @see com.ibm.websphere.rsadapter.WSDataSource#getConnection(com.ibm.websphere.rsadapter.JDBCConnectionSpec)
 */
@Override
protected Connection doGetConnection(String username, String password) throws SQLException {
	// Create JDBCConnectionSpec using current isolation level value and read-only flag.
	Object connSpec = createConnectionSpec(
			getCurrentIsolationLevel(), getCurrentReadOnlyFlag(), username, password);
	if (logger.isDebugEnabled()) {
		logger.debug("Obtaining JDBC Connection from WebSphere DataSource [" +
				getTargetDataSource() + "], using ConnectionSpec [" + connSpec + "]");
	}
	// Create Connection through invoking WSDataSource.getConnection(JDBCConnectionSpec)
	return (Connection) ReflectionUtils.invokeJdbcMethod(
			this.wsDataSourceGetConnectionMethod, getTargetDataSource(), connSpec);
}
 
Example 11
/**
 * Retrieve the Connection via JBoss' {@code getUnderlyingStatement} method.
 */
@Override
public Statement getNativeStatement(Statement stmt) throws SQLException {
	if (this.wrappedStatementClass.isAssignableFrom(stmt.getClass())) {
		return (Statement) ReflectionUtils.invokeJdbcMethod(this.getUnderlyingStatementMethod, stmt);
	}
	return stmt;
}
 
Example 12
/**
 * Retrieve the Connection via WebLogic's {@code getVendorConnection} method.
 */
@Override
protected Connection doGetNativeConnection(Connection con) throws SQLException {
	if (this.jdbcExtensionClass.isAssignableFrom(con.getClass())) {
		return (Connection) ReflectionUtils.invokeJdbcMethod(this.getVendorConnectionMethod, con);
	}
	return con;
}
 
Example 13
/**
 * Retrieve the Connection via JBoss' {@code getUnderlyingConnection} method.
 */
@Override
protected Connection doGetNativeConnection(Connection con) throws SQLException {
	if (this.wrappedConnectionClass.isAssignableFrom(con.getClass())) {
		return (Connection) ReflectionUtils.invokeJdbcMethod(this.getUnderlyingConnectionMethod, con);
	}
	return con;
}
 
Example 14
/**
 * Retrieve the Connection via JBoss' {@code getUnderlyingStatement} method.
 */
@Override
public Statement getNativeStatement(Statement stmt) throws SQLException {
	if (this.wrappedStatementClass.isAssignableFrom(stmt.getClass())) {
		return (Statement) ReflectionUtils.invokeJdbcMethod(this.getUnderlyingStatementMethod, stmt);
	}
	return stmt;
}
 
Example 15
/**
 * Retrieve the Connection via JBoss' {@code getUnderlyingResultSet} method.
 */
@Override
public ResultSet getNativeResultSet(ResultSet rs) throws SQLException {
	if (this.wrappedResultSetClass.isAssignableFrom(rs.getClass())) {
		return (ResultSet) ReflectionUtils.invokeJdbcMethod(this.getUnderlyingResultSetMethod, rs);
	}
	return rs;
}
 
Example 16
/**
 * Builds a WebSphere JDBCConnectionSpec object for the current settings
 * and calls {@code WSDataSource.getConnection(JDBCConnectionSpec)}.
 * @see #createConnectionSpec
 * @see com.ibm.websphere.rsadapter.WSDataSource#getConnection(com.ibm.websphere.rsadapter.JDBCConnectionSpec)
 */
@Override
protected Connection doGetConnection(String username, String password) throws SQLException {
	// Create JDBCConnectionSpec using current isolation level value and read-only flag.
	Object connSpec = createConnectionSpec(
			getCurrentIsolationLevel(), getCurrentReadOnlyFlag(), username, password);
	if (logger.isDebugEnabled()) {
		logger.debug("Obtaining JDBC Connection from WebSphere DataSource [" +
				getTargetDataSource() + "], using ConnectionSpec [" + connSpec + "]");
	}
	// Create Connection through invoking WSDataSource.getConnection(JDBCConnectionSpec)
	return (Connection) ReflectionUtils.invokeJdbcMethod(
			this.wsDataSourceGetConnectionMethod, getTargetDataSource(), connSpec);
}
 
Example 17
/**
 * Retrieve the Connection via WebSphere's {@code getNativeConnection} method.
 */
@Override
protected Connection doGetNativeConnection(Connection con) throws SQLException {
	if (this.webSphereConnectionClass.isAssignableFrom(con.getClass())) {
		return (Connection) ReflectionUtils.invokeJdbcMethod(this.webSphereNativeConnectionMethod, null, con);
	}
	return con;
}
 
Example 18
/**
 * Retrieve the Connection via WebLogic's {@code getVendorConnection} method.
 */
@Override
protected Connection doGetNativeConnection(Connection con) throws SQLException {
	if (this.jdbcExtensionClass.isAssignableFrom(con.getClass())) {
		return (Connection) ReflectionUtils.invokeJdbcMethod(this.getVendorConnectionMethod, con);
	}
	return con;
}
 
Example 19
/**
 * Retrieve the Connection via JBoss' {@code getUnderlyingResultSet} method.
 */
@Override
public ResultSet getNativeResultSet(ResultSet rs) throws SQLException {
	if (this.wrappedResultSetClass.isAssignableFrom(rs.getClass())) {
		return (ResultSet) ReflectionUtils.invokeJdbcMethod(this.getUnderlyingResultSetMethod, rs);
	}
	return rs;
}
 
Example 20
Source Project: compass   File: JdbcMethodUtils.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * 通过反射来执行JDBC接口的方法
 * @param interfaceClass
 * @param methodName
 * @param argTypes
 * @param target
 * @param args
 * @return
 * @throws SQLException
 */
public static Object invokeJdbcMethod(Class<?> interfaceClass,String methodName,Class<?>[] argTypes,Object target,Object[] args) throws SQLException
{
 Method method=ClassUtils.getMethodIfAvailable(interfaceClass, methodName, argTypes);
 if(method == null)
 {
  return null;
 }
 return ReflectionUtils.invokeJdbcMethod(method, target, args);
}