Search in sources :

Example 1 with SQLRecoverableException

use of java.sql.SQLRecoverableException in project elasticsearch-jdbc by jprante.

the class StandardSource method fetch.

/**
     * Fetch, issue SQL statements.
     *
     * @throws SQLException when SQL execution gives an error
     * @throws IOException  when input/output error occurs
     */
@Override
public void fetch() throws SQLException, IOException {
    logger.debug("fetching, {} SQL commands", getStatements().size());
    DateTime dateTime = new DateTime();
    try {
        for (SQLCommand command : getStatements()) {
            try {
                if (command.isCallable()) {
                    logger.debug("{} executing callable SQL: {}", this, command);
                    executeCallable(command);
                } else if (!command.getParameters().isEmpty()) {
                    logger.debug("{} executing SQL with params: {}", this, command);
                    executeWithParameter(command);
                } else {
                    logger.debug("{} executing SQL without params: {}", this, command);
                    execute(command);
                }
                if (sourceMetric != null) {
                    sourceMetric.getSucceeded().inc();
                    sourceMetric.setLastExecutionStart(dateTime);
                    sourceMetric.setLastExecutionEnd(new DateTime());
                }
            } catch (SQLRecoverableException e) {
                long millis = getMaxRetryWait().getMillis();
                logger.warn("retrying after " + millis / 1000 + " seconds, got exception ", e);
                Thread.sleep(getMaxRetryWait().getMillis());
                if (command.isCallable()) {
                    logger.debug("retrying, executing callable SQL: {}", command);
                    executeCallable(command);
                } else if (!command.getParameters().isEmpty()) {
                    logger.debug("retrying, executing SQL with params: {}", command);
                    executeWithParameter(command);
                } else {
                    logger.debug("retrying, executing SQL without params: {}", command);
                    execute(command);
                }
                if (sourceMetric != null) {
                    sourceMetric.getSucceeded().inc();
                    sourceMetric.setLastExecutionStart(dateTime);
                    sourceMetric.setLastExecutionEnd(new DateTime());
                }
            }
        }
    } catch (Exception e) {
        if (sourceMetric != null) {
            sourceMetric.getFailed().inc();
            sourceMetric.setLastExecutionStart(dateTime);
            sourceMetric.setLastExecutionEnd(new DateTime());
        }
        throw new IOException(e);
    } finally {
        if (sourceMetric != null) {
            sourceMetric.incCounter();
        }
    }
}
Also used : SQLRecoverableException(java.sql.SQLRecoverableException) SQLCommand(org.xbib.elasticsearch.common.util.SQLCommand) IOException(java.io.IOException) DateTime(org.joda.time.DateTime) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException) SQLDataException(java.sql.SQLDataException) ParseException(java.text.ParseException) SQLRecoverableException(java.sql.SQLRecoverableException) IOException(java.io.IOException) SQLNonTransientConnectionException(java.sql.SQLNonTransientConnectionException)

Example 2 with SQLRecoverableException

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

the class SQLRecoverableExceptionTests method test10.

/**
     * Serialize a SQLRecoverableException and make sure you can read it back properly
     */
@Test
public void test10() throws Exception {
    SQLRecoverableException e = new SQLRecoverableException(reason, state, errorCode, t);
    SQLRecoverableException ex1 = createSerializedException(e);
    assertTrue(reason.equals(ex1.getMessage()) && ex1.getSQLState().equals(state) && cause.equals(ex1.getCause().toString()) && ex1.getErrorCode() == errorCode);
}
Also used : SQLRecoverableException(java.sql.SQLRecoverableException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 3 with SQLRecoverableException

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

the class SQLRecoverableExceptionTests method test9.

/**
     * Create SQLRecoverableException with Throwable
     */
@Test
public void test9() {
    SQLRecoverableException ex = new SQLRecoverableException(t);
    assertTrue(ex.getMessage().equals(cause) && ex.getSQLState() == null && cause.equals(ex.getCause().toString()) && ex.getErrorCode() == 0);
}
Also used : SQLRecoverableException(java.sql.SQLRecoverableException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 4 with SQLRecoverableException

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

the class SQLRecoverableExceptionTests method test6.

/**
     * Create SQLRecoverableException with message, SQLState, and Throwable
     */
@Test
public void test6() {
    SQLRecoverableException ex = new SQLRecoverableException(reason, state, t);
    assertTrue(ex.getMessage().equals(reason) && ex.getSQLState().equals(state) && cause.equals(ex.getCause().toString()) && ex.getErrorCode() == 0);
}
Also used : SQLRecoverableException(java.sql.SQLRecoverableException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 5 with SQLRecoverableException

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

the class SQLRecoverableExceptionTests method test5.

/**
     * Create SQLRecoverableException with message, SQLState, errorCode, and Throwable
     */
@Test
public void test5() {
    SQLRecoverableException ex = new SQLRecoverableException(reason, state, errorCode, t);
    assertTrue(ex.getMessage().equals(reason) && ex.getSQLState().equals(state) && cause.equals(ex.getCause().toString()) && ex.getErrorCode() == errorCode);
}
Also used : SQLRecoverableException(java.sql.SQLRecoverableException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Aggregations

SQLRecoverableException (java.sql.SQLRecoverableException)14 Test (org.testng.annotations.Test)13 BaseTest (util.BaseTest)13 SQLException (java.sql.SQLException)2 IOException (java.io.IOException)1 SQLDataException (java.sql.SQLDataException)1 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 SQLNonTransientConnectionException (java.sql.SQLNonTransientConnectionException)1 ParseException (java.text.ParseException)1 DateTime (org.joda.time.DateTime)1 SQLCommand (org.xbib.elasticsearch.common.util.SQLCommand)1