Replace relevant code with lambda

See gh-1454
This commit is contained in:
diguage
2017-06-08 00:07:34 +08:00
committed by Stephane Nicoll
parent 738160538e
commit 4b1478d830
52 changed files with 522 additions and 845 deletions

View File

@@ -222,17 +222,13 @@ public class CciTemplate implements CciOperations {
@Override
public <T> T execute(final InteractionCallback<T> action) throws DataAccessException {
Assert.notNull(action, "Callback object must not be null");
return execute(new ConnectionCallback<T>() {
@Override
public T doInConnection(Connection connection, ConnectionFactory connectionFactory)
throws ResourceException, SQLException, DataAccessException {
Interaction interaction = connection.createInteraction();
try {
return action.doInInteraction(interaction, connectionFactory);
}
finally {
closeInteraction(interaction);
}
return execute((ConnectionCallback<T>) (connection, connectionFactory) -> {
Interaction interaction = connection.createInteraction();
try {
return action.doInInteraction(interaction, connectionFactory);
}
finally {
closeInteraction(interaction);
}
});
}

View File

@@ -59,12 +59,7 @@ public class ResourceAdapterApplicationContext extends GenericApplicationContext
beanFactory.registerResolvableDependency(BootstrapContext.class, this.bootstrapContext);
// JCA WorkManager resolved lazily - may not be available.
beanFactory.registerResolvableDependency(WorkManager.class, new ObjectFactory<WorkManager>() {
@Override
public WorkManager getObject() {
return bootstrapContext.getWorkManager();
}
});
beanFactory.registerResolvableDependency(WorkManager.class, (ObjectFactory<WorkManager>) bootstrapContext::getWorkManager);
}
}

View File

@@ -303,34 +303,26 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
else {
// It's a CallbackPreferringPlatformTransactionManager: pass a TransactionCallback in.
try {
Object result = ((CallbackPreferringPlatformTransactionManager) tm).execute(txAttr,
new TransactionCallback<Object>() {
@Override
public Object doInTransaction(TransactionStatus status) {
TransactionInfo txInfo = prepareTransactionInfo(tm, txAttr, joinpointIdentification, status);
try {
return invocation.proceedWithInvocation();
}
catch (Throwable ex) {
if (txAttr.rollbackOn(ex)) {
// A RuntimeException: will lead to a rollback.
if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
}
else {
throw new ThrowableHolderException(ex);
}
}
else {
// A normal return value: will lead to a commit.
return new ThrowableHolder(ex);
}
}
finally {
cleanupTransactionInfo(txInfo);
}
Object result = ((CallbackPreferringPlatformTransactionManager) tm).execute(txAttr, status -> {
TransactionInfo txInfo = prepareTransactionInfo(tm, txAttr, joinpointIdentification, status);
try {
return invocation.proceedWithInvocation();
} catch (Throwable ex) {
if (txAttr.rollbackOn(ex)) {
// A RuntimeException: will lead to a rollback.
if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
} else {
throw new ThrowableHolderException(ex);
}
});
} else {
// A normal return value: will lead to a commit.
return new ThrowableHolder(ex);
}
} finally {
cleanupTransactionInfo(txInfo);
}
});
// Check result: It might indicate a Throwable to rethrow.
if (result instanceof ThrowableHolder) {