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();
}
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations