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

The following examples show how to use org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory. 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 File: EnumWithOgnlTest.java    From mybaties with 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 #2
Source File: MyBatisDataStore.java    From nexus-public with 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 #3
Source File: GossipDataModule.java    From gossip with 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 File: BindingTest.java    From mybatis with 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 #5
Source File: EnumWithOgnlTest.java    From mybatis with 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 #6
Source File: ManyAnnoTest.java    From mybatis with 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 #7
Source File: SubstitutionInAnnotsTest.java    From mybatis with 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 #8
Source File: MyBatisGeneratorTool.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 获取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 #9
Source File: BindingTest.java    From mybaties with 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 #10
Source File: ManyAnnoTest.java    From mybaties with 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 #11
Source File: SubstitutionInAnnotsTest.java    From mybaties with 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 #12
Source File: BaseDb.java    From live-chat-engine with 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 #13
Source File: NpeExtendsTest.java    From mybaties with 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 #14
Source File: AbstractPersistenceModule.java    From hmdm-server with 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 #15
Source File: NpeExtendsTest.java    From mybatis with 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 File: XmlExternalRefTest.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", "");
  initDb(c);

  Configuration configuration = new Configuration();
  Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource(
      "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null));
  configuration.setEnvironment(environment);

  configuration.addMapper(PersonMapper.class);
  configuration.addMapper(PetMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}
 
Example #17
Source File: ReverseIncludeTest.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", "");
  initDb(c);

  Configuration configuration = new Configuration();
  Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource(
      "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null));
  configuration.setEnvironment(environment);

  configuration.addMapper(ReverseIncludePersonMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}
 
Example #18
Source File: MultipleIncludeTest.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", "");
  initDb(c);

  Configuration configuration = new Configuration();
  Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource(
      "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null));
  configuration.setEnvironment(environment);

  configuration.addMapper(MultipleIncludePersonMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}
 
Example #19
Source File: JsonHandlersTestApi.java    From mybatis-gson with 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);
}
 
Example #20
Source File: MultipleCrossIncludeTest.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", "");
  initDb(c);

  Configuration configuration = new Configuration();
  Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource(
      "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null));
  configuration.setEnvironment(environment);

  configuration.addMapper(MultipleCrossIncludePersonMapper.class);
  configuration.addMapper(MultipleCrossIncludePetMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}
 
Example #21
Source File: TestSuite.java    From mybatis-types with MIT License 5 votes vote down vote up
static synchronized void setupSessionFactoryBuilder(DataSource ds) {
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("jneat", transactionFactory, ds);

    Configuration configuration = new Configuration(environment);
    configuration.getTypeHandlerRegistry().register("com.github.jneat.mybatis");
    configuration.setMapUnderscoreToCamelCase(true);

    // Add Mappers
    configuration.addMapper(TypesMapper.class);
    configuration.addMapper(ArraysMapper.class);
    configuration.addMapper(TimeMapper.class);

    ssf = new SqlSessionFactoryBuilder().build(configuration);
}
 
Example #22
Source File: Configuration.java    From mybatis with Apache License 2.0 5 votes vote down vote up
public Configuration() {
  //注册更多的类型别名,至于为何不直接在TypeAliasRegistry里注册,还需进一步研究
  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 #23
Source File: ResultMapExtendsTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", "");
  initDb(c);

  Configuration configuration = new Configuration();
  Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource(
      "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null));
  configuration.setEnvironment(environment);

  configuration.addMapper(ResultMapReferencePersonMapper.class);
  configuration.addMapper(ResultMapReferencePetMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}
 
Example #24
Source File: MultipleReverseIncludeTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", "");
  initDb(c);

  Configuration configuration = new Configuration();
  Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource(
      "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null));
  configuration.setEnvironment(environment);

  configuration.addMapper(MultipleReverseIncludePersonMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}
 
Example #25
Source File: MultipleCrossIncludeTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", "");
  initDb(c);

  Configuration configuration = new Configuration();
  Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource(
      "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null));
  configuration.setEnvironment(environment);

  configuration.addMapper(MultipleCrossIncludePersonMapper.class);
  configuration.addMapper(MultipleCrossIncludePetMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}
 
Example #26
Source File: ResultMapReferenceTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", "");
  initDb(c);

  Configuration configuration = new Configuration();
  Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource(
      "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null));
  configuration.setEnvironment(environment);

  configuration.addMapper(ResultMapReferencePersonMapper.class);
  configuration.addMapper(ResultMapReferencePetMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}
 
Example #27
Source File: ParameterMapReferenceTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", "");
  initDb(c);

  Configuration configuration = new Configuration();
  Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource(
      "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null));
  configuration.setEnvironment(environment);

  configuration.addMapper(ParameterMapReferencePersonMapper.class);
  configuration.addMapper(ParameterMapReferencePetMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}
 
Example #28
Source File: SameIdTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", "");
  initDb(c);

  Configuration configuration = new Configuration();
  Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource(
      "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null));
  configuration.setEnvironment(environment);

  configuration.addMapper(SameIdPersonMapper.class);
  configuration.addMapper(SameIdPetMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}
 
Example #29
Source File: XmlExternalRefTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", "");
  initDb(c);

  Configuration configuration = new Configuration();
  Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource(
      "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null));
  configuration.setEnvironment(environment);

  configuration.addMapper(PersonMapper.class);
  configuration.addMapper(PetMapper.class);

  return new SqlSessionFactoryBuilder().build(configuration);
}
 
Example #30
Source File: MultipleIncludeTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", "");
  initDb(c);

  Configuration configuration = new Configuration();
  Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource(
      "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null));
  configuration.setEnvironment(environment);

  configuration.addMapper(MultipleIncludePersonMapper.class);

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