Commit 9586ea39 authored by Quxl's avatar Quxl

x

parent 61255652
package com.egolm.common.jdbc;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
......@@ -200,22 +202,18 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
Desc iSql = dialect.getDesc(obj.getClass());
Map<String, Object> pkFieldMap = dialect.getFieldValue(obj, byFields);
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.size() == 1) {
String[] columnNames = iSql.getColumnNames();
String[] fieldNames = iSql.getFieldNames();
for(int i = 0; i < fieldNames.length; i++) {
String fieldName = fieldNames[i];
Object fieldObj = ReflexUtil.readField(fieldName, obj);
if(fieldObj == null) {
fieldObj = objMaps.get(0).get(columnNames[i]);
if(fieldObj != null) {
ReflexUtil.writeField(fieldName, obj, fieldObj);
}
Map<String, Object> map = new HashMap<String, Object>();
Field[] fields = obj.getClass().getDeclaredFields();
for(Field field : fields) {
Object fieldValue = ReflexUtil.getFieldValue(field, obj);
if(fieldValue != null) {
map.put(field.getName(), fieldValue);
}
}
return this.updateByField(obj, byFields);
return this.updateByColumn(iSql.getName(), iSql.getColumnPkNames(), map);
} else if(objMaps.size() > 1) {
throw new MustBeOneRowException();
} 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