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;
}
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;
}
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();
}
Aggregations