Java Code Examples for tk.mybatis.mapper.entity.EntityTable#getResultMap()

The following examples show how to use tk.mybatis.mapper.entity.EntityTable#getResultMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IdTest.java    From Mapper with MIT License 6 votes vote down vote up
@Test
public void testSingleId(){
    EntityHelper.initEntityNameMap(UserSingleId.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserSingleId.class);
    Assert.assertNotNull(entityTable);

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertTrue(column.isId());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals(1, resultMap.getResultMappings().size());
    Assert.assertTrue(resultMap.getResultMappings().get(0).getFlags().contains(ResultFlag.ID));

    Assert.assertEquals("<where> AND name = #{name}</where>", SqlHelper.wherePKColumns(UserSingleId.class));
}
 
Example 2
Source File: IdTest.java    From Mapper with MIT License 6 votes vote down vote up
@Test
public void testCompositeKeys(){
    EntityHelper.initEntityNameMap(UserCompositeKeys.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserCompositeKeys.class);
    Assert.assertNotNull(entityTable);

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(2, columns.size());
    Assert.assertEquals(2, entityTable.getEntityClassPKColumns().size());

    for (EntityColumn column : columns) {
        Assert.assertTrue(column.isId());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals(2, resultMap.getResultMappings().size());
    Assert.assertTrue(resultMap.getResultMappings().get(0).getFlags().contains(ResultFlag.ID));
    Assert.assertTrue(resultMap.getResultMappings().get(1).getFlags().contains(ResultFlag.ID));

    Assert.assertEquals("<where> AND name = #{name} AND orgId = #{orgId}</where>", SqlHelper.wherePKColumns(UserCompositeKeys.class));
}
 
Example 3
Source File: NameStyleTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testCamelhump(){
    EntityHelper.initEntityNameMap(UserCamelhump.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserCamelhump.class);
    Assert.assertNotNull(entityTable);
    Assert.assertEquals("user_camelhump", entityTable.getName());

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("user_name", column.getColumn());
        Assert.assertEquals("userName", column.getProperty());

        Assert.assertEquals("user_name = #{userName}", column.getColumnEqualsHolder());
        Assert.assertEquals("user_name = #{record.userName}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{userName}", column.getColumnHolder());
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.userNamesuffix},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("user_name", resultMapping.getColumn());
    Assert.assertEquals("userName", resultMapping.getProperty());
    Assert.assertNull(resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example 4
Source File: NameStyleTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testCamelhumpAndUppercase(){
    EntityHelper.initEntityNameMap(UserCamelhumpAndUppercase.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserCamelhumpAndUppercase.class);
    Assert.assertNotNull(entityTable);
    Assert.assertEquals("USER_CAMELHUMP_AND_UPPERCASE", entityTable.getName());

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("USER_NAME", column.getColumn());
        Assert.assertEquals("userName", column.getProperty());

        Assert.assertEquals("USER_NAME = #{userName}", column.getColumnEqualsHolder());
        Assert.assertEquals("USER_NAME = #{record.userName}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{userName}", column.getColumnHolder());
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.userNamesuffix},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("USER_NAME", resultMapping.getColumn());
    Assert.assertEquals("userName", resultMapping.getProperty());
    Assert.assertNull(resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example 5
Source File: NameStyleTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testCamelhumpAndLowercase(){
    EntityHelper.initEntityNameMap(UserCamelhumpAndLowercase.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserCamelhumpAndLowercase.class);
    Assert.assertNotNull(entityTable);
    Assert.assertEquals("user_camelhump_and_lowercase", entityTable.getName());

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("user_name", column.getColumn());
        Assert.assertEquals("userName", column.getProperty());

        Assert.assertEquals("user_name = #{userName}", column.getColumnEqualsHolder());
        Assert.assertEquals("user_name = #{record.userName}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{userName}", column.getColumnHolder());
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.userNamesuffix},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("user_name", resultMapping.getColumn());
    Assert.assertEquals("userName", resultMapping.getProperty());
    Assert.assertNull(resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example 6
Source File: NameStyleTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testNormal(){
    EntityHelper.initEntityNameMap(UserNormal.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserNormal.class);
    Assert.assertNotNull(entityTable);
    Assert.assertEquals("UserNormal", entityTable.getName());

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("userName", column.getColumn());
        Assert.assertEquals("userName", column.getProperty());

        Assert.assertEquals("userName = #{userName}", column.getColumnEqualsHolder());
        Assert.assertEquals("userName = #{record.userName}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{userName}", column.getColumnHolder());
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.userNamesuffix},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[USERNAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("userName", resultMapping.getColumn());
    Assert.assertEquals("userName", resultMapping.getProperty());
    Assert.assertNull(resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example 7
Source File: NameStyleTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testUppercase(){
    EntityHelper.initEntityNameMap(UserUppercase.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserUppercase.class);
    Assert.assertNotNull(entityTable);
    Assert.assertEquals("USERUPPERCASE", entityTable.getName());

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("USERNAME", column.getColumn());
        Assert.assertEquals("userName", column.getProperty());

        Assert.assertEquals("USERNAME = #{userName}", column.getColumnEqualsHolder());
        Assert.assertEquals("USERNAME = #{record.userName}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{userName}", column.getColumnHolder());
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.userNamesuffix},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[USERNAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("USERNAME", resultMapping.getColumn());
    Assert.assertEquals("userName", resultMapping.getProperty());
    Assert.assertNull(resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example 8
Source File: NameStyleTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testLowercase(){
    EntityHelper.initEntityNameMap(UserLowercase.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserLowercase.class);
    Assert.assertNotNull(entityTable);
    Assert.assertEquals("userlowercase", entityTable.getName());

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("username", column.getColumn());
        Assert.assertEquals("userName", column.getProperty());

        Assert.assertEquals("username = #{userName}", column.getColumnEqualsHolder());
        Assert.assertEquals("username = #{record.userName}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{userName}", column.getColumnHolder());
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.userNamesuffix},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[USERNAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("username", resultMapping.getColumn());
    Assert.assertEquals("userName", resultMapping.getProperty());
    Assert.assertNull(resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example 9
Source File: ColumnTypeTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testColumn(){
    EntityHelper.initEntityNameMap(UserColumn.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserColumn.class);
    Assert.assertNotNull(entityTable);

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("user_name", column.getColumn());
        Assert.assertEquals("name", column.getProperty());

        Assert.assertEquals("user_name = #{name}", column.getColumnEqualsHolder());
        Assert.assertEquals("user_name = #{record.name}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{name}", column.getColumnHolder());
        Assert.assertEquals("#{record.name}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.name}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.namesuffix},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("user_name", resultMapping.getColumn());
    Assert.assertEquals("name", resultMapping.getProperty());
    Assert.assertNull(resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example 10
Source File: ColumnTypeTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testJdbcTypeVarchar(){
    EntityHelper.initEntityNameMap(UserJdbcTypeVarchar.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserJdbcTypeVarchar.class);
    Assert.assertNotNull(entityTable);

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("name", column.getColumn());
        Assert.assertEquals("name", column.getProperty());

        Assert.assertEquals("name = #{name, jdbcType=VARCHAR}", column.getColumnEqualsHolder());
        Assert.assertEquals("name = #{record.name, jdbcType=VARCHAR}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{name, jdbcType=VARCHAR}", column.getColumnHolder());
        Assert.assertEquals("#{record.name, jdbcType=VARCHAR}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.name, jdbcType=VARCHAR}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.namesuffix, jdbcType=VARCHAR},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[NAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("name", resultMapping.getColumn());
    Assert.assertEquals("name", resultMapping.getProperty());
    Assert.assertNotNull(resultMapping.getJdbcType());
    Assert.assertEquals(JdbcType.VARCHAR, resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example 11
Source File: ColumnTypeTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testJdbcTypeBlob(){
    EntityHelper.initEntityNameMap(UserJdbcTypeBlob.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserJdbcTypeBlob.class);
    Assert.assertNotNull(entityTable);

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("name", column.getColumn());
        Assert.assertEquals("name", column.getProperty());

        Assert.assertEquals("name = #{name, jdbcType=BLOB}", column.getColumnEqualsHolder());
        Assert.assertEquals("name = #{record.name, jdbcType=BLOB}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{name, jdbcType=BLOB}", column.getColumnHolder());
        Assert.assertEquals("#{record.name, jdbcType=BLOB}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.name, jdbcType=BLOB}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.namesuffix, jdbcType=BLOB},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[NAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("name", resultMapping.getColumn());
    Assert.assertEquals("name", resultMapping.getProperty());
    Assert.assertNotNull(resultMapping.getJdbcType());
    Assert.assertEquals(JdbcType.BLOB, resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example 12
Source File: ColumnTypeTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testTypehandler(){
    EntityHelper.initEntityNameMap(UserTypehandler.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserTypehandler.class);
    Assert.assertNotNull(entityTable);

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("name", column.getColumn());
        Assert.assertEquals("name", column.getProperty());

        Assert.assertEquals("name = #{name, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnEqualsHolder());
        Assert.assertEquals("name = #{record.name, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{name, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnHolder());
        Assert.assertEquals("#{record.name, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.name, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.namesuffix, typeHandler=org.apache.ibatis.type.BlobTypeHandler},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNotNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[NAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("name", resultMapping.getColumn());
    Assert.assertEquals("name", resultMapping.getProperty());
    Assert.assertNull(resultMapping.getJdbcType());
    Assert.assertEquals(BlobTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example 13
Source File: ColumnTypeTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testAll(){
    EntityHelper.initEntityNameMap(UserAll.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserAll.class);
    Assert.assertNotNull(entityTable);

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("user_name", column.getColumn());
        Assert.assertEquals("name", column.getProperty());

        Assert.assertEquals("user_name = #{name, jdbcType=BLOB, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnEqualsHolder());
        Assert.assertEquals("user_name = #{record.name, jdbcType=BLOB, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{name, jdbcType=BLOB, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnHolder());
        Assert.assertEquals("#{record.name, jdbcType=BLOB, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.name, jdbcType=BLOB, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.namesuffix, jdbcType=BLOB, typeHandler=org.apache.ibatis.type.BlobTypeHandler},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNotNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("user_name", resultMapping.getColumn());
    Assert.assertEquals("name", resultMapping.getProperty());
    Assert.assertNotNull(resultMapping.getJdbcType());
    Assert.assertEquals(BlobTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example 14
Source File: ColumnTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testColumn(){
    EntityHelper.initEntityNameMap(UserColumn.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserColumn.class);
    Assert.assertNotNull(entityTable);

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("user_name", column.getColumn());
        Assert.assertEquals("name", column.getProperty());

        Assert.assertEquals("user_name = #{name}", column.getColumnEqualsHolder());
        Assert.assertEquals("user_name = #{record.name}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{name}", column.getColumnHolder());
        Assert.assertEquals("#{record.name}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.name}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.namesuffix},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("user_name", resultMapping.getColumn());
    Assert.assertEquals("name", resultMapping.getProperty());
    Assert.assertNull(resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example 15
Source File: ComplexEntityTest.java    From Mapper with MIT License 4 votes vote down vote up
@Test
public void test() {
    Class<?> entityClass = User.class;
    EntityHelper.initEntityNameMap(entityClass, config);
    StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append(SqlHelper.selectAllColumns(entityClass));
    final EntityTable entityTable = EntityHelper.getEntityTable(entityClass);
    sqlBuilder.append(SqlHelper.fromTable(entityClass, entityTable.getName()));
    sqlBuilder.append(SqlHelper.whereAllIfColumns(entityClass, config.isNotEmpty()));
    final String sql = sqlBuilder.toString();
    Assert.assertEquals("SELECT id,user_name,address,state  FROM user " +
            "<where>" +
            "<if test=\"id != null\"> AND id = #{id}</if>" +
            "<if test=\"userName != null\"> AND user_name = #{userName}</if>" +
            "<if test=\"address != null\"> AND address = #{address, typeHandler=tk.mybatis.mapper.mapperhelper.ComplexEntityTest.AddressHandler}</if>" +
            "<if test=\"state != null\"> AND state = #{state}</if></where>", sql);

    final ResultMap resultMap = entityTable.getResultMap(configuration);
    final List<ResultMapping> resultMappings = resultMap.getResultMappings();
    final ResultMapping idMapping = resultMappings.get(0);
    final ResultMapping userNameMapping = resultMappings.get(1);
    final ResultMapping addressMapping = resultMappings.get(2);
    final ResultMapping stateMapping = resultMappings.get(3);

    Assert.assertEquals("id", idMapping.getColumn());
    Assert.assertEquals("id", idMapping.getProperty());
    Assert.assertTrue(idMapping.getFlags().contains(ResultFlag.ID));

    Assert.assertEquals("user_name", userNameMapping.getColumn());
    Assert.assertEquals("userName", userNameMapping.getProperty());

    Assert.assertEquals("address", addressMapping.getColumn());
    Assert.assertEquals("address", addressMapping.getProperty());
    Assert.assertEquals(AddressHandler.class, addressMapping.getTypeHandler().getClass());

    Assert.assertEquals("state", stateMapping.getColumn());
    Assert.assertEquals("state", stateMapping.getProperty());
    Assert.assertEquals(EnumTypeHandler.class, stateMapping.getTypeHandler().getClass());


}