Skip to content

Instantly share code, notes, and snippets.

package com.mirkorossini.transactionaltest;
import com.google.inject.*;
import org.apache.ibatis.session.SqlSessionManager;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
import org.mybatis.guice.MyBatisModule;
import org.mybatis.guice.datasource.builtin.PooledDataSourceProvider;
import org.mybatis.guice.datasource.helper.JdbcHelper;
import org.mybatis.guice.transactional.Transactional;
@Test
public void testBindMapperPrivateModuleExposeSqlSessionManager() {
/**
*/
final Module privateModule = new PrivateModule() {
@Override
protected void configure() {
final Module myBatisModule = new MyBatisModule() {
@Override
protected void initialize() {
@Test
public void testBindMapperPrivateModuleExposedInterfaceExposeSqlSessionManager() {
/**
*/
final Module privateModule = new PrivateModule() {
@Override
protected void configure() {
final Module myBatisModule = new MyBatisModule() {
@Override
protected void initialize() {
@Test
public void testBindMapperPrivateModuleExposedInterface() {
/**
*/
final Module privateModule = new PrivateModule() {
@Override
protected void configure() {
final Module myBatisModule = new MyBatisModule() {
@Override
protected void initialize() {
@Test
public void testBindMapperPrivateModuleExposedService() {
/**
*/
final Module privateModule = new PrivateModule() {
@Override
protected void configure() {
final Module myBatisModule = new MyBatisModule() {
@Override
@Test
public void testBindMapperPrivateModule() {
final Module privateModule = new PrivateModule() {
@Override
protected void configure() {
final Module myBatisModule = new MyBatisModule() {
@Override
protected void initialize() {
environmentId(ENV);
@Test
public void testBindMapperPrivateMethod() {
/**
* Won't work: mybatis doesn't know about the service
*/
final Module myBatisModule = new MyBatisModule() {
@Override
protected void initialize() {
environmentId(ENV);
install(JdbcHelper.H2_EMBEDDED);
@Test
public void testBindMapper() {
final Module myBatisModule = new MyBatisModule() {
@Override
protected void initialize() {
environmentId(ENV);
install(JdbcHelper.H2_EMBEDDED);
bindDataSourceProviderType(PooledDataSourceProvider.class);
bindTransactionFactoryType(JdbcTransactionFactory.class);
addMapperClass(DummyMapper.class);
package com.mirkorossini.transactionaltest.services;
import com.mirkorossini.transactionaltest.mappers.DummyMapper;
import org.apache.ibatis.session.SqlSessionManager;
import org.mybatis.guice.transactional.Transactional;
import javax.inject.Inject;
package com.mirkorossini.transactionaltest.services;
public interface DummyServiceInt {
void insertValue(int value);
}