Note that there are some explanatory texts on larger screens.

plurals
  1. POCoherence and container managed transactions
    text
    copied!<p>I'm implementing simultaneous write into database and Oracle Coherence 3.7.1 and want to make whole operation transactional. </p> <p>I would like to have a critique on my approach. </p> <p>Currently, I've created façade class like this:</p> <pre><code>public class Facade { @EJB private JdbcDao jdbcDao; @EJB private CoherenceDao coherenceDao; @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) private void updateMethod(List&lt;DomainObject&gt; list) { jdbcDao.update(list); coherenceDao.update(list); } } </code></pre> <p>I guess JDBC DAO would not need to do anything specific about transactions, it something happens Hibernate would throw some kind of RuntimeException. </p> <pre><code>public class JdbcDao { private void update(List&lt;DomainObject&gt; list) { // I presume there is nothing specific I have to do about transactions. // if I don't catch any exceptions it would work just fine } } </code></pre> <p>Here is interesting part. How do I make Coherence support transactions? I guess I should open coherence transaction inside update() method and on any exceptions inside it I should throw RuntimeException myself?</p> <p>I currently thinking of something like this: </p> <pre><code>public class CoherenceDao { private void update(List&lt;DomainObject&gt; list) { // how should I make it transactional? // I guess it should somehow throw RuntimeException? TransactionMap mapTx = CacheFactory.getLocalTransaction(cache); mapTx.setTransactionIsolation(TransactionMap.TRANSACTION_REPEATABLE_GET); mapTx.setConcurrency(TransactionMap.CONCUR_PESSIMISTIC); // gather the cache(s) into a Collection Collection txnCollection = Collections.singleton(mapTx); try { mapTx.begin(); // put into mapTx here CacheFactory.commitTransactionCollection(txnCollection, 1); } catch (Throwable t) { CacheFactory.rollbackTransactionCollection(txnCollection); throw new RuntimeException(); } } } </code></pre> <p>Would this approach work as expected? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload