Search in sources :

Example 36 with Author

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

the class ExpressionEvaluatorTest method shouldReturnTrueIfNotNull.

@Test
public void shouldReturnTrueIfNotNull() {
    boolean value = evaluator.evaluateBoolean("username", new Author(1, "cbegin", "******", "cbegin@apache.org", "N/A", Section.NEWS));
    assertEquals(true, value);
}
Also used : Author(org.apache.ibatis.domain.blog.Author) Test(org.junit.Test)

Example 37 with Author

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

the class ExecutorTestHelper method prepareSelectOneAuthorMappedStatement.

public static MappedStatement prepareSelectOneAuthorMappedStatement(final Configuration config) {
    final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
    final ResultMap rm = new ResultMap.Builder(config, "defaultResultMap", Author.class, new ArrayList<ResultMapping>() {

        {
            add(new ResultMapping.Builder(config, "id", "id", registry.getTypeHandler(int.class)).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();
    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(rm);
        }
    }).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) StaticSqlSource(org.apache.ibatis.builder.StaticSqlSource)

Example 38 with Author

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

the class CglibProxyTest method shouldCreateAProxyForAPartiallyLoadedBean.

@Test
public void shouldCreateAProxyForAPartiallyLoadedBean() 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));
    assertTrue(author2 instanceof Factory);
}
Also used : Configuration(org.apache.ibatis.session.Configuration) DefaultObjectFactory(org.apache.ibatis.reflection.factory.DefaultObjectFactory) Author(org.apache.ibatis.domain.blog.Author) CglibProxyFactory(org.apache.ibatis.executor.loader.cglib.CglibProxyFactory) Factory(net.sf.cglib.proxy.Factory) DefaultObjectFactory(org.apache.ibatis.reflection.factory.DefaultObjectFactory) Test(org.junit.Test)

Example 39 with Author

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

the class CglibProxyTest method shouldLetCallALoadedProperty.

@Test
public void shouldLetCallALoadedProperty() throws Exception {
    Author author2 = (Author) ((CglibProxyFactory) 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 40 with Author

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

the class CglibProxyTest method shouldFailCallingAnUnloadedProperty.

@Test(expected = ExecutorException.class)
public void shouldFailCallingAnUnloadedProperty() throws Exception {
    // yes, it must go in uppercase
    HashMap<String, ResultLoaderMap.LoadPair> unloadedProperties = new HashMap<String, ResultLoaderMap.LoadPair>();
    unloadedProperties.put("ID", null);
    Author author2 = (Author) ((CglibProxyFactory) proxyFactory).createDeserializationProxy(author, unloadedProperties, new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
    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)

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