use of org.dbflute.hook.AccessContext in project lastaflute by lastaflute.
the class SimpleAsyncManager method createRunnable.
// ===================================================================================
// Create Runnable
// ===============
protected Runnable createRunnable(ConcurrentAsyncCall call, String keyword) {
// in caller thread
final Map<String, Object> threadCacheMap = inheritThreadCacheContext(call);
final AccessContext accessContext = inheritAccessContext(call);
final CallbackContext callbackContext = inheritCallbackContext(call);
final Map<String, Object> variousContextMap = findCallerVariousContextMap();
return () -> {
// in new thread
prepareThreadCacheContext(call, threadCacheMap);
preparePreparedAccessContext(call, accessContext);
prepareCallbackContext(call, callbackContext);
final Object variousPreparedObj = prepareVariousContext(call, variousContextMap);
final long before = showRunning(keyword);
Throwable cause = null;
try {
call.callback();
} catch (Throwable e) {
handleAsyncCallbackException(call, before, e);
cause = e;
} finally {
// should be before clearing because of using them
showFinishing(keyword, before, cause);
clearVariousContext(call, variousContextMap, variousPreparedObj);
clearCallbackContext(call);
clearPreparedAccessContext(call);
clearThreadCacheContext(call);
}
};
}
use of org.dbflute.hook.AccessContext in project lastaflute by lastaflute.
the class SimpleAsyncManager method doInheritAccessContext.
protected AccessContext doInheritAccessContext() {
// null allowed
// null allowed
final AccessContext src = PreparedAccessContext.getAccessContextOnThread();
if (src == null) {
return null;
}
final AccessContext dest = newAccessContext();
dest.setAccessDate(src.getAccessDate());
dest.setAccessDateProvider(src.getAccessDateProvider());
dest.setAccessTimestamp(src.getAccessTimestamp());
dest.setAccessTimestampProvider(src.getAccessTimestampProvider());
dest.setAccessLocalDate(src.getAccessLocalDate());
dest.setAccessLocalDateProvider(src.getAccessLocalDateProvider());
dest.setAccessLocalDateTime(src.getAccessLocalDateTime());
dest.setAccessLocalDateTimeProvider(src.getAccessLocalDateTimeProvider());
final String accessUser = src.getAccessUser();
if (accessUser != null) {
dest.setAccessUser(accessUser);
} else {
final AccessUserProvider accessUserProvider = src.getAccessUserProvider();
if (accessUserProvider != null) {
// fixed
dest.setAccessUser(accessUserProvider.provideUser());
}
}
final String accessProcess = src.getAccessProcess();
if (accessProcess != null) {
dest.setAccessProcess(accessProcess);
} else {
final AccessProcessProvider accessProcessProvider = src.getAccessProcessProvider();
if (accessProcessProvider != null) {
// fixed
dest.setAccessProcess(accessProcessProvider.provideProcess());
}
}
final String accessModule = src.getAccessModule();
if (accessModule != null) {
dest.setAccessModule(accessModule);
} else {
final AccessModuleProvider accessModuleProvider = src.getAccessModuleProvider();
if (accessModuleProvider != null) {
// fixed
dest.setAccessModule(accessModuleProvider.provideModule());
}
}
final Map<String, Object> accessValueMap = src.getAccessValueMap();
if (accessValueMap != null) {
for (Entry<String, Object> entry : accessValueMap.entrySet()) {
dest.registerAccessValue(entry.getKey(), entry.getValue());
}
}
return dest;
}
use of org.dbflute.hook.AccessContext in project dbflute-core by dbflute.
the class EngineTestCase method xprepareAccessContext.
// ===================================================================================
// DBFlute
// =======
// -----------------------------------------------------
// AccessContext
// -------------
protected void xprepareAccessContext() {
final AccessContext context = new AccessContext();
context.setAccessLocalDate(currentLocalDate());
context.setAccessLocalDateTime(currentLocalDateTime());
context.setAccessTimestamp(currentTimestamp());
context.setAccessDate(currentUtilDate());
context.setAccessUser(Thread.currentThread().getName());
context.setAccessProcess(getClass().getSimpleName());
context.setAccessModule(getClass().getSimpleName());
AccessContext.setAccessContextOnThread(context);
}
use of org.dbflute.hook.AccessContext in project dbflute-core by dbflute.
the class RuntimeTestCase method xprepareAccessContext.
protected void xprepareAccessContext() {
final AccessContext context = new AccessContext();
context.setAccessTimestamp(currentTimestamp());
context.setAccessDate(currentDate());
context.setAccessUser(Thread.currentThread().getName());
context.setAccessProcess(getClass().getSimpleName());
AccessContext.setAccessContextOnThread(context);
}
use of org.dbflute.hook.AccessContext in project lastaflute by lastaflute.
the class PreparedAccessContext method endAccessContext.
/**
* End access-context use for DBFlute.
*/
public static void endAccessContext() {
AccessContext.clearAccessContextOnThread();
final AccessContext accessContext = SuspendedAccessContext.getAccessContextOnThread();
if (accessContext != null) {
// resume
AccessContext.setAccessContextOnThread(accessContext);
SuspendedAccessContext.clearAccessContextOnThread();
}
}
Aggregations