use of org.dbflute.outsidesql.OutsideSqlContext in project dbflute-core by dbflute.
the class BehaviorCommandInvoker method createUnknownInvokeNameResult.
protected BehaviorInvokeNameResult createUnknownInvokeNameResult() {
// basically no way
final String unknownKeyword;
if (OutsideSqlContext.isExistOutsideSqlContextOnThread()) {
// e.g. OutsideSql engine use
final OutsideSqlContext context = OutsideSqlContext.getOutsideSqlContextOnThread();
unknownKeyword = context.getTableDbName();
} else {
unknownKeyword = "Unknown";
}
final String expNoMethodSuffix = unknownKeyword + ".invoke";
return new BehaviorInvokeNameResult(expNoMethodSuffix + "()", expNoMethodSuffix, null, null);
}
use of org.dbflute.outsidesql.OutsideSqlContext in project dbflute-core by dbflute.
the class BehaviorCommandInvoker method logInvocation.
// ===================================================================================
// Log Invocation
// ==============
protected <RESULT> void logInvocation(BehaviorCommand<RESULT> behaviorCommand, boolean saveOnly) {
final StackTraceElement[] stackTrace = new Exception().getStackTrace();
final BehaviorInvokeNameResult behaviorInvokeNameResult = extractBehaviorInvoke(behaviorCommand, stackTrace);
saveBehaviorInvokeName(behaviorInvokeNameResult);
final BehaviorInvokePathResult invokePathResult = buildInvokePath(behaviorCommand, stackTrace, behaviorInvokeNameResult);
if (invokePathResult != null) {
saveClientInvokeName(invokePathResult);
saveByPassInvokeName(invokePathResult);
saveInvokePath(invokePathResult);
}
if (saveOnly) {
// e.g. log level is INFO and invocation path ready
return;
}
final String expNoMethodSuffix = behaviorInvokeNameResult.getInvocationExpNoMethodSuffix();
final String equalBorder = buildFitBorder("", "=", expNoMethodSuffix, false);
final String frameBase = "/=====================================================";
final String spaceBase = " ";
log(frameBase + equalBorder + "==");
log(spaceBase + behaviorInvokeNameResult.getInvocationExp());
log(spaceBase + equalBorder + "=/");
if (invokePathResult != null) {
final String invokePath = invokePathResult.getInvokePath();
if (Srl.is_NotNull_and_NotTrimmedEmpty(invokePath)) {
// just in case
log(invokePath);
}
}
if (behaviorCommand.isOutsideSql() && !behaviorCommand.isProcedure()) {
final OutsideSqlContext outsideSqlContext = getOutsideSqlContext();
if (outsideSqlContext != null) {
log("path: " + behaviorCommand.getOutsideSqlPath());
log("option: " + behaviorCommand.getOutsideSqlOption());
}
}
}
use of org.dbflute.outsidesql.OutsideSqlContext in project dbflute-core by dbflute.
the class BehaviorCommandInvoker method extractBehaviorInvoke.
// -----------------------------------------------------
// Extract BehaviorInvoke
// ----------------------
protected <RESULT> BehaviorInvokeNameResult extractBehaviorInvoke(BehaviorCommand<RESULT> behaviorCommand, StackTraceElement[] stackTrace) {
final DBMeta dbmeta = ResourceContext.provideDBMeta(behaviorCommand.getTableDbName());
if (dbmeta == null) {
// basically no way, only direct invoking
return createUnknownInvokeNameResult();
}
Class<?> outsideSqlResultType = null;
boolean outsideSqlAutoPaging = false;
if (behaviorCommand.isOutsideSql()) {
final OutsideSqlContext outsideSqlContext = getOutsideSqlContext();
outsideSqlResultType = outsideSqlContext.getResultType();
outsideSqlAutoPaging = outsideSqlContext.isAutoPagingLogging();
}
final BehaviorInvokeNameExtractor extractor = createBehaviorInvokeNameExtractor(dbmeta, outsideSqlResultType, outsideSqlAutoPaging);
return extractor.extractBehaviorInvoke(stackTrace);
}
use of org.dbflute.outsidesql.OutsideSqlContext in project dbflute-core by dbflute.
the class OutsideSqlSelectCursorCommand method createOutsideSqlSelectResultSetHandler.
// ===================================================================================
// SqlExecution Handling
// =====================
@Override
protected TnResultSetHandler createOutsideSqlSelectResultSetHandler() {
return new TnResultSetHandler() {
public Object handle(ResultSet rs) throws SQLException {
if (!OutsideSqlContext.isExistOutsideSqlContextOnThread()) {
String msg = "The context of outside SQL should be required here!";
throw new IllegalStateException(msg);
}
OutsideSqlContext context = OutsideSqlContext.getOutsideSqlContextOnThread();
CursorHandler cursorHandler = context.getCursorHandler();
return cursorHandler.handle(rs);
}
};
}
use of org.dbflute.outsidesql.OutsideSqlContext in project dbflute-core by dbflute.
the class ContextStack method restoreAllContextOnThreadIfExists.
public static void restoreAllContextOnThreadIfExists() {
if (!isExistContextStackOnThread()) {
return;
}
final Stack<ContextStack> stackOnThread = getContextStackOnThread();
if (stackOnThread.isEmpty()) {
clearContextStackOnThread();
return;
}
final ContextStack contextStack = stackOnThread.pop();
final ConditionBean cb = contextStack.getConditionBean();
if (cb != null) {
ConditionBeanContext.setConditionBeanOnThread(cb);
}
final EntityRowHandler<? extends Entity> entityRowHandler = contextStack.getEntityRowHandler();
if (entityRowHandler != null) {
ConditionBeanContext.setEntityRowHandlerOnThread(entityRowHandler);
}
final OutsideSqlContext outsideSqlContext = contextStack.getOutsideSqlContext();
if (outsideSqlContext != null) {
OutsideSqlContext.setOutsideSqlContextOnThread(outsideSqlContext);
}
final FetchBean fetchBean = contextStack.getFetchBean();
if (fetchBean != null) {
FetchAssistContext.setFetchBeanOnThread(fetchBean);
}
final Map<String, Object> internalMap = contextStack.getInternalMap();
if (internalMap != null) {
InternalMapContext.clearInternalMapContextOnThread();
final Set<Entry<String, Object>> entrySet = internalMap.entrySet();
for (Entry<String, Object> entry : entrySet) {
InternalMapContext.setObject(entry.getKey(), entry.getValue());
}
}
final ResourceContext resourceContext = contextStack.getResourceContext();
if (resourceContext != null) {
ResourceContext.setResourceContextOnThread(resourceContext);
}
}
Aggregations