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;
}
}
}
}
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.");
}
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);
}
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);
}
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);
}
Aggregations