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

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

Introduction

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

Prototype

AutoMappingBehavior PARTIAL

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

Click Source Link

Document

Will only auto-map results with no nested result mappings defined inside.

Usage

From source file:com.dvdprime.server.mobile.config.MyBatisConfig.java

License:Apache License

/**
 * MyBatis ?  Configuration? ./* w  ww  .j  a va 2  s  .  c  o  m*/
 * 
 * @return
 */
public Configuration getConfig() {
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("master", transactionFactory, getTomcatDataSource());

    logger.info("MyBatis Configuration Initialization.");
    Configuration configuration = new Configuration(environment);
    configuration.setCacheEnabled(true);
    configuration.setLazyLoadingEnabled(false);
    configuration.setAggressiveLazyLoading(false);
    configuration.setUseColumnLabel(true);
    configuration.setUseGeneratedKeys(false);
    configuration.setAutoMappingBehavior(AutoMappingBehavior.PARTIAL);
    configuration.setDefaultExecutorType(ExecutorType.REUSE);
    configuration.setDefaultStatementTimeout(25000);
    configuration.setSafeRowBoundsEnabled(true);

    // Alias Type
    Iterator<String> it = TypeAliasProp.getProperties().keySet().iterator();
    while (it.hasNext()) {
        String key = it.next();
        logger.info("typeAliasRegistry: [{}] -> [{}]", key, TypeAliasProp.getProperties().get(key));
        configuration.getTypeAliasRegistry().registerAlias(key,
                (String) TypeAliasProp.getProperties().get(key));
    }

    // Mapper
    it = MapperProp.getProperties().keySet().iterator();
    while (it.hasNext()) {
        String key = it.next();
        logger.info("mapper loaded: [{}]", MapperProp.getProperties().get(key));
        try {
            InputStream inputStream = Resources
                    .getResourceAsStream((String) MapperProp.getProperties().get(key));
            XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration,
                    (String) MapperProp.getProperties().get(key), configuration.getSqlFragments());
            mapperParser.parse();
        } catch (IOException e) {
            logger.error("mapper parsing   ?.");
        }
    }

    return configuration;
}

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

License:Apache License

@Test
public void get() {
    injector = Guice.createInjector(new AbstractModule() {
        @Override//from  w ww . j  a  v a 2  s  . c om
        protected void configure() {
            bind(Environment.class).toInstance(environment);
            bind(DataSource.class).toInstance(dataSource);
            bind(Configuration.class).toProvider(configurationProvider);
        }
    });

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

    configuration.getMappedStatementNames(); // Test that configuration is valid.
    assertEquals(environment, configuration.getEnvironment());
    assertNull(configuration.getTypeAliasRegistry().getTypeAliases().get("alias"));
    assertFalse(configuration.getTypeHandlerRegistry().hasTypeHandler(Alias.class));
    assertFalse(configuration.getTypeHandlerRegistry().hasTypeHandler(Human.class));
    assertEquals(0, configuration.getMapperRegistry().getMappers().size());
    assertEquals(0, configuration.getInterceptors().size());
    assertFalse(configuration.isLazyLoadingEnabled());
    assertTrue(configuration.isAggressiveLazyLoading());
    assertTrue(configuration.isMultipleResultSetsEnabled());
    assertFalse(configuration.isUseGeneratedKeys());
    assertTrue(configuration.isUseColumnLabel());
    assertTrue(configuration.isCacheEnabled());
    assertEquals(ExecutorType.SIMPLE, configuration.getDefaultExecutorType());
    assertEquals(AutoMappingBehavior.PARTIAL, configuration.getAutoMappingBehavior());
    assertFalse(configuration.isCallSettersOnNulls());
    assertNull(configuration.getDefaultStatementTimeout());
    assertFalse(configuration.isMapUnderscoreToCamelCase());
}

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

License:Apache License

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

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

License:Apache License

@Test
public void autoMappingBehavior_Default() {
    Injector injector = Guice.createInjector(new MyBatisModule() {
        @Override//from w  w  w.j  a v  a  2 s  .c  o m
        protected void initialize() {
            environmentId("test_environment");
            bindDataSourceProvider(dataSourceProvider);
            bindTransactionFactory(transactionFactoryProvider);
        }
    });

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

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