Java Code Examples for org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory

The following examples show how to use org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hmdm-server   Source File: AbstractPersistenceModule.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <p>Initializes this module.</p>
 *
 * <ul>
 *     <li>Binds the constants with names starting with "JDBC" to values set in context</li>
 *     <li>Configures the SQL session factory to use conection pool and JDBC transaction strategy</li>
 *     <li>Sets database connection poll size to 30</li>
 *     <li>Register the mapper classes and aliases for domain objects</li>
 * </ul>
 *
 * <p>The plugin MUST override the {@link #getMapperPackageName()} and {@link #getDomainObjectsPackageName()} to
 * return the package names specific to plugins.</p>
 *
 * @see PooledDataSourceProvider
 * @see JdbcTransactionFactory
 */
protected final void initialize() {
    Enumeration params = this.context.getInitParameterNames();

    while(params.hasMoreElements()) {
        String paramName = params.nextElement().toString();
        if (paramName.startsWith("JDBC") && this.context.getInitParameter(paramName) != null) {
            this.bindConstant().annotatedWith(Names.named(paramName)).to(this.context.getInitParameter(paramName));
        }
    }

    this.bindConstant().annotatedWith(Names.named("mybatis.pooled.maximumActiveConnections")).to(30);
    this.environmentId("production");
    this.bindDataSourceProviderType(PooledDataSourceProvider.class);
    this.bindTransactionFactoryType(JdbcTransactionFactory.class);
    this.addMapperClasses(getMapperPackageName());
    this.addSimpleAliases(getDomainObjectsPackageName());
}
 
Example 2
/**
 * 获取SqlSession
 * @return
 * @throws IOException
 */
public SqlSession getSqlSession() throws IOException, ClassNotFoundException {
    org.apache.ibatis.session.Configuration config = new org.apache.ibatis.session.Configuration();
    config.setCallSettersOnNulls(true); // 设计null调用setter方法
    config.setMapUnderscoreToCamelCase(true);   // 驼峰命名支持

    // 设置mapper
    config.addMappers(targetPackage);
    // 设置数据源,事务
    PooledDataSourceFactory dataSourceFactory = new PooledDataSourceFactory();
    dataSourceFactory.setProperties(DBHelper.properties);
    DataSource dataSource = dataSourceFactory.getDataSource();
    JdbcTransactionFactory transactionFactory = new JdbcTransactionFactory();

    Environment environment = new Environment("test", transactionFactory, dataSource);
    config.setEnvironment(environment);
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
    return sqlSessionFactory.openSession(true);
}
 
Example 3
Source Project: gossip   Source File: GossipDataModule.java    License: MIT License 6 votes vote down vote up
@Override
protected void initialize() {
    initialDatabaseType();

    environmentId("default");
    useGeneratedKeys(true);
    mapUnderscoreToCamelCase(true);

    bindDataSourceProviderType(GossipDataSourceProvider.class);
    bindTransactionFactoryType(JdbcTransactionFactory.class);
    addSimpleAliases("me.yufan.gossip.mybatis.entity");
    addMapperClasses("me.yufan.gossip.mybatis.mapper");
    addTypeHandlerClasses("me.yufan.gossip.mybatis.handler");

    initialService();
}
 
Example 4
Source Project: nexus-public   Source File: MyBatisDataStore.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void doStart(final String storeName, final Map<String, String> attributes) throws Exception {
  boolean isContentStore = !CONFIG_DATASTORE_NAME.equalsIgnoreCase(storeName);

  dataSource = new HikariDataSource(configureHikari(storeName, attributes));
  Environment environment = new Environment(storeName, new JdbcTransactionFactory(), dataSource);
  sessionFactory = new DefaultSqlSessionFactory(configureMyBatis(environment));

  registerCommonTypeHandlers(isContentStore);

  if (beanLocator != null) {
    // register the appropriate type handlers with the store
    beanLocator.watch(TYPE_HANDLER_KEY,
        isContentStore ? CONTENT_TYPE_HANDLER_MEDIATOR : CONFIG_TYPE_HANDLER_MEDIATOR, this);
  }
}
 
Example 5
Source Project: mybaties   Source File: BindingTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws Exception {
  DataSource dataSource = BaseDataTest.createBlogDataSource();
  BaseDataTest.runScript(dataSource, BaseDataTest.BLOG_DDL);
  BaseDataTest.runScript(dataSource, BaseDataTest.BLOG_DATA);
  TransactionFactory transactionFactory = new JdbcTransactionFactory();
  Environment environment = new Environment("Production", transactionFactory, dataSource);
  Configuration configuration = new Configuration(environment);
  configuration.setLazyLoadingEnabled(true);
  configuration.getTypeAliasRegistry().registerAlias(Blog.class);
  configuration.getTypeAliasRegistry().registerAlias(Post.class);
  configuration.getTypeAliasRegistry().registerAlias(Author.class);
  configuration.addMapper(BoundBlogMapper.class);
  configuration.addMapper(BoundAuthorMapper.class);
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
 
Example 6
Source Project: mybaties   Source File: EnumWithOgnlTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testConfiguration() {
    UnpooledDataSourceFactory dataSourceFactory = new UnpooledDataSourceFactory();
    Properties dataSourceProperties = new Properties();
    dataSourceProperties.put("driver", "org.hsqldb.jdbcDriver");
    dataSourceProperties.put("url", "jdbc:hsqldb:mem:xml_references");
    dataSourceProperties.put("username", "sa");
    dataSourceFactory.setProperties(dataSourceProperties);
    Environment environment = new Environment("test", new JdbcTransactionFactory(), dataSourceFactory.getDataSource());
    Configuration configuration = new Configuration();
    configuration.setEnvironment(environment);
    configuration.getTypeAliasRegistry().registerAlias(Person.class);
    configuration.addMapper(PersonMapper.class);
    configuration.addMapper(PersonMapper2.class);
    new DefaultSqlSessionFactory(configuration);
}
 
Example 7
Source Project: mybaties   Source File: ManyAnnoTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetMessageForEmptyDatabase() throws Exception {
  final Environment environment = new Environment("test", new JdbcTransactionFactory(), BaseDataTest.createBlogDataSource());
  final Configuration config = new Configuration(environment);
  config.addMapper(PostMapper.class);
  final SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(config);
  final SqlSession session = factory.openSession();
  
  PostMapper mapper = session.getMapper(PostMapper.class);
  List<AnnoPost> posts = mapper.getPosts(101);


  assertEquals(3,posts.size());
  assertEquals(3,posts.get(0).getTags().size());
  assertEquals(1,posts.get(1).getTags().size());
  assertEquals(0,posts.get(2).getTags().size());

  session.close();

}
 
Example 8
Source Project: mybaties   Source File: SubstitutionInAnnotsTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:annots", "sa", "");
  Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/substitution_in_annots/CreateDB.sql");
  ScriptRunner runner = new ScriptRunner(c);
  runner.setLogWriter(null);
  runner.setErrorLogWriter(null);
  runner.runScript(reader);
  c.commit();
  reader.close();

  Configuration configuration = new Configuration();
  Environment environment = new Environment("test", new JdbcTransactionFactory(), new UnpooledDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:annots", null));
  configuration.setEnvironment(environment);
  
  configuration.addMapper(SubstitutionInAnnotsMapper.class);
  
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
 
Example 9
Source Project: mybaties   Source File: NpeExtendsTest.java    License: Apache License 2.0 6 votes vote down vote up
private SqlSessionFactory getSqlSessionFactoryWithConstructor() {
    UnpooledDataSourceFactory unpooledDataSourceFactory = new UnpooledDataSourceFactory();
    Properties properties = new Properties();
    properties.setProperty("driver", "org.hsqldb.jdbcDriver");
    properties.setProperty("url", "jdbc:hsqldb:mem:extends_with_constructor");
    properties.setProperty("username", "sa");
    unpooledDataSourceFactory.setProperties(properties);
    Environment environment = new Environment("extends_with_constructor", new JdbcTransactionFactory(), unpooledDataSourceFactory.getDataSource());
    
    Configuration configuration = new Configuration();
    configuration.setEnvironment(environment);
    configuration.addMapper(StudentConstructorMapper.class);
    configuration.addMapper(TeacherMapper.class);
    configuration.getMappedStatementNames();
    configuration.setAutoMappingBehavior(AutoMappingBehavior.NONE);
    
    return new DefaultSqlSessionFactory(configuration);
}
 
Example 10
Source Project: live-chat-engine   Source File: BaseDb.java    License: Apache License 2.0 6 votes vote down vote up
public BaseDb(DataSource ds, Props props, String url) {
	
	this.ds = ds;
	this.props = props;
	this.dialect = props.getStrVal(PropKey.db_dialect);
	
	String mappersPackageName = getClass().getPackage().getName();
	
	//mybatis
	TransactionFactory txFactory = new JdbcTransactionFactory();
	Environment environment = new Environment("prod", txFactory, ds);
	Configuration config = new Configuration(environment);
	config.addMappers(mappersPackageName, BaseMapper.class);
	mappers = config.getMapperRegistry().getMappers();
	sessionFactory = new SqlSessionFactoryBuilder().build(config);
	
	universal = new UniversalQueries(ds, props, url);
}
 
Example 11
Source Project: mybatis   Source File: BindingTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws Exception {
  DataSource dataSource = BaseDataTest.createBlogDataSource();
  BaseDataTest.runScript(dataSource, BaseDataTest.BLOG_DDL);
  BaseDataTest.runScript(dataSource, BaseDataTest.BLOG_DATA);
  TransactionFactory transactionFactory = new JdbcTransactionFactory();
  Environment environment = new Environment("Production", transactionFactory, dataSource);
  Configuration configuration = new Configuration(environment);
  configuration.setLazyLoadingEnabled(true);
  configuration.getTypeAliasRegistry().registerAlias(Blog.class);
  configuration.getTypeAliasRegistry().registerAlias(Post.class);
  configuration.getTypeAliasRegistry().registerAlias(Author.class);
  configuration.addMapper(BoundBlogMapper.class);
  configuration.addMapper(BoundAuthorMapper.class);
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
 
Example 12
Source Project: mybatis   Source File: EnumWithOgnlTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testConfiguration() {
    UnpooledDataSourceFactory dataSourceFactory = new UnpooledDataSourceFactory();
    Properties dataSourceProperties = new Properties();
    dataSourceProperties.put("driver", "org.hsqldb.jdbcDriver");
    dataSourceProperties.put("url", "jdbc:hsqldb:mem:xml_references");
    dataSourceProperties.put("username", "sa");
    dataSourceFactory.setProperties(dataSourceProperties);
    Environment environment = new Environment("test", new JdbcTransactionFactory(), dataSourceFactory.getDataSource());
    Configuration configuration = new Configuration();
    configuration.setEnvironment(environment);
    configuration.getTypeAliasRegistry().registerAlias(Person.class);
    configuration.addMapper(PersonMapper.class);
    configuration.addMapper(PersonMapper2.class);
    new DefaultSqlSessionFactory(configuration);
}
 
Example 13
Source Project: mybatis   Source File: ManyAnnoTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetMessageForEmptyDatabase() throws Exception {
  final Environment environment = new Environment("test", new JdbcTransactionFactory(), BaseDataTest.createBlogDataSource());
  final Configuration config = new Configuration(environment);
  config.addMapper(PostMapper.class);
  final SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(config);
  final SqlSession session = factory.openSession();
  
  PostMapper mapper = session.getMapper(PostMapper.class);
  List<AnnoPost> posts = mapper.getPosts(101);


  assertEquals(3,posts.size());
  assertEquals(3,posts.get(0).getTags().size());
  assertEquals(1,posts.get(1).getTags().size());
  assertEquals(0,posts.get(2).getTags().size());

  session.close();

}
 
Example 14
Source Project: mybatis   Source File: SubstitutionInAnnotsTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:annots", "sa", "");
  Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/substitution_in_annots/CreateDB.sql");
  ScriptRunner runner = new ScriptRunner(c);
  runner.setLogWriter(null);
  runner.setErrorLogWriter(null);
  runner.runScript(reader);
  c.commit();
  reader.close();

  Configuration configuration = new Configuration();
  Environment environment = new Environment("test", new JdbcTransactionFactory(), new UnpooledDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:annots", null));
  configuration.setEnvironment(environment);
  
  configuration.addMapper(SubstitutionInAnnotsMapper.class);
  
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
 
Example 15
Source Project: mybatis   Source File: NpeExtendsTest.java    License: Apache License 2.0 6 votes vote down vote up
private SqlSessionFactory getSqlSessionFactoryWithConstructor() {
    UnpooledDataSourceFactory unpooledDataSourceFactory = new UnpooledDataSourceFactory();
    Properties properties = new Properties();
    properties.setProperty("driver", "org.hsqldb.jdbcDriver");
    properties.setProperty("url", "jdbc:hsqldb:mem:extends_with_constructor");
    properties.setProperty("username", "sa");
    unpooledDataSourceFactory.setProperties(properties);
    Environment environment = new Environment("extends_with_constructor", new JdbcTransactionFactory(), unpooledDataSourceFactory.getDataSource());
    
    Configuration configuration = new Configuration();
    configuration.setEnvironment(environment);
    configuration.addMapper(StudentConstructorMapper.class);
    configuration.addMapper(TeacherMapper.class);
    configuration.getMappedStatementNames();
    configuration.setAutoMappingBehavior(AutoMappingBehavior.NONE);
    
    return new DefaultSqlSessionFactory(configuration);
}
 
Example 16
Source Project: seata-samples   Source File: SeataAutoConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * init mybatis sqlSessionFactory
 * @Param: dataSourceProxy  datasource proxy
 * @Return: DataSourceProxy  datasource proxy
 */
@Bean
public SqlSessionFactory sqlSessionFactory(DataSourceProxy dataSourceProxy) throws Exception {
    SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
    factoryBean.setDataSource(dataSourceProxy);
    factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver()
            .getResources("classpath*:/mapper/*.xml"));
    factoryBean.setTransactionFactory(new JdbcTransactionFactory());
    return factoryBean.getObject();
}
 
Example 17
Source Project: seata-samples   Source File: SeataAutoConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * init mybatis sqlSessionFactory
 * @Param: dataSourceProxy  datasource proxy
 * @Return: DataSourceProxy  datasource proxy
 */
@Bean
public SqlSessionFactory sqlSessionFactory(DataSourceProxy dataSourceProxy) throws Exception {
    SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
    factoryBean.setDataSource(dataSourceProxy);
    factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver()
            .getResources("classpath*:/mapper/*.xml"));
    factoryBean.setTransactionFactory(new JdbcTransactionFactory());
    return factoryBean.getObject();
}
 
Example 18
Source Project: demo-seata-springcloud   Source File: SeataAutoConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 初始化mybatis sqlSessionFactory
 * 
 * @param dataSourceProxy
 * @return
 * @throws Exception
 * @author sly
 * @time 2019年6月11日
 */
@Bean
public SqlSessionFactory sqlSessionFactory(DataSourceProxy dataSourceProxy) throws Exception {
	SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
	factoryBean.setDataSource(dataSourceProxy);
	factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml"));
	factoryBean.setTypeAliasesPackage("com.sly.seata.common.model");
	factoryBean.setTransactionFactory(new JdbcTransactionFactory());
	return factoryBean.getObject();
}
 
Example 19
Source Project: demo-seata-springcloud   Source File: SeataAutoConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 初始化mybatis sqlSessionFactory
 * 
 * @param dataSourceProxy
 * @return
 * @throws Exception
 * @author sly
 * @time 2019年6月11日
 */
@Bean
public SqlSessionFactory sqlSessionFactory(DataSourceProxy dataSourceProxy) throws Exception {
	SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
	factoryBean.setDataSource(dataSourceProxy);
	factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml"));
	factoryBean.setTypeAliasesPackage("com.sly.seata.common.model");
	factoryBean.setTransactionFactory(new JdbcTransactionFactory());
	return factoryBean.getObject();
}
 
Example 20
Source Project: demo-seata-springcloud   Source File: SeataAutoConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 初始化mybatis sqlSessionFactory
 * 
 * @param dataSourceProxy
 * @return
 * @throws Exception
 * @author sly
 * @time 2019年6月11日
 */
@Bean
public SqlSessionFactory sqlSessionFactory(DataSourceProxy dataSourceProxy) throws Exception {
	SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
	factoryBean.setDataSource(dataSourceProxy);
	factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml"));
	factoryBean.setTypeAliasesPackage("com.sly.seata.common.model");
	factoryBean.setTransactionFactory(new JdbcTransactionFactory());
	return factoryBean.getObject();
}
 
Example 21
Source Project: SpringMVC-Project   Source File: IDAllocDaoImpl.java    License: MIT License 5 votes vote down vote up
public IDAllocDaoImpl(DataSource dataSource) {
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("development", transactionFactory, dataSource);
    Configuration configuration = new Configuration(environment);
    configuration.addMapper(IDAllocMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
 
Example 22
Source Project: ClosureTableCateogryStore   Source File: Utils.java    License: MIT License 5 votes vote down vote up
public static SqlSession createSqlSession(DataSource dataSource) {
	TransactionFactory transactionFactory = new JdbcTransactionFactory();
	Environment environment = new Environment("test", transactionFactory, dataSource);

	Configuration config = new Configuration();
	config.setCacheEnabled(false);
	config.addMapper(CategoryMapper.class);
	config.setEnvironment(environment);

	SqlSessionFactory sessionFactory = new DefaultSqlSessionFactory(config);
	return sessionFactory.openSession();
}
 
Example 23
Source Project: Leaf   Source File: IDAllocDaoImpl.java    License: Apache License 2.0 5 votes vote down vote up
public IDAllocDaoImpl(DataSource dataSource) {
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("development", transactionFactory, dataSource);
    Configuration configuration = new Configuration(environment);
    configuration.addMapper(IDAllocMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
 
Example 24
Source Project: taskana   Source File: TaskanaEngineImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * creates the MyBatis transaction factory.
 *
 * @param useManagedTransactions true, if managed transations should be used. Otherwise false.
 */
private void createTransactionFactory(boolean useManagedTransactions) {
  if (useManagedTransactions) {
    this.transactionFactory = new ManagedTransactionFactory();
  } else {
    this.transactionFactory = new JdbcTransactionFactory();
  }
}
 
Example 25
Source Project: taskana   Source File: TaskanaHistoryEngineImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * creates the MyBatis transaction factory.
 *
 * @param useManagedTransactions true if TASKANA should use a ManagedTransactionFactory.
 */
private void createTransactionFactory(boolean useManagedTransactions) {
  if (useManagedTransactions) {
    this.transactionFactory = new ManagedTransactionFactory();
  } else {
    this.transactionFactory = new JdbcTransactionFactory();
  }
}
 
Example 26
public static void setupSqlSessionFactory(String initSqlPath) throws Exception {
    DataSource dataSource = BaseDataTest.createUnpooledDataSource("jdbc.properties");
    BaseDataTest.runScript(dataSource, initSqlPath);
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("Production", transactionFactory, dataSource);
    Configuration configuration = new Configuration(environment);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
 
Example 27
Source Project: tephra   Source File: SessionFactoryImpl.java    License: MIT License 5 votes vote down vote up
private SqlSessionFactory create(String key, Mode mode, DataSource dataSource, String[] mappers) {
    Environment environment = new Environment(key + "-" + mode.ordinal(), new JdbcTransactionFactory(), dataSource);
    Configuration configuration = new Configuration(environment);
    for (String mapper : mappers)
        configuration.addMappers(mapper);

    return builder.build(configuration);
}
 
Example 28
Source Project: apollo   Source File: ApolloMyBatisModule.java    License: Apache License 2.0 5 votes vote down vote up
private void init() {
    environmentId("production");

    bind(DataSource.class).toInstance(dataSource);
    bindTransactionFactoryType(JdbcTransactionFactory.class);
    bind(SqlSessionManagerProvider.class);
    bind(EnvironmentProvider.class);
    bind(ConfigurationProvider.class);
    bind(SqlSessionFactoryProvider.class);

    mapUnderscoreToCamelCase(true);
}
 
Example 29
Source Project: Shop-for-JavaWeb   Source File: Configuration.java    License: MIT License 5 votes vote down vote up
public Configuration() {
	typeAliasRegistry.registerAlias("JDBC", JdbcTransactionFactory.class);
	typeAliasRegistry.registerAlias("MANAGED",
			ManagedTransactionFactory.class);

	typeAliasRegistry.registerAlias("JNDI", JndiDataSourceFactory.class);
	typeAliasRegistry
			.registerAlias("POOLED", PooledDataSourceFactory.class);
	typeAliasRegistry.registerAlias("UNPOOLED",
			UnpooledDataSourceFactory.class);

	typeAliasRegistry.registerAlias("PERPETUAL", PerpetualCache.class);
	typeAliasRegistry.registerAlias("FIFO", FifoCache.class);
	typeAliasRegistry.registerAlias("LRU", LruCache.class);
	typeAliasRegistry.registerAlias("SOFT", SoftCache.class);
	typeAliasRegistry.registerAlias("WEAK", WeakCache.class);

	typeAliasRegistry.registerAlias("DB_VENDOR",
			VendorDatabaseIdProvider.class);

	typeAliasRegistry.registerAlias("XML", XMLLanguageDriver.class);
	typeAliasRegistry.registerAlias("RAW", RawLanguageDriver.class);

	typeAliasRegistry.registerAlias("SLF4J", Slf4jImpl.class);
	typeAliasRegistry.registerAlias("COMMONS_LOGGING",
			JakartaCommonsLoggingImpl.class);
	typeAliasRegistry.registerAlias("LOG4J", Log4jImpl.class);
	typeAliasRegistry.registerAlias("LOG4J2", Log4j2Impl.class);
	typeAliasRegistry.registerAlias("JDK_LOGGING", Jdk14LoggingImpl.class);
	typeAliasRegistry.registerAlias("STDOUT_LOGGING", StdOutImpl.class);
	typeAliasRegistry.registerAlias("NO_LOGGING", NoLoggingImpl.class);

	typeAliasRegistry.registerAlias("CGLIB", CglibProxyFactory.class);
	typeAliasRegistry.registerAlias("JAVASSIST",
			JavassistProxyFactory.class);

	languageRegistry.setDefaultDriverClass(XMLLanguageDriver.class);
	languageRegistry.register(RawLanguageDriver.class);
}
 
Example 30
Source Project: mybatis-jackson   Source File: JsonHandlersTestApi.java    License: MIT License 5 votes vote down vote up
protected static SqlSessionFactory setUpDb(DataSource ds, String initSql) throws SQLException, IOException {
    try (final Connection cnx = ds.getConnection(); final Statement st = cnx.createStatement()) {
        st.execute(getResourceAsString(initSql));
    }

    // Init mybatis
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("jneat", transactionFactory, ds);
    Configuration configuration = new Configuration(environment);
    configuration.getTypeHandlerRegistry().register("com.github.jneat.mybatis");
    configuration.addMapper(JsonMapper.class);

    return new SqlSessionFactoryBuilder().build(configuration);
}