| <!DOCTYPE html> |
| <html lang="en"> |
| |
| <head> |
| <meta charset="UTF-8"> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| <title>Apache TomEE</title> |
| <meta name="description" |
| content="Apache TomEE is a lightweight, yet powerful, JavaEE Application server with feature rich tooling." /> |
| <meta name="keywords" content="tomee,asf,apache,javaee,jee,shade,embedded,test,junit,applicationcomposer,maven,arquillian" /> |
| <meta name="author" content="Luka Cvetinovic for Codrops" /> |
| <link rel="icon" href="../../favicon.ico"> |
| <link rel="icon" type="image/png" href="../../favicon.png"> |
| <meta name="msapplication-TileColor" content="#80287a"> |
| <meta name="theme-color" content="#80287a"> |
| <link rel="stylesheet" type="text/css" href="../../css/normalize.css"> |
| <link rel="stylesheet" type="text/css" href="../../css/bootstrap.css"> |
| <link rel="stylesheet" type="text/css" href="../../css/owl.css"> |
| <link rel="stylesheet" type="text/css" href="../../css/animate.css"> |
| <link rel="stylesheet" type="text/css" href="../../fonts/font-awesome-4.1.0/css/font-awesome.min.css"> |
| <link rel="stylesheet" type="text/css" href="../../fonts/eleganticons/et-icons.css"> |
| <link rel="stylesheet" type="text/css" href="../../css/jqtree.css"> |
| <link rel="stylesheet" type="text/css" href="../../css/idea.css"> |
| <link rel="stylesheet" type="text/css" href="../../css/cardio.css"> |
| |
| <script type="text/javascript"> |
| |
| var _gaq = _gaq || []; |
| _gaq.push(['_setAccount', 'UA-2717626-1']); |
| _gaq.push(['_setDomainName', 'apache.org']); |
| _gaq.push(['_trackPageview']); |
| |
| (function() { |
| var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; |
| ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; |
| var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); |
| })(); |
| |
| </script> |
| </head> |
| |
| <body> |
| <div class="preloader"> |
| <img src="../../img/loader.gif" alt="Preloader image"> |
| </div> |
| <nav class="navbar"> |
| <div class="container"> |
| <div class="row"> <div class="col-md-12"> |
| |
| <!-- Brand and toggle get grouped for better mobile display --> |
| <div class="navbar-header"> |
| <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> |
| <span class="sr-only">Toggle navigation</span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| </button> |
| <a class="navbar-brand" href="/" title="Apache TomEE"> |
| <span> |
| |
| |
| <img |
| src="../../img/apache_tomee-logo.svg" |
| onerror="this.src='../../img/apache_tomee-logo.jpg'" |
| height="50" |
| > |
| |
| |
| </span> |
| </a> |
| </div> |
| <!-- Collect the nav links, forms, and other content for toggling --> |
| <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> |
| <ul class="nav navbar-nav navbar-right main-nav"> |
| <li><a href="../../docs.html">Documentation</a></li> |
| <li><a href="../../community/index.html">Community</a></li> |
| <li><a href="../../security/security.html">Security</a></li> |
| <li><a class="btn btn-accent accent-orange no-shadow" href="../../download-ng.html">Downloads</a></li> |
| </ul> |
| </div> |
| <!-- /.navbar-collapse --> |
| </div></div> |
| </div> |
| <!-- /.container-fluid --> |
| </nav> |
| |
| |
| <div id="main-block" class="container main-block"> |
| <div class="row title"> |
| <div class="col-md-12"> |
| <div class='page-header'> |
| |
| <h1>XA DataSource Configuration</h1> |
| </div> |
| </div> |
| </div> |
| <div class="row"> |
| |
| <div class="col-md-12"> |
| <div class="sect1"> |
| <h2 id="_introduction">Introduction</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>XA datasources are able to participate in global transactions involving |
| more than one resource - for example, scenarios where a transaction needs |
| to encompass connections to two different databases,, or a database and |
| a JMS resource.</p> |
| </div> |
| <div class="paragraph"> |
| <p>The global transaction manager will provide a two phase commit for all |
| the resources enlisted in the transaction - if any of the commit |
| operations fail, then all the resources in the global transaction will |
| be rolled back.</p> |
| </div> |
| <div class="paragraph"> |
| <p>JTA can still be used with non-XA datasources, however the datasource will |
| use a local transaction as opposed to a global transaction.</p> |
| </div> |
| <div class="paragraph"> |
| <p>JDBC drivers providing XA capabilities provide an implementation of |
| <code>javax.sql.XADataSource</code>. This makes them a little more tricky to configure |
| than non-XA datasources. The general technique is to configure an instance |
| of the vendor-provided <code>XADataSource</code> implementation, and to then point |
| the usual non-XA resource at this instance. Sounds complex? Let’s walk |
| through an example. We’ll also provide tested example configs for a number |
| of well known databases at the end of this document.</p> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="_example">Example</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>In this example, we’ll look at MySQL. First off, download the MySQL driver |
| from: <a href="https://dev.mysql.com/downloads/connector/j/" class="bare">https://dev.mysql.com/downloads/connector/j/</a>. Once you have the .jar |
| file, add it to the TomEE <code>lib</code> directory. This driver provides the |
| <code>com.mysql.cj.jdbc.MysqlXADataSource</code> class. The properties that need to |
| be configured vary between datasources, so we’ll need to get a list of the |
| properties and work out the values to set.</p> |
| </div> |
| <div class="paragraph"> |
| <p>From the TomEE bin directory, execute the following command: |
| <code>./tomee.sh setters -c com.mysql.cj.jdbc.MysqlXADataSource</code> on *nix systems, |
| or</p> |
| </div> |
| <div class="paragraph"> |
| <p><code>tomee.bat setters -c com.mysql.cj.jdbc.MysqlXADataSource</code> on Windows systems.</p> |
| </div> |
| <div class="paragraph"> |
| <p>This will give a complete list of paramaters that are available for the XA |
| datasource. We’ll simply use the <code>URL</code> paramater for the datasource.</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code> <Resource id="demo/jdbc/XADataSourceXA" type="XADataSource" class-name="com.mysql.cj.jdbc.MysqlXADataSource"> |
| Url jdbc:mysql://192.168.37.202:3306/movie |
| </Resource></code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>Next, we create a JtaManaged datasource as we normally would, and point it to the |
| XA datasource using the <code>XaDataSource</code> attribute.</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code> <Resource id="demo/jdbc/XADataSource" type="DataSource"> |
| XaDataSource demo/jdbc/XADataSourceXA |
| JdbcDriver com.mysql.cj.jdbc.Driver |
| JdbcUrl jdbc:mysql://192.168.37.202:3306/movie |
| username root |
| password my-secret-pw |
| JtaManaged true |
| InitialSize 10 |
| MaxActive 128 |
| MaxIdle 25 |
| MinIdle 10 |
| AccessToUnderlyingConnectionAllowed true |
| TestOnBorrow false |
| TestWhileIdle true |
| TimeBetweenEvictionRuns 1 minute |
| MaxWaitTime 0 seconds |
| ValidationQuery select 1 |
| </Resource></code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>And finally, a non-JTA managed datasource as well:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code> <Resource id="demo/jdbc/XADataSourceUnmanaged" type="DataSource"> |
| JdbcDriver com.mysql.cj.jdbc.Driver |
| JdbcUrl jdbc:mysql://192.168.37.202:3306/movie |
| UserName root |
| password my-secret-pw |
| JtaManaged false |
| InitialSize 10 |
| MaxActive 100 |
| MaxIdle 50 |
| MinIdle 10 |
| AccessToUnderlyingConnectionAllowed true |
| TestOnBorrow false |
| TestWhileIdle true |
| TimeBetweenEvictionRuns 1 minute |
| MaxWaitTime 0 seconds |
| ValidationQuery select 1 |
| </Resource></code></pre> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="_sample_configs">Sample configs</h2> |
| <div class="sectionbody"> |
| <div class="sect2"> |
| <h3 id="_oracle">Oracle</h3> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code> <Resource id="demo/jdbc/XADataSource" type="DataSource"> |
| XaDataSource demo/jdbc/XADataSourceXA |
| JdbcDriver oracle.jdbc.OracleDriver |
| JdbcUrl jdbc:oracle:thin:@//192.168.37.214:1521/XE |
| username system |
| password my-cool-password |
| JtaManaged true |
| InitialSize 10 |
| MaxActive 128 |
| MaxIdle 25 |
| MinIdle 10 |
| AccessToUnderlyingConnectionAllowed true |
| TestOnBorrow false |
| TestWhileIdle true |
| TimeBetweenEvictionRuns 1 minute |
| MaxWaitTime 0 seconds |
| PoolPreparedStatements true |
| MaxOpenPreparedStatements 1024 |
| ValidationQuery select 1 from dual |
| </Resource> |
| |
| <Resource id="demo/jdbc/XADataSourceXA" type="XADataSource" class-name="oracle.jdbc.xa.client.OracleXADataSource"> |
| Url jdbc:oracle:thin:@//192.168.37.214:1521/XE |
| </Resource> |
| |
| <Resource id="demo/jdbc/XADataSourceUnmanaged" type="DataSource"> |
| JdbcDriver oracle.jdbc.OracleDriver |
| JdbcUrl jdbc:oracle:thin:@//192.168.37.214:1521/XE |
| UserName system |
| password my-cool-password |
| JtaManaged false |
| InitialSize 10 |
| MaxActive 100 |
| MaxIdle 50 |
| MinIdle 10 |
| AccessToUnderlyingConnectionAllowed true |
| TestOnBorrow false |
| TestWhileIdle true |
| TimeBetweenEvictionRuns 1 minute |
| MaxWaitTime 0 seconds |
| PoolPreparedStatements true |
| MaxOpenPreparedStatements 1024 |
| ValidationQuery select 1 from dual |
| </Resource></code></pre> |
| </div> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="_microsoft_sql_server">Microsoft SQL Server</h3> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code> <Resource id="demo/jdbc/XADataSource" type="DataSource"> |
| XaDataSource demo/jdbc/XADataSourceXA |
| JdbcDriver com.microsoft.sqlserver.jdbc.SQLServerDriver |
| JdbcUrl jdbc:sqlserver://yourserver.database.windows.net:1433;database=test |
| username sa |
| password my-secret-pw1 |
| JtaManaged true |
| InitialSize 10 |
| MaxActive 128 |
| MaxIdle 25 |
| MinIdle 10 |
| AccessToUnderlyingConnectionAllowed true |
| TestOnBorrow false |
| TestWhileIdle true |
| TimeBetweenEvictionRuns 1 minute |
| MaxWaitTime 0 seconds |
| PoolPreparedStatements true |
| MaxOpenPreparedStatements 1024 |
| ValidationQuery select 1 |
| </Resource> |
| |
| <Resource id="demo/jdbc/XADataSourceXA" type="XADataSource" class-name="com.microsoft.sqlserver.jdbc.SQLServerXADataSource"> |
| URL jdbc:sqlserver://yourserver.database.windows.net:1433;database=test |
| </Resource> |
| |
| <Resource id="demo/jdbc/XADataSourceUnmanaged" type="DataSource"> |
| JdbcDriver com.microsoft.sqlserver.jdbc.SQLServerDriver |
| JdbcUrl jdbc:sqlserver://yourserver.database.windows.net:1433;database=test |
| UserName sa |
| password my-secret-pw1 |
| JtaManaged false |
| InitialSize 10 |
| MaxActive 100 |
| MaxIdle 50 |
| MinIdle 10 |
| AccessToUnderlyingConnectionAllowed true |
| TestOnBorrow false |
| TestWhileIdle true |
| TimeBetweenEvictionRuns 1 minute |
| MaxWaitTime 0 seconds |
| PoolPreparedStatements true |
| MaxOpenPreparedStatements 1024 |
| ValidationQuery select 1 |
| </Resource></code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>Please note that using XA with Microsoft SQL Server requires the MS DTC to be configured correctly, and sqljdbc_xa.dll to be installed. For instructions, please see this Microsoft article: <a href="https://docs.microsoft.com/en-us/sql/connect/jdbc/understanding-xa-transactions?view=sql-server-2017" class="bare">https://docs.microsoft.com/en-us/sql/connect/jdbc/understanding-xa-transactions?view=sql-server-2017</a></p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="_mysql">MySQL</h3> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code> <resources> |
| <Resource id="demo/jdbc/XADataSource" type="DataSource"> |
| XaDataSource demo/jdbc/XADataSourceXA |
| JdbcDriver com.mysql.cj.jdbc.Driver |
| JdbcUrl jdbc:mysql://192.168.37.202:3306/movie |
| username root |
| password my-secret-pw |
| JtaManaged true |
| InitialSize 10 |
| MaxActive 128 |
| MaxIdle 25 |
| MinIdle 10 |
| AccessToUnderlyingConnectionAllowed true |
| TestOnBorrow false |
| TestWhileIdle true |
| TimeBetweenEvictionRuns 1 minute |
| MaxWaitTime 0 seconds |
| ValidationQuery select 1 |
| |
| <Resource id="demo/jdbc/XADataSourceXA" type="XADataSource" class-name="com.mysql.cj.jdbc.MysqlXADataSource"> |
| Url jdbc:mysql://192.168.37.202:3306/movie |
| </Resource> |
| |
| <Resource id="demo/jdbc/XADataSourceUnmanaged" type="DataSource"> |
| JdbcDriver com.mysql.cj.jdbc.Driver |
| JdbcUrl jdbc:mysql://192.168.37.202:3306/movie |
| UserName root |
| password my-secret-pw |
| JtaManaged false |
| InitialSize 10 |
| MaxActive 100 |
| MaxIdle 50 |
| MinIdle 10 |
| AccessToUnderlyingConnectionAllowed true |
| TestOnBorrow false |
| TestWhileIdle true |
| TimeBetweenEvictionRuns 1 minute |
| MaxWaitTime 0 seconds |
| ValidationQuery select 1 |
| </Resource> |
| </resources></code></pre> |
| </div> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="_postgresql">PostgreSQL</h3> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code> <resources> |
| <Resource id="demo/jdbc/XADataSource" type="DataSource"> |
| XaDataSource demo/jdbc/XADataSourceXA |
| JdbcDriver org.postgresql.Driver |
| JdbcUrl jdbc:postgresql://192.168.37.200:5432/movie |
| username postgres |
| password mysecretpassword |
| JtaManaged true |
| InitialSize 10 |
| MaxActive 128 |
| MaxIdle 25 |
| MinIdle 10 |
| AccessToUnderlyingConnectionAllowed true |
| TestOnBorrow false |
| TestWhileIdle true |
| TimeBetweenEvictionRuns 1 minute |
| MaxWaitTime 0 seconds |
| PoolPreparedStatements true |
| MaxOpenPreparedStatements 1024 |
| ValidationQuery select 1 |
| </Resource> |
| |
| <Resource id="demo/jdbc/XADataSourceXA" type="XADataSource" class-name="org.postgresql.xa.PGXADataSource"> |
| URL jdbc:postgresql://192.168.37.200:5432/movie |
| </Resource> |
| |
| <Resource id="demo/jdbc/XADataSourceUnmanaged" type="DataSource"> |
| JdbcDriver org.postgresql.Driver |
| JdbcUrl jdbc:postgresql://192.168.37.200:5432/movie |
| UserName postgres |
| password mysecretpassword |
| JtaManaged false |
| InitialSize 10 |
| MaxActive 100 |
| MaxIdle 50 |
| MinIdle 10 |
| AccessToUnderlyingConnectionAllowed true |
| TestOnBorrow false |
| TestWhileIdle true |
| TimeBetweenEvictionRuns 1 minute |
| MaxWaitTime 0 seconds |
| PoolPreparedStatements true |
| MaxOpenPreparedStatements 1024 |
| ValidationQuery select 1 |
| </Resource> |
| </resources></code></pre> |
| </div> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="_derby">Derby</h3> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlight"><code> <resources> |
| <Resource id="movieDatabaseXA" type="javax.sql.XADataSource" class-name="org.apache.derby.jdbc.ClientXADataSource"> |
| DatabaseName=testdb |
| CreateDatabase=create |
| ServerName=localhost |
| PortName=1527 |
| UserName=admin |
| Password=admin |
| </Resource> |
| <Resource id="movieDatabase" type="DataSource"> |
| JdbcDriver org.apache.derby.jdbc.ClientDriver |
| JdbcUrl jdbc:derby://localhost:1527/testdb;create=true |
| XaDataSource=movieDatabaseXA |
| UserName=admin |
| Password=admin |
| ValidationQuery=values 1 |
| InitialSize=2 |
| MaxActive=128 |
| MaxIdle=25 |
| MinIdle=10 |
| TestWhileIdle=true |
| TestOnBorrow=false |
| TestOnReturn=false |
| AccessToUnderlyingConnectionAllowed=true |
| TimeBetweenEvictionRuns=1 minute |
| MaxWaitTime=0 seconds |
| JtaManaged=true |
| </Resource> |
| <Resource id="movieDatabaseUnmanaged" type="DataSource"> |
| JdbcDriver org.apache.derby.jdbc.ClientDriver |
| JdbcUrl jdbc:derby://localhost:1527/testdb;create=true |
| UserName admin |
| Password admin |
| ValidationQuery=values 1 |
| InitialSize=2 |
| MaxActive=128 |
| MaxIdle=25 |
| MinIdle=10 |
| TestWhileIdle=true |
| TestOnBorrow=false |
| TestOnReturn=false |
| AccessToUnderlyingConnectionAllowed=true |
| TimeBetweenEvictionRuns=1 minute |
| MaxWaitTime=0 seconds |
| JtaManaged=false |
| </Resource> |
| </resources></code></pre> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| |
| </div> |
| </div> |
| <div style="margin-bottom: 30px;"></div> |
| <footer> |
| <div class="container"> |
| <div class="row"> |
| <div class="col-sm-6 text-center-mobile"> |
| <h3 class="white">Be simple. Be certified. Be Tomcat.</h3> |
| <h5 class="light regular light-white">"A good application in a good server"</h5> |
| <ul class="social-footer"> |
| <li><a href="https://www.facebook.com/ApacheTomEE/"><i class="fa fa-facebook"></i></a></li> |
| <li><a href="https://twitter.com/apachetomee"><i class="fa fa-twitter"></i></a></li> |
| </ul> |
| </div> |
| <div class="col-sm-6 text-center-mobile"> |
| <div class="row opening-hours"> |
| <div class="col-sm-3 text-center-mobile"> |
| <h5><a href="../../latest/docs/" class="white">Documentation</a></h5> |
| <ul class="list-unstyled"> |
| <li><a href="../../latest/docs/admin/configuration/index.html" class="regular light-white">How to configure</a></li> |
| <li><a href="../../latest/docs/admin/file-layout.html" class="regular light-white">Dir. Structure</a></li> |
| <li><a href="../../latest/docs/developer/testing/index.html" class="regular light-white">Testing</a></li> |
| <li><a href="../../latest/docs/admin/cluster/index.html" class="regular light-white">Clustering</a></li> |
| </ul> |
| </div> |
| <div class="col-sm-3 text-center-mobile"> |
| <h5><a href="../../latest/examples/" class="white">Examples</a></h5> |
| <ul class="list-unstyled"> |
| <li><a href="../../latest/examples/simple-cdi-interceptor.html" class="regular light-white">CDI Interceptor</a></li> |
| <li><a href="../../latest/examples/rest-cdi.html" class="regular light-white">REST with CDI</a></li> |
| <li><a href="../../latest/examples/ejb-examples.html" class="regular light-white">EJB</a></li> |
| <li><a href="../../latest/examples/jsf-managedBean-and-ejb.html" class="regular light-white">JSF</a></li> |
| </ul> |
| </div> |
| <div class="col-sm-3 text-center-mobile"> |
| <h5><a href="../../community/index.html" class="white">Community</a></h5> |
| <ul class="list-unstyled"> |
| <li><a href="../../community/contributors.html" class="regular light-white">Contributors</a></li> |
| <li><a href="../../community/social.html" class="regular light-white">Social</a></li> |
| <li><a href="../../community/sources.html" class="regular light-white">Sources</a></li> |
| </ul> |
| </div> |
| <div class="col-sm-3 text-center-mobile"> |
| <h5><a href="../../security/index.html" class="white">Security</a></h5> |
| <ul class="list-unstyled"> |
| <li><a href="http://apache.org/security" target="_blank" class="regular light-white">Apache Security</a></li> |
| <li><a href="http://apache.org/security/projects.html" target="_blank" class="regular light-white">Security Projects</a></li> |
| <li><a href="http://cve.mitre.org" target="_blank" class="regular light-white">CVE</a></li> |
| </ul> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="row bottom-footer text-center-mobile"> |
| <div class="col-sm-12 light-white"> |
| <p>Copyright © 1999-2021 The Apache Software Foundation, Licensed under the Apache License, Version 2.0. Apache TomEE, TomEE, Apache, the Apache feather logo, and the Apache TomEE project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.</p> |
| </div> |
| </div> |
| </div> |
| </footer> |
| <!-- Holder for mobile navigation --> |
| <div class="mobile-nav"> |
| <ul> |
| <li><a hef="../../latest/docs/admin/index.html">Administrators</a> |
| <li><a hef="../../latest/docs/developer/index.html">Developers</a> |
| <li><a hef="../../latest/docs/advanced/index.html">Advanced</a> |
| <li><a hef="../../community/index.html">Community</a> |
| </ul> |
| <a href="#" class="close-link"><i class="arrow_up"></i></a> |
| </div> |
| <!-- Scripts --> |
| <script src="../../js/jquery-1.11.1.min.js"></script> |
| <script src="../../js/owl.carousel.min.js"></script> |
| <script src="../../js/bootstrap.min.js"></script> |
| <script src="../../js/wow.min.js"></script> |
| <script src="../../js/typewriter.js"></script> |
| <script src="../../js/jquery.onepagenav.js"></script> |
| <script src="../../js/tree.jquery.js"></script> |
| <script src="../../js/highlight.pack.js"></script> |
| <script src="../../js/main.js"></script> |
| </body> |
| |
| </html> |
| |