List of usage examples for org.apache.ibatis.session SqlSession getMapper
<T> T getMapper(Class<T> type);
From source file:com.quancheng.mybatis.mapper.test.example.TestSelectCountByExample.java
License:Open Source License
@Test public void testSelectCountByExample3() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try {/* ww w . j a v a 2s . c om*/ CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); CountryExample example = new CountryExample(); example.createCriteria().andCountrynameLike("A%"); example.or().andIdGreaterThan(100); example.setDistinct(true); int count = mapper.selectCountByExample(example); // Assert.assertEquals(true, count > 83); } finally { sqlSession.close(); } }
From source file:com.quancheng.mybatis.mapper.test.example.TestUpdateByExample.java
License:Open Source License
@Test public void testUpdateByExample() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try {//from www .ja v a 2 s . c om CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Example example = new Example(Country.class); example.createCriteria().andEqualTo("id", 35); Country country = new Country(); //country.setDynamicTableName123("country_123"); country.setCountryname("?"); country.setId(1000); int count = mapper.updateByExample(country, example); Assert.assertEquals(1, count); example = new Example(Country.class); example.createCriteria().andIsNull("countrycode"); count = mapper.selectCountByExample(example); Assert.assertEquals(1, count); } finally { sqlSession.rollback(); sqlSession.close(); } }
From source file:com.quancheng.mybatis.mapper.test.example.TestUpdateByExample.java
License:Open Source License
@Test public void testUpdateByExample2() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try {/*w w w . j av a 2 s. com*/ 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(); } }
From source file:com.quancheng.mybatis.mapper.test.example.TestUpdateByExampleSelective.java
License:Open Source License
@Test public void testUpdateByExampleSelective() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try {// w w w. ja v a 2s . c om CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Example example = new Example(Country.class); example.createCriteria().andGreaterThan("id", 100); Country country = new Country(); country.setCountryname("?"); int count = mapper.updateByExampleSelective(country, example); Assert.assertEquals(83, count); example = new Example(Country.class); example.createCriteria().andEqualTo("countryname", "?"); count = mapper.selectCountByExample(example); Assert.assertEquals(83, count); } finally { sqlSession.rollback(); sqlSession.close(); } }
From source file:com.quancheng.mybatis.mapper.test.example.TestUpdateByExampleSelective.java
License:Open Source License
@Test public void testUpdateByExampleSelective2() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try {//from w w w . j a v a 2s . c om CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Example example = new Example(Country.class); example.createCriteria().andLike("countryname", "A%"); example.or().andGreaterThan("id", 100); example.setDistinct(true); Country country = new Country(); country.setCountryname("?"); int count = mapper.updateByExampleSelective(country, example); Assert.assertEquals(true, count > 83); example = new Example(Country.class); example.createCriteria().andEqualTo("countryname", "?"); count = mapper.selectCountByExample(example); Assert.assertEquals(true, count > 83); } finally { sqlSession.rollback(); sqlSession.close(); } }
From source file:com.quancheng.mybatis.mapper.test.example.TestUpdateByExampleSelective.java
License:Open Source License
@Test public void testUpdateByExampleSelective3() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try {//from w w w.j a v a2s . com CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); CountryExample example = new CountryExample(); example.createCriteria().andCountrynameLike("A%"); example.or().andIdGreaterThan(100); example.setDistinct(true); Country country = new Country(); country.setCountryname("?"); int count = mapper.updateByExampleSelective(country, example); Assert.assertEquals(true, count > 83); example = new CountryExample(); example.createCriteria().andCountrynameEqualTo("?"); count = mapper.selectCountByExample(example); Assert.assertEquals(true, count > 83); } finally { sqlSession.rollback(); sqlSession.close(); } }
From source file:com.quancheng.mybatis.mapper.test.identity.TestIndentity.java
License:Open Source License
/** * ??/*from ww w . j a va 2 s .co m*/ */ @Test public void testINDENTITYInsert() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { CountryIMapper mapper = sqlSession.getMapper(CountryIMapper.class); CountryI country = new CountryI(); country.setCountrycode("CN"); Assert.assertEquals(1, mapper.insert(country)); //ID Assert.assertNotNull(country.getId()); //??,?? Assert.assertEquals(1, mapper.deleteByPrimaryKey(country.getId())); } finally { sqlSession.close(); } }
From source file:com.quancheng.mybatis.mapper.test.identity.TestIndentity.java
License:Open Source License
/** * ??/* w w w. j av a2s .co m*/ */ @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(); } }
From source file:com.quancheng.mybatis.mapper.test.identity.TestIndentity.java
License:Open Source License
/** * ??// w w w . j av a2 s .c o m */ @Test public void testINDENTITYInsertSelective() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { CountryIMapper mapper = sqlSession.getMapper(CountryIMapper.class); CountryI country = new CountryI(); Assert.assertEquals(1, mapper.insertSelective(country)); //ID Assert.assertNotNull(country.getId()); //?,? country = mapper.selectByPrimaryKey(country); //?,?null Assert.assertNotNull(country.getCountrycode()); Assert.assertEquals("HH", country.getCountrycode()); //??,?? Assert.assertEquals(1, mapper.deleteByPrimaryKey(country.getId())); } finally { sqlSession.close(); } }
From source file:com.quancheng.mybatis.mapper.test.identity.TestIndentity.java
License:Open Source License
/** * ??//www . j a va2 s .c o m */ @Test public void testINDENTITYInsertSelective2() { 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.insertSelective(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(); } }