org.apache.ibatis.session.SqlSession Java Examples

The following examples show how to use org.apache.ibatis.session.SqlSession. 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: ComplexTypeTest.java    From mybaties with Apache License 2.0 10 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  // create a SqlSessionFactory
  Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/complex_type/mybatis-config.xml");
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
  reader.close();

  // populate in-memory database
  SqlSession session = sqlSessionFactory.openSession();
  Connection conn = session.getConnection();
  reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/complex_type/CreateDB.sql");
  ScriptRunner runner = new ScriptRunner(conn);
  runner.setLogWriter(null);
  runner.runScript(reader);
  reader.close();
  session.close();
}
 
Example #2
Source File: NestedResultHandlerAssociationTest.java    From mybatis with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  // create an SqlSessionFactory
  Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler_association/mybatis-config.xml");
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
  reader.close();

  // populate in-memory database
  SqlSession session = sqlSessionFactory.openSession();
  Connection conn = session.getConnection();
  reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler_association/CreateDB.sql");
  ScriptRunner runner = new ScriptRunner(conn);
  runner.setLogWriter(null);
  runner.runScript(reader);
  reader.close();
  session.close();
}
 
Example #3
Source File: SysUserMapperTest.java    From mybatis-action with Apache License 2.0 6 votes vote down vote up
@Test
public void testSelectRolesByUserAndRole() {
    SqlSession sqlSession = getSqlSession();

    try {
        SysUserMapper sysUserMapper = sqlSession.getMapper(SysUserMapper.class);

        SysUser sysUser = new SysUser();
        sysUser.setId(1L);
        SysRole sysRole = new SysRole();
        sysRole.setEnabled(Enabled.enabled);

        List<SysRole> sysRoleList = sysUserMapper.selectRolesByUserAndRole(sysUser, sysRole);

        Assert.assertNotNull(sysRoleList);
        Assert.assertTrue(sysRoleList.size() > 0);
    } finally {
        sqlSession.rollback();
        sqlSession.close();
    }
}
 
Example #4
Source File: HeartBeatActor.java    From Nickle-Scheduler with Apache License 2.0 6 votes vote down vote up
/**
 * 更新执行器时间
 *
 * @param sqlSession
 * @param heatBeatEvent
 */
private void updateExecutorTime(SqlSession sqlSession, HeatBeatEvent heatBeatEvent) {
    //更新主机
    NickleSchedulerExecutorMapper executorMapper = sqlSession.getMapper(NickleSchedulerExecutorMapper.class);
    String ip = heatBeatEvent.getIp();
    Integer port = heatBeatEvent.getPort();
    log.info("更新主机updateTime:{}", heatBeatEvent);
    int count = executorMapper.updateByIpAndPort(heatBeatEvent.getIp(), heatBeatEvent.getPort(), System.currentTimeMillis());
    if (count == 0) {
        log.info("主机已被删除,将再次增加主机");
        //插入主机
        Delegate.insertExecutor(sqlSession, ip, port);
        //插入关联表
        List<String> jobNameList = heatBeatEvent.getJobNameList();
        for (String jobName : jobNameList) {
            Delegate.insertExecutorJob(sqlSession, ip, port, jobName);
        }
    }
    //回复心跳信息
    getSender().tell(HEARTBEAT_OK, getSelf());
}
 
Example #5
Source File: OneopsCmsManager.java    From oneops with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the clazzes.
 *
 * @return the clazzes
 */
public List<CmsClazz> getClazzes() {
	SqlSession session = sqlSessionFactory.openSession();
	List<CmsClazz> clazzes;
	try {
		ClazzMapper mapper = session.getMapper(ClazzMapper.class);
		clazzes = mapper.getClazzes();
		for(CmsClazz clazz : clazzes) {
			clazz.setMdAttributes(mapper.getClazzAttrs(clazz.getClassId()));
			clazz.setFromRelations(mapper.getFromClazzRelations(clazz.getClassId()));
			clazz.setToRelations(mapper.getToClazzRelations(clazz.getClassId()));
		}
	} finally {
		session.close();
	}
	return clazzes;
}
 
