use of jodd.jtx.JtxTransactionMode in project jodd by oblac.
the class DbTransactionTest method service0_1.
void service0_1(JtxTransaction uptx) {
assertTotals(1, 1);
DbJtxTransaction tx = dbtxm.requestTransaction(new JtxTransactionMode().propagationSupports());
assertTotals(1, 1);
assertEquals(uptx, tx);
DbSession s1 = tx.requestResource();
assertEquals(s0, s1);
}
use of jodd.jtx.JtxTransactionMode in project jodd by oblac.
the class AnnotationTxAdvice method execute.
public Object execute() throws Exception {
Class type = targetClass();
String methodName = targetMethodName();
Class[] methodArgsTypes = createArgumentsClassArray();
String methodDescription = targetMethodDescription();
// read transaction mode from annotation
JtxTransactionMode txMode = manager.getTxMode(type, methodName, methodArgsTypes, methodDescription);
// request transaction
JtxTransaction tx = null;
try {
String scope = manager.resolveScope(type, methodName);
tx = manager.getJtxWorker().maybeRequestTransaction(txMode, scope);
Object result = invoke();
manager.getJtxWorker().maybeCommitTransaction(tx);
return result;
} catch (Exception ex) {
manager.getJtxWorker().markOrRollbackTransaction(tx, ex);
throw ex;
}
}
use of jodd.jtx.JtxTransactionMode in project jodd by oblac.
the class AnnotationTxAdviceManager method getTxMode.
/**
* Reads transaction mode from method annotation. Annotations are cached for better performances.
* @param type target class
* @param methodName target method name over which the transaction should be wrapped
* @param methodArgTypes types of arguments, used to find the method
* @param unique unique method fingerprint that contains return and arguments type information
*/
public synchronized JtxTransactionMode getTxMode(Class type, String methodName, Class[] methodArgTypes, String unique) {
String signature = type.getName() + '#' + methodName + '%' + unique;
JtxTransactionMode txMode = txmap.get(signature);
if (txMode == null) {
if (!txmap.containsKey(signature)) {
Method m;
try {
m = type.getMethod(methodName, methodArgTypes);
} catch (NoSuchMethodException nsmex) {
throw new ProxettaException(nsmex);
}
TransactionAnnotationData txAnn = getTransactionAnnotation(m);
if (txAnn != null) {
txMode = new JtxTransactionMode();
txMode.setPropagationBehaviour(txAnn.getPropagation());
txMode.setIsolationLevel(txAnn.getIsolation());
txMode.setReadOnly(txAnn.isReadOnly());
txMode.setTransactionTimeout(txAnn.getTimeout());
} else {
txMode = defaultTransactionMode;
}
txmap.put(signature, txMode);
}
}
return txMode;
}
Aggregations