use of org.dbflute.bhv.core.context.ResourceContext in project dbflute-core by dbflute.
the class BehaviorCommandInvoker method invoke.
// ===================================================================================
// Command Invoke
// ==============
/**
* Invoke the command of behavior. {Public Interface}
* This method is an entry point!
* @param <RESULT> The type of result.
* @param behaviorCommand The command of behavior. (NotNull)
* @return The result object. (NullAllowed)
*/
public <RESULT> RESULT invoke(BehaviorCommand<RESULT> behaviorCommand) {
RuntimeException cause = null;
RESULT result = null;
try {
final ResourceContext parentContext = getParentContext();
initializeContext();
setupResourceContext(behaviorCommand, parentContext);
processBeforeHook(behaviorCommand);
result = dispatchInvoking(behaviorCommand);
} catch (RuntimeException e) {
cause = e;
} finally {
processFinallyHook(behaviorCommand, cause);
closeContext();
}
if (cause != null) {
throw cause;
} else {
return result;
}
}
use of org.dbflute.bhv.core.context.ResourceContext in project dbflute-core by dbflute.
the class BehaviorCommandInvoker method setupResourceContext.
protected <RESULT> void setupResourceContext(BehaviorCommand<RESULT> behaviorCommand, ResourceContext parentContext) {
assertInvokerAssistant();
final ResourceContext resourceContext = new ResourceContext();
// not null only when recursive call
resourceContext.setParentContext(parentContext);
resourceContext.setBehaviorCommand(behaviorCommand);
resourceContext.setCurrentDBDef(_invokerAssistant.assistCurrentDBDef());
resourceContext.setDBMetaProvider(_invokerAssistant.assistDBMetaProvider());
resourceContext.setSqlClauseCreator(_invokerAssistant.assistSqlClauseCreator());
resourceContext.setSqlAnalyzerFactory(_invokerAssistant.assistSqlAnalyzerFactory());
resourceContext.setSQLExceptionHandlerFactory(_invokerAssistant.assistSQLExceptionHandlerFactory());
resourceContext.setGearedCipherManager(_invokerAssistant.assistGearedCipherManager());
resourceContext.setResourceParameter(_invokerAssistant.assistResourceParameter());
ResourceContext.setResourceContextOnThread(resourceContext);
}
use of org.dbflute.bhv.core.context.ResourceContext in project dbflute-core by dbflute.
the class SequenceCacheHandlerTest method test_filterNextValSql_incrementOne_Oracle.
public void test_filterNextValSql_incrementOne_Oracle() {
// ## Arrange ##
SequenceCacheHandler handler = new SequenceCacheHandler();
String sql = "select SEQ_MEMBER.nextval from dual";
ResourceContext context = new ResourceContext();
context.setCurrentDBDef(DBDef.Oracle);
ResourceContext.setResourceContextOnThread(context);
try {
// ## Act ##
String actual = handler.filterNextValSql(54, 1, sql);
// ## Assert ##
log(actual);
assertTrue(actual.contains("nextval"));
assertTrue(actual.contains("select * from dual"));
assertTrue(actual.contains(" union all"));
assertTrue(actual.contains(" join_1"));
assertTrue(actual.contains(" join_2"));
assertFalse(actual.contains(" join_3"));
assertTrue(actual.contains(" rownum <= 54"));
} finally {
ResourceContext.clearResourceContextOnThread();
}
}
use of org.dbflute.bhv.core.context.ResourceContext in project dbflute-core by dbflute.
the class SequenceCacheHandlerTest method test_filterNextValSql_incrementOne_largeSize_plus_Oracle.
public void test_filterNextValSql_incrementOne_largeSize_plus_Oracle() {
// ## Arrange ##
SequenceCacheHandler handler = new SequenceCacheHandler();
String sql = "select SEQ_MEMBER.nextval from dual";
ResourceContext context = new ResourceContext();
context.setCurrentDBDef(DBDef.Oracle);
ResourceContext.setResourceContextOnThread(context);
try {
// ## Act ##
String actual = handler.filterNextValSql(10001, 1, sql);
// ## Assert ##
log(actual);
assertTrue(actual.contains("nextval"));
assertTrue(actual.contains("select * from dual"));
assertTrue(actual.contains(" union all"));
assertTrue(actual.contains(" join_1"));
assertTrue(actual.contains(" join_2"));
assertTrue(actual.contains(" join_3"));
assertTrue(actual.contains(" join_4"));
assertTrue(actual.contains(" join_5"));
assertFalse(actual.contains(" join_6"));
assertEquals(43, DfStringUtil.splitList(actual, "select * from dual").size());
assertTrue(actual.contains(" rownum <= 10001"));
} finally {
ResourceContext.clearResourceContextOnThread();
}
}
use of org.dbflute.bhv.core.context.ResourceContext in project dbflute-core by dbflute.
the class DfTaskControlLogic method initializeDatabaseInfo.
// ===================================================================================
// Prepare Execution
// =================
public void initializeDatabaseInfo() {
_databaseResource.setDriver(getDatabaseProperties().getDatabaseDriver());
_databaseResource.setUrl(getDatabaseProperties().getDatabaseUrl());
_databaseResource.setUser(getDatabaseProperties().getDatabaseUser());
_databaseResource.setMainSchema(getDatabaseProperties().getDatabaseSchema());
_databaseResource.setPassword(getDatabaseProperties().getDatabasePassword());
_databaseResource.setConnectionProperties(getDatabaseProperties().getConnectionProperties());
final ResourceContext context = new ResourceContext();
context.setCurrentDBDef(getBasicProperties().getCurrentDBDef());
// no need to clear because of one thread
ResourceContext.setResourceContextOnThread(context);
}
Aggregations