Example usage for org.apache.ibatis.mapping Environment Environment

List of usage examples for org.apache.ibatis.mapping Environment Environment

Introduction

In this page you can find the example usage for org.apache.ibatis.mapping Environment Environment.

Prototype

public Environment(String id, TransactionFactory transactionFactory, DataSource dataSource) 

Source Link

Usage

From source file:org.activiti.engine.impl.persistence.db.DbSqlSessionFactory.java

License:Apache License

protected SqlSessionFactory createSessionFactory(DataSource dataSource, TransactionFactory transactionFactory) {
    try {/*from  www.  jav a 2s.com*/
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        InputStream inputStream = classLoader
                .getResourceAsStream("org/activiti/db/ibatis/activiti.ibatis.mem.conf.xml");

        // update the jdbc parameters to the configured ones...
        Environment environment = new Environment("default", transactionFactory, dataSource);
        Reader reader = new InputStreamReader(inputStream);
        XMLConfigBuilder parser = new XMLConfigBuilder(reader);
        Configuration configuration = parser.getConfiguration();
        configuration.setEnvironment(environment);
        configuration.getTypeHandlerRegistry().register(Type.class, JdbcType.VARCHAR,
                new IbatisVariableTypeHandler());
        configuration = parser.parse();

        return new DefaultSqlSessionFactory(configuration);

    } catch (Exception e) {
        throw new ActivitiException("Error while building ibatis SqlSessionFactory: " + e.getMessage(), e);
    }
}

From source file:org.activiti.impl.persistence.IbatisPersistenceSessionFactory.java

License:Apache License

private SqlSessionFactory createSessionFactory(DataSource dataSource, TransactionFactory transactionFactory) {
    try {//  w w  w.ja  va  2  s  .com
        initializeDatabaseStatements(databaseName);

        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        InputStream inputStream = classLoader
                .getResourceAsStream("org/activiti/db/ibatis/activiti.ibatis.mem.conf.xml");

        // update the jdbc parameters to the configured ones...
        Environment environment = new Environment("default", transactionFactory, dataSource);
        Reader reader = new InputStreamReader(inputStream);
        XMLConfigBuilder parser = new XMLConfigBuilder(reader);
        Configuration configuration = parser.getConfiguration();
        configuration.setEnvironment(environment);
        configuration.getTypeHandlerRegistry().register(Type.class, JdbcType.VARCHAR,
                new IbatisVariableTypeHandler(variableTypes));
        configuration.setObjectFactory(new ActivitiObjectFactory(variableTypes));
        configuration = parser.parse();

        return new DefaultSqlSessionFactory(configuration);

    } catch (Exception e) {
        throw new ActivitiException("Error while building ibatis SqlSessionFactory: " + e.getMessage(), e);
    }
}

From source file:org.activiti5.engine.impl.cfg.ProcessEngineConfigurationImpl.java

License:Apache License

protected void initSqlSessionFactory() {
    if (sqlSessionFactory == null) {
        InputStream inputStream = null;
        try {// w  w  w.j a  v  a2s. c  o  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);

            String wildcardEscapeClause = "";
            if ((databaseWildcardEscapeCharacter != null) && (databaseWildcardEscapeCharacter.length() != 0)) {
                wildcardEscapeClause = " escape '" + databaseWildcardEscapeCharacter + "'";
            }
            properties.put("wildcardEscapeClause", wildcardEscapeClause);

            if (databaseType != null) {
                properties.put("limitBefore",
                        DbSqlSessionFactory.databaseSpecificLimitBeforeStatements.get(databaseType));
                properties.put("limitAfter",
                        DbSqlSessionFactory.databaseSpecificLimitAfterStatements.get(databaseType));
                properties.put("limitBetween",
                        DbSqlSessionFactory.databaseSpecificLimitBetweenStatements.get(databaseType));
                properties.put("limitOuterJoinBetween",
                        DbSqlSessionFactory.databaseOuterJoinLimitBetweenStatements.get(databaseType));
                properties.put("orderBy",
                        DbSqlSessionFactory.databaseSpecificOrderByStatements.get(databaseType));
                properties.put("limitBeforeNativeQuery",
                        ObjectUtils
                                .toString(DbSqlSessionFactory.databaseSpecificLimitBeforeNativeQueryStatements
                                        .get(databaseType)));
            }

            Configuration configuration = initMybatisConfiguration(environment, reader, properties);
            sqlSessionFactory = new DefaultSqlSessionFactory(configuration);

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

From source file:org.alfresco.ibatis.HierarchicalSqlSessionFactoryBean.java

License:Open Source License

/**
 * Build a {@code SqlSessionFactory} instance.
 * <p/>//from w ww.  ja v a 2 s. co  m
 * The default implementation uses the standard MyBatis {@code XMLConfigBuilder} API to build a
 * {@code SqlSessionFactory} instance based on an Reader.
 *
 * @return SqlSessionFactory
 * @throws IOException if loading the config file failed
 */
protected SqlSessionFactory buildSqlSessionFactory() throws IOException {

    Configuration configuration;

    HierarchicalXMLConfigBuilder xmlConfigBuilder = null;
    if (this.configLocation != null) {
        try {
            xmlConfigBuilder = new HierarchicalXMLConfigBuilder(resourceLoader,
                    this.configLocation.getInputStream(), null, this.configurationProperties);
            configuration = xmlConfigBuilder.getConfiguration();
        } catch (Exception ex) {
            throw new NestedIOException("Failed to parse config resource: " + this.configLocation, ex);
        } finally {
            ErrorContext.instance().reset();
        }
    } else {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("Property 'configLocation' not specified, using default MyBatis Configuration");
        }
        configuration = new Configuration();
        configuration.setVariables(this.configurationProperties);
    }

    if (this.objectFactory != null) {
        configuration.setObjectFactory(this.objectFactory);
    }

    if (this.objectWrapperFactory != null) {
        configuration.setObjectWrapperFactory(this.objectWrapperFactory);
    }

    if (hasLength(this.typeAliasesPackage)) {
        String[] typeAliasPackageArray = tokenizeToStringArray(this.typeAliasesPackage,
                ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
        for (String packageToScan : typeAliasPackageArray) {
            configuration.getTypeAliasRegistry().registerAliases(packageToScan,
                    typeAliasesSuperType == null ? Object.class : typeAliasesSuperType);
            if (this.logger.isDebugEnabled()) {
                this.logger.debug("Scanned package: '" + packageToScan + "' for aliases");
            }
        }
    }

    if (!isEmpty(this.typeAliases)) {
        for (Class<?> typeAlias : this.typeAliases) {
            configuration.getTypeAliasRegistry().registerAlias(typeAlias);
            if (this.logger.isDebugEnabled()) {
                this.logger.debug("Registered type alias: '" + typeAlias + "'");
            }
        }
    }

    if (!isEmpty(this.plugins)) {
        for (Interceptor plugin : this.plugins) {
            configuration.addInterceptor(plugin);
            if (this.logger.isDebugEnabled()) {
                this.logger.debug("Registered plugin: '" + plugin + "'");
            }
        }
    }

    if (hasLength(this.typeHandlersPackage)) {
        String[] typeHandlersPackageArray = tokenizeToStringArray(this.typeHandlersPackage,
                ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
        for (String packageToScan : typeHandlersPackageArray) {
            configuration.getTypeHandlerRegistry().register(packageToScan);
            if (this.logger.isDebugEnabled()) {
                this.logger.debug("Scanned package: '" + packageToScan + "' for type handlers");
            }
        }
    }

    if (!isEmpty(this.typeHandlers)) {
        for (TypeHandler<?> typeHandler : this.typeHandlers) {
            configuration.getTypeHandlerRegistry().register(typeHandler);
            if (this.logger.isDebugEnabled()) {
                this.logger.debug("Registered type handler: '" + typeHandler + "'");
            }
        }
    }

    if (xmlConfigBuilder != null) {
        try {
            xmlConfigBuilder.parse();

            if (this.logger.isDebugEnabled()) {
                this.logger.debug("Parsed configuration file: '" + this.configLocation + "'");
            }
        } catch (Exception ex) {
            throw new NestedIOException("Failed to parse config resource: " + this.configLocation, ex);
        } finally {
            ErrorContext.instance().reset();
        }
    }

    if (this.transactionFactory == null) {
        this.transactionFactory = new SpringManagedTransactionFactory();
    }

    Environment environment = new Environment(this.environment, this.transactionFactory, this.dataSource);
    configuration.setEnvironment(environment);

    //Commented out to be able to use dummy dataSource in tests.
    /*
    if (this.databaseIdProvider != null) {
    try {
        configuration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));
    } catch (SQLException e) {
        throw new NestedIOException("Failed getting a databaseId", e);
    }
    }
    */

    if (!isEmpty(this.mapperLocations)) {
        for (Resource mapperLocation : this.mapperLocations) {
            if (mapperLocation == null) {
                continue;
            }

            try {
                XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(mapperLocation.getInputStream(),
                        configuration, mapperLocation.toString(), configuration.getSqlFragments());
                xmlMapperBuilder.parse();
            } catch (Exception e) {
                throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", e);
            } finally {
                ErrorContext.instance().reset();
            }

            if (this.logger.isDebugEnabled()) {
                this.logger.debug("Parsed mapper file: '" + mapperLocation + "'");
            }
        }
    } else {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug(
                    "Property 'mapperLocations' was not specified, only MyBatis mapper files specified in the config xml were loaded");
        }
    }

    return this.sqlSessionFactoryBuilder.build(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 {/*  ww  w  . ja v  a 2  s.c  o  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.codehaus.griffon.runtime.mybatis.DefaultMybatisFactory.java

License:Apache License

@Nonnull
@SuppressWarnings("ConstantConditions")
private SqlSessionFactory createSqlSessionFactory(@Nonnull Map<String, Object> config,
        @Nonnull String dataSourceName) {
    DataSource dataSource = getDataSource(dataSourceName);
    Environment environment = new Environment(dataSourceName, new JdbcTransactionFactory(), dataSource);
    Configuration configuration = new Configuration(environment);

    Map<String, Object> copyOfConfig = new LinkedHashMap<>(config);
    copyOfConfig.remove("connect_on_startup");
    GriffonClassUtils.setProperties(configuration, copyOfConfig);

    if (mappers.isEmpty()) {
        readMappers();/*from ww  w . j a va2  s .c  o  m*/
    }

    for (Class<?> mapper : mappers) {
        configuration.addMapper(mapper);
    }

    return new RecordingSqlSessionFactory(new SqlSessionFactoryBuilder().build(configuration));
}

From source file:org.danielli.xultimate.orm.mybatis.SqlSessionFactoryBean.java

License:Apache License

/**
 * Build a {@code SqlSessionFactory} instance.
 *
 * The default implementation uses the standard MyBatis {@code XMLConfigBuilder} API to build a
 * {@code SqlSessionFactory} instance based on an Reader.
 *
 * @return SqlSessionFactory/*from w  ww .  ja v  a  2 s. co  m*/
 * @throws IOException if loading the config file failed
 */
protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
    if (this.configuration == null) {
        this.configuration = new Configuration();
    }
    //    Configuration configuration;

    //    XMLConfigBuilder xmlConfigBuilder = null;
    //    if (this.configLocation != null) {
    //      xmlConfigBuilder = new XMLConfigBuilder(this.configLocation.getInputStream(), null, this.configurationProperties);
    //      configuration = xmlConfigBuilder.getConfiguration();
    //    } else {
    //      if (logger.isDebugEnabled()) {
    //        logger.debug("Property 'configLocation' not specified, using default MyBatis Configuration");
    //      }
    //      configuration = new Configuration();
    //      configuration.setVariables(this.configurationProperties);
    //    }

    if (this.objectFactory != null) {
        configuration.setObjectFactory(this.objectFactory);
    }

    if (this.objectWrapperFactory != null) {
        configuration.setObjectWrapperFactory(this.objectWrapperFactory);
    }

    if (hasLength(this.typeAliasesPackage)) {
        String[] typeAliasPackageArray = tokenizeToStringArray(this.typeAliasesPackage,
                ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
        for (String packageToScan : typeAliasPackageArray) {
            configuration.getTypeAliasRegistry().registerAliases(packageToScan,
                    typeAliasesSuperType == null ? Object.class : typeAliasesSuperType);
            if (logger.isDebugEnabled()) {
                logger.debug("Scanned package: '" + packageToScan + "' for aliases");
            }
        }
    }

    if (!isEmpty(this.typeAliases)) {
        for (Class<?> typeAlias : this.typeAliases) {
            configuration.getTypeAliasRegistry().registerAlias(typeAlias);
            if (logger.isDebugEnabled()) {
                logger.debug("Registered type alias: '" + typeAlias + "'");
            }
        }
    }

    if (!isEmpty(this.plugins)) {
        for (Interceptor plugin : this.plugins) {
            configuration.addInterceptor(plugin);
            if (logger.isDebugEnabled()) {
                logger.debug("Registered plugin: '" + plugin + "'");
            }
        }
    }

    if (hasLength(this.typeHandlersPackage)) {
        String[] typeHandlersPackageArray = tokenizeToStringArray(this.typeHandlersPackage,
                ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
        for (String packageToScan : typeHandlersPackageArray) {
            configuration.getTypeHandlerRegistry().register(packageToScan);
            if (logger.isDebugEnabled()) {
                logger.debug("Scanned package: '" + packageToScan + "' for type handlers");
            }
        }
    }

    if (!isEmpty(this.typeHandlers)) {
        for (TypeHandler<?> typeHandler : this.typeHandlers) {
            configuration.getTypeHandlerRegistry().register(typeHandler);
            if (logger.isDebugEnabled()) {
                logger.debug("Registered type handler: '" + typeHandler + "'");
            }
        }
    }

    //    if (xmlConfigBuilder != null) {
    //      try {
    //        xmlConfigBuilder.parse();
    //
    //        if (logger.isDebugEnabled()) {
    //          logger.debug("Parsed configuration file: '" + this.configLocation + "'");
    //        }
    //      } catch (Exception ex) {
    //        throw new NestedIOException("Failed to parse config resource: " + this.configLocation, ex);
    //      } finally {
    //        ErrorContext.instance().reset();
    //      }
    //    }

    if (this.transactionFactory == null) {
        this.transactionFactory = new SpringManagedTransactionFactory();
    }

    Environment environment = new Environment(this.environment, this.transactionFactory, this.dataSource);
    configuration.setEnvironment(environment);

    if (this.databaseIdProvider != null) {
        try {
            configuration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));
        } catch (SQLException e) {
            throw new NestedIOException("Failed getting a databaseId", e);
        }
    }

    if (!isEmpty(this.mapperLocations)) {
        for (Resource mapperLocation : this.mapperLocations) {
            if (mapperLocation == null) {
                continue;
            }

            try {
                XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(mapperLocation.getInputStream(),
                        configuration, mapperLocation.toString(), configuration.getSqlFragments());
                xmlMapperBuilder.parse();
            } catch (Exception e) {
                throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", e);
            } finally {
                ErrorContext.instance().reset();
            }

            if (logger.isDebugEnabled()) {
                logger.debug("Parsed mapper file: '" + mapperLocation + "'");
            }
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Property 'mapperLocations' was not specified or no matching resources found");
        }
    }

    return this.sqlSessionFactoryBuilder.build(configuration);
}

From source file:org.flowable.common.engine.impl.AbstractEngineConfiguration.java

License:Apache License

public void initSqlSessionFactory() {
    if (sqlSessionFactory == null) {
        InputStream inputStream = null;
        try {/*from   w  w  w .  ja v  a2 s. com*/
            inputStream = getMyBatisXmlConfigurationStream();

            Environment environment = new Environment("default", transactionFactory, dataSource);
            Reader reader = new InputStreamReader(inputStream);
            Properties properties = new Properties();
            properties.put("prefix", databaseTablePrefix);

            String wildcardEscapeClause = "";
            if ((databaseWildcardEscapeCharacter != null) && (databaseWildcardEscapeCharacter.length() != 0)) {
                wildcardEscapeClause = " escape '" + databaseWildcardEscapeCharacter + "'";
            }
            properties.put("wildcardEscapeClause", wildcardEscapeClause);

            // set default properties
            properties.put("limitBefore", "");
            properties.put("limitAfter", "");
            properties.put("limitBetween", "");
            properties.put("limitOuterJoinBetween", "");
            properties.put("limitBeforeNativeQuery", "");
            properties.put("blobType", "BLOB");
            properties.put("boolValue", "TRUE");

            if (databaseType != null) {
                properties.load(getResourceAsStream(pathToEngineDbProperties()));
            }

            Configuration configuration = initMybatisConfiguration(environment, reader, properties);
            sqlSessionFactory = new DefaultSqlSessionFactory(configuration);

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

From source file:org.flowable.engine.common.AbstractEngineConfiguration.java

License:Apache License

public void initSqlSessionFactory() {
    if (sqlSessionFactory == null) {
        InputStream inputStream = null;
        try {//from   w  w w .j a v a 2s.c  om
            inputStream = getMyBatisXmlConfigurationStream();

            Environment environment = new Environment("default", transactionFactory, dataSource);
            Reader reader = new InputStreamReader(inputStream);
            Properties properties = new Properties();
            properties.put("prefix", databaseTablePrefix);

            String wildcardEscapeClause = "";
            if ((databaseWildcardEscapeCharacter != null) && (databaseWildcardEscapeCharacter.length() != 0)) {
                wildcardEscapeClause = " escape '" + databaseWildcardEscapeCharacter + "'";
            }
            properties.put("wildcardEscapeClause", wildcardEscapeClause);

            // set default properties
            properties.put("limitBefore", "");
            properties.put("limitAfter", "");
            properties.put("limitBetween", "");
            properties.put("limitOuterJoinBetween", "");
            properties.put("limitBeforeNativeQuery", "");
            properties.put("orderBy", "order by ${orderByColumns}");
            properties.put("blobType", "BLOB");
            properties.put("boolValue", "TRUE");

            if (databaseType != null) {
                properties.load(getResourceAsStream(pathToEngineDbProperties()));
            }

            Configuration configuration = initMybatisConfiguration(environment, reader, properties);
            sqlSessionFactory = new DefaultSqlSessionFactory(configuration);

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

From source file:org.foxbpm.engine.impl.mybatis.MyBatisSqlSessionFactory.java

License:Apache License

public void init(ProcessEngineConfigurationImpl processEngineConfig) throws SQLException {

    DataSource dataSource = processEngineConfig.getDataSource();
    if (dataSource == null) {
        throw ExceptionUtil.getException("00002003");
    }/*from   w ww . ja  v  a 2  s.  com*/
    Connection connection = null;
    String databaseType = null;
    try {
        connection = dataSource.getConnection();
        DatabaseMetaData databaseMetaData = connection.getMetaData();
        String databaseProductName = databaseMetaData.getDatabaseProductName();
        log.debug("database product name: '{}'", databaseProductName);
        databaseType = databaseTypeMappings.getProperty(databaseProductName);
        if (databaseType == null) {
            throw new FoxBPMException(
                    "couldn't deduct database type from database product name '" + databaseProductName + "'");
        }

    } catch (SQLException e) {
        log.error("Exception while initializing Database connection", e);
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            log.error("Exception while closing the Database connection", e);
            throw e;
        }
    }
    if (sqlSessionFactory == null) {
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream("mybatis/mapping/mappings.xml");
            TransactionFactory transactionFactory = new ManagedTransactionFactory();
            Environment environment = new Environment("default", transactionFactory, dataSource);
            Reader reader = new InputStreamReader(inputStream);
            Properties properties = new Properties();
            if (databaseType != null) {
                properties.put("limitBefore", databaseSpecificLimitBeforeStatements.get(databaseType));
                properties.put("limitAfter", databaseSpecificLimitAfterStatements.get(databaseType));
                properties.put("limitBetween", databaseSpecificLimitBetweenStatements.get(databaseType));
                properties.put("limitOuterJoinBetween",
                        databaseOuterJoinLimitBetweenStatements.get(databaseType));
                properties.put("orderBy", databaseSpecificOrderByStatements.get(databaseType));
                properties.put("prefix", processEngineConfig.getPrefix());
            }
            XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties);
            Configuration configuration = parser.getConfiguration();
            configuration.setEnvironment(environment);
            configuration = parser.parse();

            Iterator<FoxbpmMapperConfig> mapperIterator = processEngineConfig.getCustomMapperConfig()
                    .iterator();
            while (mapperIterator.hasNext()) {
                FoxbpmMapperConfig tmpMapper = mapperIterator.next();
                log.debug("?mapperConifg{};", tmpMapper.getClass());
                List<String> mapperPaths = tmpMapper.getMapperConfig();
                if (mapperPaths != null) {
                    for (String mapPath : mapperPaths) {
                        InputStream input = Resources.getResourceAsStream(mapPath);
                        if (input != null) {
                            XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(input, configuration,
                                    mapPath, configuration.getSqlFragments());
                            xmlMapperBuilder.parse();
                            log.debug("?mapper{};", mapPath);
                        } else {
                            log.warn("mapper:" + mapPath + "?;");
                        }
                    }
                }
            }
            sqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        } catch (Exception e) {
            throw new RuntimeException("Error while building ibatis SqlSessionFactory: " + e.getMessage(), e);
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}