Search in sources :

Example 1 with AccessModuleProvider

use of org.dbflute.hook.AccessContext.AccessModuleProvider 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;
}
Also used : AccessModuleProvider(org.dbflute.hook.AccessContext.AccessModuleProvider) AccessContext(org.dbflute.hook.AccessContext) PreparedAccessContext(org.lastaflute.db.dbflute.accesscontext.PreparedAccessContext) AccessUserProvider(org.dbflute.hook.AccessContext.AccessUserProvider) AccessProcessProvider(org.dbflute.hook.AccessContext.AccessProcessProvider)

Example 2 with AccessModuleProvider

use of org.dbflute.hook.AccessContext.AccessModuleProvider 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());
}
Also used : AccessTimestampProvider(org.dbflute.hook.AccessContext.AccessTimestampProvider) AccessModuleProvider(org.dbflute.hook.AccessContext.AccessModuleProvider) AccessDateProvider(org.dbflute.hook.AccessContext.AccessDateProvider) AccessUserProvider(org.dbflute.hook.AccessContext.AccessUserProvider) AccessProcessProvider(org.dbflute.hook.AccessContext.AccessProcessProvider) Timestamp(java.sql.Timestamp) Date(java.util.Date) LocalDate(java.time.LocalDate)

Aggregations

AccessModuleProvider (org.dbflute.hook.AccessContext.AccessModuleProvider)2 AccessProcessProvider (org.dbflute.hook.AccessContext.AccessProcessProvider)2 AccessUserProvider (org.dbflute.hook.AccessContext.AccessUserProvider)2 Timestamp (java.sql.Timestamp)1 LocalDate (java.time.LocalDate)1 Date (java.util.Date)1 AccessContext (org.dbflute.hook.AccessContext)1 AccessDateProvider (org.dbflute.hook.AccessContext.AccessDateProvider)1 AccessTimestampProvider (org.dbflute.hook.AccessContext.AccessTimestampProvider)1 PreparedAccessContext (org.lastaflute.db.dbflute.accesscontext.PreparedAccessContext)1