use of org.apache.ibatis.jdbc.SQL in project qiuyj-code by qiuyuanjun.
the class SqlProvider method delete.
public ReturnValueWrapper delete(MappedStatement ms, SqlInfo sqlInfo) {
checkPrimaryKey(sqlInfo);
String sql = new SQL().DELETE_FROM(sqlInfo.getTableName()).WHERE(sqlInfo.getPrimaryKeyCondition()).toString();
return primaryKeyResolver(sqlInfo.getPrimaryKey(), ms.getConfiguration(), sql);
}
use of org.apache.ibatis.jdbc.SQL in project qiuyj-code by qiuyuanjun.
the class SqlProvider method update.
public ReturnValueWrapper update(MappedStatement ms, SqlInfo sqlInfo, Object args) {
checkPrimaryKey(sqlInfo);
checkBeanType(sqlInfo.getBeanType(), args);
BeanExampleResolver exampleResolver = new BeanExampleResolver(args, sqlInfo.getJavaProperties(), sqlInfo.getDatabaseColumns());
if (!exampleResolver.hasPrimaryKeyAndNotDefault()) {
throw new NoPrimaryKeyException("primary key is default value");
} else {
List<PropertyColumnMapping> nonNullColumns = exampleResolver.getWithoutPrimaryKey();
if (nonNullColumns.isEmpty()) {
throw new IllegalStateException("Please update at least one column");
} else {
List<ParameterMapping> parameterMappings = new ArrayList<>(nonNullColumns.size() + 1);
SQL sql = new SQL();
sql.UPDATE(sqlInfo.getTableName());
for (PropertyColumnMapping pcm : nonNullColumns) {
sql.SET(pcm.getDatabaseColumnName() + " = ?");
parameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), pcm.getJavaClassPropertyName(), pcm.getValue().getClass()).build());
}
sql.WHERE(sqlInfo.getPrimaryKey().getDatabaseColumnName() + " = ?");
parameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), sqlInfo.getPrimaryKey().getJavaClassPropertyName(), sqlInfo.getPrimaryKey().getTypeHandler()).build());
return new ReturnValueWrapper(new StaticTextSqlNode(sql.toString()), parameterMappings);
}
}
}
use of org.apache.ibatis.jdbc.SQL in project qiuyj-code by qiuyuanjun.
the class SqlProvider method insert.
public ReturnValueWrapper insert(MappedStatement ms, SqlInfo sqlInfo) {
// 不建议以下这种方式创建SQL,这样会增加编译之后的字节码文件数量
// 因为这样会创建一个匿名内部类
/*SQL sql = new SQL() {
{
INSERT_INTO(sqlInfo.getTableName());
INTO_COLUMNS(sqlInfo.getAllColumnsWithoutAlias());
String[] prepareColumnValues = new String[sqlInfo.getFiledCount()];
Arrays.fill(prepareColumnValues, PREPARE_FLAG);
INTO_VALUES(prepareColumnValues);
}
};*/
String[] prepareColumnValues = new String[sqlInfo.getFieldCount()];
Arrays.fill(prepareColumnValues, PREPARE_FLAG);
String sql = new SQL().INSERT_INTO(sqlInfo.getTableName()).INTO_COLUMNS(sqlInfo.getAllColumnsWithoutAlias()).INTO_VALUES(prepareColumnValues).toString();
List<ParameterMapping> parameterMappings = new ArrayList<>(sqlInfo.getFieldCount());
TypeHandlerRegistry reg = ms.getConfiguration().getTypeHandlerRegistry();
ParameterMapping.Builder parameterBuilder;
for (PropertyColumnMapping mapping : sqlInfo.getPropertyColumnMappings()) {
parameterBuilder = new ParameterMapping.Builder(ms.getConfiguration(), mapping.getJavaClassPropertyName(), mapping.getTypeHandler());
parameterMappings.add(parameterBuilder.build());
}
return new ReturnValueWrapper(new StaticTextSqlNode(sql), parameterMappings);
}
use of org.apache.ibatis.jdbc.SQL in project qiuyj-code by qiuyuanjun.
the class SqlProvider method selectList.
public ReturnValueWrapper selectList(MappedStatement ms, 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(ms.getConfiguration(), pcm.getJavaClassPropertyName(), pcm.getValue().getClass()).build());
sql.WHERE(pcm.getDatabaseColumnName() + " = ?");
}
return new ReturnValueWrapper(new StaticTextSqlNode(sql.toString()), parameterMappings);
}
}
use of org.apache.ibatis.jdbc.SQL in project QFGame by porschan.
the class GSUserSqlProvider method insertSelective.
public String insertSelective(GSUser record) {
SQL sql = new SQL();
sql.INSERT_INTO("gs_user");
if (record.getUserid() != null) {
sql.VALUES("userID", "#{userid,jdbcType=BIGINT}");
}
if (record.getUsername() != null) {
sql.VALUES("userName", "#{username,jdbcType=VARCHAR}");
}
if (record.getUserpassword() != null) {
sql.VALUES("userPassword", "#{userpassword,jdbcType=VARCHAR}");
}
if (record.getUserphone() != null) {
sql.VALUES("userPhone", "#{userphone,jdbcType=VARCHAR}");
}
return sql.toString();
}
Aggregations