-
1. Re: Transaction over SQL reference bindings
ozkin Jul 17, 2015 3:19 PM (in response to ozkin)In Camel there is "transacted()" block which one could you. But what if your component (which is invoking those multiple SQL bindings) is just a Bean?
-
2. Re: Transaction over SQL reference bindings
ozkin Jul 17, 2015 5:28 PM (in response to ozkin)Heh..if I use TransactionManager directly in the Bean component implementation then it seems it solves the problem. That's the code:
// For SY1.1.0-Final
import javax.inject.Inject;
import javax.naming.InitialContext;
import javax.transaction.TransactionManager;
import org.switchyard.component.bean.Reference;
import org.switchyard.component.bean.Service;
@Service(MyService.class)
public class MyServiceBean implements MyService {
private static final String JNDI_TRANSACTION_MANAGER = "java:jboss/TransactionManager";
@Inject @Reference("SqlBinding1")
private FooService sqlBinding1;
@Inject @Reference("SqlBinding2")
private FooService sqlBinding2;
@Override
public void foo() throws Exception {
TransactionManager tm = (TransactionManager) new InitialContext().lookup(JNDI_TRANSACTION_MANAGER);
try {
tm.begin();
sqlBinding1.execute();
sqlBinding2.execute();
tm.commit();
} catch (Exception e) {
tm.rollback();
throw e;
}
}
}
Could someone confirm that this is ok'ish approach?
-
3. Re: Transaction over SQL reference bindings
jorgemoralespou_2 Jul 18, 2015 3:16 AM (in response to ozkin)Hi Max,
Switchyard provides with declarative transactions, so there is no need to manage them yourself.
In the component you have to define the transaction type (local or global) and on the interface you need to select tree behavior you want.
Here's some doc fsw-documentation/transactions.adoc at master · jorgemoralespou/fsw-documentation · GitHub
-
4. Re: Transaction over SQL reference bindings
ozkin Jul 18, 2015 7:53 AM (in response to jorgemoralespou_2)Thanks for reply Jorge. Of course, I've read about SY's declarative transactions, but I didn't find it fitting my case (or I misunderstood something).
My example above is just oversimplification. The gateway for my service is not transactional. My bean implementation also doesn't participate in any transactions. I just need one operation (foo() above) to implement a transactional behaviour for a couple of SQL binding invocations. I considered this to be noManagedTransaction case (or simply None) and let application itself manage transactions.. Any suggestions how it can be improved maybe?
-
5. Re: Transaction over SQL reference bindings
igarashitm Jul 23, 2015 9:31 PM (in response to ozkin)You can use managedTransaction.Global on your bean. If no transaction is propageted through service binding, then SY runtime will begin new global transaction before execution and commit it after execution.
https://docs.jboss.org/author/display/SWITCHYARD/Policy
Please take a look at policy-transaction demo for example.
switchyard/quickstarts/demos/policy-transaction at master · jboss-switchyard/switchyard · GitHub