java.sql.SQLIntegrityConstraintViolationException Java Examples

The following examples show how to use java.sql.SQLIntegrityConstraintViolationException. 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
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #6
Source File: DocFragmentRepository_IntegTest.java    From estatio with 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 #7
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 File: SQLIntegrityConstraintViolationExceptionTests.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #9
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #10
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #11
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #12
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #13
Source File: UseCase1Client.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private int insertChnHistStmt(PreparedStatement ps)
throws SQLException {
  long stmt_start = this.useCase1stats.startStmt(Stmt.insertChnHist);
  int rows = 0;
  try {
    rows = INSERT_CHN_HIST_PS.executeUpdate();
    this.useCase1stats.endStmt(Stmt.insertChnHist, stmt_start);
  } catch (SQLIntegrityConstraintViolationException e) {
    this.useCase1stats.endStmt(Stmt.insertChnHistConstraintViolation, stmt_start);
  }
  return rows;
}
 
Example #14
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #15
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #17
Source File: SQLExceptionSubclassTranslator.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected DataAccessException doTranslate(String task, String sql, SQLException ex) {
	if (ex instanceof SQLTransientException) {
		if (ex instanceof SQLTransientConnectionException) {
			return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLTransactionRollbackException) {
			return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLTimeoutException) {
			return new QueryTimeoutException(buildMessage(task, sql, ex), ex);
		}
	}
	else if (ex instanceof SQLNonTransientException) {
		if (ex instanceof SQLNonTransientConnectionException) {
			return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLDataException) {
			return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLIntegrityConstraintViolationException) {
			return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLInvalidAuthorizationSpecException) {
			return new PermissionDeniedDataAccessException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLSyntaxErrorException) {
			return new BadSqlGrammarException(task, sql, ex);
		}
		else if (ex instanceof SQLFeatureNotSupportedException) {
			return new InvalidDataAccessApiUsageException(buildMessage(task, sql, ex), ex);
		}
	}
	else if (ex instanceof SQLRecoverableException) {
		return new RecoverableDataAccessException(buildMessage(task, sql, ex), ex);
	}

	// Fallback to Spring's own SQL state translation...
	return null;
}
 
Example #18
Source File: TransactionTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testBug41168() throws Exception {
  Connection conn = TestUtil.getConnection();
  Statement stmt = conn.createStatement();

  conn.setTransactionIsolation(getIsolationLevel());

  // Create the table with self-reference FKs
  stmt.execute("create table BinaryTree (id int primary key, "
      + "leftId int, rightId int, depth int not null,"
      + " foreign key (leftId) references BinaryTree(id),"
      + " foreign key (rightId) references BinaryTree(id)) replicate"+getSuffix());

  addExpectedException(SQLIntegrityConstraintViolationException.class);
  doBinaryTreeChecks(conn, true);
  removeExpectedException(SQLIntegrityConstraintViolationException.class);

  // now do the same for partitioned table
  stmt.execute("drop table BinaryTree");
  this.waitTillAllClear();
  stmt.execute("create table BinaryTree (id int primary key, "
      + "leftId int, rightId int, depth int not null,"
      + " foreign key (leftId) references BinaryTree(id),"
      + " foreign key (rightId) references BinaryTree(id))"+getSuffix());

  addExpectedException(SQLIntegrityConstraintViolationException.class);
  doBinaryTreeChecks(conn, true);
  removeExpectedException(SQLIntegrityConstraintViolationException.class);
}
 
Example #19
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #20
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #21
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #22
Source File: TestJDBC40Exception.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
public void testIntegrityConstraintViolationException()
        throws SQLException {
    try {
        createStatement().execute(
            "insert into EXCEPTION_TABLE1 (id, data) values (1, 'data1')");
        fail("Statement didn't fail.");
    } catch (SQLIntegrityConstraintViolationException e) {
        assertTrue("Unexpected SQL State: " + e.getSQLState(),
                   e.getSQLState().startsWith("23"));
    }
}
 
Example #23
Source File: DerbyDbDialect.java    From copper-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void insert(List<Workflow<?>> wfs, Connection con) throws DuplicateIdException, Exception {
    try {
        super.insert(wfs, con);
    } catch (SQLException e) {
        if (e instanceof SQLIntegrityConstraintViolationException || (e.getCause() != null && e.getCause() instanceof SQLIntegrityConstraintViolationException)) {
            throw new DuplicateIdException(e);
        }
        throw e;
    }
}
 
Example #24
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #25
Source File: TransactionBugsReportedDUnit.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Test foreign key constraint with null values for FK field under
 * transactions.
 * 
 * @throws Exception
 */
public void testBug41168() throws Exception {

  // Start two clients and three servers
  startVMs(2, 3);

  // Create the table with self-reference FKs
  clientSQLExecute(1, "create table BinaryTree (id int primary key, "
      + "leftId int, rightId int, depth int not null,"
      + " foreign key (leftId) references BinaryTree(id),"
      + " foreign key (rightId) references BinaryTree(id)) replicate");

  Connection conn = TestUtil.getConnection();
  conn.setTransactionIsolation(getIsolationLevel());
  conn.setAutoCommit(false);

  addExpectedException(new int[] { 1, 2 }, new int[] { 1, 2, 3 },
      SQLIntegrityConstraintViolationException.class);
  TransactionTest.doBinaryTreeChecks(conn, true);
  removeExpectedException(new int[] { 1, 2 }, new int[] { 1, 2, 3 },
      SQLIntegrityConstraintViolationException.class);

  // now do the same for partitioned table
  serverSQLExecute(2, "drop table BinaryTree");
  clientSQLExecute(1, "create table BinaryTree (id int primary key, "
      + "leftId int, rightId int, depth int not null,"
      + " foreign key (leftId) references BinaryTree(id),"
      + " foreign key (rightId) references BinaryTree(id))");

  addExpectedException(new int[] { 1, 2 }, new int[] { 1, 2, 3 },
      SQLIntegrityConstraintViolationException.class);
  TransactionTest.doBinaryTreeChecks(conn, false);
  removeExpectedException(new int[] { 1, 2 }, new int[] { 1, 2, 3 },
      SQLIntegrityConstraintViolationException.class);
}
 
Example #26
Source File: TransactionTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testBug41168() throws Exception {
  Connection conn = TestUtil.getConnection();
  Statement stmt = conn.createStatement();

  conn.setTransactionIsolation(getIsolationLevel());

  // Create the table with self-reference FKs
  stmt.execute("create table BinaryTree (id int primary key, "
      + "leftId int, rightId int, depth int not null,"
      + " foreign key (leftId) references BinaryTree(id),"
      + " foreign key (rightId) references BinaryTree(id)) replicate"+getSuffix());

  addExpectedException(SQLIntegrityConstraintViolationException.class);
  doBinaryTreeChecks(conn, true);
  removeExpectedException(SQLIntegrityConstraintViolationException.class);

  // now do the same for partitioned table
  stmt.execute("drop table BinaryTree");
  this.waitTillAllClear();
  stmt.execute("create table BinaryTree (id int primary key, "
      + "leftId int, rightId int, depth int not null,"
      + " foreign key (leftId) references BinaryTree(id),"
      + " foreign key (rightId) references BinaryTree(id))"+getSuffix());

  addExpectedException(SQLIntegrityConstraintViolationException.class);
  doBinaryTreeChecks(conn, true);
  removeExpectedException(SQLIntegrityConstraintViolationException.class);
}
 
Example #27
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #28
Source File: TestRepositoryUpgrade.java    From sqoop-on-spark with 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 #29
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #30
Source File: SQLIntegrityConstraintViolationExceptionTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}