Example #6
Source File: DynSqlTest.java    From mybatis with Apache License 2.0 6 votes vote down vote up
@Test
public void testDynamicSelectWithTypeHandler() {
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    List<Name> names = new ArrayList<Name>();

    Name name = new Name();
    name.setFirstName("Fred");
    name.setLastName("Flintstone");
    names.add(name);

    name = new Name();
    name.setFirstName("Barney");
    name.setLastName("Rubble");
    names.add(name);

    Parameter parameter = new Parameter();
    parameter.setNames(names);

    List<Map<String, Object>> answer = sqlSession.selectList("org.apache.ibatis.submitted.dynsql2.dynamicSelectWithTypeHandler", parameter);

    assertTrue(answer.size() == 2);
  } finally {
    sqlSession.close();
  }
}
 
Example #7
Source File: TestTransient.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 插入完整数据
 */
@Test
public void testDynamicInsert() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryTMapper mapper = sqlSession.getMapper(CountryTMapper.class);
        CountryT country = new CountryT();
        country.setId(10086);
        country.setCountrycode("CN");
        country.setCountryname("天朝");
        Assert.assertEquals(1, mapper.insert(country));

        //查询CN结果
        country = new CountryT();
        country.setCountrycode("CN");
        List<CountryT> list = mapper.select(country);

        Assert.assertEquals(2, list.size());
        //屏蔽的数据是null
        Assert.assertNull(list.get(0).getCountrycode());
        //删除插入的数据,以免对其他测试产生影响
        Assert.assertEquals(1, mapper.deleteByPrimaryKey(10086));
    } finally {
        sqlSession.close();
    }
}
 
Example #8
Source File: CustomCollectionHandlingTest.java    From mybatis with Apache License 2.0 6 votes vote down vote up
/**
 * Custom collections with nested resultMap.
 *
 * @throws Exception
 */
@Test
public void testSelectListWithNestedResultMap() throws Exception {
    String xmlConfig = "org/apache/ibatis/submitted/custom_collection_handling/MapperConfig.xml";
    SqlSessionFactory sqlSessionFactory = getSqlSessionFactoryXmlConfig(xmlConfig);
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        List<Person> list = sqlSession.selectList("org.apache.ibatis.submitted.custom_collection_handling.PersonMapper.findWithResultMap");
        assertEquals(2, list.size());
        assertEquals(2, list.get(0).getContacts().size());
        assertEquals(1, list.get(1).getContacts().size());
        assertEquals("3 Wall Street", list.get(0).getContacts().get(1).getAddress());
    } finally {
        sqlSession.close();
    }
}
 
Example #9
Source File: TestUserLogin2.java    From tk-mybatis with MIT License 6 votes vote down vote up
/**
 * 主要测试删除
 */
@Test
public void testDelete() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        UserLogin2Mapper mapper = sqlSession.getMapper(UserLogin2Mapper.class);
        //查询总数
        Assert.assertEquals(10, mapper.selectCount(new UserLogin2()));
        //根据主键查询
        UserLogin2Key key = new UserLogin2();
        key.setLogid(1);
        key.setUsername("test1");
        UserLogin2 userLogin = mapper.selectByPrimaryKey(key);
        //根据主键删除
        Assert.assertEquals(1, mapper.deleteByPrimaryKey(key));

        //查询总数
        Assert.assertEquals(9, mapper.selectCount(new UserLogin2()));
        //插入
        Assert.assertEquals(1, mapper.insert(userLogin));
    } finally {
        sqlSession.close();
    }
}
 
Example #10
Source File: SPTest.java    From mybatis with Apache License 2.0 6 votes vote down vote up
@Test
public void testAdderAsSelectDoubleCall2() {
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Parameter parameter = new Parameter();
    parameter.setAddend1(2);
    parameter.setAddend2(3);

    SPMapper spMapper = sqlSession.getMapper(SPMapper.class);

    spMapper.adderAsSelect(parameter);
    assertEquals((Integer) 5, parameter.getSum());

    parameter = new Parameter();
    parameter.setAddend1(4);
    parameter.setAddend2(5);
    spMapper.adderAsSelect(parameter);
    assertEquals((Integer) 9, parameter.getSum());

  } finally {
    sqlSession.close();
  }
}
 
Example #11
Source File: TestIndentity.java    From tk-mybatis with MIT License 6 votes vote down vote up
/**
 * 插入完整数据
 */
