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

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

Introduction

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

Prototype

public void setDefaultStatementTimeout(Integer defaultStatementTimeout) 

Source Link

Usage

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

License:Apache License

/**
 * MyBatis ?  Configuration? .//from   w  w w.ja  v a2 s . co  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.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl.java

License:Apache License

protected void initSqlSessionFactory() {
    if (sqlSessionFactory == null) {
        InputStream inputStream = null;
        try {/*from w  w w. jav a  2s .co  m*/
            inputStream = getMyBatisXmlConfigurationSteam();

            // update the jdbc parameters to the configured ones...
            Environment environment = new Environment("default", transactionFactory, dataSource);
            Reader reader = new InputStreamReader(inputStream);
            Properties properties = new Properties();
            properties.put("prefix", databaseTablePrefix);
            if (databaseType != null) {
                properties.put("limitBefore",
                        DbSqlSessionFactory.databaseSpecificLimitBeforeStatements.get(databaseType));
                properties.put("limitAfter",
                        DbSqlSessionFactory.databaseSpecificLimitAfterStatements.get(databaseType));
                properties.put("innerLimitAfter",
                        DbSqlSessionFactory.databaseSpecificInnerLimitAfterStatements.get(databaseType));
                properties.put("limitBetween",
                        DbSqlSessionFactory.databaseSpecificLimitBetweenStatements.get(databaseType));
                properties.put("limitBetweenClob",
                        DbSqlSessionFactory.databaseSpecificLimitBetweenClobStatements.get(databaseType));
                properties.put("orderBy",
                        DbSqlSessionFactory.databaseSpecificOrderByStatements.get(databaseType));
                properties.put("limitBeforeNativeQuery",
                        DbSqlSessionFactory.databaseSpecificLimitBeforeNativeQueryStatements.get(databaseType));

                properties.put("bitand1", DbSqlSessionFactory.databaseSpecificBitAnd1.get(databaseType));
                properties.put("bitand2", DbSqlSessionFactory.databaseSpecificBitAnd2.get(databaseType));
                properties.put("bitand3", DbSqlSessionFactory.databaseSpecificBitAnd3.get(databaseType));

                properties.put("datepart1", DbSqlSessionFactory.databaseSpecificDatepart1.get(databaseType));
                properties.put("datepart2", DbSqlSessionFactory.databaseSpecificDatepart2.get(databaseType));
                properties.put("datepart3", DbSqlSessionFactory.databaseSpecificDatepart3.get(databaseType));

                properties.put("trueConstant",
                        DbSqlSessionFactory.databaseSpecificTrueConstant.get(databaseType));
                properties.put("falseConstant",
                        DbSqlSessionFactory.databaseSpecificFalseConstant.get(databaseType));

                properties.put("dbSpecificDummyTable",
                        DbSqlSessionFactory.databaseSpecificDummyTable.get(databaseType));
                properties.put("dbSpecificIfNullFunction",
                        DbSqlSessionFactory.databaseSpecificIfNull.get(databaseType));

                Map<String, String> constants = DbSqlSessionFactory.dbSpecificConstants.get(databaseType);
                for (Entry<String, String> entry : constants.entrySet()) {
                    properties.put(entry.getKey(), entry.getValue());
                }

            }
            XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties);
            Configuration configuration = parser.getConfiguration();
            configuration.setEnvironment(environment);
            configuration = parser.parse();

            configuration.setDefaultStatementTimeout(jdbcStatementTimeout);

            sqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        } catch (Exception e) {
            throw new ProcessEngineException("Error while building ibatis SqlSessionFactory: " + e.getMessage(),
                    e);
        } finally {
            IoUtil.closeSilently(inputStream);
        }
    }
}

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. ja 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.DefaultStatementTimeoutConfigurationSetting.java

License:Apache License

@Override
public void applyConfigurationSetting(Configuration configuration) {
    configuration.setDefaultStatementTimeout(defaultStatementTimeout);
}