Search in sources :

Example 1 with DefaultTransactionAttribute

use of io.micronaut.transaction.interceptor.DefaultTransactionAttribute in project micronaut-data by micronaut-projects.

the class DefaultStoredDataOperation method getTransactionDefinition.

@NonNull
@Override
public final Optional<TransactionDefinition> getTransactionDefinition() {
    if (transactionDefinition == null) {
        AnnotationValue<TransactionalAdvice> annotation = method.getAnnotation(TransactionalAdvice.class);
        if (annotation != null) {
            DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
            attribute.setName(method.getDeclaringType().getSimpleName() + "." + method.getMethodName());
            attribute.setReadOnly(annotation.isTrue("readOnly"));
            annotation.intValue("timeout").ifPresent(value -> attribute.setTimeout(Duration.ofSeconds(value)));
            final Class[] noRollbackFors = annotation.classValues("noRollbackFor");
            // noinspection unchecked
            attribute.setNoRollbackFor(noRollbackFors);
            annotation.enumValue("propagation", TransactionDefinition.Propagation.class).ifPresent(attribute::setPropagationBehavior);
            annotation.enumValue("isolation", TransactionDefinition.Isolation.class).ifPresent(attribute::setIsolationLevel);
            this.transactionDefinition = attribute;
        } else {
            transactionDefinition = NO_TRANSACTION;
        }
    }
    if (transactionDefinition != NO_TRANSACTION) {
        return Optional.of(transactionDefinition);
    }
    return Optional.empty();
}
Also used : TransactionalAdvice(io.micronaut.transaction.annotation.TransactionalAdvice) DefaultTransactionAttribute(io.micronaut.transaction.interceptor.DefaultTransactionAttribute) NonNull(io.micronaut.core.annotation.NonNull)

Aggregations

NonNull (io.micronaut.core.annotation.NonNull)1 TransactionalAdvice (io.micronaut.transaction.annotation.TransactionalAdvice)1 DefaultTransactionAttribute (io.micronaut.transaction.interceptor.DefaultTransactionAttribute)1