Java 类java.sql.SQLTimeoutException 实例源码

项目:Lernkartei_2017    文件:DBDriver.java   
/**
 * To execute a SQL command (except a query like SELECT)
 * 
 * @param SQLcommand
 * @return 0, 1,2 or -1 on error
 */
protected int doCommand(String SQLcommand) {
    if (stmt == null) {
        Logger.out("connection was closed before command " + SQLcommand);
        setConnection();
    }
    try {
        setLastSQLCommand(SQLcommand);
        // returns 0, 1, 2, ...
        return stmt.executeUpdate(SQLcommand); // for CREATE,
                                                // UPDATE, DELETE,
                                                // INSERT
    } catch (SQLTimeoutException e) {
        Logger.out("SQL CMD Timeout Exception: " + e.getCause(), SQLcommand);
    } catch (SQLException e2) {
        Logger.out("SQL CMD Exception: " + e2.getMessage() + "/" + e2.getCause(), SQLcommand);
    } catch (Exception e3) {
        Logger.out("Exception: " + e3.getMessage() + "/" + e3.getCause(), SQLcommand);
    }
    return -1;
}
项目:jdk8u-jdk    文件:SQLTimeoutExceptionTests.java   
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLTimeoutException ex = new SQLTimeoutException("Exception 1", t1);
    SQLTimeoutException ex1 = new SQLTimeoutException("Exception 2");
    SQLTimeoutException ex2 = new SQLTimeoutException("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();
    }
}
项目:openjdk-jdk10    文件:SQLTimeoutExceptionTests.java   
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLTimeoutException ex = new SQLTimeoutException("Exception 1", t1);
    SQLTimeoutException ex1 = new SQLTimeoutException("Exception 2");
    SQLTimeoutException ex2 = new SQLTimeoutException("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();
    }
}
项目:morf    文件:DatabaseExceptionHelper.java   
/**
 * <p>Checks if the throwable was caused by timeout exception.</p>
 * <b>This method has been tested for Oracle and MySQL only and might not work
 * for other DB engines.</b>
 *
 * @param throwable to check
 * @return true if the throwable is caused by a timeout, false otherwise
 */
public boolean isCausedByTimeoutException(Throwable throwable) {
  // Valid test for Oracle timeout exception and some (not all!) MySQL
  // exceptions.
  if (ExceptionUtils.indexOfType(throwable, SQLTimeoutException.class) != -1) {
    return true;
  }
  // MySQL database has two timeout exceptions in two packages. One of them
  // doesn't extend SQLTimeoutException but only SQLException. It is therefore
  // necessary to do ugly name check...
  for (Throwable causeThrowable : ExceptionUtils.getThrowables(throwable)) {
    if (MYSQL_TIMEOUT_EXCEPTION_NAME.equals(causeThrowable.getClass().getSimpleName())) {
      return true;
    }
  }
  return false;
}
项目:openjdk9    文件:SQLTimeoutExceptionTests.java   
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLTimeoutException ex = new SQLTimeoutException("Exception 1", t1);
    SQLTimeoutException ex1 = new SQLTimeoutException("Exception 2");
    SQLTimeoutException ex2 = new SQLTimeoutException("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();
    }
}
项目:Lernkartei    文件:DBDriver.java   
/**
 * To execute a SQL command (except a query like SELECT)
 * 
 * @param SQLcommand
 * @return 0, 1,2 or -1 on error
 */
