com.jaregu.database.queries.ext.dalesbred.TransactionalMethodInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of queries Show documentation
Show all versions of queries Show documentation
Java based SQL templating project. Store your queries in *.sql files and build queries for execution. Supports simple expressions and conditional clauses and interface proxying for java-sql bridge.
package com.jaregu.database.queries.ext.dalesbred;
import java.lang.reflect.Method;
import javax.inject.Provider;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.dalesbred.Database;
import org.dalesbred.transaction.TransactionCallback;
import org.dalesbred.transaction.TransactionContext;
import org.dalesbred.transaction.TransactionSettings;
public final class TransactionalMethodInterceptor implements MethodInterceptor {
private final Provider databaseProvider;
public TransactionalMethodInterceptor(Provider databaseProvider) {
this.databaseProvider = databaseProvider;
}
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable {
try {
TransactionSettings settings = getTransactionSettings(invocation);
return databaseProvider.get().withTransaction(settings, new TransactionCallback