Example usage for org.apache.ibatis.session AutoMappingBehavior FULL

List of usage examples for org.apache.ibatis.session AutoMappingBehavior FULL

Introduction

In this page you can find the example usage for org.apache.ibatis.session AutoMappingBehavior FULL.

Prototype

AutoMappingBehavior FULL

To view the source code for org.apache.ibatis.session AutoMappingBehavior FULL.

Click Source Link

Document

Will auto-map result mappings of any complexity (containing nested or otherwise).

Usage

From source file:com.ibatis.sqlmap.engine.builder.Ibatis2Configuration.java

License:Apache License

public Ibatis2Configuration() {
    setAutoMappingBehavior(AutoMappingBehavior.FULL);
    setUseGeneratedKeys(false);/*from  ww w .  j a v a  2  s . c  o  m*/
    this.flushCachePlugin = new FlushCacheInterceptor();
    this.addInterceptor(flushCachePlugin);
    this.postSelectKeyMap = new HashMap<String, Boolean>();
    registerDefaultTypeAliases();
}

From source file:org.apache.aurora.scheduler.storage.db.DbModule.java

License:Apache License

@Override
protected void configure() {
    install(new MyBatisModule() {
        @Override//w w w .jav a2 s.co m
        protected void initialize() {
            if (ENABLE_DB_METRICS.get()) {
                addInterceptorClass(InstrumentingInterceptor.class);
            }

            bindProperties(binder(), ImmutableMap.of("JDBC.schema", jdbcSchema));
            install(JdbcHelper.H2_IN_MEMORY_NAMED);

            // We have no plans to take advantage of multiple DB environments. This is a
            // required property though, so we use an unnamed environment.
            environmentId("");

            bindTransactionFactoryType(JdbcTransactionFactory.class);
            bindDataSourceProviderType(PooledDataSourceProvider.class);
            addMapperClasses(MAPPER_CLASSES);

            // Full auto-mapping enables population of nested objects with minimal mapper configuration.
            // Docs on settings can be found here:
            // http://mybatis.github.io/mybatis-3/configuration.html#settings
            autoMappingBehavior(AutoMappingBehavior.FULL);

            addTypeHandlersClasses(TypeHandlers.getAll());

            bind(new TypeLiteral<Amount<Long, Time>>() {
            }).toInstance(SLOW_QUERY_LOG_THRESHOLD.get());

            // Enable a ping query which will prevent the use of invalid connections in the
            // connection pool.
            bindProperties(binder(), ImmutableMap.of("mybatis.pooled.pingEnabled", "true"));
            bindProperties(binder(), ImmutableMap.of("mybatis.pooled.pingQuery", "SELECT 1;"));

            if (MYBATIS_MAX_ACTIVE_CONNECTION_COUNT.hasAppliedValue()) {
                String val = MYBATIS_MAX_ACTIVE_CONNECTION_COUNT.get().toString();
                bindProperties(binder(), ImmutableMap.of("mybatis.pooled.maximumActiveConnections", val));
            }

            if (MYBATIS_MAX_IDLE_CONNECTION_COUNT.hasAppliedValue()) {
                String val = MYBATIS_MAX_IDLE_CONNECTION_COUNT.get().toString();
                bindProperties(binder(), ImmutableMap.of("mybatis.pooled.maximumIdleConnections", val));
            }

            // Exposed for unit tests.
            bind(TaskConfigManager.class);
            expose(TaskConfigManager.class);

            // TODO(wfarner): Don't expose these bindings once the task store is directly bound here.
            expose(TaskMapper.class);
            expose(TaskConfigManager.class);
            expose(JobKeyMapper.class);
        }
    });
    install(taskStoresModule);
    expose(keyFactory.create(CronJobStore.Mutable.class));
    expose(keyFactory.create(TaskStore.Mutable.class));

    bindStore(AttributeStore.Mutable.class, DbAttributeStore.class);
    bindStore(LockStore.Mutable.class, DbLockStore.class);
    bindStore(QuotaStore.Mutable.class, DbQuotaStore.class);
    bindStore(SchedulerStore.Mutable.class, DbSchedulerStore.class);
    bindStore(JobUpdateStore.Mutable.class, DbJobUpdateStore.class);

    Key<Storage> storageKey = keyFactory.create(Storage.class);
    bind(storageKey).to(DbStorage.class);
    bind(DbStorage.class).in(Singleton.class);
    expose(storageKey);

    bind(EnumBackfill.class).to(EnumBackfill.EnumBackfillImpl.class);
    bind(EnumBackfill.EnumBackfillImpl.class).in(Singleton.class);
    expose(EnumBackfill.class);

    expose(DbStorage.class);
    expose(SqlSessionFactory.class);
    expose(TaskMapper.class);
    expose(TaskConfigMapper.class);
    expose(JobKeyMapper.class);
}

