use of com.netflix.conductor.core.execution.ApplicationException.Code.BACKEND_ERROR in project conductor by Netflix.
the class PostgresBaseDAO method getWithTransaction.
/**
* Initialize a new transactional {@link Connection} from {@link #dataSource} and pass it to {@literal function}.
* <p>
* Successful executions of {@literal function} will result in a commit and return of
* {@link TransactionalFunction#apply(Connection)}.
* <p>
* If any {@link Throwable} thrown from {@code TransactionalFunction#apply(Connection)} will result in a rollback
* of the transaction
* and will be wrapped in an {@link ApplicationException} if it is not already one.
* <p>
* Generally this is used to wrap multiple {@link #execute(Connection, String, ExecuteFunction)} or
* {@link #query(Connection, String, QueryFunction)} invocations that produce some expected return value.
*
* @param function The function to apply with a new transactional {@link Connection}
* @param <R> The return type.
* @return The result of {@code TransactionalFunction#apply(Connection)}
* @throws ApplicationException If any errors occur.
*/
private <R> R getWithTransaction(final TransactionalFunction<R> function) {
final Instant start = Instant.now();
LazyToString callingMethod = getCallingMethod();
logger.trace("{} : starting transaction", callingMethod);
try (Connection tx = dataSource.getConnection()) {
boolean previousAutoCommitMode = tx.getAutoCommit();
tx.setAutoCommit(false);
try {
R result = function.apply(tx);
tx.commit();
return result;
} catch (Throwable th) {
tx.rollback();
if (th instanceof ApplicationException) {
throw th;
}
throw new ApplicationException(BACKEND_ERROR, th.getMessage(), th);
} finally {
tx.setAutoCommit(previousAutoCommitMode);
}
} catch (SQLException ex) {
throw new ApplicationException(BACKEND_ERROR, ex.getMessage(), ex);
} finally {
logger.trace("{} : took {}ms", callingMethod, Duration.between(start, Instant.now()).toMillis());
}
}
use of com.netflix.conductor.core.execution.ApplicationException.Code.BACKEND_ERROR in project conductor by Netflix.
the class PostgresBaseDAO method getWithTransactionWithOutErrorPropagation.
protected <R> R getWithTransactionWithOutErrorPropagation(TransactionalFunction<R> function) {
Instant start = Instant.now();
LazyToString callingMethod = getCallingMethod();
logger.trace("{} : starting transaction", callingMethod);
try (Connection tx = dataSource.getConnection()) {
boolean previousAutoCommitMode = tx.getAutoCommit();
tx.setAutoCommit(false);
try {
R result = function.apply(tx);
tx.commit();
return result;
} catch (Throwable th) {
tx.rollback();
logger.info(CONFLICT + " " + th.getMessage());
return null;
} finally {
tx.setAutoCommit(previousAutoCommitMode);
}
} catch (SQLException ex) {
throw new ApplicationException(BACKEND_ERROR, ex.getMessage(), ex);
} finally {
logger.trace("{} : took {}ms", callingMethod, Duration.between(start, Instant.now()).toMillis());
}
}
use of com.netflix.conductor.core.execution.ApplicationException.Code.BACKEND_ERROR in project conductor by Netflix.
the class MySQLBaseDAO method getWithTransaction.
/**
* Initialize a new transactional {@link Connection} from {@link #dataSource} and pass it to {@literal function}.
* <p>
* Successful executions of {@literal function} will result in a commit and return of
* {@link TransactionalFunction#apply(Connection)}.
* <p>
* If any {@link Throwable} thrown from {@code TransactionalFunction#apply(Connection)} will result in a rollback
* of the transaction
* and will be wrapped in an {@link ApplicationException} if it is not already one.
* <p>
* Generally this is used to wrap multiple {@link #execute(Connection, String, ExecuteFunction)} or
* {@link #query(Connection, String, QueryFunction)} invocations that produce some expected return value.
*
* @param function The function to apply with a new transactional {@link Connection}
* @param <R> The return type.
* @return The result of {@code TransactionalFunction#apply(Connection)}
* @throws ApplicationException If any errors occur.
*/
private <R> R getWithTransaction(final TransactionalFunction<R> function) {
final Instant start = Instant.now();
LazyToString callingMethod = getCallingMethod();
logger.trace("{} : starting transaction", callingMethod);
try (Connection tx = dataSource.getConnection()) {
boolean previousAutoCommitMode = tx.getAutoCommit();
tx.setAutoCommit(false);
try {
R result = function.apply(tx);
tx.commit();
return result;
} catch (Throwable th) {
tx.rollback();
if (th instanceof ApplicationException) {
throw th;
}
throw new ApplicationException(BACKEND_ERROR, th.getMessage(), th);
} finally {
tx.setAutoCommit(previousAutoCommitMode);
}
} catch (SQLException ex) {
throw new ApplicationException(BACKEND_ERROR, ex.getMessage(), ex);
} finally {
logger.trace("{} : took {}ms", callingMethod, Duration.between(start, Instant.now()).toMillis());
}
}
use of com.netflix.conductor.core.execution.ApplicationException.Code.BACKEND_ERROR in project conductor by Netflix.
the class MySQLBaseDAO method getWithTransactionWithOutErrorPropagation.
protected <R> R getWithTransactionWithOutErrorPropagation(TransactionalFunction<R> function) {
Instant start = Instant.now();
LazyToString callingMethod = getCallingMethod();
logger.trace("{} : starting transaction", callingMethod);
try (Connection tx = dataSource.getConnection()) {
boolean previousAutoCommitMode = tx.getAutoCommit();
tx.setAutoCommit(false);
try {
R result = function.apply(tx);
tx.commit();
return result;
} catch (Throwable th) {
tx.rollback();
logger.info(CONFLICT + " " + th.getMessage());
return null;
} finally {
tx.setAutoCommit(previousAutoCommitMode);
}
} catch (SQLException ex) {
throw new ApplicationException(BACKEND_ERROR, ex.getMessage(), ex);
} finally {
logger.trace("{} : took {}ms", callingMethod, Duration.between(start, Instant.now()).toMillis());
}
}
Aggregations