protected int doCommand(String SQLcommand) {
    if (stmt == null) {
        Logger.out("connection was closed before command " + SQLcommand);
        setConnection();
    }
    try {
        setLastSQLCommand(SQLcommand);
        // returns 0, 1, 2, ...
        return stmt.executeUpdate(SQLcommand); // for CREATE,
                                                // UPDATE, DELETE,
                                                // INSERT
    } catch (SQLTimeoutException e) {
        Logger.out("SQL CMD Timeout Exception: " + e.getCause(), SQLcommand);
    } catch (SQLException e2) {
        Logger.out("SQL CMD Exception: " + e2.getMessage() + "/" + e2.getCause(), SQLcommand);
    } catch (Exception e3) {
        Logger.out("Exception: " + e3.getMessage() + "/" + e3.getCause(), SQLcommand);
    }
    return -1;
}
项目:jdk8u_jdk    文件:SQLTimeoutExceptionTests.java   
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLTimeoutException ex = new SQLTimeoutException("Exception 1", t1);
    SQLTimeoutException ex1 = new SQLTimeoutException("Exception 2");
    SQLTimeoutException ex2 = new SQLTimeoutException("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();
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:SQLTimeoutExceptionTests.java   
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLTimeoutException ex = new SQLTimeoutException("Exception 1", t1);
    SQLTimeoutException ex1 = new SQLTimeoutException("Exception 2");
    SQLTimeoutException ex2 = new SQLTimeoutException("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();
    }
}
项目:athenz    文件:JDBCCertRecordStoreConnectionTest.java   
@Test
public void testSqlError() throws SQLException {

    JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);

    SQLException ex = new SQLException("sql-reason", "08S01", 9999);
    ResourceException rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError");
    assertEquals(ResourceException.INTERNAL_SERVER_ERROR, rEx.getCode());

    ex = new SQLException("sql-reason", "40001", 9999);
    rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError");
    assertEquals(ResourceException.INTERNAL_SERVER_ERROR, rEx.getCode());

    SQLTimeoutException tex = new SQLTimeoutException();
    rEx = (ResourceException) jdbcConn.sqlError(tex, "sqlError");
    assertEquals(ResourceException.SERVICE_UNAVAILABLE, rEx.getCode());

    jdbcConn.close();
}
项目:ignite    文件:JdbcThinStatementSelfTest.java   
/**
 * @throws Exception If failed.
 */
public void testExecuteQueryTimeout() throws Exception {
    fail("https://issues.apache.org/jira/browse/IGNITE-5438");

    final String sqlText = "select sleep_func(3)";

    stmt.setQueryTimeout(1);

    // Timeout
    GridTestUtils.assertThrows(log,
        new Callable<Object>() {
            @Override public Object call() throws Exception {
                return stmt.executeQuery(sqlText);
            }
        },
        SQLTimeoutException.class,
        "Timeout"
    );
}
项目:ignite    文件:JdbcThinStatementSelfTest.java   
/**
 * @throws Exception If failed.
 */
public void testExecuteUpdateTimeout() throws Exception {
    fail("https://issues.apache.org/jira/browse/IGNITE-5438");

    final String sqlText = "update test set val=1 where _key=sleep_func(3)";

    stmt.setQueryTimeout(1);

    // Timeout
    GridTestUtils.assertThrows(log,
        new Callable<Object>() {
            @Override public Object call() throws Exception {
                return stmt.executeUpdate(sqlText);
            }
        },
        SQLTimeoutException.class,
        "Timeout"
    );
}
项目:vibur-dbcp    文件:PoolOperations.java   
private SQLException createSQLException(double elapsedMs) {
    String poolName = getPoolName(dataSource);
    if (poolService.isTerminated())
        return new SQLException(format("Pool %s, the poolService is terminated.", poolName),
                SQLSTATE_POOL_CLOSED_ERROR);

    boolean isInterrupted = Thread.currentThread().isInterrupted(); // someone else has interrupted us, so we do not clear the flag
    if (!isInterrupted && dataSource.isLogTakenConnectionsOnTimeout() && logger.isWarnEnabled())
        logger.warn(format("Pool %s, couldn't obtain SQL connection within %.3f ms, full list of taken connections begins:\n%s",
                poolName, elapsedMs, dataSource.getTakenConnectionsStackTraces()));

    int intElapsedMs = (int) Math.round(elapsedMs);
    return !isInterrupted ?
            new SQLTimeoutException(format("Pool %s, couldn't obtain SQL connection within %.3f ms.",
                    poolName, elapsedMs), SQLSTATE_TIMEOUT_ERROR, intElapsedMs) :
            new SQLException(format("Pool %s, interrupted while getting SQL connection, waited for %.3f ms.",
                    poolName, elapsedMs), SQLSTATE_INTERRUPTED_ERROR, intElapsedMs);
}
项目:jTDS    文件:TdsCore.java   
/**
 * Waits for the first byte of the server response.
 *
 * @param timeOut the timeout period in seconds or 0
 */
private void wait(int timeOut) throws IOException, SQLException {
    Object timer = null;
    try {
        if (timeOut > 0) {
            // Start a query timeout timer
            timer = TimerThread.getInstance().setTimer(timeOut * 1000,
                    new TimerThread.TimerListener() {
                        public void timerExpired() {
                            TdsCore.this.cancel(true);
                        }
                    });
        }
        in.peek();
    } finally {
        if (timer != null) {
            if (!TimerThread.getInstance().cancelTimer(timer)) {
                throw new SQLTimeoutException(
                      Messages.get("error.generic.timeout"), "HYT00");
            }
        }
    }
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(Throwable)
 */
public void test_Constructor_LThrowable() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(cause);
    assertNotNull(sQLTimeoutException);
    assertEquals(
            "The reason of SQLTimeoutException should be equals to cause.toString()",
            "java.lang.Exception: MYTHROWABLE", sQLTimeoutException
                    .getMessage());
    assertNull("The SQLState of SQLTimeoutException should be null",
            sQLTimeoutException.getSQLState());
    assertEquals("The error code of SQLTimeoutException should be 0",
            sQLTimeoutException.getErrorCode(), 0);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, Throwable)
 */
