Search in sources :

Example 1 with DataSourceFactory

use of org.apache.ibatis.datasource.DataSourceFactory in project mybatis-3 by mybatis.

the class XMLConfigBuilder method environmentsElement.

private void environmentsElement(XNode context) throws Exception {
    if (context != null) {
        if (environment == null) {
            environment = context.getStringAttribute("default");
        }
        for (XNode child : context.getChildren()) {
            String id = child.getStringAttribute("id");
            if (isSpecifiedEnvironment(id)) {
                TransactionFactory txFactory = transactionManagerElement(child.evalNode("transactionManager"));
                DataSourceFactory dsFactory = dataSourceElement(child.evalNode("dataSource"));
                DataSource dataSource = dsFactory.getDataSource();
                Environment.Builder environmentBuilder = new Environment.Builder(id).transactionFactory(txFactory).dataSource(dataSource);
                configuration.setEnvironment(environmentBuilder.build());
                break;
            }
        }
    }
}
Also used : DataSourceFactory(org.apache.ibatis.datasource.DataSourceFactory) XNode(org.apache.ibatis.parsing.XNode) TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) BaseBuilder(org.apache.ibatis.builder.BaseBuilder) Environment(org.apache.ibatis.mapping.Environment) DataSource(javax.sql.DataSource)

Example 2 with DataSourceFactory

use of org.apache.ibatis.datasource.DataSourceFactory in project mybatis-3 by mybatis.

the class XMLConfigBuilder method dataSourceElement.

private DataSourceFactory dataSourceElement(XNode context) throws Exception {
    if (context != null) {
        String type = context.getStringAttribute("type");
        Properties props = context.getChildrenAsProperties();
        DataSourceFactory factory = (DataSourceFactory) resolveClass(type).getDeclaredConstructor().newInstance();
        factory.setProperties(props);
        return factory;
    }
    throw new BuilderException("Environment declaration requires a DataSourceFactory.");
}
Also used : BuilderException(org.apache.ibatis.builder.BuilderException) DataSourceFactory(org.apache.ibatis.datasource.DataSourceFactory) Properties(java.util.Properties)

Aggregations

DataSourceFactory (org.apache.ibatis.datasource.DataSourceFactory)2 Properties (java.util.Properties)1 DataSource (javax.sql.DataSource)1 BaseBuilder (org.apache.ibatis.builder.BaseBuilder)1 BuilderException (org.apache.ibatis.builder.BuilderException)1 Environment (org.apache.ibatis.mapping.Environment)1 XNode (org.apache.ibatis.parsing.XNode)1 TransactionFactory (org.apache.ibatis.transaction.TransactionFactory)1