/** * Test XA Connection for chinese database name, user and password. * * @throws SQLException */ public void testXADSConnect() throws SQLException { // Test chinese database name. XADataSource ds = J2EEDataSource.getXADataSource(); J2EEDataSource.setBeanProperty(ds, "databaseName", "\u4e10"); J2EEDataSource.setBeanProperty(ds, "createDatabase", "create"); try { XAConnection xaconn = ds.getXAConnection(); Connection conn = xaconn.getConnection(); conn.close(); } catch (SQLException se) { if (usingEmbedded()) throw se; else assertSQLState("22005", se); } // Chinese user try { J2EEDataSource.setBeanProperty(ds, "user", "\u4e10"); XAConnection xaconn = ds.getXAConnection(); Connection conn = xaconn.getConnection(); conn.close(); } catch (SQLException se) { if (usingEmbedded()) throw se; else assertSQLState("22005", se); } // Chinese password try { J2EEDataSource.setBeanProperty(ds, "password", "\u4e10"); XAConnection xaconn = ds.getXAConnection(); Connection conn = xaconn.getConnection(); conn.close(); } catch (SQLException se) { if (usingEmbedded()) throw se; else assertSQLState("22005", se); } }
// // Find all the objects inside the XADataSource and vet them. // private void vetXADataSource(HashSet<String> unsupportedList, HashSet<String> notUnderstoodList) throws Exception { XADataSource ds = J2EEDataSource.getXADataSource(); XAConnection xaconn = ds.getXAConnection( getTestConfiguration().getUserName(), getTestConfiguration().getUserPassword()); Connection conn = xaconn.getConnection(); vetObject(ds, unsupportedList, notUnderstoodList); vetObject(xaconn, unsupportedList, notUnderstoodList); connectionWorkhorse(conn, unsupportedList, notUnderstoodList); }
public void testWrappers() throws Exception { if (log.isDebugEnabled()) { log.debug("*** Starting testWrappers"); } try { Connection.class.getMethod("isWrapperFor"); } catch (NoSuchMethodException e) { // if there is no such method this means the JVM is running with pre-JDBC4 classes // so this test becomes pointless and must be skipped return; } // XADataSource assertTrue(pds.isWrapperFor(XADataSource.class)); assertFalse(pds.isWrapperFor(DataSource.class)); XADataSource unwrappedXads = (XADataSource) pds.unwrap(XADataSource.class); assertEquals(MockitoXADataSource.class.getName(), unwrappedXads.getClass().getName()); // Connection Connection c = pds.getConnection(); assertTrue(isWrapperFor(c, Connection.class)); Connection unwrappedConnection = (Connection) unwrap(c, Connection.class); assertTrue( unwrappedConnection.getClass().getName().contains("java.sql.Connection") && unwrappedConnection.getClass().getName().contains("EnhancerByMockito")); // Statement Statement stmt = c.createStatement(); assertTrue(isWrapperFor(stmt, Statement.class)); Statement unwrappedStmt = (Statement) unwrap(stmt, Statement.class); assertTrue( unwrappedStmt.getClass().getName().contains("java.sql.Statement") && unwrappedStmt.getClass().getName().contains("EnhancerByMockito")); // PreparedStatement PreparedStatement pstmt = c.prepareStatement("mock sql"); assertTrue(isWrapperFor(pstmt, PreparedStatement.class)); Statement unwrappedPStmt = (Statement) unwrap(pstmt, PreparedStatement.class); assertTrue( unwrappedPStmt.getClass().getName().contains("java.sql.PreparedStatement") && unwrappedPStmt.getClass().getName().contains("EnhancerByMockito")); // CallableStatement CallableStatement cstmt = c.prepareCall("mock stored proc"); assertTrue(isWrapperFor(cstmt, CallableStatement.class)); Statement unwrappedCStmt = (Statement) unwrap(cstmt, CallableStatement.class); assertTrue( unwrappedCStmt.getClass().getName().contains("java.sql.CallableStatement") && unwrappedCStmt.getClass().getName().contains("EnhancerByMockito")); }
protected void setUp() throws Exception { include(PATH); xads2_ = (XADataSource) getComponent("xads"); xacon_ = xads2_.getXAConnection(); con_ = xacon_.getConnection(); xares_ = new DBXAResourceImpl(con_); }
public int getLoginTimeout() throws SQLException { return _dataSource.getLoginTimeout(); }
public void setLoginTimeout(int seconds) throws SQLException { _dataSource.setLoginTimeout(seconds); }
public void setLogWriter(PrintWriter out) throws SQLException { _dataSource.setLogWriter(out); }
public PrintWriter getLogWriter() throws SQLException { return _dataSource.getLogWriter(); }
public XAConnection getXAConnection(String user, String password) throws SQLException { return wrap(_dataSource.getXAConnection(user, password)); }
public XAConnection getXAConnection() throws SQLException { return wrap(_dataSource.getXAConnection()); }
/** * Sets the XADataSource instance used by the XAConnectionFactory. * * <p>Note: this method currently has no effect once the pool has been initialized. The pool is * initialized the first time one of the following methods is invoked: <code> * getConnection, setLogwriter, * setLoginTimeout, getLoginTimeout, getLogWriter.</code> * * @param xaDataSourceInstance XADataSource instance */ public synchronized void setXaDataSourceInstance(XADataSource xaDataSourceInstance) { this.xaDataSourceInstance = xaDataSourceInstance; xaDataSource = xaDataSourceInstance == null ? null : xaDataSourceInstance.getClass().getName(); }