use of javax.sql.XAConnection in project druid by alibaba.
the class DruidXADataSource method getXAConnection.
@Override
public XAConnection getXAConnection() throws SQLException {
DruidPooledConnection conn = this.getConnection();
Connection physicalConn = conn.unwrap(Connection.class);
XAConnection rawXAConnection = createPhysicalXAConnection(physicalConn);
return new DruidPooledXAConnection(conn, rawXAConnection);
}
use of javax.sql.XAConnection in project spring-boot by spring-projects.
the class PoolingDataSourceBeanTests method setDataSource.
@Test
public void setDataSource() throws Exception {
XADataSource dataSource = mock(XADataSource.class);
XAConnection xaConnection = mock(XAConnection.class);
Connection connection = mock(Connection.class);
given(dataSource.getXAConnection()).willReturn(xaConnection);
given(xaConnection.getConnection()).willReturn(connection);
this.bean.setDataSource(dataSource);
this.bean.setBeanName("beanName");
this.bean.afterPropertiesSet();
this.bean.init();
this.bean.createPooledConnection(dataSource, this.bean);
verify(dataSource).getXAConnection();
TransactionManagerServices.getTaskScheduler().shutdown();
}
use of javax.sql.XAConnection in project spring-boot by spring-projects.
the class NarayanaDataSourceBeanTests method shouldGetConnectionAndCommit.
@Test
public void shouldGetConnectionAndCommit() throws SQLException {
Connection mockConnection = mock(Connection.class);
XAConnection mockXaConnection = mock(XAConnection.class);
given(mockXaConnection.getConnection()).willReturn(mockConnection);
given(this.dataSource.getXAConnection("", "")).willReturn(mockXaConnection);
Properties properties = new Properties();
properties.put(TransactionalDriver.XADataSource, this.dataSource);
Connection connection = this.dataSourceBean.getConnection();
assertThat(connection).isInstanceOf(ConnectionImple.class);
connection.commit();
verify(this.dataSource, times(1)).getXAConnection("", "");
verify(mockXaConnection, times(1)).getConnection();
verify(mockConnection, times(1)).commit();
}
use of javax.sql.XAConnection in project aries by apache.
the class TxDBServlet method insertIntoTransaction.
/**
* This method demonstrates how to enlist JDBC connection into Transaction according OSGi enterprise specification.
*
* @param xads XADataSource
* @param tm TransactionManager
* @param value which will be inserted into table
* @param toCommit Specify if the transaction will be committed or rolledback
* @throws SQLException
* @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();
}
} catch (RollbackException e) {
throw new GenericJTAException(e);
} catch (SecurityException e) {
throw new GenericJTAException(e);
} catch (IllegalStateException e) {
throw new GenericJTAException(e);
} catch (HeuristicMixedException e) {
throw new GenericJTAException(e);
} catch (HeuristicRollbackException e) {
throw new GenericJTAException(e);
} catch (SystemException e) {
throw new GenericJTAException(e);
} catch (NotSupportedException e) {
throw new GenericJTAException(e);
}
}
use of javax.sql.XAConnection in project aries by apache.
the class TxDBServlet method printTable.
// end of doPost(HttpServletRequest request, HttpServletResponse response)
/**
* Prints the table
* @param xaDataSource
* @throws SQLException
*/
private void printTable(XADataSource xaDataSource) throws SQLException {
XAConnection xaConnection = xaDataSource.getXAConnection();
Connection connection = xaConnection.getConnection();
PreparedStatement selectStatement = connection.prepareStatement(SELECT_TABLE);
ResultSet set = selectStatement.executeQuery();
pw.write("<center><br><table>");
pw.write("<tr BGCOLOR=#FFCC33>");
pw.write("<td><font face=\"Tahoma\"><b>VALUES</font></td>");
pw.write("</tr>");
while (set.next()) {
pw.write("<tr>");
pw.write("<td><font face=\"Tahoma\">");
pw.write(set.getString("value"));
pw.write("</font></td>");
pw.write("</tr>");
}
pw.write("</table><br></center>");
}
Aggregations