public abstract class MySQLBaseDAO
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected javax.sql.DataSource |
dataSource |
protected org.slf4j.Logger |
logger |
protected com.fasterxml.jackson.databind.ObjectMapper |
objectMapper |
| Modifier | Constructor and Description |
|---|---|
protected |
MySQLBaseDAO(com.fasterxml.jackson.databind.ObjectMapper om,
javax.sql.DataSource dataSource) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
execute(java.sql.Connection tx,
java.lang.String query,
ExecuteFunction function)
Execute a statement with no expected return value within a given transaction.
|
protected void |
executeWithTransaction(java.lang.String query,
ExecuteFunction function)
Instantiates a new transactional connection and invokes
execute(Connection, String, ExecuteFunction) |
protected com.netflix.conductor.dao.mysql.LazyToString |
getCallingMethod() |
protected <R> R |
getWithTransaction(TransactionalFunction<R> function)
Initialize a new transactional
Connection from dataSource and pass it to function. |
protected <R> R |
query(java.sql.Connection tx,
java.lang.String query,
QueryFunction<R> function)
Execute a
Query within the context of a given transaction and return the results of function. |
protected <R> R |
queryWithTransaction(java.lang.String query,
QueryFunction<R> function)
Initiate a new transaction and execute a
Query within that context,
then return the results of function. |
protected <T> T |
readValue(java.lang.String json,
java.lang.Class<T> tClass) |
protected <T> T |
readValue(java.lang.String json,
com.fasterxml.jackson.core.type.TypeReference<T> typeReference) |
protected java.lang.String |
toJson(java.lang.Object value) |
protected void |
withTransaction(java.util.function.Consumer<java.sql.Connection> consumer)
Wraps
getWithTransaction(TransactionalFunction) with no return value. |
protected final org.slf4j.Logger logger
protected final com.fasterxml.jackson.databind.ObjectMapper objectMapper
protected final javax.sql.DataSource dataSource
protected MySQLBaseDAO(com.fasterxml.jackson.databind.ObjectMapper om,
javax.sql.DataSource dataSource)
protected final com.netflix.conductor.dao.mysql.LazyToString getCallingMethod()
protected java.lang.String toJson(java.lang.Object value)
protected <T> T readValue(java.lang.String json,
java.lang.Class<T> tClass)
protected <T> T readValue(java.lang.String json,
com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
protected <R> R getWithTransaction(TransactionalFunction<R> function)
Connection from dataSource and pass it to function.
Successful executions of function will result in a commit and return of
TransactionalFunction.apply(Connection).
If any Throwable thrown from TransactionalFunction#apply(Connection) will result in a rollback
of the transaction
and will be wrapped in an ApplicationException if it is not already one.
Generally this is used to wrap multiple execute(Connection, String, ExecuteFunction) or
query(Connection, String, QueryFunction) invocations that produce some expected return value.
R - The return type.function - The function to apply with a new transactional ConnectionTransactionalFunction#apply(Connection)com.netflix.conductor.core.execution.ApplicationException - If any errors occur.protected void withTransaction(java.util.function.Consumer<java.sql.Connection> consumer)
getWithTransaction(TransactionalFunction) with no return value.
Generally this is used to wrap multiple execute(Connection, String, ExecuteFunction) or
query(Connection, String, QueryFunction) invocations that produce no expected return value.
consumer - The Consumer callback to pass a transactional Connection to.com.netflix.conductor.core.execution.ApplicationException - If any errors occur.getWithTransaction(TransactionalFunction)protected <R> R queryWithTransaction(java.lang.String query,
QueryFunction<R> function)
Query within that context,
then return the results of function.R - The expected return type of function.query - The query string to prepare.function - The functional callback to pass a Query to.protected <R> R query(java.sql.Connection tx,
java.lang.String query,
QueryFunction<R> function)
Query within the context of a given transaction and return the results of function.R - The expected return type of function.tx - The transactional Connection to use.query - The query string to prepare.function - The functional callback to pass a Query to.protected void execute(java.sql.Connection tx,
java.lang.String query,
ExecuteFunction function)
tx - The transactional Connection to use.query - The query string to prepare.function - The functional callback to pass a Query to.protected void executeWithTransaction(java.lang.String query,
ExecuteFunction function)
execute(Connection, String, ExecuteFunction)query - The query string to prepare.function - The functional callback to pass a Query to.