private void addRollbackRuleAttributesTo(List<RollbackRuleAttribute> rollbackRules, String rollbackForValue) { String[] exceptionTypeNames = StringUtils.commaDelimitedListToStringArray(rollbackForValue); for (String typeName : exceptionTypeNames) { rollbackRules.add(new RollbackRuleAttribute(StringUtils.trimWhitespace(typeName))); } }
@Test public void foundImmediatelyWithString() { RollbackRuleAttribute rr = new RollbackRuleAttribute(java.lang.Exception.class.getName()); assertEquals(0, rr.getDepth(new Exception())); }
@Override public String toString() { StringBuilder result = getAttributeDescription(); if (this.rollbackRules != null) { for (RollbackRuleAttribute rule : this.rollbackRules) { String sign = (rule instanceof NoRollbackRuleAttribute ? PREFIX_COMMIT_RULE : PREFIX_ROLLBACK_RULE); result.append(',').append(sign).append(rule.getExceptionName()); } } return result.toString(); }
/** * 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); }
@Override public String toString() { return "No" + super.toString(); }
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); }
@Override public String toString() { return "No" + super.toString(); }
private void addRollbackRuleAttributesTo(List<RollbackRuleAttribute> rollbackRules, String rollbackForValue) { String[] exceptionTypeNames = StringUtils.commaDelimitedListToStringArray(rollbackForValue); for (String typeName : exceptionTypeNames) { rollbackRules.add(new RollbackRuleAttribute(StringUtils.trimWhitespace(typeName))); } }
@Test public void foundImmediatelyWithClass() { RollbackRuleAttribute rr = new RollbackRuleAttribute(Exception.class); assertEquals(0, rr.getDepth(new Exception())); }
/** * 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); }
@Override public String toString() { StringBuilder result = getAttributeDescription(); if (this.rollbackRules != null) { for (RollbackRuleAttribute rule : this.rollbackRules) { String sign = (rule instanceof NoRollbackRuleAttribute ? PREFIX_COMMIT_RULE : PREFIX_ROLLBACK_RULE); result.append(',').append(sign).append(rule.getExceptionName()); } } return result.toString(); }
@Override public String toString() { return "No" + super.toString(); }
@Test(expected = IllegalArgumentException.class) public void ctorArgMustBeAThrowableClassWithNonThrowableType() { new RollbackRuleAttribute(StringBuffer.class); }
@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); }
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); }
@Override public String toString() { StringBuilder result = getAttributeDescription(); if (this.rollbackRules != null) { for (RollbackRuleAttribute rule : this.rollbackRules) { String sign = (rule instanceof NoRollbackRuleAttribute ? PREFIX_COMMIT_RULE : PREFIX_ROLLBACK_RULE); result.append(',').append(sign).append(rule.getExceptionName()); } } return result.toString(); }
@Override public String toString() { return "No" + super.toString(); }
@Test(expected = IllegalArgumentException.class) public void ctorArgExceptionStringNameVersionWithNull() { new RollbackRuleAttribute((String) null); }
@Test public void ancestry() { RollbackRuleAttribute rr = new RollbackRuleAttribute(java.lang.Exception.class.getName()); // Exception -> Runtime -> NestedRuntime -> MyRuntimeException assertThat(rr.getDepth(new MyRuntimeException("")), equalTo(3)); }
int depth = rule.getDepth(ex); if (depth >= 0 && depth < deepest) { deepest = depth;