Java 8 XAConnection - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 XAConnection class.

This code example shows how to use the following methods:getConnection, getXAResource
	 * @throws GenericJTAException 
	 */ 
	private void insertIntoTransaction(XADataSource xads, TransactionManager tm, String value, boolean toCommit) throws SQLException, GenericJTAException{
		 
		XAConnection xaConnection = xads.getXAConnection();
		Connection connection = xaConnection.getConnection();
		XAResource xaResource  = xaConnection.getXAResource();
		try{ 
			tm.begin();
			Transaction transaction = tm.getTransaction();
			transaction.enlistResource(xaResource);
	 
			PreparedStatement insertStatement = connection.prepareStatement(INSERT_INTO_TABLE);
			insertStatement.setString(1, value);
			insertStatement.executeUpdate();
			if(toCommit){
				transaction.commit();
			} else { 
				transaction.rollback();
			} 
5
CodeRank
This code example shows how to use the following methods:getConnection
			if (username != null) {
				xaConnection = xaDataSource.getXAConnection(username, password);
			} else { 
				xaConnection = xaDataSource.getXAConnection();
			} 
			return xaConnection.getConnection();
		} catch (SQLException sex) {
			throw new DbSqlException("Unable to get connection from XA datasource", sex);
		} 
	} 
 
	public void closeConnection(Connection connection) {
		try { 
			connection.close();
		} catch (SQLException sex) {
			// ignore 
		} 
	} 
 
	public void close() {} 
5
CodeRank
This code example shows how to use the following methods:addConnectionEventListener, getConnection, getXAResource
        } else { 
            xaConnection = xaDataSource.getXAConnection(username, password);
        } 
 
        // get the real connection and XAResource from the connection 
        Connection connection = xaConnection.getConnection();
        XAResource xaResource = xaConnection.getXAResource();
 
        // register the xa resource for the connection 
        transactionRegistry.registerConnection(connection, xaResource);
 
        // The Connection we're returning is a handle on the XAConnection. 
        // When the pool calling us closes the Connection, we need to 
        // also close the XAConnection that holds the physical connection. 
        xaConnection.addConnectionEventListener(new ConnectionEventListener() {
 
            @Override 
            public void connectionClosed(ConnectionEvent event) {
                PooledConnection pc = (PooledConnection) event.getSource();
                pc.removeConnectionEventListener(this);
5
CodeRank
This code example shows how to use the following methods:getConnection, getXAResource
        TestUtil.createTable(_conn, "testxa1", "foo int");
 
        clearAllPrepared(); 
 
        xaconn = _ds.getXAConnection();
        xaRes = xaconn.getXAResource();
        conn = xaconn.getConnection();
    } 
 
    protected void tearDown() throws SQLException {
        xaconn.close();
        clearAllPrepared(); 
 
        TestUtil.dropTable(_conn, "testxa1");
        TestUtil.closeDB(_conn);
 
    } 
 
    private void clearAllPrepared() throws SQLException
5
CodeRank
This code example shows how to use the following methods:close
        } finally { 
            physicalConnection_ = null;
        } 
 
        try { 
            xaConnection_.close();
            logger_.log("DSSR0001", null); 
        } catch (final SQLException ex) {
            logger_.log(ex);
        } finally { 
            xaConnection_ = null;
        } 
    } 
 
    private void assertOpened() throws SQLException {
        if (closed_) {
            throw new SSQLException("ESSR0062", null); 
        } 
    } 
 
3
CodeRank
This code example shows how to use the following methods:close
	 *            the XA connection or null 
	 */ 
	public static void closeSilently(XAConnection conn) {
		if (conn != null) {
			try { 
				conn.close();
			} catch (SQLException e) {
				// ignore 
			} 
		} 
	} 
 
	/** 
	 * Open a new database connection with the given settings. 
	 *  
	 * @param driver 
	 *            the driver class name 
	 * @param url 
	 *            the database URL 
	 * @param user 
3
CodeRank
This code example shows how to use the following methods:getConnection
    public synchronized java.sql.Connection getConnection() throws SQLException {
        if (this.currentXAConnection == null) {
            return getConnection(false, true); 
        } 
 
        return this.currentXAConnection.getConnection();
    } 
 
    @Override 
    public void close() throws SQLException {
        if (this.currentXAConnection == null) {
            super.close(); 
        } else { 
            removeXAConnectionMapping(this.currentXid);
            this.currentXAConnection.close();
        } 
    } 
} 
3
CodeRank
This code example shows how to use the following methods:getConnection
  @Test
  public void testGetXAConnection() throws Exception {
    assertNotNull(con);
    assertFalse(con instanceof PGConnection);
 
    Connection c = con.getConnection();
    assertNotNull(c);
    assertTrue(c instanceof PGConnection);
    assertTrue(c.isValid(5));
  } 
} 
3
CodeRank
This code example shows how to use the following methods:close
        con_ = xacon_.getConnection();
        xares_ = new DBXAResourceImpl(con_);
    } 
 
    protected void tearDown() throws Exception {
        xacon_.close();
    } 
} 
3
CodeRank
This code example shows how to use the following methods:close
    { 
	try 
	{ 
	    if (_theConnection != null)
	    { 
		_theConnection.close();
		_theConnection = null;
	    } 
	} 
	catch (SQLException e)
	{ 
        jdbcLogger.i18NLogger.warn_drcdest(e);
	} 
    } 
 
    public boolean packInto (OutputObjectState os)
    { 
	if (jdbcLogger.logger.isTraceEnabled()) { 
        jdbcLogger.logger.trace("IndirectRecoverableConnection.packInto ()"); 
    } 
4
CodeRank
See Code Examples for Java 8 XAConnection Methods: