Search in sources :

Example 6 with AuthorMapper

use of org.apache.ibatis.domain.blog.mappers.AuthorMapper in project mybatis-3 by mybatis.

the class SqlSessionTest method shouldExecuteSelectOneAuthorUsingMapperClass.

@Test
public void shouldExecuteSelectOneAuthorUsingMapperClass() {
    SqlSession session = sqlMapper.openSession();
    try {
        AuthorMapper mapper = session.getMapper(AuthorMapper.class);
        Author author = mapper.selectAuthor(101);
        assertEquals(101, author.getId());
    } finally {
        session.close();
    }
}
Also used : AuthorMapper(org.apache.ibatis.domain.blog.mappers.AuthorMapper) ImmutableAuthor(org.apache.ibatis.domain.blog.ImmutableAuthor) Author(org.apache.ibatis.domain.blog.Author) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 7 with AuthorMapper

use of org.apache.ibatis.domain.blog.mappers.AuthorMapper in project mybatis-3 by mybatis.

the class SqlSessionTest method shouldDeleteAuthorUsingMapperClass.

@Test
public void shouldDeleteAuthorUsingMapperClass() throws Exception {
    SqlSession session = sqlMapper.openSession();
    try {
        AuthorMapper mapper = session.getMapper(AuthorMapper.class);
        int count = mapper.deleteAuthor(101);
        assertEquals(1, count);
        assertNull(mapper.selectAuthor(101));
    } finally {
        session.close();
    }
}
Also used : AuthorMapper(org.apache.ibatis.domain.blog.mappers.AuthorMapper) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 8 with AuthorMapper

use of org.apache.ibatis.domain.blog.mappers.AuthorMapper in project mybatis-3 by mybatis.

the class SqlSessionTest method shouldExecuteSelectOneAuthorUsingMapperClassWithResultHandler.

@Test
public void shouldExecuteSelectOneAuthorUsingMapperClassWithResultHandler() {
    SqlSession session = sqlMapper.openSession();
    try {
        DefaultResultHandler handler = new DefaultResultHandler();
        AuthorMapper mapper = session.getMapper(AuthorMapper.class);
        mapper.selectAuthor(101, handler);
        Author author = (Author) handler.getResultList().get(0);
        assertEquals(101, author.getId());
    } finally {
        session.close();
    }
}
Also used : AuthorMapper(org.apache.ibatis.domain.blog.mappers.AuthorMapper) ImmutableAuthor(org.apache.ibatis.domain.blog.ImmutableAuthor) Author(org.apache.ibatis.domain.blog.Author) DefaultResultHandler(org.apache.ibatis.executor.result.DefaultResultHandler) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 9 with AuthorMapper

use of org.apache.ibatis.domain.blog.mappers.AuthorMapper in project mybatis-3 by mybatis.

the class SqlSessionTest method shouldExecuteSelectAllAuthorsUsingMapperClassThatReturnsLinkedList.

@Test
public void shouldExecuteSelectAllAuthorsUsingMapperClassThatReturnsLinkedList() {
    SqlSession session = sqlMapper.openSession();
    try {
        AuthorMapper mapper = session.getMapper(AuthorMapper.class);
        Collection<Author> authors = mapper.selectAllAuthorsLinkedList();
        assertEquals(2, authors.size());
    } finally {
        session.close();
    }
}
Also used : AuthorMapper(org.apache.ibatis.domain.blog.mappers.AuthorMapper) ImmutableAuthor(org.apache.ibatis.domain.blog.ImmutableAuthor) Author(org.apache.ibatis.domain.blog.Author) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 10 with AuthorMapper

use of org.apache.ibatis.domain.blog.mappers.AuthorMapper in project mybatis-3 by mybatis.

the class SqlSessionTest method shouldExecuteSelectAllAuthorsUsingMapperClassThatReturnsAnArray.

@Test
public void shouldExecuteSelectAllAuthorsUsingMapperClassThatReturnsAnArray() {
    SqlSession session = sqlMapper.openSession();
    try {
        AuthorMapper mapper = session.getMapper(AuthorMapper.class);
        Author[] authors = mapper.selectAllAuthorsArray();
        assertEquals(2, authors.length);
    } finally {
        session.close();
    }
}
Also used : AuthorMapper(org.apache.ibatis.domain.blog.mappers.AuthorMapper) ImmutableAuthor(org.apache.ibatis.domain.blog.ImmutableAuthor) Author(org.apache.ibatis.domain.blog.Author) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Aggregations

BaseDataTest (org.apache.ibatis.BaseDataTest)16 AuthorMapper (org.apache.ibatis.domain.blog.mappers.AuthorMapper)16 Test (org.junit.Test)16 Author (org.apache.ibatis.domain.blog.Author)13 ImmutableAuthor (org.apache.ibatis.domain.blog.ImmutableAuthor)10 DefaultResultHandler (org.apache.ibatis.executor.result.DefaultResultHandler)3