public void test_Constructor_LStringLThrowable() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(
            "MYTESTSTRING", cause);
    assertNotNull(sQLTimeoutException);
    assertEquals(
            "The reason of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING", sQLTimeoutException.getMessage());
    assertNull("The SQLState of SQLTimeoutException should be null",
            sQLTimeoutException.getSQLState());
    assertEquals("The error code of SQLTimeoutException should be 0",
            sQLTimeoutException.getErrorCode(), 0);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, Throwable)
 */
public void test_Constructor_LStringLStringLThrowable() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(
            "MYTESTSTRING1", "MYTESTSTRING2", cause);
    assertNotNull(sQLTimeoutException);
    assertEquals(
            "The SQLState of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING2", sQLTimeoutException.getSQLState());
    assertEquals(
            "The reason of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING1", sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be 0",
            sQLTimeoutException.getErrorCode(), 0);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, Throwable)
 */
public void test_Constructor_LStringLStringLThrowable_1() {
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(
            "MYTESTSTRING1", "MYTESTSTRING2", null);
    assertNotNull(sQLTimeoutException);
    assertEquals(
            "The SQLState of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING2", sQLTimeoutException.getSQLState());
    assertEquals(
            "The reason of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING1", sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be 0",
            sQLTimeoutException.getErrorCode(), 0);
    assertNull("The cause of SQLTimeoutException should be null",
            sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, Throwable)
 */
public void test_Constructor_LStringLStringLThrowable_2() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(
            "MYTESTSTRING", null, cause);
    assertNotNull(sQLTimeoutException);
    assertNull("The SQLState of SQLTimeoutException should be null",
            sQLTimeoutException.getSQLState());
    assertEquals(
            "The reason of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING", sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be 0",
            sQLTimeoutException.getErrorCode(), 0);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, Throwable)
 */
public void test_Constructor_LStringLStringLThrowable_4() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(null,
            "MYTESTSTRING", cause);
    assertNotNull(sQLTimeoutException);
    assertEquals(
            "The SQLState of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING", sQLTimeoutException.getSQLState());
    assertNull("The reason of SQLTimeoutException should be null",
            sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be 0",
            sQLTimeoutException.getErrorCode(), 0);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, Throwable)
 */
public void test_Constructor_LStringLStringLThrowable_6() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(null,
            null, cause);
    assertNotNull(sQLTimeoutException);
    assertNull("The SQLState of SQLTimeoutException should be null",
            sQLTimeoutException.getSQLState());
    assertNull("The reason of SQLTimeoutException should be null",
            sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be 0",
            sQLTimeoutException.getErrorCode(), 0);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, int, Throwable)
 */
