/** * Return the depth of the superclass matching. * <p>{@code 0} means {@code ex} matches exactly. Returns * {@code -1} if there is no match. Otherwise, returns depth with the * lowest depth winning. */ public int getDepth(Throwable ex) { return getDepth(ex.getClass(), 0); }
private int getDepth(Class<?> exceptionClass, int depth) { if (exceptionClass.getName().contains(this.exceptionName)) { // Found it! return depth; } // If we've gone as far as we can go and haven't found it... if (exceptionClass == Throwable.class) { return -1; } return getDepth(exceptionClass.getSuperclass(), depth + 1); }
/** * Return the depth of the superclass matching. * <p>{@code 0} means {@code ex} matches exactly. Returns * {@code -1} if there is no match. Otherwise, returns depth with the * lowest depth winning. */ public int getDepth(Throwable ex) { return getDepth(ex.getClass(), 0); }
private int getDepth(Class<?> exceptionClass, int depth) { if (exceptionClass.getName().contains(this.exceptionName)) { // Found it! return depth; } // If we've gone as far as we can go and haven't found it... if (exceptionClass == Throwable.class) { return -1; } return getDepth(exceptionClass.getSuperclass(), depth + 1); }
int depth = rule.getDepth(ex); if (depth >= 0 && depth < deepest) { deepest = depth;
int depth = rule.getDepth(ex); if (depth >= 0 && depth < deepest) { deepest = depth;
@Test public void alwaysTrueForThrowable() { RollbackRuleAttribute rr = new RollbackRuleAttribute(java.lang.Throwable.class.getName()); assertTrue(rr.getDepth(new MyRuntimeException("")) > 0); assertTrue(rr.getDepth(new IOException()) > 0); assertTrue(rr.getDepth(new FatalBeanException(null,null)) > 0); assertTrue(rr.getDepth(new RuntimeException()) > 0); }
@Test public void foundImmediatelyWithString() { RollbackRuleAttribute rr = new RollbackRuleAttribute(java.lang.Exception.class.getName()); assertEquals(0, rr.getDepth(new Exception())); }
@Test public void foundImmediatelyWithClass() { RollbackRuleAttribute rr = new RollbackRuleAttribute(Exception.class); assertEquals(0, rr.getDepth(new Exception())); }
@Test public void ancestry() { RollbackRuleAttribute rr = new RollbackRuleAttribute(java.lang.Exception.class.getName()); // Exception -> Runtime -> NestedRuntime -> MyRuntimeException assertThat(rr.getDepth(new MyRuntimeException("")), equalTo(3)); }
@Test public void notFound() { RollbackRuleAttribute rr = new RollbackRuleAttribute(java.io.IOException.class.getName()); assertEquals(-1, rr.getDepth(new MyRuntimeException(""))); }
/** * Return the depth of the superclass matching. * <p>{@code 0} means {@code ex} matches exactly. Returns * {@code -1} if there is no match. Otherwise, returns depth with the * lowest depth winning. */ public int getDepth(Throwable ex) { return getDepth(ex.getClass(), 0); }
/** * Return the depth of the superclass matching. * <p>{@code 0} means {@code ex} matches exactly. Returns * {@code -1} if there is no match. Otherwise, returns depth with the * lowest depth winning. */ public int getDepth(Throwable ex) { return getDepth(ex.getClass(), 0); }
/** * Return the depth to the superclass matching. * 0 means ex matches exactly. Returns -1 if there's no match. * Otherwise, returns depth. Lowest depth wins. */ public int getDepth(Throwable ex) { return getDepth(ex.getClass(), 0); }
private int getDepth(Class<?> exceptionClass, int depth) { if (exceptionClass.getName().contains(this.exceptionName)) { // Found it! return depth; } // If we've gone as far as we can go and haven't found it... if (exceptionClass == Throwable.class) { return -1; } return getDepth(exceptionClass.getSuperclass(), depth + 1); }
private int getDepth(Class<?> exceptionClass, int depth) { if (exceptionClass.getName().contains(this.exceptionName)) { // Found it! return depth; } // If we've gone as far as we can go and haven't found it... if (exceptionClass == Throwable.class) { return -1; } return getDepth(exceptionClass.getSuperclass(), depth + 1); }
private int getDepth(Class exceptionClass, int depth) { if (exceptionClass.getName().indexOf(this.exceptionName) != -1) { // Found it! return depth; } // If we've gone as far as we can go and haven't found it... if (exceptionClass.equals(Throwable.class)) { return -1; } return getDepth(exceptionClass.getSuperclass(), depth + 1); }
@Override public boolean rollbackOn(Throwable ex) { if (log.isTraceEnabled()) { log.trace("Applying rules to determine whether transaction should rollback on $ex"); } RollbackRuleAttribute winner = null; int deepest = Integer.MAX_VALUE; List<RollbackRuleAttribute> rollbackRules = getRollbackRules(); if (rollbackRules != null) { for (RollbackRuleAttribute rule : rollbackRules) { int depth = rule.getDepth(ex); if (depth >= 0 && depth < deepest) { deepest = depth; winner = rule; } } } if (log.isTraceEnabled()) { log.trace("Winning rollback rule is: $winner" ); } // User superclass behavior (rollback on unchecked) if no rule matches. if (winner == null) { log.trace("No relevant rollback rule found: applying default rules"); // always rollback regardless if it is a checked or unchecked exception since Groovy doesn't differentiate those return true; } return !(winner instanceof NoRollbackRuleAttribute); } public boolean isInheritRollbackOnly() {
int depth = rule.getDepth(ex); if (depth >= 0 && depth < deepest) { deepest = depth;
int depth = rule.getDepth(ex); if (depth >= 0 && depth < deepest) { deepest = depth;