Search in sources :

Example 56 with Author

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();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) Author(org.apache.ibatis.domain.blog.Author) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 57 with Author

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();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) Author(org.apache.ibatis.domain.blog.Author) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 58 with Author

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();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) Author(org.apache.ibatis.domain.blog.Author) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 59 with Author

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();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) Author(org.apache.ibatis.domain.blog.Author) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 60 with Author

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();
    }
}
Also used : Author(org.apache.ibatis.domain.blog.Author) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Aggregations

Author (org.apache.ibatis.domain.blog.Author)70 Test (org.junit.Test)68 BaseDataTest (org.apache.ibatis.BaseDataTest)45 ImmutableAuthor (org.apache.ibatis.domain.blog.ImmutableAuthor)20 MappedStatement (org.apache.ibatis.mapping.MappedStatement)14 AuthorMapper (org.apache.ibatis.domain.blog.mappers.AuthorMapper)13 DefaultObjectFactory (org.apache.ibatis.reflection.factory.DefaultObjectFactory)13 JdbcTransaction (org.apache.ibatis.transaction.jdbc.JdbcTransaction)12 ArrayList (java.util.ArrayList)8 Configuration (org.apache.ibatis.session.Configuration)7 SqlSession (org.apache.ibatis.session.SqlSession)7 HashMap (java.util.HashMap)4 Blog (org.apache.ibatis.domain.blog.Blog)3 DraftPost (org.apache.ibatis.domain.blog.DraftPost)3 Post (org.apache.ibatis.domain.blog.Post)3 StaticSqlSource (org.apache.ibatis.builder.StaticSqlSource)2 Comment (org.apache.ibatis.domain.blog.Comment)2 Section (org.apache.ibatis.domain.blog.Section)2 Tag (org.apache.ibatis.domain.blog.Tag)2 CglibProxyFactory (org.apache.ibatis.executor.loader.cglib.CglibProxyFactory)2