Example usage for org.apache.ibatis.session SqlSession getMapper

List of usage examples for org.apache.ibatis.session SqlSession getMapper

Introduction

In this page you can find the example usage for org.apache.ibatis.session SqlSession getMapper.

Prototype

<T> T getMapper(Class<T> type);

Source Link

Document

Retrieves a mapper.

Usage

From source file:com.quancheng.mybatis.mapper.test.country.TestUpdateByPrimaryKey.java

License:Open Source License

/**
 * 0//from w ww .java2s .c o  m
 */
@Test
public void testDynamicUpdateByPrimaryKeyAll() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Assert.assertEquals(0, mapper.updateByPrimaryKey(new Country()));
    } finally {
        sqlSession.close();
    }
}

From source file:com.quancheng.mybatis.mapper.test.country.TestUpdateByPrimaryKey.java

License:Open Source License

/**
 * ?null/*from w  ww  .  j a  v  a2s.  c o  m*/
 */
@Test
public void testDynamicUpdateByPrimaryKeyAllByNull() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        mapper.updateByPrimaryKey(null);
    } finally {
        sqlSession.close();
    }
}

From source file:com.quancheng.mybatis.mapper.test.country.TestUpdateByPrimaryKey.java

License:Open Source License

/**
 * ??//from   w  w  w.  j  a v  a  2 s  .c  o  m
 */
@Test
public void testDynamicUpdateByPrimaryKey() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country country = new Country();
        country.setId(174);
        country.setCountryname(null);
        country.setCountryname("");
        Assert.assertEquals(1, mapper.updateByPrimaryKey(country));

        country = mapper.selectByPrimaryKey(174);
        Assert.assertNotNull(country);
        Assert.assertEquals(174, (int) country.getId());
        Assert.assertEquals("", country.getCountryname());
        Assert.assertNull(country.getCountrycode());
    } finally {
        sqlSession.close();
    }
}

From source file:com.quancheng.mybatis.mapper.test.country.TestUpdateByPrimaryKey.java

License:Open Source License

/**
 * ?,?//from  www.  j  ava  2 s.  c o  m
 */
@Test
public void testDynamicUpdateByPrimaryKeyNotFoundKeyProperties() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);

        Assert.assertEquals(0, mapper.updateByPrimaryKey(new Key()));

        Key key = new Key();
        key.setId(174);
        key.setCountrycode("CN");
        key.setCountrytel("+86");
        Assert.assertEquals(1, mapper.updateByPrimaryKey(key));
    } finally {
        sqlSession.close();
    }
}

From source file:com.quancheng.mybatis.mapper.test.country.TestUpdateByPrimaryKeySelective.java

License:Open Source License

/**
 * set0,/*from  w w  w . j  a v  a2 s  . c  o m*/
 */
@Test(expected = Exception.class)
//TODO ?
public void testDynamicUpdateByPrimaryKeySelectiveAll() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        mapper.updateByPrimaryKeySelective(new Country());
    } finally {
        sqlSession.close();
    }
}

From source file:com.quancheng.mybatis.mapper.test.country.TestUpdateByPrimaryKeySelective.java

License:Open Source License

/**
 * ??null/*from ww  w .  ja v  a  2s.  c o  m*/
 */
@Test(expected = RuntimeException.class)
public void testDynamicUpdateByPrimaryKeySelectiveAllByNull() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        mapper.updateByPrimaryKeySelective(null);
    } finally {
        sqlSession.close();
    }
}

From source file:com.quancheng.mybatis.mapper.test.country.TestUpdateByPrimaryKeySelective.java

License:Open Source License

/**
 * ??// w  ww . j a v a 2  s  .  c  o m
 */
@Test
public void testDynamicUpdateByPrimaryKeySelective() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country country = new Country();
        country.setId(173);
        country.setCountryname("");
        Assert.assertEquals(1, mapper.updateByPrimaryKeySelective(country));

        country = mapper.selectByPrimaryKey(173);
        Assert.assertNotNull(country);
        Assert.assertEquals(173, (int) country.getId());
        Assert.assertEquals("", country.getCountryname());
        Assert.assertNotNull(country.getCountrycode());
        Assert.assertEquals("GB", country.getCountrycode());
    } finally {
        sqlSession.close();
    }
}

From source file:com.quancheng.mybatis.mapper.test.country.TestUpdateByPrimaryKeySelective.java

License:Open Source License

/**
 * ?,?/*w  w w.j a  v  a 2 s .  c  o  m*/
 */
@Test
public void testDynamicUpdateByPrimaryKeySelectiveNotFoundKeyProperties() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Key key = new Key();
        key.setId(173);
        key.setCountrycode("CN");
        key.setCountrytel("+86");
        Assert.assertEquals(1, mapper.updateByPrimaryKeySelective(key));
    } finally {
        sqlSession.close();
    }
}

From source file:com.quancheng.mybatis.mapper.test.country2.TestInsert.java

License:Open Source License

/**
 * ??,id?null,/*w w w . j ava 2s. c  om*/
 */
@Test
public void testDynamicInsertAll() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        Country2Mapper mapper = sqlSession.getMapper(Country2Mapper.class);
        Country2 country2 = new Country2();
        country2.setCountrycode("CN");
        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.quancheng.mybatis.mapper.test.country2.TestInsert.java

License:Open Source License

/**
 * ??null/*from   www .j  a  v a 2s.  co  m*/
 */
@Test
public void testDynamicInsertAllByNull() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        Country2Mapper mapper = sqlSession.getMapper(Country2Mapper.class);
        mapper.insert(null);
    } finally {
        sqlSession.close();
    }
}