@Test
public void testINDENTITYInsert2() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryIMapper mapper = sqlSession.getMapper(CountryIMapper.class);
        CountryI country = new CountryI();
        country.setId(10086);
        country.setCountrycode("CN");
        country.setCountryname("天朝");
        Assert.assertEquals(1, mapper.insert(country));

        //查询CN结果
        country = new CountryI();
        country.setCountrycode("CN");
        List<CountryI> list = mapper.select(country);

        Assert.assertEquals(1, list.size());
        Assert.assertNotNull(list.get(0).getCountryname());
        Assert.assertEquals("天朝", list.get(0).getCountryname());
        //删除插入的数据,以免对其他测试产生影响
        Assert.assertEquals(1, mapper.deleteByPrimaryKey(10086));
    } finally {
        sqlSession.close();
    }
}
 
Example #12
Source File: NestedResultHandlerTest.java    From mybaties with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  // create a SqlSessionFactory
  Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler/mybatis-config.xml");
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
  reader.close();

  // populate in-memory database
  SqlSession session = sqlSessionFactory.openSession();
  Connection conn = session.getConnection();
  reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler/CreateDB.sql");
  ScriptRunner runner = new ScriptRunner(conn);
  runner.setLogWriter(null);
  runner.runScript(reader);
  reader.close();
  session.close();
}
 
Example #13
Source File: SelectKeyTest.java    From mybaties with Apache License 2.0 6 votes vote down vote up
@Test
public void testAnnotatedUpdateTable2WithSelectKeyWithKeyMap() {
    SqlSession sqlSession = sqlSessionFactory.openSession();

    try {
      Name name = new Name();
      name.setName("barney");
      AnnotatedMapper mapper = sqlSession.getMapper(AnnotatedMapper.class);
      int rows = mapper.insertTable2WithSelectKeyWithKeyMap(name);
      assertEquals(1, rows);
      assertEquals(22, name.getNameId());
      assertEquals("barney_fred", name.getGeneratedName());
      
      name.setName("Wilma");
      rows = mapper.updateTable2WithSelectKeyWithKeyMap(name);
      assertEquals(1, rows);
      assertEquals(22, name.getNameId());
      assertEquals("Wilma_fred", name.getGeneratedName());
    } finally {
      sqlSession.close();
    }
}
 
Example #14
Source File: TestInsert.java    From tk-mybatis with MIT License 6 votes vote down vote up
/**
 * 插入空数据,id不能为null,会报错
 */
@Test
public void testDynamicInsertAll() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        Country2Mapper mapper = sqlSession.getMapper(Country2Mapper.class);
        Country2 country2 = new Country2();
        country2.setCountrycode("CN");
        country2.setId(100);
        Assert.assertEquals(1, mapper.insert(country2));

        country2 = mapper.select(country2).get(0);
        Assert.assertNotNull(country2);

        Assert.assertEquals(1, mapper.deleteByPrimaryKey(country2.getId()));

    } finally {
        sqlSession.close();
    }
}
 
Example #15
Source File: LogicalDeletePluginTest.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 测试 logicalDeleteByPrimaryKey
 */
@Test
public void testLogicalDeleteByPrimaryKey() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator.xml");
    tool.generate(new AbstractShellCallback() {
        @Override
        public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception{
            ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper")));

            // 验证sql
            String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "logicalDeleteByPrimaryKey", 2l);
            Assert.assertEquals(sql, "update tb set del_flag = 1 where id = 2");
            // 验证执行
            Object result = tbMapper.invoke("logicalDeleteByPrimaryKey", 2l);
            Assert.assertEquals(result, 1);
            ResultSet rs = DBHelper.execute(sqlSession.getConnection(), "select del_flag from tb where id = 2");
            rs.first();
            Assert.assertEquals(rs.getInt("del_flag"), 1);
        }
    });
}
 
Example #16
Source File: ForEachTest.java    From mybatis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldHandleComplexNullItem() {
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user1 = new User();
    user1.setId(2);
    user1.setName("User2");
    List<User> users = new ArrayList<User>();
    users.add(user1);
    users.add(null);
    int count = mapper.countByUserList(users);
    Assert.assertEquals(1, count);
  } finally {
    sqlSession.close();
  }
}
 
