use of org.dbflute.hook.SqlLogHandler in project lastaflute by lastaflute.
the class SimpleAsyncManager method doInheritCallbackContext.
protected CallbackContext doInheritCallbackContext(ConcurrentAsyncCall call) {
// null allowed
final CallbackContext src = CallbackContext.getCallbackContextOnThread();
if (src == null) {
return null;
}
final CallbackContext dest = newCallbackContext();
final ConcurrentAsyncOption option = call.option();
final ConcurrentAsyncOption defaultOption = defaultConcurrentAsyncOption;
if (isInherit(option.getBehaviorCommandHookType(), defaultOption.getBehaviorCommandHookType())) {
final BehaviorCommandHook hook = src.getBehaviorCommandHook();
if (hook != null) {
dest.setBehaviorCommandHook(hook);
}
}
if (isInherit(option.getSqlFireHookType(), defaultOption.getSqlFireHookType())) {
final SqlFireHook hook = src.getSqlFireHook();
if (hook != null) {
dest.setSqlFireHook(hook);
}
} else {
// as default
dest.setSqlFireHook(createDefaultSqlFireHook(call));
}
if (isInherit(option.getSqlLogHandlerType(), defaultOption.getSqlLogHandlerType())) {
final SqlLogHandler handler = src.getSqlLogHandler();
if (handler != null) {
dest.setSqlLogHandler(handler);
}
}
if (isInherit(option.getSqlResultHandlerType(), defaultOption.getSqlResultHandlerType())) {
final SqlResultHandler handler = src.getSqlResultHandler();
if (handler != null) {
dest.setSqlResultHandler(handler);
}
} else {
dest.setSqlResultHandler(createDefaultSqlResultHandler(call));
}
if (isInherit(option.getSqlStringFilterType(), defaultOption.getSqlStringFilterType())) {
final SqlStringFilter filter = src.getSqlStringFilter();
if (filter != null) {
dest.setSqlStringFilter(filter);
}
} else {
// as default
dest.setSqlStringFilter(createDefaultSqlStringFilter(call));
}
return dest;
}
use of org.dbflute.hook.SqlLogHandler in project dbflute-core by dbflute.
the class TnAbstractBasicSqlHandlerTest method test_logSql_whitebox_sqlLogHandlerOnly.
public void test_logSql_whitebox_sqlLogHandlerOnly() {
// ## Arrange ##
final List<String> markList = new ArrayList<String>();
final Object[] args = new Object[] {};
final Class<?>[] argsTypes = new Class<?>[] {};
TnAbstractBasicSqlHandler handler = new TnAbstractBasicSqlHandler(null, null, "select ...") {
@Override
protected String buildDisplaySql(String sql, Object[] args) {
markList.add("buildDisplaySql");
return "select ...";
}
@Override
protected void logDisplaySql(String displaySql) {
throw new IllegalStateException("log should not be called!");
}
@Override
protected void log(String msg) {
throw new IllegalStateException("log should not be called!");
}
@Override
protected void saveResultSqlLogInfo(SqlLogInfo sqlLogInfo) {
throw new IllegalStateException("log should not be called!");
}
@Override
protected boolean isLogEnabled() {
return false;
}
@Override
protected void assertObjectNotNull(String variableName, Object value) {
// for no check of constructor
}
};
// ## Act ##
try {
CallbackContext callbackContext = new CallbackContext();
callbackContext.setSqlLogHandler(new SqlLogHandler() {
public void handle(SqlLogInfo info) {
markList.add("handle");
assertEquals("select ...", info.getDisplaySql());
assertEquals(newArrayList(args), newArrayList(info.getBindArgs()));
assertEquals(newArrayList(argsTypes), newArrayList(info.getBindArgTypes()));
}
});
CallbackContext.setCallbackContextOnThread(callbackContext);
handler.logSql(args, argsTypes);
assertNull(InternalMapContext.getResultSqlLogInfo());
} finally {
CallbackContext.clearCallbackContextOnThread();
InternalMapContext.clearInternalMapContextOnThread();
}
// ## Assert ##
assertEquals(2, markList.size());
assertEquals("handle", markList.get(0));
assertEquals("buildDisplaySql", markList.get(1));
}
use of org.dbflute.hook.SqlLogHandler in project dbflute-core by dbflute.
the class TnAbstractBasicSqlHandlerTest method test_logSql_whitebox_bigThree.
public void test_logSql_whitebox_bigThree() {
// ## Arrange ##
final List<String> markList = new ArrayList<String>();
final Object[] args = new Object[] {};
final Class<?>[] argsTypes = new Class<?>[] {};
TnAbstractBasicSqlHandler handler = new TnAbstractBasicSqlHandler(null, null, null) {
@Override
protected String buildDisplaySql(String sql, Object[] args) {
markList.add("getDisplaySql");
return "select ..." + ln() + " from ...";
}
@Override
protected void logDisplaySql(String displaySql) {
markList.add("logDisplaySql");
assertEquals("select ..." + ln() + " from ...", displaySql);
super.logDisplaySql(displaySql);
}
@Override
protected void log(String msg) {
markList.add("log");
assertEquals(ln() + "select ..." + ln() + " from ...", msg);
}
@Override
protected void saveResultSqlLogInfo(SqlLogInfo sqlLogInfo) {
markList.add("saveResultSqlLogInfo");
super.saveResultSqlLogInfo(sqlLogInfo);
}
@Override
protected boolean isLogEnabled() {
return true;
}
@Override
protected void assertObjectNotNull(String variableName, Object value) {
// for no check of constructor
}
};
// ## Act ##
try {
CallbackContext callbackContext = new CallbackContext();
callbackContext.setSqlLogHandler(new SqlLogHandler() {
public void handle(SqlLogInfo info) {
markList.add("handle");
assertEquals("select ..." + ln() + " from ...", info.getDisplaySql());
assertEquals(newArrayList(args), newArrayList(info.getBindArgs()));
assertEquals(newArrayList(argsTypes), newArrayList(info.getBindArgTypes()));
}
});
callbackContext.setSqlResultHandler(new SqlResultHandler() {
public void handle(SqlResultInfo sqlResultInfo) {
throw new IllegalStateException("handle should not be called!");
}
});
CallbackContext.setCallbackContextOnThread(callbackContext);
handler.logSql(args, argsTypes);
assertEquals("select ..." + ln() + " from ...", InternalMapContext.getResultSqlLogInfo().getDisplaySql());
} finally {
CallbackContext.clearCallbackContextOnThread();
InternalMapContext.clearInternalMapContextOnThread();
}
// ## Assert ##
assertEquals(5, markList.size());
assertEquals("getDisplaySql", markList.get(0));
assertEquals("logDisplaySql", markList.get(1));
assertEquals("log", markList.get(2));
assertEquals("handle", markList.get(3));
assertEquals("saveResultSqlLogInfo", markList.get(4));
}
Aggregations