Search in sources :

Example 6 with Author

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

the class SerializableProxyTest method shouldNotLetReadUnloadedPropertyAfterSerialization.

@Test(expected = ExecutorException.class)
public void shouldNotLetReadUnloadedPropertyAfterSerialization() throws Exception {
    ResultLoaderMap loader = new ResultLoaderMap();
    loader.addLoader("id", null, null);
    Object proxy = proxyFactory.createProxy(author, loader, new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
    Author author2 = (Author) deserialize(serialize((Serializable) proxy));
    author2.getId();
}
Also used : Configuration(org.apache.ibatis.session.Configuration) DefaultObjectFactory(org.apache.ibatis.reflection.factory.DefaultObjectFactory) Author(org.apache.ibatis.domain.blog.Author) Test(org.junit.Test)

Example 7 with Author

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

the class BaseExecutorTest method shouldSelectAllAuthorsAutoMapped.

@Test
public void shouldSelectAllAuthorsAutoMapped() throws Exception {
    Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
    try {
        MappedStatement selectStatement = ExecutorTestHelper.prepareSelectAllAuthorsAutoMappedStatement(config);
        List<Author> authors = executor.query(selectStatement, null, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
        assertEquals(2, authors.size());
        Author author = authors.get(0);
        // id,username, password, email, bio, favourite_section
        // (101,'jim','********','jim@ibatis.apache.org','','NEWS');
        assertEquals(101, author.getId());
        assertEquals("jim", author.getUsername());
        assertEquals("jim@ibatis.apache.org", author.getEmail());
        assertEquals("", author.getBio());
        assertEquals(Section.NEWS, author.getFavouriteSection());
    } finally {
        executor.rollback(true);
        executor.close(false);
    }
}
Also used : JdbcTransaction(org.apache.ibatis.transaction.jdbc.JdbcTransaction) Author(org.apache.ibatis.domain.blog.Author) MappedStatement(org.apache.ibatis.mapping.MappedStatement) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 8 with Author

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

the class BaseExecutorTest method shouldDeleteAuthor.

@Test
public void shouldDeleteAuthor() throws Exception {
    Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
    try {
        Author author = new Author(101, null, null, null, null, null);
        MappedStatement deleteStatement = ExecutorTestHelper.prepareDeleteAuthorMappedStatement(config);
        MappedStatement selectStatement = ExecutorTestHelper.prepareSelectOneAuthorMappedStatement(config);
        int rows = executor.update(deleteStatement, author);
        List<Author> authors = executor.query(selectStatement, 101, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
        executor.flushStatements();
        executor.rollback(true);
        assertEquals(0, authors.size());
        assertTrue(1 == rows || BatchExecutor.BATCH_UPDATE_RETURN_VALUE == rows);
    } finally {
        executor.rollback(true);
        executor.close(false);
    }
}
Also used : JdbcTransaction(org.apache.ibatis.transaction.jdbc.JdbcTransaction) Author(org.apache.ibatis.domain.blog.Author) MappedStatement(org.apache.ibatis.mapping.MappedStatement) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 9 with Author

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

the class CglibProxyTest method shouldSerizalizeADeserlizaliedProxy.

@Test
public void shouldSerizalizeADeserlizaliedProxy() throws Exception {
    Object proxy = ((CglibProxyFactory) proxyFactory).createDeserializationProxy(author, new HashMap<String, ResultLoaderMap.LoadPair>(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
    Author author2 = (Author) deserialize(serialize((Serializable) proxy));
    assertEquals(author, author2);
    assertFalse(author.getClass().equals(author2.getClass()));
}
Also used : CglibProxyFactory(org.apache.ibatis.executor.loader.cglib.CglibProxyFactory) DefaultObjectFactory(org.apache.ibatis.reflection.factory.DefaultObjectFactory) Author(org.apache.ibatis.domain.blog.Author) Test(org.junit.Test)

Example 10 with Author

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

the class BaseExecutorTest method shouldMapConstructorResults.

@Test
public void shouldMapConstructorResults() throws Exception {
    Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
    try {
        MappedStatement selectStatement = ExecutorTestHelper.prepareSelectOneAuthorMappedStatementWithConstructorResults(config);
        List<Author> authors = executor.query(selectStatement, 102, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
        executor.flushStatements();
        executor.rollback(true);
        assertEquals(1, authors.size());
        Author author = authors.get(0);
        assertEquals(102, author.getId());
    } finally {
        executor.rollback(true);
        executor.close(false);
    }
}
Also used : JdbcTransaction(org.apache.ibatis.transaction.jdbc.JdbcTransaction) Author(org.apache.ibatis.domain.blog.Author) MappedStatement(org.apache.ibatis.mapping.MappedStatement) 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