Search in sources :

Example 11 with TransactionFactory

use of org.apache.ibatis.transaction.TransactionFactory 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 12 with TransactionFactory

use of org.apache.ibatis.transaction.TransactionFactory in project mybatis-3 by mybatis.

the class XMLConfigBuilder method transactionManagerElement.

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

Example 13 with TransactionFactory

use of org.apache.ibatis.transaction.TransactionFactory in project mybatis-3 by mybatis.

the class ResultLoader method newExecutor.

private Executor newExecutor() {
    final Environment environment = configuration.getEnvironment();
    if (environment == null) {
        throw new ExecutorException("ResultLoader could not load lazily.  Environment was not configured.");
    }
    final DataSource ds = environment.getDataSource();
    if (ds == null) {
        throw new ExecutorException("ResultLoader could not load lazily.  DataSource was not configured.");
    }
    final TransactionFactory transactionFactory = environment.getTransactionFactory();
    final Transaction tx = transactionFactory.newTransaction(ds, null, false);
    return configuration.newExecutor(tx, ExecutorType.SIMPLE);
}
Also used : ExecutorException(org.apache.ibatis.executor.ExecutorException) Transaction(org.apache.ibatis.transaction.Transaction) TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) Environment(org.apache.ibatis.mapping.Environment) DataSource(javax.sql.DataSource)

Example 14 with TransactionFactory

use of org.apache.ibatis.transaction.TransactionFactory in project mybatis-3 by mybatis.

the class AutoMappingUnknownColumnBehaviorTest method setup.

@BeforeAll
static void setup() throws Exception {
    DataSource dataSource = BaseDataTest.createBlogDataSource();
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("Production", transactionFactory, dataSource);
    Configuration configuration = new Configuration(environment);
    configuration.addMapper(Mapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
Also used : TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) Environment(org.apache.ibatis.mapping.Environment) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) DataSource(javax.sql.DataSource) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 15 with TransactionFactory

use of org.apache.ibatis.transaction.TransactionFactory in project pinpoint by naver.

the class SqlSessionTemplateITBase method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    Configuration configuration = mock(Configuration.class);
    TransactionFactory transactionFactory = mock(TransactionFactory.class);
    DataSource dataSource = mock(DataSource.class);
    Environment environment = new Environment("test", transactionFactory, dataSource);
    when(configuration.getEnvironment()).thenReturn(environment);
    when(this.sqlSessionFactory.getConfiguration()).thenReturn(configuration);
    when(this.sqlSessionFactory.openSession(EXECUTOR_TYPE)).thenReturn(this.sqlSessionProxy);
    this.sqlSessionTemplate = new SqlSessionTemplate(this.sqlSessionFactory, EXECUTOR_TYPE);
}
Also used : SqlSessionTemplate(org.mybatis.spring.SqlSessionTemplate) Configuration(org.apache.ibatis.session.Configuration) TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) Environment(org.apache.ibatis.mapping.Environment) DataSource(javax.sql.DataSource) Before(org.junit.Before)

Aggregations

TransactionFactory (org.apache.ibatis.transaction.TransactionFactory)15 Environment (org.apache.ibatis.mapping.Environment)12 DataSource (javax.sql.DataSource)9 JdbcTransactionFactory (org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)7 Configuration (org.apache.ibatis.session.Configuration)6 BeforeAll (org.junit.jupiter.api.BeforeAll)6 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)5 Transaction (org.apache.ibatis.transaction.Transaction)5 Properties (java.util.Properties)3 SQLException (java.sql.SQLException)2 BaseDataTest (org.apache.ibatis.BaseDataTest)2 Executor (org.apache.ibatis.executor.Executor)2 ManagedTransactionFactory (org.apache.ibatis.transaction.managed.ManagedTransactionFactory)2 Test (org.junit.jupiter.api.Test)2 BaseBuilder (org.apache.ibatis.builder.BaseBuilder)1 BuilderException (org.apache.ibatis.builder.BuilderException)1 DataSourceFactory (org.apache.ibatis.datasource.DataSourceFactory)1 ExecutorException (org.apache.ibatis.executor.ExecutorException)1 XNode (org.apache.ibatis.parsing.XNode)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1