public void test_Constructor_LStringLStringILThrowable() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(
            "MYTESTSTRING1", "MYTESTSTRING2", 1, cause);
    assertNotNull(sQLTimeoutException);
    assertEquals(
            "The SQLState of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING2", sQLTimeoutException.getSQLState());
    assertEquals(
            "The reason of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING1", sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be 1",
            sQLTimeoutException.getErrorCode(), 1);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, int, Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_1() {
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(
            "MYTESTSTRING1", "MYTESTSTRING2", 1, null);
    assertNotNull(sQLTimeoutException);
    assertEquals(
            "The SQLState of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING2", sQLTimeoutException.getSQLState());
    assertEquals(
            "The reason of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING1", sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be 1",
            sQLTimeoutException.getErrorCode(), 1);
    assertNull("The cause of SQLTimeoutException should be null",
            sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, int, Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_2() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(
            "MYTESTSTRING1", "MYTESTSTRING2", 0, cause);
    assertNotNull(sQLTimeoutException);
    assertEquals(
            "The SQLState of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING2", sQLTimeoutException.getSQLState());
    assertEquals(
            "The reason of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING1", sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be 0",
            sQLTimeoutException.getErrorCode(), 0);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, int, Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_3() {
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(
            "MYTESTSTRING1", "MYTESTSTRING2", 0, null);
    assertNotNull(sQLTimeoutException);
    assertEquals(
            "The SQLState of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING2", sQLTimeoutException.getSQLState());
    assertEquals(
            "The reason of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING1", sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be 0",
            sQLTimeoutException.getErrorCode(), 0);
    assertNull("The cause of SQLTimeoutException should be null",
            sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, int, Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_4() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(
            "MYTESTSTRING1", "MYTESTSTRING2", -1, cause);
    assertNotNull(sQLTimeoutException);
    assertEquals(
            "The SQLState of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING2", sQLTimeoutException.getSQLState());
    assertEquals(
            "The reason of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING1", sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be -1",
            sQLTimeoutException.getErrorCode(), -1);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, int, Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_5() {
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(
            "MYTESTSTRING1", "MYTESTSTRING2", -1, null);
    assertNotNull(sQLTimeoutException);
    assertEquals(
            "The SQLState of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING2", sQLTimeoutException.getSQLState());
    assertEquals(
            "The reason of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING1", sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be -1",
            sQLTimeoutException.getErrorCode(), -1);
    assertNull("The cause of SQLTimeoutException should be null",
            sQLTimeoutException.getCause());

}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, int, Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_6() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(
            "MYTESTSTRING", null, 1, cause);
    assertNotNull(sQLTimeoutException);
    assertNull("The SQLState of SQLTimeoutException should be null",
            sQLTimeoutException.getSQLState());
    assertEquals(
            "The reason of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING", sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be 1",
            sQLTimeoutException.getErrorCode(), 1);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, int, Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_7() {
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(
            "MYTESTSTRING", null, 1, null);
    assertNotNull(sQLTimeoutException);
    assertNotNull(sQLTimeoutException);
    assertNull("The SQLState of SQLTimeoutException should be null",
            sQLTimeoutException.getSQLState());
    assertEquals(
            "The reason of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING", sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be 1",
            sQLTimeoutException.getErrorCode(), 1);
    assertNull("The cause of SQLTimeoutException should be null",
            sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, int, Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_8() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(
            "MYTESTSTRING", null, 0, cause);
    assertNotNull(sQLTimeoutException);
    assertNull("The SQLState of SQLTimeoutException should be null",
            sQLTimeoutException.getSQLState());
    assertEquals(
            "The reason of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING", sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be 0",
            sQLTimeoutException.getErrorCode(), 0);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, int, Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_10() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(
            "MYTESTSTRING", null, -1, cause);
    assertNotNull(sQLTimeoutException);
    assertNull("The SQLState of SQLTimeoutException should be null",
            sQLTimeoutException.getSQLState());
    assertEquals(
            "The reason of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING", sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be -1",
            sQLTimeoutException.getErrorCode(), -1);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, int, Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_12() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(null,
            "MYTESTSTRING", 1, cause);
    assertNotNull(sQLTimeoutException);
    assertEquals(
            "The SQLState of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING", sQLTimeoutException.getSQLState());
    assertNull("The reason of SQLTimeoutException should be null",
            sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be 1",
            sQLTimeoutException.getErrorCode(), 1);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, int, Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_14() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(null,
            "MYTESTSTRING", 0, cause);
    assertNotNull(sQLTimeoutException);
    assertEquals(
            "The SQLState of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING", sQLTimeoutException.getSQLState());
    assertNull("The reason of SQLTimeoutException should be null",
            sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be 0",
            sQLTimeoutException.getErrorCode(), 0);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, int, Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_15() {
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(null,
            "MYTESTSTRING", 0, null);
    assertNotNull(sQLTimeoutException);
    assertEquals(
            "The SQLState of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING", sQLTimeoutException.getSQLState());
    assertNull("The reason of SQLTimeoutException should be null",
            sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be 0",
            sQLTimeoutException.getErrorCode(), 0);
    assertNull("The cause of SQLTimeoutException should be null",
            sQLTimeoutException.getCause());

}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, int, Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_16() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(null,
            "MYTESTSTRING", -1, cause);
    assertNotNull(sQLTimeoutException);
    assertEquals(
            "The SQLState of SQLTimeoutException set and get should be equivalent",
            "MYTESTSTRING", sQLTimeoutException.getSQLState());
    assertNull("The reason of SQLTimeoutException should be null",
            sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be -1",
            sQLTimeoutException.getErrorCode(), -1);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, int, Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_18() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(null,
            null, 1, cause);
    assertNotNull(sQLTimeoutException);
    assertNull("The SQLState of SQLTimeoutException should be null",
            sQLTimeoutException.getSQLState());
    assertNull("The reason of SQLTimeoutException should be null",
            sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be 1",
            sQLTimeoutException.getErrorCode(), 1);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, int, Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_20() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(null,
            null, 0, cause);
    assertNotNull(sQLTimeoutException);
    assertNull("The SQLState of SQLTimeoutException should be null",
            sQLTimeoutException.getSQLState());
    assertNull("The reason of SQLTimeoutException should be null",
            sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be 0",
            sQLTimeoutException.getErrorCode(), 0);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:cn1    文件:SQLTimeoutExceptionTest.java   
/**
 * @test java.sql.SQLTimeoutException(String, String, int, Throwable)
 */
public void test_Constructor_LStringLStringILThrowable_22() {
    Throwable cause = new Exception("MYTHROWABLE");
    SQLTimeoutException sQLTimeoutException = new SQLTimeoutException(null,
            null, -1, cause);
    assertNotNull(sQLTimeoutException);
    assertNull("The SQLState of SQLTimeoutException should be null",
            sQLTimeoutException.getSQLState());
    assertNull("The reason of SQLTimeoutException should be null",
            sQLTimeoutException.getMessage());
    assertEquals("The error code of SQLTimeoutException should be -1",
            sQLTimeoutException.getErrorCode(), -1);
    assertEquals(
            "The cause of SQLTimeoutException set and get should be equivalent",
            cause, sQLTimeoutException.getCause());
}
项目:jporm    文件:SpringBasedSQLStateSQLExceptionTranslator.java   
public static RuntimeException doTranslate(final String task, final String sql, final SQLException ex) {
    if (ex instanceof SQLTimeoutException) {
        return new JpoTransactionTimedOutException(ex);
    }
    String sqlState = getSqlState(ex);
    LOGGER.info("SQLException state: [{}]", sqlState);
    if ((sqlState != null) && (sqlState.length() >= 2)) {
        String classCode = sqlState.substring(0, 2);
        if (BAD_SQL_GRAMMAR_CODES.contains(classCode)) {
            return new JpoSqlBadGrammarException(buildMessage(task, sql, ex), ex);
        } else if (DATA_INTEGRITY_VIOLATION_CODES.contains(classCode)) {
            return new JpoSqlDataIntegrityViolationException(buildMessage(task, sql, ex), ex);
        } else if (DATA_ACCESS_RESOURCE_FAILURE_CODES.contains(classCode)) {
            return new JpoSqlDataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
        } else if (TRANSIENT_DATA_ACCESS_RESOURCE_CODES.contains(classCode)) {
            return new JpoSqlTransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
        } else if (CONCURRENCY_FAILURE_CODES.contains(classCode)) {
            return new JpoSqlConcurrencyFailureException(buildMessage(task, sql, ex), ex);
        }
    }
    return new JpoSqlException(buildMessage(task, sql, ex), ex);
}
项目:lams    文件:SQLExceptionSubclassTranslator.java   
@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;
}
项目:lams    文件:SQLExceptionTypeDelegate.java   
@Override
public JDBCException convert(SQLException sqlException, String message, String sql) {
    if ( SQLClientInfoException.class.isInstance( sqlException )
            || SQLInvalidAuthorizationSpecException.class.isInstance( sqlException )
            || SQLNonTransientConnectionException.class.isInstance( sqlException )
            || SQLTransientConnectionException.class.isInstance( sqlException ) ) {
        return new JDBCConnectionException( message, sqlException, sql );
    }
    else if ( DataTruncation.class.isInstance( sqlException ) ||
            SQLDataException.class.isInstance( sqlException ) ) {
        throw new DataException( message, sqlException, sql );
    }
    else if ( SQLIntegrityConstraintViolationException.class.isInstance( sqlException ) ) {
        return new ConstraintViolationException(
                message,
                sqlException,
                sql,
                getConversionContext().getViolatedConstraintNameExtracter().extractConstraintName( sqlException )
        );
    }
    else if ( SQLSyntaxErrorException.class.isInstance( sqlException ) ) {
        return new SQLGrammarException( message, sqlException, sql );
    }
    else if ( SQLTimeoutException.class.isInstance( sqlException ) ) {
        return new QueryTimeoutException( message, sqlException, sql );
    }
    else if ( SQLTransactionRollbackException.class.isInstance( sqlException ) ) {
        // Not 100% sure this is completely accurate.  The JavaDocs for SQLTransactionRollbackException state that
        // it indicates sql states starting with '40' and that those usually indicate that:
        //      <quote>
        //          the current statement was automatically rolled back by the database because of deadlock or
        //          other transaction serialization failures.
        //      </quote>
        return new LockAcquisitionException( message, sqlException, sql );
    }

    return null; // allow other delegates the chance to look
}