public class MockDbConnectionManager extends Object implements DbConnectionManager
Constructor and Description |
---|
MockDbConnectionManager() |
Modifier and Type | Method and Description |
---|---|
void |
assertAllExpectedStatementsWereRun() |
void |
execute(SqlCallback callback)
Executes SQL statements as defined in the callback function.
|
<T> T |
executeQuery(QueryCallback<T> callback)
Executes SQL statements as defined in the callback function and returns the results.
|
com.querydsl.sql.SQLTemplates |
getDialect()
This will return a DB dialect as appropriate for usage with Querydsl.
|
org.ofbiz.core.entity.DelegatorInterface |
getMockDelegatorInterface() |
void |
onSqlListener(String sql,
Runnable action)
Require MockDbConnectionManager to invoke some action, when specified sql is being executed.
|
void |
reset() |
void |
setQueryResults(String sql,
Iterable<ResultRow> expectedResults) |
void |
setUpdateResults(String sql,
int rowCount) |
void |
setUpdateResults(String sql,
java.util.function.Supplier<RuntimeException> exFactory) |
public <T> T executeQuery(@Nonnull QueryCallback<T> callback)
DbConnectionManager
This method is mostly useful for running SELECT statements and returning the given results in some form.
Even if OfBiz is currently running in a ThreadLocal transaction, this will retrieve a fresh connection from the pool. Do not close the given connection - this manager will return it to the pool after the method is complete. If the Callback function throws a RuntimeException and the connection is not in auto-commit mode, then this method will perform a rollback on the connection.
The connection will have the default auto-commit value as defined by the JIRA connection pool.
As at JIRA 6.4 this means autocommit == true.
See org.apache.commons.dbcp.PoolableConnectionFactory#activateObject(Object)
for details.
executeQuery
in interface DbConnectionManager
T
- type of resultscallback
- the callback function that runs the queryDbConnectionManager.execute(SqlCallback)
public void execute(@Nonnull SqlCallback callback)
DbConnectionManager
This method does not return results and is mostly useful for running INSERT, UPDATE, and DELETE operations.
Example Usage:
dbConnectionManager.execute(new SqlCallback() { public void run(final DbConnection dbConnection) { dbConnection.update(QIssueLink.ISSUE_LINK) .set(QIssueLink.ISSUE_LINK.linktype, issueLinkType.getId()) .where(QIssueLink.ISSUE_LINK.id.eq(issueLink.getId())) .execute(); } });
Even if OfBiz is currently running in a ThreadLocal transaction, this will retrieve a fresh connection from the pool. Do not close the given connection - this manager will return it to the pool after the method is complete. If the Callback function throws a RuntimeException and the connection is not in auto-commit mode, then this method will perform a rollback on the connection.
The connection will have the default auto-commit value as defined by the JIRA connection pool.
As at JIRA 6.4 this means autocommit == true.
See org.apache.commons.dbcp.PoolableConnectionFactory#activateObject(Object)
for details.
execute
in interface DbConnectionManager
callback
- the callback function that runs the queryDbConnectionManager.executeQuery(QueryCallback)
@Nonnull public com.querydsl.sql.SQLTemplates getDialect()
DbConnectionManager
getDialect
in interface DbConnectionManager
public void setUpdateResults(String sql, int rowCount)
public void setUpdateResults(String sql, java.util.function.Supplier<RuntimeException> exFactory)
public void assertAllExpectedStatementsWereRun()
public void reset()
public void onSqlListener(String sql, Runnable action)
sql
- SQL query we listen onaction
- Action to be invoked when the sql is runpublic org.ofbiz.core.entity.DelegatorInterface getMockDelegatorInterface()
Copyright © 2002-2019 Atlassian. All Rights Reserved.