use of javax.sql.XADataSource in project spring-boot by spring-projects.
the class XADataSourceAutoConfigurationTests method wrapExistingXaDataSource.
@Test
public void wrapExistingXaDataSource() throws Exception {
ApplicationContext context = createContext(WrapExisting.class);
context.getBean(DataSource.class);
XADataSource source = context.getBean(XADataSource.class);
MockXADataSourceWrapper wrapper = context.getBean(MockXADataSourceWrapper.class);
assertThat(wrapper.getXaDataSource()).isEqualTo(source);
}
use of javax.sql.XADataSource in project spring-boot by spring-projects.
the class XADataSourceAutoConfiguration method createXaDataSource.
private XADataSource createXaDataSource() {
String className = this.properties.getXa().getDataSourceClassName();
if (!StringUtils.hasLength(className)) {
className = DatabaseDriver.fromJdbcUrl(this.properties.determineUrl()).getXaDataSourceClassName();
}
Assert.state(StringUtils.hasLength(className), "No XA DataSource class name specified");
XADataSource dataSource = createXaDataSourceInstance(className);
bindXaProperties(dataSource, this.properties);
return dataSource;
}
use of javax.sql.XADataSource in project spring-boot by spring-projects.
the class BitronixXADataSourceWrapperTests method wrap.
@Test
public void wrap() throws Exception {
XADataSource dataSource = mock(XADataSource.class);
BitronixXADataSourceWrapper wrapper = new BitronixXADataSourceWrapper();
DataSource wrapped = wrapper.wrapDataSource(dataSource);
assertThat(wrapped).isInstanceOf(PoolingDataSourceBean.class);
assertThat(((PoolingDataSourceBean) wrapped).getDataSource()).isSameAs(dataSource);
}
use of javax.sql.XADataSource 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.XADataSource in project aries by apache.
the class TxDBServlet method doGet.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
pw = response.getWriter();
pw.write(LOGO_HEADER);
// Get the bundle context from ServletContext attributes
BundleContext ctx = (BundleContext) getServletContext().getAttribute(OSGI_BUNDLECONTEXT_ATTRIBUTE);
pw.println("<html>");
pw.println("<head>");
pw.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"tableTemplate.css\"/>");
pw.println("<body>");
pw.println("<h2 align=center><p><font face=\"Tahoma\">Sample Application for JDBC usage in JTA Transactions.</font></h2>");
pw.println("<p><p>");
ServiceReference tmServiceRef = ctx.getServiceReference("javax.transaction.TransactionManager");
ServiceReference derbyServiceRef = ctx.getServiceReference(DataSourceFactory.class.getName());
if (tmServiceRef == null || derbyServiceRef == null) {
pw.println("<font face=\"Tahoma\">TransactionManager or Derby driver are not available in the OSGI registry.</font><br>");
} else {
TransactionManager tm = (TransactionManager) ctx.getService(tmServiceRef);
DataSourceFactory derbyRegistry = (DataSourceFactory) ctx.getService(derbyServiceRef);
try {
// Set the needed properties for the database connection
Properties props = new Properties();
props.put(DataSourceFactory.JDBC_URL, "jdbc:derby:txDemo");
props.put(DataSourceFactory.JDBC_DATABASE_NAME, "txDemo");
props.put(DataSourceFactory.JDBC_USER, "");
props.put(DataSourceFactory.JDBC_PASSWORD, "");
XADataSource xaDataSource = derbyRegistry.createXADataSource(props);
pw.println("<center><form><table><tr><td align='right'>Value: </td><td align=left><input type='text' name='value' value='' size='12'/><input type='submit' name='action' value='InsertAndCommit' size='100'/></td></tr>");
pw.println("<tr><td align='right'>Value: </td><td align=left><input type='text' name='value' value='' size='12'/><input type='submit' name='action' value='InsertAndRollback' size='100'/></center></td></tr>");
pw.println("<tr colspan='2' align='center'><td> </td><td><input type='submit' name='action' value='cleanTable' size='100' /> <input type='submit' name='action' value='printTable' size='100'/></td><tr></table></form></center>");
String value = request.getParameter("value");
String action = request.getParameter("action");
if (action != null && action.equals("InsertAndCommit")) {
insertIntoTransaction(xaDataSource, tm, value, true);
} else if (action != null && action.equals("InsertAndRollback")) {
insertIntoTransaction(xaDataSource, tm, value, false);
} else if (action != null && action.equals("cleanTable")) {
cleanTable(xaDataSource);
}
printTable(xaDataSource);
} catch (Exception e) {
pw.println("<font face=\"Tahoma\">Unexpected exception occurred " + e.toString() + ".</font><br>");
e.printStackTrace(pw);
}
}
pw.println("</body>");
pw.println("</html>");
pw.flush();
}
Aggregations