org.cloudfoundry.multiapps.controller.persistence.TransactionalExecutor Maven / Gradle / Ivy
package org.cloudfoundry.multiapps.controller.persistence;
import java.util.function.Function;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
public class TransactionalExecutor extends Executor {
public TransactionalExecutor(EntityManager manager) {
super(manager);
}
@Override
public T execute(Function function) {
T result = null;
try {
EntityTransaction transaction = manager.getTransaction();
transaction.begin();
result = function.apply(manager);
transaction.commit();
} finally {
cleanUp();
}
return result;
}
}