wangzhuangwei commented on issue #9250:
URL: https://github.com/apache/shardingsphere/issues/9250#issuecomment-770749119
EntityMapper<?> entityMapper =
MappingBuilder.ME.getTableMapper(object.getClass());
String tableName = entityMapper.getTableName(object);
StringBuilder tableSql = new StringBuilder();
StringBuilder valueSql = new StringBuilder();
tableSql.append("insert into ").append(tableName).append("(");
valueSql.append("values(");
boolean allFieldNull = true;
int columnCount = 0;
Collection<FieldMapper> fields = entityMapper.getFieldMapperList();
for (FieldMapper fieldMapper : fields) {
String fieldName = fieldMapper.getFieldName();
String dbFieldName = fieldMapper.getDbFieldName();
Object value = PropertyUtil.getProperty(object, fieldName);
if (value == null) {
continue;
}
allFieldNull = false;
columnCount++;
if (columnCount > 1) {
tableSql.append(", ");
valueSql.append(", ");
}
tableSql.append(dbFieldName);
valueSql.append(placeholderPrefix).append(fieldName).append(placeholderSuffix);
//valueSql.append(",").append("jdbcType=").append(fieldMapper.getJdbcType().toString());
}
//XXX:allFieldNull
if (allFieldNull) {
throw new RuntimeException(object.getClass().getName() + "'s all
fields are null, how can i build sql for it?!");
}
String sql = tableSql.append(")
").append(valueSql).append(")").toString();
SqlModel<Object> model = new SqlModel<Object>(sql, object,
entityMapper);
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]