Commit 9586ea39 authored by Quxl's avatar Quxl

x

parent 61255652
package com.egolm.common.jdbc; package com.egolm.common.jdbc;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.sql.CallableStatement; import java.sql.CallableStatement;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
...@@ -200,22 +202,18 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate { ...@@ -200,22 +202,18 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
Desc iSql = dialect.getDesc(obj.getClass()); Desc iSql = dialect.getDesc(obj.getClass());
Map<String, Object> pkFieldMap = dialect.getFieldValue(obj, byFields); Map<String, Object> pkFieldMap = dialect.getFieldValue(obj, byFields);
if(dialect.hasPkValue(obj) && pkFieldMap != null && pkFieldMap.size() > 0) { if(dialect.hasPkValue(obj) && pkFieldMap != null && pkFieldMap.size() > 0) {
List<Map<String, Object>> objMaps = queryForListByColumn(iSql.getName(), pkFieldMap); List<Map<String, Object>> objMaps = this.queryForListByColumn(iSql.getName(), pkFieldMap);
if(objMaps != null) { if(objMaps != null) {
if(objMaps.size() == 1) { if(objMaps.size() == 1) {
String[] columnNames = iSql.getColumnNames(); Map<String, Object> map = new HashMap<String, Object>();
String[] fieldNames = iSql.getFieldNames(); Field[] fields = obj.getClass().getDeclaredFields();
for(int i = 0; i < fieldNames.length; i++) { for(Field field : fields) {
String fieldName = fieldNames[i]; Object fieldValue = ReflexUtil.getFieldValue(field, obj);
Object fieldObj = ReflexUtil.readField(fieldName, obj); if(fieldValue != null) {
if(fieldObj == null) { map.put(field.getName(), fieldValue);
fieldObj = objMaps.get(0).get(columnNames[i]);
if(fieldObj != null) {
ReflexUtil.writeField(fieldName, obj, fieldObj);
}
} }
} }
return this.updateByField(obj, byFields); return this.updateByColumn(iSql.getName(), iSql.getColumnPkNames(), map);
} else if(objMaps.size() > 1) { } else if(objMaps.size() > 1) {
throw new MustBeOneRowException(); throw new MustBeOneRowException();
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment