Example usage for org.apache.ibatis.session.defaults DefaultSqlSessionFactory DefaultSqlSessionFactory

List of usage examples for org.apache.ibatis.session.defaults DefaultSqlSessionFactory DefaultSqlSessionFactory

Introduction

In this page you can find the example usage for org.apache.ibatis.session.defaults DefaultSqlSessionFactory DefaultSqlSessionFactory.

Prototype

public DefaultSqlSessionFactory(Configuration configuration) 

Source Link

Usage

From source file:com.cetiti.dsp.builder.SqlSessionFactoryBuilder.java

License:Apache License

public SqlSessionFactory build(Configuration config) {
    return new DefaultSqlSessionFactory(config);
}

From source file:com.glaf.activiti.spring.SpringProcessEngineConfigurationBean.java

License:Apache License

@Override
protected void initSqlSessionFactory() {
    logger.info("-------------------------------------------");
    logger.info("-------------initSqlSessionFactory()-------");
    logger.info("sqlSessionFactory:" + sqlSessionFactory);
    logger.info("transactionFactory:" + transactionFactory);
    if (sqlSessionFactory == null) {
        InputStream inputStream = null;
        try {/*from  w  w  w  .  ja v  a 2s .c om*/
            if (configLocation != null) {
                logger.info("mybatis config:" + this.configLocation.getFile().getAbsolutePath());
                inputStream = this.configLocation.getInputStream();
            } else {
                Resource resource = new ClassPathResource("com/glaf/activiti/activiti.mybatis.conf.xml");
                inputStream = resource.getInputStream();
            }

            if (!ObjectUtils.isEmpty(this.mapperLocations)) {
                SAXReader xmlReader = new SAXReader();
                EntityResolver entityResolver = new XMLMapperEntityResolver();
                xmlReader.setEntityResolver(entityResolver);
                Document doc = xmlReader.read(inputStream);
                Element root = doc.getRootElement();
                Element mappers = root.element("mappers");
                if (mappers != null) {
                    java.util.List<?> list = mappers.elements();
                    Collection<String> files = new HashSet<String>();

                    if (list != null && !list.isEmpty()) {
                        Iterator<?> iterator = list.iterator();
                        while (iterator.hasNext()) {
                            Element elem = (Element) iterator.next();
                            if (elem.attributeValue("resource") != null) {
                                String file = elem.attributeValue("resource");
                                files.add(file);
                            } else if (elem.attributeValue("url") != null) {
                                String file = elem.attributeValue("url");
                                files.add(file);
                            }
                        }
                    }

                    for (Resource mapperLocation : this.mapperLocations) {
                        if (mapperLocation == null) {
                            continue;
                        }
                        String url = mapperLocation.getURL().toString();
                        // logger.debug("find mapper:" + url);
                        if (!files.contains(url)) {
                            Element element = mappers.addElement("mapper");
                            element.addAttribute("url", url);
                        }
                    }
                }

                IOUtils.closeStream(inputStream);

                byte[] bytes = Dom4jUtils.getBytesFromPrettyDocument(doc);
                inputStream = new ByteArrayInputStream(bytes);

            }

            // 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("limitBetween",
                        DbSqlSessionFactory.databaseSpecificLimitBetweenStatements.get(databaseType));
                properties.put("orderBy",
                        DbSqlSessionFactory.databaseSpecificOrderByStatements.get(databaseType));
            }
            XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties);
            Configuration configuration = parser.getConfiguration();
            configuration.setEnvironment(environment);
            configuration.getTypeHandlerRegistry().register(VariableType.class, JdbcType.VARCHAR,
                    new IbatisVariableTypeHandler());
            configuration = parser.parse();

            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:com.raise.orgs.impl.cfg.ProcessEngineConfigurationImpl.java

License:Apache License

protected void initSqlSessionFactory() {
    if (sqlSessionFactory == null) {
        InputStream inputStream = null;
        try {/*from w  w w  . ja  v a2 s  . c  om*/
            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("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)));
            }
            XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties);
            Configuration configuration = parser.getConfiguration();
            configuration.setEnvironment(environment);
            configuration.getTypeHandlerRegistry().register(VariableType.class, JdbcType.VARCHAR,
                    new IbatisVariableTypeHandler());

            if (getCustomMybatisMappers() != null) {
                for (Class<?> clazz : getCustomMybatisMappers()) {
                    configuration.addMapper(clazz);
                }
            }

            configuration = parser.parse();

            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:jp.co.ctc_g.jfw.core.jdbc.JxSqlSessionFactoryTest.java

License:Apache License

@Before
public void instantiate() {
    factory = new JxSqlSessionFactory(new DefaultSqlSessionFactory(null));
}

From source file:org.activiti.crystalball.simulator.impl.cfg.SimulationEngineConfigurationImpl.java

License:Apache License

protected void initSqlSessionFactory() {
    if (sqlSessionFactory == null) {
        InputStream inputStream = null;
        try {/* w  w w . j av  a 2  s  . c  om*/
            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",
                        DbSimulatorSqlSessionFactory.databaseSpecificLimitBeforeStatements.get(databaseType));
                properties.put("limitAfter",
                        DbSimulatorSqlSessionFactory.databaseSpecificLimitAfterStatements.get(databaseType));
                properties.put("limitBetween",
                        DbSimulatorSqlSessionFactory.databaseSpecificLimitBetweenStatements.get(databaseType));
                properties.put("orderBy",
                        DbSimulatorSqlSessionFactory.databaseSpecificOrderByStatements.get(databaseType));
            }
            XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties);
            Configuration configuration = parser.getConfiguration();
            configuration.setEnvironment(environment);
            configuration.getTypeHandlerRegistry().register(VariableType.class, JdbcType.VARCHAR,
                    new IbatisVariableTypeHandler());
            configuration = parser.parse();

            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.activiti.engine.AbstractEngineConfiguration.java

License:Apache License

public void initSqlSessionFactory() {
    if (sqlSessionFactory == null) {
        InputStream inputStream = null;
        try {//from  ww w . jav a 2  s  .co m
            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 ActivitiException("Error while building ibatis SqlSessionFactory: " + e.getMessage(), e);
        } finally {
            IoUtil.closeSilently(inputStream);
        }
    }
}

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

License:Apache License

protected void initSqlSessionFactory() {
    if (sqlSessionFactory == null) {
        InputStream inputStream = null;
        try {//w  w w  .  ja va 2s  .  c om
            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("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.activiti.engine.impl.persistence.db.DbSqlSessionFactory.java

License:Apache License

protected SqlSessionFactory createSessionFactory(DataSource dataSource, TransactionFactory transactionFactory) {
    try {/*  www .  ja v  a 2s.c  o m*/
        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 {/*from w w w. j  a  v a  2  s.c  o m*/
        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 {//from   w w w . j  a  va 2  s. 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);

            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);
        }
    }
}