use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class NestedQueryCacheTest method testThatNestedQueryItemsAreRetrievedIfNotInCache.
@Test
public void testThatNestedQueryItemsAreRetrievedIfNotInCache() throws Exception {
SqlSession sqlSession = sqlSessionFactory.openSession();
Author author = null;
try {
final BlogMapper blogMapper = sqlSession.getMapper(BlogMapper.class);
author = blogMapper.selectBlog(1).getAuthor();
// ensure that nested author within blog is cached
assertNotNull("blog author", blogMapper.selectBlog(1).getAuthor());
assertNotNull("blog author", blogMapper.selectBlogUsingConstructor(1).getAuthor());
} finally {
sqlSession.close();
}
// open a new session
sqlSession = sqlSessionFactory.openSession();
try {
final AuthorMapper authorMapper = sqlSession.getMapper(AuthorMapper.class);
Author cachedAuthor = authorMapper.selectAuthor(101);
// ensure that nested author within blog is cached
assertThat("blog author", cachedAuthor, sameInstance(author));
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class BindingTest method shouldSelectOneAuthorByConstructor.
@Test
public void shouldSelectOneAuthorByConstructor() {
SqlSession session = sqlSessionFactory.openSession();
try {
BoundAuthorMapper mapper = session.getMapper(BoundAuthorMapper.class);
Author author = mapper.selectAuthorConstructor(101);
assertEquals(101, author.getId());
assertEquals("jim", author.getUsername());
assertEquals("********", author.getPassword());
assertEquals("jim@ibatis.apache.org", author.getEmail());
assertEquals("", author.getBio());
} finally {
session.close();
}
}
use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class BindingTest method shouldInsertAuthorWithSelectKeyAndDynamicParams.
@Test
public void shouldInsertAuthorWithSelectKeyAndDynamicParams() {
SqlSession session = sqlSessionFactory.openSession();
try {
BoundAuthorMapper mapper = session.getMapper(BoundAuthorMapper.class);
Author author = new Author(-1, "cbegin", "******", "cbegin@nowhere.com", "N/A", Section.NEWS);
int rows = mapper.insertAuthorDynamic(author);
assertEquals(1, rows);
// id must be autogenerated
assertFalse(-1 == author.getId());
Author author2 = mapper.selectAuthor(author.getId());
assertNotNull(author2);
assertEquals(author.getEmail(), author2.getEmail());
session.rollback();
} finally {
session.close();
}
}
use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class BindingTest method shouldSelectOneAuthor.
@Test
public void shouldSelectOneAuthor() {
SqlSession session = sqlSessionFactory.openSession();
try {
BoundAuthorMapper mapper = session.getMapper(BoundAuthorMapper.class);
Author author = mapper.selectAuthor(101);
assertEquals(101, author.getId());
assertEquals("jim", author.getUsername());
assertEquals("********", author.getPassword());
assertEquals("jim@ibatis.apache.org", author.getEmail());
assertEquals("", author.getBio());
} finally {
session.close();
}
}
use of org.apache.ibatis.domain.blog.Author in project mybatis-3 by mybatis.
the class AutoMappingUnknownColumnBehaviorTest method none.
@Test
public void none() {
sqlSessionFactory.getConfiguration().setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior.NONE);
SqlSession session = sqlSessionFactory.openSession();
try {
Mapper mapper = session.getMapper(Mapper.class);
Author author = mapper.selectAuthor(101);
assertThat(author.getId(), is(101));
assertThat(author.getUsername(), nullValue());
} finally {
session.close();
}
}
Aggregations