Example #17
Source File: PrimitivesTest.java    From mybaties with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  // create an SqlSessionFactory
  Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/primitives/mybatis-config.xml");
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
  reader.close();

  // populate in-memory database
  SqlSession session = sqlSessionFactory.openSession();
  Connection conn = session.getConnection();
  reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/primitives/CreateDB.sql");
  ScriptRunner runner = new ScriptRunner(conn);
  runner.setLogWriter(null);
  runner.runScript(reader);
  reader.close();
  session.close();
}
 
Example #18
Source File: VersionTest.java    From Mapper with MIT License 6 votes vote down vote up
@Test
public void testUpdate() {
    SqlSession sqlSession = getSqlSession();
    try {
        UserTimestampMapper mapper = sqlSession.getMapper(UserTimestampMapper.class);
        UserTimestamp user = mapper.selectByPrimaryKey(999);
        assertNotNull(user);
        Timestamp joinDate = user.getJoinDate();
        int count = mapper.updateByPrimaryKey(user);
        assertEquals(1, count);

        user = mapper.selectByPrimaryKey(999);
        assertFalse(joinDate.equals(user.getJoinDate()));
    } finally {
        sqlSession.close();
    }
}
 
Example #19
Source File: TestSelectByPrimaryKey.java    From tk-mybatis with MIT License 6 votes vote down vote up
/**
 * 查询不存在的结果
 */
@Test
public void testDynamicSelectByPrimaryKeyZero() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Assert.assertNull(mapper.selectByPrimaryKey(new Country()));
        Assert.assertNull(mapper.selectByPrimaryKey(new HashMap<String,Object>()));
        Assert.assertNull(mapper.selectByPrimaryKey(-10));
        Assert.assertNull(mapper.selectByPrimaryKey(0));
        Assert.assertNull(mapper.selectByPrimaryKey(1000));
        Assert.assertNull(mapper.selectByPrimaryKey(null));
    } finally {
        sqlSession.close();
    }
}
 
Example #20
Source File: TestUpdateByExample.java    From tk-mybatis with MIT License 6 votes vote down vote up
@Test
public void testUpdateByExample2() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country country = new Country();
        country.setCountryname("天朝");
        country.setId(1000);


        CountryExample example = new CountryExample();
        example.createCriteria().andIdEqualTo(35);
        int count = mapper.updateByExample(country, example);
        Assert.assertEquals(1, count);

        example = new CountryExample();
        example.createCriteria().andCountrycodeIsNull();
        count = mapper.selectCountByExample(example);
        Assert.assertEquals(1, count);
    } finally {
        sqlSession.rollback();
        sqlSession.close();
    }
}
 
Example #21
Source File: TestExists.java    From Mybatis-PageHelper with MIT License 6 votes vote down vote up
/**
 * union的count查询sql特殊
 */
@Test
public void testExists() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    try {
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        List<User> list = userMapper.selectExists();
        assertEquals(101, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(83, ((Page<?>) list).getTotal());

        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(2, 10);
        list = userMapper.selectExists();
        assertEquals(111, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(83, ((Page<?>) list).getTotal());
    } finally {
        sqlSession.close();
    }
}
 
Example #22
Source File: TestTransient.java    From tk-mybatis with MIT License 6 votes vote down vote up
/**
 * 根据查询条件进行查询
 */
@Test
public void testDynamicSelect() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryTMapper mapper = sqlSession.getMapper(CountryTMapper.class);
        CountryT country = new CountryT();
        country.setId(174);
        country.setCountrycode("US");
        List<CountryT> countryList = mapper.select(country);

        Assert.assertEquals(1, countryList.size());
        Assert.assertEquals(true, countryList.get(0).getId() == 174);
        Assert.assertNotNull(countryList.get(0).getCountryname());
        Assert.assertNull(countryList.get(0).getCountrycode());
    } finally {
        sqlSession.close();
    }
}
 
Example #23
Source File: TestExampleBuilder.java    From Mapper with MIT License 6 votes vote down vote up
@Test
public void testDistinct() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Example example = Example.builder(Country.class)
                .distinct()
                .build();
        List<Country> countries = mapper.selectByExample(example);
        Assert.assertEquals(183, countries.size());

        // distinct和order by冲突问题
        Example example0 = Example.builder(Country.class)
                .selectDistinct("id", "countryname").build();
        List<Country> countries0 = mapper.selectByExample(example0);
        Assert.assertEquals(183, countries0.size());
    } finally {
        sqlSession.close();
    }
}
 
