Search in sources :

Example 41 with Author

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

the class JavassistProxyTest method shouldLetCallALoadedProperty.

@Test
public void shouldLetCallALoadedProperty() throws Exception {
    Author author2 = (Author) ((JavassistProxyFactory) proxyFactory).createDeserializationProxy(author, new HashMap<String, ResultLoaderMap.LoadPair>(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
    assertEquals(999, author2.getId());
}
Also used : HashMap(java.util.HashMap) DefaultObjectFactory(org.apache.ibatis.reflection.factory.DefaultObjectFactory) ArrayList(java.util.ArrayList) Author(org.apache.ibatis.domain.blog.Author) Test(org.junit.Test)

Example 42 with Author

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

the class BaseExecutorTest method shouldSelectAuthorViaOutParams.

@Test
public void shouldSelectAuthorViaOutParams() throws Exception {
    Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
    try {
        MappedStatement selectStatement = ExecutorTestHelper.prepareSelectAuthorViaOutParams(config);
        Author author = new Author(102, null, null, null, null, null);
        executor.query(selectStatement, author, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
        assertEquals("sally", author.getUsername());
        assertEquals("********", author.getPassword());
        assertEquals("sally@ibatis.apache.org", author.getEmail());
        assertEquals(null, author.getBio());
    } catch (ExecutorException e) {
        if (executor instanceof CachingExecutor) {
            // TODO see issue #464. Fail is OK.
            assertTrue(e.getMessage().contains("OUT params is not supported"));
        } else {
            throw e;
        }
    } 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 43 with Author

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

the class BaseExecutorTest method shouldInsertNewAuthorByProc.

@Test
public void shouldInsertNewAuthorByProc() throws Exception {
    Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
    try {
        Author author = new Author(97, "someone", "******", "someone@apache.org", null, null);
        MappedStatement insertStatement = ExecutorTestHelper.prepareInsertAuthorProc(config);
        MappedStatement selectStatement = ExecutorTestHelper.prepareSelectOneAuthorMappedStatement(config);
        int rows = executor.update(insertStatement, author);
        List<Author> authors = executor.query(selectStatement, 97, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
        executor.flushStatements();
        executor.rollback(true);
        assertEquals(1, authors.size());
        assertEquals(author.toString(), authors.get(0).toString());
    } 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 44 with Author

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

the class BaseExecutorTest method shouldInsertNewAuthor.

@Test
public void shouldInsertNewAuthor() throws Exception {
    Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
    try {
        Author author = new Author(99, "someone", "******", "someone@apache.org", null, Section.NEWS);
        MappedStatement insertStatement = ExecutorTestHelper.prepareInsertAuthorMappedStatement(config);
        MappedStatement selectStatement = ExecutorTestHelper.prepareSelectOneAuthorMappedStatement(config);
        int rows = executor.update(insertStatement, author);
        List<Author> authors = executor.query(selectStatement, 99, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
        executor.flushStatements();
        executor.rollback(true);
        assertEquals(1, authors.size());
        assertEquals(author.toString(), authors.get(0).toString());
        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 45 with Author

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

the class BaseExecutorTest method shouldInsertNewAuthorWithBeforeAutoKey.

@Test
public void shouldInsertNewAuthorWithBeforeAutoKey() throws Exception {
    Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
    try {
        Author author = new Author(-1, "someone", "******", "someone@apache.org", null, Section.NEWS);
        MappedStatement insertStatement = ExecutorTestHelper.prepareInsertAuthorMappedStatementWithBeforeAutoKey(config);
        MappedStatement selectStatement = ExecutorTestHelper.prepareSelectOneAuthorMappedStatement(config);
        int rows = executor.update(insertStatement, author);
        assertTrue(rows > 0 || rows == BatchExecutor.BATCH_UPDATE_RETURN_VALUE);
        if (rows == BatchExecutor.BATCH_UPDATE_RETURN_VALUE) {
            executor.flushStatements();
        }
        assertEquals(123456, author.getId());
        if (author.getId() != BatchExecutor.BATCH_UPDATE_RETURN_VALUE) {
            List<Author> authors = executor.query(selectStatement, author.getId(), RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
            executor.rollback(true);
            assertEquals(1, authors.size());
            assertEquals(author.toString(), authors.get(0).toString());
            assertTrue(author.getId() >= 10000);
        }
    } 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