Commit 6cb16bb0 authored by 张永's avatar 张永
parents 627adf37 f0643bdb
......@@ -72,7 +72,7 @@ public class ReflexUtil {
try {
return new PropertyDescriptor(field.getName(), clazz).getReadMethod();
} catch (IntrospectionException e1) {
throw new ReflectException("MethodNotFound:" + methodName);
throw new ReflectException("MethodNotFound:" + methodName + " class:" + clazz.getName() + " field:" + field.getName());
}
}
} else {
......@@ -163,4 +163,5 @@ public class ReflexUtil {
throw new ReflectException("GetMethodException", e);
}
}
}
package com.egolm.common.jdbc;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
......@@ -200,22 +202,21 @@ 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) {
int mod = field.getModifiers();
if(!Modifier.isStatic(mod) && !Modifier.isFinal(mod)) {
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 {
......@@ -389,7 +390,7 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
return this.queryForBeans(iSql.getSql(), type, iSql.getArgs());
}
public <T> List<T> queryForBeansByField(T obj, String... byFields) {
public <T> List<T> queryForBeansByField(T obj, String[] byFields) {
@SuppressWarnings("unchecked")
Class<T> type = (Class<T>) obj.getClass();
Desc desc = dialect.getDesc(type);
......@@ -414,12 +415,18 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
}
public int[] batchSave(Object... objs) {
Sql i = dialect.batchInsert(objs);
return this.batchUpdate(i.getSql(), i.getBachArgs());
if(objs != null && objs.length > 0) {
Sql i = dialect.batchInsert(objs);
return this.batchUpdate(i.getSql(), i.getBachArgs());
}
return new int[]{0};
}
public int[] batchSave(List<?> objs) {
return this.batchSave(objs.toArray());
if(objs != null && objs.size() > 0) {
return this.batchSave(objs.toArray());
}
return new int[]{0};
}
public int batchSave(String tableName, List<Map<String, Object>> objs) {
......
......@@ -2,10 +2,8 @@ package com.egolm.common.jdbc.dialect;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import com.egolm.common.DateUtil;
import com.egolm.common.FileUtil;
import com.egolm.common.StringUtil;
......@@ -50,8 +48,8 @@ public class ReverseUtil {
sb.append("/**" + "\n");
sb.append(" * @author " + author + "\n");
sb.append(" * @since " + DateUtil.format(new Date(), DateUtil.FMT_DATE) + "\n");
sb.append(" * @version v-1.0" + "\n");
// sb.append(" * @since " + DateUtil.format(new Date(), DateUtil.FMT_DATE) + "\n");
// sb.append(" * @version v-1.0" + "\n");
sb.append(" */" + "\n");
sb.append("@Entity(name=\"" + name + "\")" + "\n");
sb.append("public class " + StringUtil.upperFirst(name) + " implements java.io.Serializable {" + "\n\n" + "\tprivate static final long serialVersionUID = 1L;" + "\n\n");
......
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