@Override public List<CountryDetails> retrieveCountries() { try { context.authenticatedUser(); final CountryMapper mapper = new CountryMapper(); final String sql = "select " + mapper.schema(); return this.jdbcTemplate.query(sql, mapper, new Object[] {}); } catch (final EmptyResultDataAccessException e) { return null; } }
@Test public void shouldInsertListAndRetrieveId() throws Exception { Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/keygen/MapperConfig.xml"); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); SqlSession sqlSession = sqlSessionFactory.openSession(); try { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); List<Country> countries = new ArrayList<Country>(); countries.add(new Country("China", "CN")); countries.add(new Country("United Kiongdom", "GB")); countries.add(new Country("United States of America", "US")); mapper.insertList(countries); for (Country country : countries) { assertNotNull(country.getId()); } } finally { sqlSession.rollback(); sqlSession.close(); } }