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.user.TestUserLogin2.java
License:Open Source License
/** * ??null/*from ww w. j a va2s .co m*/ */ @Test public void testUpdateByPrimaryKeySelective() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { UserLogin2Mapper mapper = sqlSession.getMapper(UserLogin2Mapper.class); UserLogin2Key key = new UserLogin2(); key.setLogid(1); key.setUsername("test1"); UserLogin2 userLogin = mapper.selectByPrimaryKey(key); Assert.assertNotNull(userLogin); userLogin.setLogindate(null); userLogin.setLoginip("1.1.1.1"); //?username Assert.assertEquals(1, mapper.updateByPrimaryKeySelective(userLogin)); userLogin = mapper.selectByPrimaryKey(key); Assert.assertNotNull(userLogin.getLogindate()); Assert.assertEquals("1.1.1.1", userLogin.getLoginip()); } finally { sqlSession.close(); } }
From source file:com.quancheng.mybatis.mapper.test.uuid.TestUUID.java
License:Open Source License
/** * ??//ww w . j ava 2 s. c o m */ @Test public void testUUID() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { CountryUMapper mapper = sqlSession.getMapper(CountryUMapper.class); CountryU country = new CountryU(); country.setId(10086); country.setCountrycode("CN"); Assert.assertEquals(1, mapper.insert(country)); //CN country = new CountryU(); country.setCountrycode("CN"); List<CountryU> list = mapper.select(country); Assert.assertEquals(1, list.size()); Assert.assertNotNull(list.get(0).getCountryname()); //??,?? Assert.assertEquals(1, mapper.deleteByPrimaryKey(10086)); } finally { sqlSession.close(); } }
From source file:com.quancheng.mybatis.mapper.test.uuid.TestUUID.java
License:Open Source License
/** * ??//from w ww. ja v a2s . com */ @Test public void testUUID2() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { CountryUMapper mapper = sqlSession.getMapper(CountryUMapper.class); CountryU country = new CountryU(); country.setId(10086); country.setCountrycode("CN"); country.setCountryname("?"); Assert.assertEquals(1, mapper.insert(country)); //CN country = new CountryU(); country.setCountrycode("CN"); List<CountryU> 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.sinotopia.mybatis.mapper.test.country.TestExistsWithPrimaryKey.java
License:Open Source License
/** * ?PK// w ww . j av a 2s. co m */ @Test public void testDynamicExistsWithPrimaryKey() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Country country = new Country(); country.setId(35); Assert.assertEquals(true, mapper.existsWithPrimaryKey(country)); country.setId(0); Assert.assertEquals(false, mapper.existsWithPrimaryKey(country)); } finally { sqlSession.close(); } }
From source file:com.sinotopia.mybatis.mapper.test.country2.TestInsert.java
License:Open Source License
/** * ??,id?null,/* w w w . j ava2s . c o m*/ */ @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(); } }
From source file:com.sinotopia.mybatis.mapper.test.country2.TestInsertSelective.java
License:Open Source License
/** * ??null/* w ww.j a va2s . c o m*/ */ @Test //(expected = PersistenceException.class) public void testDynamicInsertSelectiveAllByNull() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { Country2Mapper mapper = sqlSession.getMapper(Country2Mapper.class); mapper.insertSelective(null); } finally { sqlSession.close(); } }
From source file:com.sinotopia.mybatis.mapper.test.example.TestSelectByExample.java
License:Open Source License
@Test(expected = Exception.class) public void testSelectByExampleException() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try {/*from www.ja va2s . c om*/ CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Example example = new Example(Country2.class); example.createCriteria().andGreaterThan("id", 100); mapper.selectByExample(example); } finally { sqlSession.close(); } }
From source file:com.sinotopia.mybatis.mapper.test.example.TestSelectByExample.java
License:Open Source License
@Test public void testSelectByExampleForUpdate() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try {/*from w w w .j a va 2s. c o m*/ CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Example example = new Example(Country.class); example.setForUpdate(true); example.createCriteria().andGreaterThan("id", 100).andLessThan("id", 151); example.or().andLessThan("id", 41); List<Country> countries = mapper.selectByExample(example); // Assert.assertEquals(90, countries.size()); } finally { sqlSession.close(); } }
From source file:com.sinotopia.mybatis.mapper.test.example.TestSelectByExample.java
License:Open Source License
@Test public void testExcludeColumnsByExample() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try {/*from ww w . j a v a2 s.c o m*/ CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Example example = new Example(Country.class); example.createCriteria().andGreaterThan("id", 100).andLessThan("id", 151); example.or().andLessThan("id", 41); example.excludeProperties("id"); List<Country> countries = mapper.selectByExample(example); // Assert.assertEquals(90, countries.size()); } finally { sqlSession.close(); } }
From source file:com.sinotopia.mybatis.mapper.test.example.TestSelectByExample.java
License:Open Source License
@Test public void testAndOr() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try {//from ww w.j a va2 s . co m CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Example example = new Example(Country.class); example.createCriteria().andGreaterThan("id", 100).andLessThan("id", 151); example.or().andLessThan("id", 41); List<Country> countries = mapper.selectByExample(example); // Assert.assertEquals(90, countries.size()); //??? example = new Example(Country.class); example.createCriteria(); example.or(); example.and(); countries = mapper.selectByExample(example); // Assert.assertEquals(183, countries.size()); } finally { sqlSession.close(); } }