Java Code Examples for java.sql.SQLIntegrityConstraintViolationException

The following examples show how to use java.sql.SQLIntegrityConstraintViolationException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException("Exception 1", t1);
    SQLIntegrityConstraintViolationException ex1 =
            new SQLIntegrityConstraintViolationException("Exception 2");
    SQLIntegrityConstraintViolationException ex2 =
            new SQLIntegrityConstraintViolationException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    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();
    }
}
 
Example 2
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException("Exception 1", t1);
    SQLIntegrityConstraintViolationException ex1 =
            new SQLIntegrityConstraintViolationException("Exception 2");
    SQLIntegrityConstraintViolationException ex2 =
            new SQLIntegrityConstraintViolationException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    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();
    }
}
 
Example 3
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException("Exception 1", t1);
    SQLIntegrityConstraintViolationException ex1 =
            new SQLIntegrityConstraintViolationException("Exception 2");
    SQLIntegrityConstraintViolationException ex2 =
            new SQLIntegrityConstraintViolationException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    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();
    }
}
 
Example 4
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using for-each loop
 */
@Test
public void test11() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException("Exception 1", t1);
    SQLIntegrityConstraintViolationException ex1 =
            new SQLIntegrityConstraintViolationException("Exception 2");
    SQLIntegrityConstraintViolationException ex2 =
            new SQLIntegrityConstraintViolationException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    for (Throwable e : ex) {
        assertTrue(msgs[num++].equals(e.getMessage()));
    }
}
 
Example 5
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException("Exception 1", t1);
    SQLIntegrityConstraintViolationException ex1 =
            new SQLIntegrityConstraintViolationException("Exception 2");
    SQLIntegrityConstraintViolationException ex2 =
            new SQLIntegrityConstraintViolationException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    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();
    }
}
 
Example 6
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using for-each loop
 */
@Test
public void test11() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException("Exception 1", t1);
    SQLIntegrityConstraintViolationException ex1 =
            new SQLIntegrityConstraintViolationException("Exception 2");
    SQLIntegrityConstraintViolationException ex2 =
            new SQLIntegrityConstraintViolationException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    for (Throwable e : ex) {
        assertTrue(msgs[num++].equals(e.getMessage()));
    }
}
 
Example 7
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException("Exception 1", t1);
    SQLIntegrityConstraintViolationException ex1 =
            new SQLIntegrityConstraintViolationException("Exception 2");
    SQLIntegrityConstraintViolationException ex2 =
            new SQLIntegrityConstraintViolationException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    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();
    }
}
 
Example 8
Source Project: estatio   Source File: DocFragmentRepository_IntegTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void whenAlreadyExists() throws Exception {

    // given
    FixtureScript fs = new DocFragment_tearDown();
    fixtureScripts.runFixtureScript(fs, null);
    transactionService.nextTransaction();

    final DocFragmentData random = fakeDataService.enums().anyOf(DocFragmentData.class);
    random.createWith(repository);
    transactionService.nextTransaction();

    // then
    expectedExceptions.expectCause(causedBy(SQLIntegrityConstraintViolationException.class));

    // when
    random.createWith(repository);
    transactionService.nextTransaction();
}
 
Example 9
Source Project: sqoop-on-spark   Source File: TestRepositoryUpgrade.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = SQLIntegrityConstraintViolationException.class)
public void testUpgradeVersion4WithNonUniqueConfigNameAndTypeAdded() throws Exception {
  super.createOrUpgradeSchema(4);
  super.addConnectorB();
  // try loading duplicate config names in version 4 and it should throw an
  // exception
  super.loadNonUniqueConfigNameTypeInVersion4();
}
 
Example 10
/**
 * Create SQLIntegrityConstraintViolationException and setting all objects to null
 */
@Test
public void test() {
    SQLIntegrityConstraintViolationException e =
            new SQLIntegrityConstraintViolationException(null,
            null, errorCode, null);
    assertTrue(e.getMessage() == null && e.getSQLState() == null
            && e.getCause() == null && e.getErrorCode() == errorCode);
}
 
Example 11
/**
 * Create SQLIntegrityConstraintViolationException with no-arg constructor
 */
