[jboss-user] [JCA/JBoss] - WHICH TYPE OF DATASOURCE SHOULD I USE (CHEAT SHEET)?
weston.price@jboss.com
do-not-reply at jboss.com
Wed Sep 6 20:24:19 EDT 2006
JBoss/JCA provides connector managers for three fundamentally different types of JDBC interactions with an underlying RDBMS. The thread breaks breaks down these ConnectionManager options with their associated *-ds.xml configuration type. Note, this is not a replacement for reading relevant documents regarding JCA and Transaction Management in general but rather should be consulted as a quick tip type document.
NoTxConnectionManager -- <no-tx-datasource>
Use this type of configuration if you, the developer, want to completely manage JDBC transactional demarcation within your code.
Example:
|
| InitialContext ctx = null;
| DataSource ds = null;
| Connection conn = null;
|
| try
| {
|
| ctx = new IntialContext();
| ds = (DataSource)ctx.lookup("java:/DefaultDS");
| conn = ds.getConnection();
| conn.setAutoCommit(false); //Transaction begins here
|
| //Do JDBC stuff here
| conn.commit();
|
| }catch (Exception e)
|
| //Evaluate exception, rollback or ignore etc, etc
| conn.rollback();
|
| }finally
| {
|
| //Close other resources Prepared|Callable Statements ehre
| if(con != null)
| con.close();
| }
|
|
TxConnectionManager -- <local-tx-datasource>
Use this type of configuration for JDBC interactions with a *single* datasource. Configurations of this type can be found in JBOSS_HOME/docs/examples/jca. Typically <local-tx-datasource> configurations will be named 'vendor'-ds.xml (ie oracle-ds.xml, postgres-ds.xml, mysql-ds.xml). Note, the important thing to remember is that for this type of configuration you *do not* control transaction boundaries.
Methods from the JDBC API such as setAutoCommit(true | false), commit(), rollback() are not used as JBoss automatically manages the enlistment/delistment of the underlying resource in the current transaction.
TxConnectionManager -- <xa-datasource>
Use this configuration when your application requires the enlistment of multiple resources in the current transaction. Typical scenarios include:
|
| JDBC
| Updating multiple DataSources in the same transaction where the commit or rollback of one DataSource would effect the other and 2PC (two phase commit) is appropriate.
|
| JMS/JDBC
| Receipt of a JMS message and JDBC create/read/update/delete should occur within the same transaction.
|
| JCBC/JCA
| JDBC interaction and XA enabled JCA adapter should occur within the same transaction.
|
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3969920#3969920
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3969920
More information about the jboss-user
mailing list