Search in sources :

Example 46 with Author

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

the class BaseExecutorTest method shouldSelectTwoSetsOfAuthorsViaProc.

@Test
public void shouldSelectTwoSetsOfAuthorsViaProc() throws Exception {
    Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
    try {
        MappedStatement selectStatement = ExecutorTestHelper.prepareSelectTwoSetsOfAuthorsProc(config);
        List<List<Author>> authorSets = executor.query(selectStatement, new HashMap<String, Object>() {

            {
                put("id1", 101);
                put("id2", 102);
            }
        }, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
        assertEquals(2, authorSets.size());
        for (List<Author> authors : authorSets) {
            assertEquals(2, authors.size());
            for (Object author : authors) {
                assertTrue(author instanceof Author);
            }
        }
    } finally {
        executor.rollback(true);
        executor.close(false);
    }
}
Also used : JdbcTransaction(org.apache.ibatis.transaction.jdbc.JdbcTransaction) Author(org.apache.ibatis.domain.blog.Author) List(java.util.List) MappedStatement(org.apache.ibatis.mapping.MappedStatement) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 47 with Author

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

the class ExecutorTestHelper method prepareSelectOneAuthorMappedStatementWithConstructorResults.

public static MappedStatement prepareSelectOneAuthorMappedStatementWithConstructorResults(final Configuration config) {
    final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
    MappedStatement ms = new MappedStatement.Builder(config, "selectAuthor", new StaticSqlSource(config, "SELECT * FROM author WHERE id = ?"), SqlCommandType.SELECT).parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() {

        {
            add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
        }
    }).build()).resultMaps(new ArrayList<ResultMap>() {

        {
            add(new ResultMap.Builder(config, "defaultResultMap", Author.class, new ArrayList<ResultMapping>() {

                {
                    add(new ResultMapping.Builder(config, null, "id", registry.getTypeHandler(Integer.class)).javaType(int.class).flags(new ArrayList<ResultFlag>() {

                        {
                            add(ResultFlag.CONSTRUCTOR);
                        }
                    }).build());
                    add(new ResultMapping.Builder(config, "username", "username", registry.getTypeHandler(String.class)).build());
                    add(new ResultMapping.Builder(config, "password", "password", registry.getTypeHandler(String.class)).build());
                    add(new ResultMapping.Builder(config, "email", "email", registry.getTypeHandler(String.class)).build());
                    add(new ResultMapping.Builder(config, "bio", "bio", registry.getTypeHandler(String.class)).build());
                    add(new ResultMapping.Builder(config, "favouriteSection", "favourite_section", registry.getTypeHandler(Section.class)).build());
                }
            }).build());
        }
    }).cache(authorCache).build();
    return ms;
}
Also used : TypeHandlerRegistry(org.apache.ibatis.type.TypeHandlerRegistry) ResultMap(org.apache.ibatis.mapping.ResultMap) ArrayList(java.util.ArrayList) ParameterMap(org.apache.ibatis.mapping.ParameterMap) Section(org.apache.ibatis.domain.blog.Section) Author(org.apache.ibatis.domain.blog.Author) MappedStatement(org.apache.ibatis.mapping.MappedStatement) ResultFlag(org.apache.ibatis.mapping.ResultFlag) StaticSqlSource(org.apache.ibatis.builder.StaticSqlSource)

Example 48 with Author

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

the class BaseExecutorTest method shouldUpdateAuthor.

@Test
public void shouldUpdateAuthor() throws Exception {
    Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
    try {
        Author author = new Author(101, "someone", "******", "someone@apache.org", null, Section.NEWS);
        MappedStatement updateStatement = ExecutorTestHelper.prepareUpdateAuthorMappedStatement(config);
        MappedStatement selectStatement = ExecutorTestHelper.prepareSelectOneAuthorMappedStatement(config);
        int rows = executor.update(updateStatement, author);
        List<Author> authors = executor.query(selectStatement, 101, 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 49 with Author

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

the class BaseExecutorTest method shouldInsertNewAuthorUsingSimpleNonPreparedStatements.

@Test
public void shouldInsertNewAuthorUsingSimpleNonPreparedStatements() throws Exception {
    Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
    try {
        Author author = new Author(99, "someone", "******", "someone@apache.org", null, null);
        MappedStatement insertStatement = ExecutorTestHelper.createInsertAuthorWithIDof99MappedStatement(config);
        MappedStatement selectStatement = ExecutorTestHelper.createSelectAuthorWithIDof99MappedStatement(config);
        int rows = executor.update(insertStatement, null);
        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 50 with Author

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

the class ExpressionEvaluatorTest method shouldCompareStringsReturnFalse.

@Test
public void shouldCompareStringsReturnFalse() {
    boolean value = evaluator.evaluateBoolean("username == 'norm'", new Author(1, "cbegin", "******", "cbegin@apache.org", "N/A", Section.NEWS));
    assertEquals(false, value);
}
Also used : Author(org.apache.ibatis.domain.blog.Author) 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