From source file:org.mybatis.guice.configuration.ConfigurationProviderTest.java

License:Apache License

@Test
public void get_Optionals() throws Throwable {
    String databaseId = "test_database_id";
    final Integer defaultFetchSize = 200;
    final Integer defaultStatementTimeout = 2000;
    when(databaseIdProvider.getDatabaseId(dataSource)).thenReturn(databaseId);
    final Key<TypeHandler<Alias>> aliasTypeHandlerKey = Key.get(new TypeLiteral<TypeHandler<Alias>>() {
    });//from w w  w  .  j ava  2  s.  c  om
    injector = Guice.createInjector(new AbstractModule() {
        @Override
        protected void configure() {
            bind(Environment.class).toInstance(environment);
            bind(DataSource.class).toInstance(dataSource);
            bindConstant().annotatedWith(Names.named("mybatis.configuration.lazyLoadingEnabled")).to(true);
            bindConstant().annotatedWith(Names.named("mybatis.configuration.aggressiveLazyLoading")).to(false);
            bindConstant().annotatedWith(Names.named("mybatis.configuration.multipleResultSetsEnabled"))
                    .to(false);
            bindConstant().annotatedWith(Names.named("mybatis.configuration.useGeneratedKeys")).to(true);
            bindConstant().annotatedWith(Names.named("mybatis.configuration.useColumnLabel")).to(false);
            bindConstant().annotatedWith(Names.named("mybatis.configuration.cacheEnabled")).to(false);
            bindConstant().annotatedWith(Names.named("mybatis.configuration.defaultExecutorType"))
                    .to(ExecutorType.REUSE);
            bindConstant().annotatedWith(Names.named("mybatis.configuration.autoMappingBehavior"))
                    .to(AutoMappingBehavior.FULL);
            bindConstant().annotatedWith(Names.named("mybatis.configuration.callSettersOnNulls")).to(true);
            bindConstant().annotatedWith(Names.named("mybatis.configuration.defaultStatementTimeout"))
                    .to(defaultStatementTimeout);
            bindConstant().annotatedWith(Names.named("mybatis.configuration.mapUnderscoreToCamelCase"))
                    .to(true);
            bind(DatabaseIdProvider.class).toInstance(databaseIdProvider);
            bind(Configuration.class).toProvider(configurationProvider);
            bind(aliasTypeHandlerKey).toInstance(aliasTypeHandler);
            bind(Interceptor.class).toInstance(interceptor);
        }
    });
    configurationProvider.addConfigurationSetting(new AliasConfigurationSetting("alias", Alias.class));
    JavaTypeAndHandlerConfigurationSettingProvider aliasTypeHandlerSetting = JavaTypeAndHandlerConfigurationSettingProvider
            .create(Alias.class, aliasTypeHandlerKey);
    injector.injectMembers(aliasTypeHandlerSetting);
    configurationProvider.addConfigurationSetting(aliasTypeHandlerSetting.get());
    TypeHandlerConfigurationSettingProvider humanTypeHandlerSetting = new TypeHandlerConfigurationSettingProvider(
            Key.get(HumanTypeHandler.class));
    injector.injectMembers(humanTypeHandlerSetting);
    configurationProvider.addConfigurationSetting(humanTypeHandlerSetting.get());
    configurationProvider.addMapperConfigurationSetting(new MapperConfigurationSetting(TestMapper.class));
    InterceptorConfigurationSettingProvider interceptorSetting = new InterceptorConfigurationSettingProvider(
            Interceptor.class);
    injector.injectMembers(interceptorSetting);
    configurationProvider.addConfigurationSetting(interceptorSetting.get());
    configurationProvider.addConfigurationSetting((new ConfigurationSetting() {
        @Override
        public void applyConfigurationSetting(Configuration configuration) {
            configuration.setDefaultFetchSize(defaultFetchSize);
        }
    }));

    Configuration configuration = injector.getInstance(Configuration.class);

    configuration.getMappedStatementNames(); // Test that configuration is valid.
    assertEquals(environment, configuration.getEnvironment());
    assertEquals(Alias.class, configuration.getTypeAliasRegistry().getTypeAliases().get("alias"));
    assertTrue(configuration.getTypeHandlerRegistry().hasTypeHandler(Alias.class));
    assertTrue(configuration.getTypeHandlerRegistry().hasTypeHandler(Human.class));
    assertEquals(1, configuration.getMapperRegistry().getMappers().size());
    assertTrue(configuration.getMapperRegistry().getMappers().contains(TestMapper.class));
    assertEquals(1, configuration.getInterceptors().size());
    assertTrue(configuration.getInterceptors().contains(interceptor));
    verify(databaseIdProvider).getDatabaseId(dataSource);
    assertEquals(databaseId, configuration.getDatabaseId());
    assertTrue(configuration.isLazyLoadingEnabled());
    assertFalse(configuration.isAggressiveLazyLoading());
    assertFalse(configuration.isMultipleResultSetsEnabled());
    assertTrue(configuration.isUseGeneratedKeys());
    assertFalse(configuration.isUseColumnLabel());
    assertFalse(configuration.isCacheEnabled());
    assertEquals(ExecutorType.REUSE, configuration.getDefaultExecutorType());
    assertEquals(AutoMappingBehavior.FULL, configuration.getAutoMappingBehavior());
    assertTrue(configuration.isCallSettersOnNulls());
    assertEquals(defaultStatementTimeout, configuration.getDefaultStatementTimeout());
    assertTrue(configuration.isMapUnderscoreToCamelCase());
    assertEquals(defaultFetchSize, configuration.getDefaultFetchSize());
}

From source file:org.mybatis.guice.configuration.settings.AutoMappingBehaviorConfigurationSettingTest.java

License:Apache License

@Test
public void applyConfigurationSetting_Full() {
    AutoMappingBehaviorConfigurationSetting setting = new AutoMappingBehaviorConfigurationSetting(
            AutoMappingBehavior.FULL);
    setting.applyConfigurationSetting(configuration);
    verify(configuration).setAutoMappingBehavior(AutoMappingBehavior.FULL);
}

From source file:org.mybatis.guice.MyBatisModuleTest.java

License:Apache License

@Test
public void autoMappingBehavior() {
    Injector injector = Guice.createInjector(new MyBatisModule() {
        @Override//from  w w w . j  a  va 2s  .  co m
        protected void initialize() {
            autoMappingBehavior(AutoMappingBehavior.FULL);
            environmentId("test_environment");
            bindDataSourceProvider(dataSourceProvider);
            bindTransactionFactory(transactionFactoryProvider);
        }
    });

    Configuration configuration = injector.getInstance(Configuration.class);

    assertEquals(AutoMappingBehavior.FULL, configuration.getAutoMappingBehavior());
}