Java Code Examples for tk.mybatis.mapper.mapperhelper.EntityHelper#getEntityTable()

The following examples show how to use tk.mybatis.mapper.mapperhelper.EntityHelper#getEntityTable() . 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: AggregationProvider.java    From Mapper with MIT License 6 votes vote down vote up
public static String aggregationSelectClause(Class<?> entityClass, String wrapKeyword, AggregateCondition condition) {
    Assert.notEmpty(condition.getAggregateProperty(), "aggregateProperty must have length; it must not be null or empty");
    Assert.notNull(condition.getAggregateType(), "aggregateType is required; it must not be null");
    EntityTable entityTable = EntityHelper.getEntityTable(entityClass);
    Map<String, EntityColumn> propertyMap = entityTable.getPropertyMap();
    StringBuilder selectBuilder = new StringBuilder();
    selectBuilder.append(condition.getAggregateType().name());
    String columnName = propertyMap.get(condition.getAggregateProperty()).getColumn();
    selectBuilder.append("(").append(columnName).append(")");
    selectBuilder.append(" AS ");
    if (StringUtil.isNotEmpty(condition.getAggregateAliasName())) {
        selectBuilder.append(condition.getAggregateAliasName());
    } else {
        selectBuilder.append(wrapKeyword(wrapKeyword, columnName));
    }
    if (condition.getGroupByProperties() != null && condition.getGroupByProperties().size() > 0) {
        for (String property : condition.getGroupByProperties()) {
            selectBuilder.append(", ");
            columnName = propertyMap.get(property).getColumn();
            selectBuilder.append(columnName).append(" AS ").append(wrapKeyword(wrapKeyword, columnName));
        }
    }
    return selectBuilder.toString();
}
 
Example 2
Source File: AggregationProvider.java    From Mapper with MIT License 6 votes vote down vote up
public static String aggregationGroupBy(Class<?> entityClass, String wrapKeyword, AggregateCondition condition) {
    if (condition.getGroupByProperties() != null && condition.getGroupByProperties().size() > 0) {
        EntityTable entityTable = EntityHelper.getEntityTable(entityClass);
        Map<String, EntityColumn> propertyMap = entityTable.getPropertyMap();
        StringBuilder groupByBuilder = new StringBuilder();
        for (String property : condition.getGroupByProperties()) {
            if (groupByBuilder.length() == 0) {
                groupByBuilder.append(" GROUP BY ");
            } else {
                groupByBuilder.append(", ");
            }
            groupByBuilder.append(propertyMap.get(property).getColumn());
        }
        return groupByBuilder.toString();
    }
    return "";
}
 
Example 3
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 4
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 5
Source File: KeySqlTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testAll2(){
    EntityHelper.initEntityNameMap(UserAll2.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserAll2.class);
    Assert.assertNotNull(entityTable);

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

    for (EntityColumn column : columns) {
        Assert.assertEquals("SELECT LAST_INSERT_ID()", column.getGenerator());
        Assert.assertEquals(ORDER.AFTER, column.getOrder());
        Assert.assertTrue(column.isIdentity());
    }
}
 
Example 6
Source File: VersionTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test(expected = VersionException.class)
public void testVersionError(){
    EntityHelper.initEntityNameMap(UserVersionError.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserVersionError.class);
    Assert.assertNotNull(entityTable);
    SqlHelper.wherePKColumns(UserVersionError.class, true);
}
 
Example 7
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 8
Source File: VersionTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testVersion(){
    EntityHelper.initEntityNameMap(UserVersion.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserVersion.class);
    Assert.assertNotNull(entityTable);

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

    for (EntityColumn column : columns) {
        Assert.assertTrue(column.getEntityField().isAnnotationPresent(Version.class));
    }
}
 
Example 9
Source File: KeySqlTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testDialect(){
    EntityHelper.initEntityNameMap(UserDialect.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserDialect.class);
    Assert.assertNotNull(entityTable);

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

    for (EntityColumn column : columns) {
        Assert.assertEquals("SELECT LAST_INSERT_ID()", column.getGenerator());
        Assert.assertEquals(ORDER.AFTER, column.getOrder());
        Assert.assertTrue(column.isIdentity());
    }
}
 
Example 10
Source File: KeySqlTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testUseGeneratedKeys(){
    EntityHelper.initEntityNameMap(UserJDBC.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserJDBC.class);
    Assert.assertNotNull(entityTable);

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

    for (EntityColumn column : columns) {
        Assert.assertEquals("JDBC", column.getGenerator());
        Assert.assertTrue(column.isIdentity());
    }
}
 
Example 11
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 12
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 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: 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 15
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 16
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 17
Source File: TableTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testColumn() {
    EntityHelper.initEntityNameMap(User.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(User.class);
    Assert.assertNotNull(entityTable);
    Assert.assertEquals("sys_user", entityTable.getName());
}
 
Example 18
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 19
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 20
Source File: SelectPropertyProvider.java    From Mapper with MIT License 2 votes vote down vote up
/**
 * 根据实体Class和属性名获取对应的表字段名
 * @param entityClass 实体Class对象
 * @param property 属性名
 * @return
 */
public static String getColumnByProperty(Class<?> entityClass, String property) {
    EntityTable entityTable = EntityHelper.getEntityTable(entityClass);
    EntityColumn entityColumn = entityTable.getPropertyMap().get(property);
    return entityColumn.getColumn();
}