@Test
public void test1() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException();
    assertTrue(ex.getMessage() == null
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example 12
/**
 * Create SQLIntegrityConstraintViolationException with no-arg constructor
 */
@Test
public void test1() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException();
    assertTrue(ex.getMessage() == null
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example 13
Source Project: mdw   Source File: EngineDataAccessDB.java    License: Apache License 2.0 5 votes vote down vote up
public void setActivityCompletionTime(ActivityInstance ai) throws SQLException {
    Long elapsedTime = getActivityElapsedTime0(ai.getId());
    try {
        setElapsedTime0(OwnerType.ACTIVITY_INSTANCE, ai.getId(), elapsedTime);
    } catch (SQLIntegrityConstraintViolationException ex) {
        // activity timing captured previously
    }
}
 
Example 14
/**
 * Create SQLIntegrityConstraintViolationException with message, and SQLState
 */
@Test
public void test3() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException(reason, state);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example 15
/**
 * Create SQLIntegrityConstraintViolationException with message, SQLState, and error code
 */
@Test
public void test4() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException(reason, state, errorCode);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == errorCode);
}
 
Example 16
/**
 * Create SQLIntegrityConstraintViolationException and setting all objects to null
 */
@Test
public void test() {
    SQLIntegrityConstraintViolationException e =
            new SQLIntegrityConstraintViolationException(null,
            null, errorCode, null);
    assertTrue(e.getMessage() == null && e.getSQLState() == null
            && e.getCause() == null && e.getErrorCode() == errorCode);
}
 
Example 17
/**
 * Create SQLIntegrityConstraintViolationException with message, and Throwable
 */
@Test
public void test7() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException(reason, t);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState() == null
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == 0);
}
 
Example 18
/**
 * Create SQLIntegrityConstraintViolationException with null Throwable
 */
@Test
public void test8() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException((Throwable)null);
    assertTrue(ex.getMessage() == null
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example 19
/**
 * Create SQLIntegrityConstraintViolationException with message, SQLState, and error code
 */
@Test
public void test4() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException(reason, state, errorCode);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == errorCode);
}
 
Example 20
/**
 * Create SQLIntegrityConstraintViolationException with message
 */
@Test
public void test2() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException(reason);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example 21
/**
 * Serialize a SQLIntegrityConstraintViolationException and make sure
 * you can read it back properly
 */
@Test
public void test10() throws Exception {
    SQLIntegrityConstraintViolationException e =
            new SQLIntegrityConstraintViolationException(reason, state, errorCode, t);
    SQLIntegrityConstraintViolationException ex1 =
            createSerializedException(e);
    assertTrue(reason.equals(ex1.getMessage())
            && ex1.getSQLState().equals(state)
            && cause.equals(ex1.getCause().toString())
            && ex1.getErrorCode() == errorCode);
}
 
Example 22
/**
 * Create SQLIntegrityConstraintViolationException with no-arg constructor
 */
@Test
public void test1() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException();
    assertTrue(ex.getMessage() == null
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example 23
/**
 * Create SQLIntegrityConstraintViolationException with message, SQLState, and Throwable
 */
@Test
public void test6() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException(reason, state, t);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == 0);
}
 
Example 24
/**
 * Create SQLIntegrityConstraintViolationException with message, and Throwable
 */
@Test
public void test7() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException(reason, t);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState() == null
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == 0);
}
 
Example 25
/**
 * Create SQLIntegrityConstraintViolationException with Throwable
 */
@Test
public void test9() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException(t);
    assertTrue(ex.getMessage().equals(cause)
            && ex.getSQLState() == null
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == 0);
}
 
Example 26
/**
 * Serialize a SQLIntegrityConstraintViolationException and make sure
 * you can read it back properly
 */
@Test
public void test10() throws Exception {
    SQLIntegrityConstraintViolationException e =
            new SQLIntegrityConstraintViolationException(reason, state, errorCode, t);
    SQLIntegrityConstraintViolationException ex1 =
            createSerializedException(e);
    assertTrue(reason.equals(ex1.getMessage())
            && ex1.getSQLState().equals(state)
            && cause.equals(ex1.getCause().toString())
            && ex1.getErrorCode() == errorCode);
}
 
Example 27
/**
 * Create SQLIntegrityConstraintViolationException with message, SQLState, errorCode, and Throwable
 */
@Test
public void test5() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException(reason, state, errorCode, t);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == errorCode);
}
 
Example 28
/**
 * Create SQLIntegrityConstraintViolationException with no-arg constructor
 */
@Test
public void test1() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException();
    assertTrue(ex.getMessage() == null
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example 29
/**
 * Create SQLIntegrityConstraintViolationException with message
 */
@Test
public void test2() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException(reason);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example 30
/**
 * Create SQLIntegrityConstraintViolationException with message, and SQLState
 */
@Test
public void test3() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException(reason, state);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}