コード例 #1
0
 /**
  * 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);
   }
 }
コード例 #2
0
  //
  // 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);
  }
コード例 #3
0
  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"));
  }
コード例 #4
0
 protected void setUp() throws Exception {
   include(PATH);
   xads2_ = (XADataSource) getComponent("xads");
   xacon_ = xads2_.getXAConnection();
   con_ = xacon_.getConnection();
   xares_ = new DBXAResourceImpl(con_);
 }
コード例 #5
0
 public int getLoginTimeout() throws SQLException {
   return _dataSource.getLoginTimeout();
 }
コード例 #6
0
 public void setLoginTimeout(int seconds) throws SQLException {
   _dataSource.setLoginTimeout(seconds);
 }
コード例 #7
0
 public void setLogWriter(PrintWriter out) throws SQLException {
   _dataSource.setLogWriter(out);
 }
コード例 #8
0
 public PrintWriter getLogWriter() throws SQLException {
   return _dataSource.getLogWriter();
 }
コード例 #9
0
 public XAConnection getXAConnection(String user, String password) throws SQLException {
   return wrap(_dataSource.getXAConnection(user, password));
 }
コード例 #10
0
 public XAConnection getXAConnection() throws SQLException {
   return wrap(_dataSource.getXAConnection());
 }
コード例 #11
0
 /**
  * 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();
 }