use of org.apache.ibatis.jdbc.SQL in project qiuyj-code by qiuyuanjun.
the class AbstractCommonSqlBuilder method selectList.
@Override
public Object selectList(SqlInfo sqlInfo, Object args) {
checkBeanType(sqlInfo.getBeanType(), args);
BeanExampleResolver resolver = new BeanExampleResolver(args, sqlInfo.getJavaProperties(), sqlInfo.getDatabaseColumns());
List<PropertyColumnMapping> exampleSelectList = resolver.selectExample();
if (exampleSelectList.isEmpty()) {
throw new IllegalStateException("Please specify at least one condition.");
} else {
SQL sql = new SQL().SELECT(sqlInfo.getAllColumnsWithAlias()).FROM(sqlInfo.getTableName());
List<ParameterMapping> parameterMappings = new ArrayList<>(exampleSelectList.size());
for (PropertyColumnMapping pcm : exampleSelectList) {
parameterMappings.add(new ParameterMapping.Builder(sqlInfo.getConfiguration(), pcm.getJavaClassPropertyName(), pcm.getValue().getClass()).build());
sql.WHERE(pcm.getDatabaseColumnName() + " = ?");
}
return new StaticSqlSource(sqlInfo.getConfiguration(), sql.toString(), parameterMappings);
}
}
use of org.apache.ibatis.jdbc.SQL in project QFGame by porschan.
the class GSUserSqlProvider method updateByPrimaryKeySelective.
public String updateByPrimaryKeySelective(GSUser record) {
SQL sql = new SQL();
sql.UPDATE("gs_user");
if (record.getUsername() != null) {
sql.SET("userName = #{username,jdbcType=VARCHAR}");
}
if (record.getUserpassword() != null) {
sql.SET("userPassword = #{userpassword,jdbcType=VARCHAR}");
}
if (record.getUserphone() != null) {
sql.SET("userPhone = #{userphone,jdbcType=VARCHAR}");
}
sql.WHERE("userID = #{userid,jdbcType=BIGINT}");
return sql.toString();
}
use of org.apache.ibatis.jdbc.SQL in project mybatis-3 by mybatis.
the class OurSqlBuilder method buildSelectByIdAndNameMultipleParamAndProviderContextWithAtParam.
public String buildSelectByIdAndNameMultipleParamAndProviderContextWithAtParam(@Param("id") final Integer id, ProviderContext context, @Param("name") final String name) {
final boolean containsLogicalDelete = context.getMapperMethod().getAnnotation(BaseMapper.ContainsLogicalDelete.class) != null;
final String tableName = context.getMapperType().getAnnotation(BaseMapper.Meta.class).tableName();
return new SQL() {
{
SELECT("*");
FROM(tableName);
if (id != null) {
WHERE("id = #{id}");
}
if (name != null) {
WHERE("name like #{name} || '%'");
}
if (!containsLogicalDelete) {
WHERE("logical_delete = false");
}
}
}.toString();
}
use of org.apache.ibatis.jdbc.SQL in project mybatis-3 by mybatis.
the class OurSqlBuilder method buildGetUsersByNameUsingMap.
public String buildGetUsersByNameUsingMap(Map<String, Object> params) {
final String name = String.class.cast(params.get("param1"));
final String orderByColumn = String.class.cast(params.get("param2"));
return new SQL() {
{
SELECT("*");
FROM("users");
if (name != null) {
WHERE("name like #{param1} || '%'");
}
ORDER_BY(orderByColumn);
}
}.toString();
}
use of org.apache.ibatis.jdbc.SQL in project mybatis-3 by mybatis.
the class OurSqlBuilder method buildSelectByNameOneParamAndProviderContext.
public String buildSelectByNameOneParamAndProviderContext(ProviderContext context, final String name) {
final boolean containsLogicalDelete = context.getMapperMethod().getAnnotation(BaseMapper.ContainsLogicalDelete.class) != null;
final String tableName = context.getMapperType().getAnnotation(BaseMapper.Meta.class).tableName();
return new SQL() {
{
SELECT("*");
FROM(tableName);
if (name != null) {
WHERE("name like #{name} || '%'");
}
if (!containsLogicalDelete) {
WHERE("logical_delete = ${LOGICAL_DELETE_OFF:0}");
}
}
}.toString();
}
Aggregations