SQLExceptionFactory extends AbstractExceptionFactory<SQLException> { @Override public boolean equals(SQLException exception1, SQLException exception2) { if ((exception1 == null) || (exception2 == null)) { return exception1 == exception2; } if (!exception1.getClass().equals(exception2.getClass())) { return false; } if ((exception1 instanceof BatchUpdateException) && (exception2 instanceof BatchUpdateException)) { BatchUpdateException e1 = (BatchUpdateException) exception1; BatchUpdateException e2 = (BatchUpdateException) exception2; int[] counts1 = e1.getUpdateCounts(); int[] counts2 = e2.getUpdateCounts(); if ((counts1 != null) && (counts2 != null) ? !Arrays.equals(counts1, counts2) : (counts1 != counts2)) { return false; } } else if ((exception1 instanceof SQLClientInfoException) && (exception2 instanceof SQLClientInfoException)) { SQLClientInfoException e1 = (SQLClientInfoException) exception1; SQLClientInfoException e2 = (SQLClientInfoException) exception2; Map<String, ClientInfoStatus> map1 = e1.getFailedProperties(); Map<String, ClientInfoStatus> map2 = e2.getFailedProperties(); return (map1 != null) && (map2 != null) ? map1.equals(map2) : (map1 != map2); } else if ((exception1 instanceof DataTruncation) && (exception2 instanceof DataTruncation)) { DataTruncation e1 = (DataTruncation) exception1; DataTruncation e2 = (DataTruncation) exception2; return (e1.getDataSize() == e2.getDataSize()) && (e1.getIndex() == e2.getIndex()) && (e1.getParameter() == e2.getParameter()) && (e1.getRead() == e2.getRead()) && (e1.getTransferSize() == e2.getTransferSize()); } SQLException nextException1 = exception1.getNextException(); SQLException nextException2 = exception2.getNextException(); int code1 = exception1.getErrorCode(); int code2 = exception2.getErrorCode(); if ((code1 != 0) || (code2 != 0)) { return (code1 == code2) ? this.equals(nextException1, nextException2) : false; } String state1 = exception1.getSQLState(); String state2 = exception2.getSQLState(); boolean hasState1 = (state1 != null); boolean hasState2 = (state2 != null); if (hasState1 || hasState2) { return (state1 == state2) || (hasState1 && hasState2 && state1.equals(state2)) ? this.equals(nextException1, nextException2) : false; } String reason1 = exception1.getMessage(); String reason2 = exception2.getMessage(); return ((reason1 == reason2) || ((reason1 != null) && (reason2 != null) && reason1.equals(reason2))) ? this.equals(nextException1, nextException2) : false; } SQLExceptionFactory(); @Override SQLException createException(String message); @Override boolean equals(SQLException exception1, SQLException exception2); @Override boolean indicatesFailure(SQLException exception, Dialect dialect); @Override ExceptionType getType();  }
@Test public void equals() { assertTrue(this.factory.equals(null, null)); assertFalse(this.factory.equals(new SQLException(), null)); assertTrue(this.factory.equals(new SQLException(), new SQLException())); assertTrue(this.factory.equals(new java.sql.SQLDataException(), new java.sql.SQLDataException())); assertFalse(this.factory.equals(new java.sql.SQLClientInfoException(), new java.sql.SQLDataException())); assertTrue(this.factory.equals(new java.sql.BatchUpdateException(new int[] { 1, 2 }), new java.sql.BatchUpdateException(new int[] { 1, 2 }))); assertFalse(this.factory.equals(new java.sql.BatchUpdateException(new int[] { 1, 2 }), new java.sql.BatchUpdateException(new int[] { 1, 3 }))); assertTrue(this.factory.equals(new java.sql.DataTruncation(1, true, true, 1, 1), new java.sql.DataTruncation(1, true, true, 1, 1))); assertFalse(this.factory.equals(new java.sql.DataTruncation(1, true, true, 1, 1), new java.sql.DataTruncation(2, true, true, 1, 1))); assertFalse(this.factory.equals(new java.sql.DataTruncation(1, true, true, 1, 1), new java.sql.DataTruncation(1, false, true, 1, 1))); assertFalse(this.factory.equals(new java.sql.DataTruncation(1, true, true, 1, 1), new java.sql.DataTruncation(1, true, false, 1, 1))); assertFalse(this.factory.equals(new java.sql.DataTruncation(1, true, true, 1, 1), new java.sql.DataTruncation(1, true, true, 2, 1))); assertFalse(this.factory.equals(new java.sql.DataTruncation(1, true, true, 1, 1), new java.sql.DataTruncation(1, true, true, 1, 2))); assertTrue(this.factory.equals(new java.sql.SQLClientInfoException(Collections.singletonMap("test", ClientInfoStatus.REASON_UNKNOWN)), new java.sql.SQLClientInfoException(Collections.singletonMap("test", ClientInfoStatus.REASON_UNKNOWN)))); assertFalse(this.factory.equals(new java.sql.SQLClientInfoException(Collections.singletonMap("test", ClientInfoStatus.REASON_UNKNOWN)), new java.sql.SQLClientInfoException(Collections.singletonMap("test", ClientInfoStatus.REASON_UNKNOWN_PROPERTY)))); assertTrue(this.factory.equals(new SQLException("reason1", "sql.state1", 1), new SQLException("reason2", "sql.state2", 1))); assertFalse(this.factory.equals(new SQLException("reason", "sql.state", 1), new SQLException("reason", "sql.state", 2))); assertFalse(this.factory.equals(new SQLException("reason", "sql.state", 1), new SQLException("reason", "sql.state", 0))); assertTrue(this.factory.equals(new SQLException("reason1", "sql.state", 0), new SQLException("reason2", "sql.state", 0))); assertFalse(this.factory.equals(new SQLException("reason", "sql.state1", 0), new SQLException("reason", "sql.state2", 0))); assertFalse(this.factory.equals(new SQLException("reason", "sql.state1", 0), new SQLException("reason", null, 0))); assertTrue(this.factory.equals(new SQLException("reason", null, 0), new SQLException("reason", null, 0))); assertFalse(this.factory.equals(new SQLException("reason1", null, 0), new SQLException("reason2", null, 0))); SQLException exception1 = new SQLException(); SQLException exception2 = new SQLException(); exception1.setNextException(new SQLException()); exception2.setNextException(new SQLException()); assertTrue(this.factory.equals(exception1, exception2)); exception1.setNextException(new SQLException("reason1")); exception2.setNextException(new SQLException("reason2")); assertFalse(this.factory.equals(exception1, exception2)); }