Search in sources :

Example 11 with JtxTransactionMode

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);
}
Also used : DbJtxTransaction(jodd.db.jtx.DbJtxTransaction) JtxTransactionMode(jodd.jtx.JtxTransactionMode)

Example 12 with JtxTransactionMode

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;
    }
}
Also used : JtxTransactionMode(jodd.jtx.JtxTransactionMode) ProxyTarget.targetClass(jodd.proxetta.ProxyTarget.targetClass) JtxTransaction(jodd.jtx.JtxTransaction)

Example 13 with JtxTransactionMode

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;
}
Also used : TransactionAnnotationData(jodd.jtx.meta.TransactionAnnotationData) ProxettaException(jodd.proxetta.ProxettaException) JtxTransactionMode(jodd.jtx.JtxTransactionMode) Method(java.lang.reflect.Method)

Aggregations

JtxTransactionMode (jodd.jtx.JtxTransactionMode)13 DbJtxTransaction (jodd.db.jtx.DbJtxTransaction)10 JtxTransaction (jodd.jtx.JtxTransaction)5 JtxTransactionManager (jodd.jtx.JtxTransactionManager)5 Test (org.junit.Test)5 DbJtxResourceManager (jodd.db.jtx.DbJtxResourceManager)4 JtxException (jodd.jtx.JtxException)2 Method (java.lang.reflect.Method)1 SQLException (java.sql.SQLException)1 DbJtxSessionProvider (jodd.db.jtx.DbJtxSessionProvider)1 DbJtxTransactionManager (jodd.db.jtx.DbJtxTransactionManager)1 TransactionAnnotationData (jodd.jtx.meta.TransactionAnnotationData)1 ProxettaException (jodd.proxetta.ProxettaException)1 ProxyTarget.targetClass (jodd.proxetta.ProxyTarget.targetClass)1