* Activate the contents of this transaction.
* @return result
*/
+ @SuppressWarnings("checkstyle:illegalcatch")
public Result activate() {
if (drivers.isEmpty()) {
throw new IllegalStateException("at least one driver required");
LOG.info("Activate transaction successful");
return Result.success();
- } catch (Exception e) {
+ } catch (Throwable e) {
//XXX add transaction identification ???
LOG.warn("Rolling back activate transaction ", e);
rollback();
* Update the contents of this transaction.
* @return result
*/
+ @SuppressWarnings("checkstyle:illegalcatch")
public Result update() {
if (drivers.isEmpty()) {
throw new IllegalStateException("at least one driver required");
LOG.info("Update transaction successful");
return Result.success();
- } catch (Exception e) {
+ } catch (Throwable e) {
//XXX add transaction identification ???
LOG.warn("Rolling back update transaction ", e);
rollback();
* Deactivate the contents of this transaction.
* @return result
*/
+ @SuppressWarnings("checkstyle:illegalcatch")
public Result deactivate() {
if (drivers.isEmpty()) {
throw new IllegalStateException("at least one driver required");
commit();
return Result.success();
- } catch (Exception e) {
+ } catch (Throwable e) {
//XXX add transaction identification ???
LOG.warn("Rolling back deactivate transaction ", e);
rollback();
drivers.sort(Comparator.comparingInt(ActivationDriver::priority));
}
- public static class Result {
+ public static final class Result {
private boolean successful;
- private Optional<String> message;
+ private final String message;
- private Optional<Throwable> cause;
+ private final Throwable cause;
- private Result(boolean successful, Optional<String> message, Optional<Throwable> cause) {
+ private Result(boolean successful, String message, Throwable cause) {
this.successful = successful;
this.message = message;
this.cause = cause;
}
public Optional<Throwable> getCause() {
- return cause;
+ return Optional.ofNullable(cause);
}
public boolean isSuccessful() {
}
public Optional<String> getMessage() {
- return message;
+ return Optional.ofNullable(message);
}
public static Result success() {
- return new Result(true, Optional.empty(), Optional.empty());
+ return new Result(true, null, null);
}
public static Result fail(String message, Throwable cause) {
- return new Result(false, Optional.of(message), Optional.of(cause));
+ return new Result(false, message, cause);
}
}