Example #24
Source File: OffsetTest.java    From Mybatis-PageHelper with MIT License 6 votes vote down vote up
@Test
public void testOffset() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    try {
        PageHelper.startPage(1, 6);
        List<User> list = userMapper.selectAll();
        assertEquals(6, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());

        PageHelper.offsetPage(6, 20);
        list = userMapper.selectAll();
        PageInfo<User> pageInfo = new PageInfo<User>(list);
        System.out.println(pageInfo.toString());
        assertEquals(2, ((Page<?>) list).getPageNum());
        assertEquals(20, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
    } finally {
        sqlSession.close();
    }
}
 
Example #25
Source File: TestDeleteByPrimaryKey.java    From tk-mybatis with MIT License 6 votes vote down vote up
/**
 * 主要测试删除
 */
@Test
public void testDynamicDelete() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        //查询总数
        Assert.assertEquals(183, mapper.selectCount(new Country()));
        //查询100
        Country country = mapper.selectByPrimaryKey(100);
        //根据主键删除
        Assert.assertEquals(1, mapper.deleteByPrimaryKey(100));
        //查询总数
        Assert.assertEquals(182, mapper.selectCount(new Country()));
        //插入
        Assert.assertEquals(1, mapper.insert(country));
    } finally {
        sqlSession.close();
    }
}
 
Example #26
Source File: ParameterMapReferenceTest.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private void testCrossReference(SqlSessionFactory sqlSessionFactory) throws Exception {
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    ParameterMapReferencePersonMapper personMapper = sqlSession.getMapper(ParameterMapReferencePersonMapper.class);
    Person parameter = new Person();
    parameter.setId(1);
    Person person = personMapper.select(parameter);
    assertEquals((Integer)1, person.getId());

  } finally {
    sqlSession.close();
  }
}
 
Example #27
Source File: SysUserMapperTest.java    From mybatis-action with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteById() {
    SqlSession sqlSession = getSqlSession();

    try {
        SysUserMapper sysUserMapper = sqlSession.getMapper(SysUserMapper.class);
        SysUser sysUser = sysUserMapper.selectById(1L);
        Assert.assertNotNull(sysUser);

        // 这里的返回值result是执行的SQL影响的行数
        int result = sysUserMapper.deleteById(1L);
        // 只删除1条数据
        Assert.assertEquals(1, result);

        Assert.assertNull(sysUserMapper.selectById(1L));

        SysUser sysUser2 = sysUserMapper.selectById(1001L);
        Assert.assertNotNull(sysUser2);

        // 只删除1条数据
        Assert.assertEquals(1, sysUserMapper.deleteBySysUser(sysUser2));

        Assert.assertNull(sysUserMapper.selectById(1001L));
    } finally {
        sqlSession.rollback();
        sqlSession.close();
    }
}
 
Example #28
Source File: InsertGenIdTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testGenIdWithExistsId(){
    SqlSession sqlSession = getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country country = new Country("test", "T");
        country.setId(9999L);
        Assert.assertEquals(1, mapper.insert(country));
        Assert.assertNotNull(country.getId());
        Assert.assertEquals(new Long(9999), country.getId());
        System.out.println(country.getId());
    } finally {
        sqlSession.close();
    }
}
 
Example #29
Source File: MultipleResultSetTest.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private static void runReaderScript(Connection conn, SqlSession session, Reader reader) throws Exception {
  ScriptRunner runner = new ScriptRunner(conn);
  runner.setLogWriter(null);
  runner.setSendFullScript(true);
  runner.setAutoCommit(true);
  runner.setStopOnError(false);
  runner.runScript(reader);
}
 
Example #30
Source File: BindingTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldExecuteBoundSelectOneBlogStatementWithConstructorUsingXMLConfig() {
  SqlSession session = sqlSessionFactory.openSession();
  try {
    BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class);
    Blog blog = mapper.selectBlogByIdUsingConstructor(1);
    assertEquals(1, blog.getId());
    assertEquals("Jim Business", blog.getTitle());
    assertNotNull("author should not be null", blog.getAuthor());
    List<Post> posts = blog.getPosts();
    assertTrue("posts should not be empty", posts != null && !posts.isEmpty());
  } finally {
    session.close();
  }
}