use of org.apache.openejb.core.transaction.JtaTransactionPolicyFactory in project tomee by apache.
the class Assembler method createTransactionPolicyFactory.
private TransactionPolicyFactory createTransactionPolicyFactory(final EjbJarInfo ejbJar, final ClassLoader classLoader) {
TransactionPolicyFactory factory = null;
final Object value = ejbJar.properties.get(TransactionPolicyFactory.class.getName());
if (value instanceof TransactionPolicyFactory) {
factory = (TransactionPolicyFactory) value;
} else if (value instanceof String) {
try {
final String[] parts = ((String) value).split(":", 2);
final ResourceFinder finder = new ResourceFinder("META-INF", classLoader);
final Map<String, Class<? extends TransactionPolicyFactory>> plugins = finder.mapAvailableImplementations(TransactionPolicyFactory.class);
final Class<? extends TransactionPolicyFactory> clazz = plugins.get(parts[0]);
if (clazz != null) {
if (parts.length == 1) {
factory = clazz.getConstructor(String.class).newInstance(parts[1]);
} else {
factory = clazz.newInstance();
}
}
} catch (final Exception ignored) {
// couldn't determine the plugins, which isn't fatal
}
}
if (factory == null) {
factory = new JtaTransactionPolicyFactory(transactionManager);
}
return factory;
}
use of org.apache.openejb.core.transaction.JtaTransactionPolicyFactory in project tomee by apache.
the class TransactionRule method apply.
@Override
public Statement apply(final Statement base, final Description description) {
final Method mtd = getMethod(description.getTestClass(), description.getMethodName());
final Transaction tx = mtd.getAnnotation(Transaction.class);
if (tx != null) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
final TransactionManager transactionManager = SystemInstance.get().getComponent(TransactionManager.class);
final JtaTransactionPolicyFactory factory = new JtaTransactionPolicyFactory(transactionManager);
final TransactionPolicy policy = factory.createTransactionPolicy(TransactionType.RequiresNew);
try {
base.evaluate();
} finally {
if (tx.rollback()) {
policy.setRollbackOnly();
}
policy.commit();
}
}
};
} else {
return new Statement() {
@Override
public void evaluate() throws Throwable {
base.evaluate();
}
};
}
}
Aggregations