Search in sources :

Example 6 with BatchUpdateException

use of java.sql.BatchUpdateException in project jdk8u_jdk by JetBrains.

the class BatchUpdateExceptionTests method test13.

/**
     * De-Serialize a BatchUpdateException from JDBC 4.0 and make sure you can
     * read it back properly
     */
@Test
public void test13() throws Exception {
    String reason1 = "This was the error msg";
    String state1 = "user defined sqlState";
    String cause1 = "java.lang.Throwable: throw 1";
    int errorCode1 = 99999;
    Throwable t = new Throwable("throw 1");
    int[] uc1 = { 1, 2, 21 };
    long[] luc1 = { 1, 2, 21 };
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(SerializedBatchUpdateException.DATA));
    BatchUpdateException bue = (BatchUpdateException) ois.readObject();
    assertTrue(reason1.equals(bue.getMessage()) && bue.getSQLState().equals(state1) && bue.getErrorCode() == errorCode1 && cause1.equals(bue.getCause().toString()) && Arrays.equals(bue.getLargeUpdateCounts(), luc1) && Arrays.equals(bue.getUpdateCounts(), uc1));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream) BatchUpdateException(java.sql.BatchUpdateException) SerializedBatchUpdateException(util.SerializedBatchUpdateException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 7 with BatchUpdateException

use of java.sql.BatchUpdateException in project jdk8u_jdk by JetBrains.

the class BatchUpdateExceptionTests method test14.

/**
     * Serialize a BatchUpdateException with an Integer.MAX_VALUE + 1 and
     * validate you can read it back properly
     */
@Test
public void test14() throws Exception {
    int[] uc1 = { Integer.MAX_VALUE, Integer.MAX_VALUE + 1 };
    long[] luc1 = { Integer.MAX_VALUE, Integer.MAX_VALUE + 1 };
    BatchUpdateException be = new BatchUpdateException(reason, state, errorCode, luc1, t);
    BatchUpdateException bue = createSerializedException(be);
    assertTrue(reason.equals(bue.getMessage()) && bue.getSQLState().equals(state) && cause.equals(bue.getCause().toString()) && bue.getErrorCode() == errorCode && Arrays.equals(bue.getLargeUpdateCounts(), luc1) && Arrays.equals(bue.getUpdateCounts(), uc1));
}
Also used : BatchUpdateException(java.sql.BatchUpdateException) SerializedBatchUpdateException(util.SerializedBatchUpdateException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 8 with BatchUpdateException

use of java.sql.BatchUpdateException in project jdk8u_jdk by JetBrains.

the class BatchUpdateExceptionTests method test6.

/**
     * Create BatchUpdateException with message, Throwable, and update counts
     */
@Test
public void test6() {
    BatchUpdateException ex = new BatchUpdateException(reason, uc, t);
    assertTrue(ex.getMessage().equals(reason) && ex.getSQLState() == null && cause.equals(ex.getCause().toString()) && ex.getErrorCode() == 0 && Arrays.equals(ex.getUpdateCounts(), uc) && Arrays.equals(ex.getLargeUpdateCounts(), luc));
}
Also used : BatchUpdateException(java.sql.BatchUpdateException) SerializedBatchUpdateException(util.SerializedBatchUpdateException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 9 with BatchUpdateException

use of java.sql.BatchUpdateException in project jdk8u_jdk by JetBrains.

the class BatchUpdateExceptionTests method test8.

/**
     * Create BatchUpdateException with message, SQLState, errorCode code
     * Throwable, and update counts
     */
@Test
public void test8() {
    BatchUpdateException ex = new BatchUpdateException(reason, state, errorCode, uc, t);
    assertTrue(ex.getMessage().equals(reason) && ex.getSQLState().equals(state) && cause.equals(ex.getCause().toString()) && ex.getErrorCode() == errorCode && Arrays.equals(ex.getUpdateCounts(), uc) && Arrays.equals(ex.getLargeUpdateCounts(), luc));
}
Also used : BatchUpdateException(java.sql.BatchUpdateException) SerializedBatchUpdateException(util.SerializedBatchUpdateException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 10 with BatchUpdateException

use of java.sql.BatchUpdateException in project jdk8u_jdk by JetBrains.

the class BatchUpdateExceptionTests method test16.

/**
     * Validate that the ordering of the returned Exceptions is correct
     * using traditional while loop
     */
@Test
public void test16() {
    BatchUpdateException ex = new BatchUpdateException("Exception 1", uc, t1);
    BatchUpdateException ex1 = new BatchUpdateException("Exception 2", uc);
    BatchUpdateException ex2 = new BatchUpdateException("Exception 3", uc, t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    SQLException sqe = ex;
    int num = 0;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
Also used : SQLException(java.sql.SQLException) BatchUpdateException(java.sql.BatchUpdateException) SerializedBatchUpdateException(util.SerializedBatchUpdateException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Aggregations

BatchUpdateException (java.sql.BatchUpdateException)103 SQLException (java.sql.SQLException)39 PreparedStatement (java.sql.PreparedStatement)33 Statement (java.sql.Statement)22 ArrayList (java.util.ArrayList)19 Test (org.junit.Test)19 Connection (java.sql.Connection)17 Test (org.testng.annotations.Test)17 BaseTest (util.BaseTest)17 SerializedBatchUpdateException (util.SerializedBatchUpdateException)17 ResultSet (java.sql.ResultSet)13 List (java.util.List)12 CallableStatement (java.sql.CallableStatement)8 HashSet (java.util.HashSet)8 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)7 HashMap (java.util.HashMap)6 Map (java.util.Map)5 CustomChangeException (liquibase.exception.CustomChangeException)5 DatabaseException (liquibase.exception.DatabaseException)5 SetupException (liquibase.exception.SetupException)5