getCause ( )源码实例Demo

java.sql.SQLException#getCause ( )源码实例Demo

下面列出了java.sql.SQLException#getCause ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Test
public void test06() {
    SQLException ex = new SyncProviderException("Exception 1");
    ex.initCause(t1);
    SyncProviderException ex1 = new SyncProviderException("Exception 2");
    SyncProviderException ex2 = new SyncProviderException("Exception 3");
    ex2.initCause(t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    while (ex != null) {
        assertTrue(msgs[num++].equals(ex.getMessage()));
        Throwable c = ex.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        ex = ex.getNextException();
    }
}
 
源代码2 项目: openjdk-jdk8u   文件: BatchUpdateExceptionTests.java
/**
 * 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();
    }
}
 
源代码3 项目: openjdk-jdk8u   文件: RowSetWarningTests.java
@Test
public void test07() {
    RowSetWarning ex = new RowSetWarning("Exception 1");
    ex.initCause(t1);
    RowSetWarning ex1 = new RowSetWarning("Exception 2");
    RowSetWarning ex2 = new RowSetWarning("Exception 3");
    ex2.initCause(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();
    }
}
 
源代码4 项目: jdk8u_jdk   文件: DataTruncationTests.java
/**
 * Validate that the ordering of the returned Exceptions is correct using
 * traditional while loop
 */
@Test
public void test12() {
    DataTruncation ex = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t1);
    DataTruncation ex1 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize);
    DataTruncation ex2 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(dtmsgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(dtmsgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
@Test
public void test04() {
    SQLException ex = new SerialException("Exception 1");
    ex.initCause(t1);
    SerialException ex1 = new SerialException("Exception 2");
    SerialException ex2 = new SerialException("Exception 3");
    ex2.initCause(t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    while (ex != null) {
        assertTrue(msgs[num++].equals(ex.getMessage()));
        Throwable c = ex.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        ex = ex.getNextException();
    }
}
 
源代码6 项目: gemfirexd-oss   文件: CreateHDFSStoreTest.java
public void testReplicatedHDFSStore() throws Exception {
  Properties props = new Properties();
  int mcastPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
  props.put("mcast-port", String.valueOf(mcastPort));
  props.put(DistributionConfig.MCAST_TTL_NAME, "0");
  Connection conn = TestUtil.getConnection(props);
  Statement st = conn.createStatement();

  checkDirExistence("./myhdfs");
  st.execute("create hdfsstore myhdfs namenode 'hdfs://127.0.0.1:" + port + "' homedir './myhdfs'");
  try {
    st.execute("create table mytab (col1 int primary key) replicate hdfsstore (myhdfs) enable concurrency checks");
    fail("Expected SQLException");
  } catch (SQLException se) {
    if (se.getCause() instanceof UnsupportedOperationException) {
      assertTrue(se
          .getMessage()
          .contains(
              LocalizedStrings.HDFSSTORE_IS_USED_IN_REPLICATED_TABLE
                  .toLocalizedString()));
    }
    se.printStackTrace();
  }
  st.execute("drop hdfsstore myhdfs");
  delete(new File("./myhdfs"));
}
 
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLFeatureNotSupportedException ex =
            new SQLFeatureNotSupportedException("Exception 1", t1);
    SQLFeatureNotSupportedException ex1 =
            new SQLFeatureNotSupportedException("Exception 2");
    SQLFeatureNotSupportedException ex2 =
            new SQLFeatureNotSupportedException("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();
    }
}
 
源代码8 项目: jdk8u-jdk   文件: SQLClientInfoExceptionTests.java
/**
 * Validate that the ordering of the returned Exceptions is correct using
 * traditional while loop
 */
@Test
public void test12() {
    SQLClientInfoException ex = new SQLClientInfoException("Exception 1",
            map, t1);
    SQLClientInfoException ex1 = new SQLClientInfoException("Exception 2",
            map);
    SQLClientInfoException ex2 = new SQLClientInfoException("Exception 3",
            map, 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();
    }
}
 
/**
 * 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();
    }
}
 
源代码10 项目: hottub   文件: DataTruncationTests.java
/**
 * Validate that the ordering of the returned Exceptions is correct using
 * traditional while loop
 */
@Test
public void test12() {
    DataTruncation ex = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t1);
    DataTruncation ex1 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize);
    DataTruncation ex2 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(dtmsgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(dtmsgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLFeatureNotSupportedException ex =
            new SQLFeatureNotSupportedException("Exception 1", t1);
    SQLFeatureNotSupportedException ex1 =
            new SQLFeatureNotSupportedException("Exception 2");
    SQLFeatureNotSupportedException ex2 =
            new SQLFeatureNotSupportedException("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();
    }
}
 
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLNonTransientException ex = new SQLNonTransientException("Exception 1", t1);
    SQLNonTransientException ex1 = new SQLNonTransientException("Exception 2");
    SQLNonTransientException ex2 = new SQLNonTransientException("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();
    }
}
 
源代码13 项目: openjdk-jdk9   文件: BatchUpdateExceptionTests.java
/**
 * 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();
    }
}
 
@Test
public void test06() {
    SQLException ex = new SyncProviderException("Exception 1");
    ex.initCause(t1);
    SyncProviderException ex1 = new SyncProviderException("Exception 2");
    SyncProviderException ex2 = new SyncProviderException("Exception 3");
    ex2.initCause(t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    while (ex != null) {
        assertTrue(msgs[num++].equals(ex.getMessage()));
        Throwable c = ex.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        ex = ex.getNextException();
    }
}
 
源代码15 项目: presto   文件: Validator.java
private static boolean isPrestoQueryInvalid(SQLException e)
{
    for (Throwable t = e.getCause(); t != null; t = t.getCause()) {
        if (t.toString().contains(".SemanticException:")) {
            return true;
        }
        if (t.toString().contains(".ParsingException:")) {
            return true;
        }
        if (nullToEmpty(t.getMessage()).matches("Function .* not registered")) {
            return true;
        }
    }
    return false;
}
 
源代码16 项目: kareldb   文件: BaseJDBCTestCase.java
/**
 * Assert that the two (2) passed-in SQLException's are equals and
 * not just '=='.
 *
 * @param se1 first SQLException to compare
 * @param se2 second SQLException to compare
 */
public static void assertSQLExceptionEquals(SQLException se1,
                                            SQLException se2) {
    // Ensure non-null SQLException's are being passed.
    assertNotNull(
        "Passed-in SQLException se1 cannot be null",
        se1);
    assertNotNull(
        "Passed-in SQLException se2 cannot be null",
        se2);

    // Now verify that the passed-in SQLException's are of the same type
    assertEquals("SQLException class types are different",
        se1.getClass().getName(), se2.getClass().getName());

    // Here we check that the detailed message of both
    // SQLException's is the same
    assertEquals(
        "Detailed messages of the SQLException's are different",
        se1.getMessage(), se2.getMessage());

    // Check that getCause() returns the same value on the two exceptions.
    Throwable se1Cause = se1.getCause();
    Throwable se2Cause = se2.getCause();
    if (se1Cause == null) {
        assertNull(se2Cause);
    } else {
        assertEquals(se1Cause, se2Cause);
    }

    // Check that the two exceptions have the same next exception.
    if (se1.getNextException() == null) {
        assertNull(se2.getNextException());
    } else {
        assertSQLExceptionEquals(se1.getNextException(),
            se2.getNextException());
    }
}
 
源代码17 项目: FoxTelem   文件: SQLError.java
public static SQLException createSQLException(String message, String sqlState, Throwable cause, ExceptionInterceptor interceptor) {
    SQLException sqlEx = createSQLException(message, sqlState, null);

    if (sqlEx.getCause() == null) {
        if (cause != null) {
            try {
                sqlEx.initCause(cause);
            } catch (Throwable t) {
                // we're not going to muck with that here, since it's an error condition anyway!
            }
        }
    }
    // Run through the exception interceptor after setting the init cause.
    return runThroughExceptionInterceptor(interceptor, sqlEx);
}
 
源代码18 项目: vertx-jdbc-client   文件: RuntimeSQLException.java
public RuntimeSQLException(SQLException exception) {
  super(exception.getMessage(), exception.getCause());
}
 
private boolean hasType(SQLException e, ErrorType errorType) {
  UserRemoteException userException = ((UserRemoteException) e.getCause());
  return userException.getErrorType() == errorType;
}
 
源代码20 项目: nifi   文件: DatabaseRecordLookupService.java
@Override
public Optional<Record> lookup(final Map<String, Object> coordinates, Map<String, String> context) throws LookupFailureException {
    if (coordinates == null) {
        return Optional.empty();
    }

    final Object key = coordinates.get(KEY);
    if (StringUtils.isBlank(key.toString())) {
        return Optional.empty();
    }

    final String tableName = getProperty(TABLE_NAME).evaluateAttributeExpressions(context).getValue();
    final String lookupValueColumnsList = getProperty(LOOKUP_VALUE_COLUMNS).evaluateAttributeExpressions(context).getValue();

    Set<String> lookupValueColumnsSet = new LinkedHashSet<>();
    if (lookupValueColumnsList != null) {
        Stream.of(lookupValueColumnsList)
                .flatMap(path -> Arrays.stream(path.split(",")))
                .filter(DatabaseRecordLookupService::isNotBlank)
                .map(String::trim)
                .forEach(lookupValueColumnsSet::add);
    }

    final String lookupValueColumns = lookupValueColumnsSet.isEmpty() ? "*" : String.join(",", lookupValueColumnsSet);

    Tuple<String, Object> cacheLookupKey = new Tuple<>(tableName, key);

    // Not using the function param of cache.get so we can catch and handle the checked exceptions
    Record foundRecord = cache.get(cacheLookupKey, k -> null);

    if (foundRecord == null) {
        final String selectQuery = "SELECT " + lookupValueColumns + " FROM " + tableName + " WHERE " + lookupKeyColumn + " = ?";
        try (final Connection con = dbcpService.getConnection(context);
             final PreparedStatement st = con.prepareStatement(selectQuery)) {

            st.setObject(1, key);
            ResultSet resultSet = st.executeQuery();
            ResultSetRecordSet resultSetRecordSet = new ResultSetRecordSet(resultSet, null);
            foundRecord = resultSetRecordSet.next();

            // Populate the cache if the record is present
            if (foundRecord != null) {
                cache.put(cacheLookupKey, foundRecord);
            }

        } catch (SQLException se) {
            throw new LookupFailureException("Error executing SQL statement: " + selectQuery + "for value " + key.toString()
                    + " : " + (se.getCause() == null ? se.getMessage() : se.getCause().getMessage()), se);
        } catch (IOException ioe) {
            throw new LookupFailureException("Error retrieving result set for SQL statement: " + selectQuery + "for value " + key.toString()
                    + " : " + (ioe.getCause() == null ? ioe.getMessage() : ioe.getCause().getMessage()), ioe);
        }
    }

    return Optional.ofNullable(foundRecord);
}