use of org.dbflute.hook.AccessContext.AccessUserProvider 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.AccessUserProvider in project dbflute-core by dbflute.
the class AccessContextTest method test_getValue_whenAccessContextProvider_Tx.
public void test_getValue_whenAccessContextProvider_Tx() throws Exception {
// ## Arrange ##
AccessContext accessContext = new AccessContext();
final String dateExp = "2013-02-02 12:34:56";
accessContext.setAccessDateProvider(new AccessDateProvider() {
public Date provideDate() {
return toDate(dateExp);
}
});
final String timestampExp = "2013-02-02 12:34:56";
accessContext.setAccessTimestampProvider(new AccessTimestampProvider() {
public Timestamp provideTimestamp() {
return toTimestamp(timestampExp);
}
});
accessContext.setAccessUserProvider(new AccessUserProvider() {
public String provideUser() {
return "foo";
}
});
accessContext.setAccessProcessProvider(new AccessProcessProvider() {
public String provideProcess() {
return "bar";
}
});
accessContext.setAccessModuleProvider(new AccessModuleProvider() {
public String provideModule() {
return "qux";
}
});
AccessContext.setAccessContextOnThread(accessContext);
// ## Act & Assert ##
assertNotNull(dateExp, AccessContext.getAccessDateOnThread());
assertNotNull(timestampExp, AccessContext.getAccessTimestampOnThread());
assertEquals("foo", AccessContext.getAccessUserOnThread());
assertEquals("bar", AccessContext.getAccessProcessOnThread());
assertEquals("qux", AccessContext.getAccessModuleOnThread());
}
Aggregations