Search in sources :

Example 11 with ColumnMetadata

use of com.mendmix.mybatis.metadata.ColumnMetadata in project jeesuite-libs by vakinge.

the class SelectByPrimaryKeysBuilder method buildSQL.

@Override
String buildSQL(EntityMetadata entityMapper, boolean selective) {
    TableMetadata tableMapper = entityMapper.getTable();
    ColumnMetadata idColumn = entityMapper.getIdColumn();
    String sql = String.format(SqlTemplate.SELECT_BY_KEYS, tableMapper.getName(), idColumn.getColumn());
    return sql;
}
Also used : TableMetadata(com.mendmix.mybatis.metadata.TableMetadata) ColumnMetadata(com.mendmix.mybatis.metadata.ColumnMetadata)

Example 12 with ColumnMetadata

use of com.mendmix.mybatis.metadata.ColumnMetadata in project jeesuite-libs by vakinge.

the class UpdateBuilder method buildSQL.

@Override
String buildSQL(EntityMetadata entityMapper, boolean selective) {
    // 从表注解里获取表名等信息
    TableMetadata tableMapper = entityMapper.getTable();
    Set<ColumnMetadata> columnMappers = entityMapper.getColumns();
    String idColumn = null;
    String idProperty = null;
    StringBuilder set = new StringBuilder();
    set.append("<trim prefix=\"SET\" suffixOverrides=\",\">");
    for (ColumnMetadata column : columnMappers) {
        if (!column.isUpdatable()) {
            continue;
        }
        if (column.isId()) {
            idColumn = column.getColumn();
            idProperty = column.getProperty();
        } else {
            String expr = SqlTemplate.wrapIfTag(column.getProperty(), column.getColumn() + "=#{" + column.getProperty() + "}", !selective);
            set.append(expr);
            if (!selective)
                set.append(",");
        }
    }
    if (!selective)
        set.deleteCharAt(set.length() - 1);
    set.append("</trim>");
    String sql = String.format(SqlTemplate.UPDATE_BY_KEY, tableMapper.getName(), set.toString(), idColumn, idProperty);
    return sql;
}
Also used : TableMetadata(com.mendmix.mybatis.metadata.TableMetadata) ColumnMetadata(com.mendmix.mybatis.metadata.ColumnMetadata)

Example 13 with ColumnMetadata

use of com.mendmix.mybatis.metadata.ColumnMetadata in project jeesuite-libs by vakinge.

the class SelectByExampleProvider method selectByExample.

public String selectByExample(Object example) throws Exception {
    EntityMetadata entityMapper = MetadataHelper.getEntityMapper(example.getClass());
    Set<ColumnMetadata> columns = entityMapper.getColumns();
    SQL sql = new SQL().SELECT("*").FROM(entityMapper.getTable().getName());
    Object value;
    StringBuilder whereBuilder = new StringBuilder();
    for (ColumnMetadata column : columns) {
        value = MetadataHelper.getEntityField(entityMapper.getTable().getName(), column.getProperty()).get(example);
        if (value == null)
            continue;
        appendWhere(whereBuilder, column);
    }
    if (whereBuilder.length() == 0)
        throw new IllegalArgumentException("至少包含一个查询条件");
    // 
    // if(DbType.MYSQL.name().equalsIgnoreCase(MybatisConfigs.getDbType("default"))){
    // whereBuilder.append(" LIMIT 20000");
    // }
    sql.WHERE(whereBuilder.toString());
    return sql.toString();
}
Also used : ColumnMetadata(com.mendmix.mybatis.metadata.ColumnMetadata) EntityMetadata(com.mendmix.mybatis.metadata.EntityMetadata) SQL(org.apache.ibatis.jdbc.SQL)

Aggregations

ColumnMetadata (com.mendmix.mybatis.metadata.ColumnMetadata)13 TableMetadata (com.mendmix.mybatis.metadata.TableMetadata)6 SQL (org.apache.ibatis.jdbc.SQL)5 ArrayList (java.util.ArrayList)4 EntityMetadata (com.mendmix.mybatis.metadata.EntityMetadata)3 MapperMetadata (com.mendmix.mybatis.metadata.MapperMetadata)3 List (java.util.List)3 CurrentRuntimeContext (com.mendmix.common.CurrentRuntimeContext)2 JeesuiteBaseException (com.mendmix.common.JeesuiteBaseException)2 MatchPolicy (com.mendmix.common.constants.MatchPolicy)2 AuthUser (com.mendmix.common.model.AuthUser)2 OrderBy (com.mendmix.common.model.OrderBy)2 OrderType (com.mendmix.common.model.OrderBy.OrderType)2 PageParams (com.mendmix.common.model.PageParams)2 ResourceUtils (com.mendmix.common.util.ResourceUtils)2 MybatisConfigs (com.mendmix.mybatis.MybatisConfigs)2 MybatisRuntimeContext (com.mendmix.mybatis.MybatisRuntimeContext)2 InterceptorHandler (com.mendmix.mybatis.core.InterceptorHandler)2 CrudMethods (com.mendmix.mybatis.crud.CrudMethods)2 MybatisSqlUtils (com.mendmix.mybatis.kit.MybatisSqlUtils)2