Example usage for org.apache.ibatis.session Configuration setDefaultExecutorType

List of usage examples for org.apache.ibatis.session Configuration setDefaultExecutorType

Introduction

In this page you can find the example usage for org.apache.ibatis.session Configuration setDefaultExecutorType.

Prototype

public void setDefaultExecutorType(ExecutorType defaultExecutorType) 

Source Link

Usage

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

License:Apache License

/**
 * MyBatis ?  Configuration? ./*from w  ww  .  j  a  v a 2s. 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.apache.aurora.scheduler.storage.db.DbStorage.java

License:Apache License

/**
 * Creates the SQL schema during service start-up.
 * Note: This design assumes a volatile database engine.
 *///www . jav a 2s .c om
@Override
@Transactional
protected void startUp() throws IOException {
    Configuration configuration = sessionFactory.getConfiguration();
    String createStatementName = "create_tables";
    configuration.setMapUnderscoreToCamelCase(true);

    // The ReuseExecutor will cache jdbc Statements with equivalent SQL, improving performance
    // slightly when redundant queries are made.
    configuration.setDefaultExecutorType(ExecutorType.REUSE);

    addMappedStatement(configuration, createStatementName, CharStreams.toString(
            new InputStreamReader(DbStorage.class.getResourceAsStream("schema.sql"), StandardCharsets.UTF_8)));

    try (SqlSession session = sessionFactory.openSession()) {
        session.update(createStatementName);
    }

    enumBackfill.backfill();

    createPoolMetrics();
}

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

License:Apache License

@Override
public Configuration get() {
    final Configuration configuration = newConfiguration(environment);
    configuration.setLazyLoadingEnabled(lazyLoadingEnabled);
    configuration.setAggressiveLazyLoading(aggressiveLazyLoading);
    configuration.setMultipleResultSetsEnabled(multipleResultSetsEnabled);
    configuration.setUseGeneratedKeys(useGeneratedKeys);
    configuration.setUseColumnLabel(useColumnLabel);
    configuration.setCacheEnabled(cacheEnabled);
    configuration.setDefaultExecutorType(defaultExecutorType);
    configuration.setAutoMappingBehavior(autoMappingBehavior);
    configuration.setCallSettersOnNulls(callSettersOnNulls);
    configuration.setDefaultStatementTimeout(defaultStatementTimeout);
    configuration.setMapUnderscoreToCamelCase(mapUnderscoreToCamelCase);

    for (ConfigurationSetting setting : configurationSettings) {
        setting.applyConfigurationSetting(configuration);
    }//from  w w w  .  j  a v  a 2  s  .c o m

    try {
        if (databaseIdProvider != null) {
            configuration.setDatabaseId(databaseIdProvider.getDatabaseId(dataSource));
        }

        for (MapperConfigurationSetting setting : mapperConfigurationSettings) {
            setting.applyConfigurationSetting(configuration);
        }

        if (failFast) {
            configuration.getMappedStatementNames();
        }
    } catch (Throwable cause) {
        throw new ProvisionException(
                "An error occurred while building the org.apache.ibatis.session.Configuration", cause);
    } finally {
        ErrorContext.instance().reset();
    }

    return configuration;
}

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

License:Apache License

@Override
public void applyConfigurationSetting(Configuration configuration) {
    configuration.setDefaultExecutorType(executorType);
}