This commit is contained in:
Redkale
2016-09-07 16:32:11 +08:00
parent fbb9cdefe1
commit a455795703
2 changed files with 20 additions and 9 deletions

View File

@@ -632,9 +632,10 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
try { try {
Class clazz = info.getType(); Class clazz = info.getType();
if (!info.isVirtualEntity()) { if (!info.isVirtualEntity()) {
if (debug.get()) logger.finest(clazz.getSimpleName() + " update sql=" + info.updateSQL); final String updateSQL = info.getUpdateSQL(values[0]);
if (debug.get()) logger.finest(clazz.getSimpleName() + " update sql=" + updateSQL);
final Attribute<T, Serializable> primary = info.getPrimary(); final Attribute<T, Serializable> primary = info.getPrimary();
final PreparedStatement prestmt = conn.prepareStatement(info.updateSQL); final PreparedStatement prestmt = conn.prepareStatement(updateSQL);
Attribute<T, Serializable>[] attrs = info.updateAttributes; Attribute<T, Serializable>[] attrs = info.updateAttributes;
String[] sqls = null; String[] sqls = null;
if (writeListener == null) { if (writeListener == null) {
@@ -647,7 +648,7 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
prestmt.addBatch(); prestmt.addBatch();
} }
} else { } else {
char[] sqlchars = info.updateSQL.toCharArray(); char[] sqlchars = updateSQL.toCharArray();
sqls = new String[values.length]; sqls = new String[values.length];
CharSequence[] ps = new CharSequence[attrs.length]; CharSequence[] ps = new CharSequence[attrs.length];
int index = 0; int index = 0;

View File

@@ -74,15 +74,15 @@ public final class EntityInfo<T> {
private final Attribute<T, Serializable>[] queryAttributes; //数据库中所有字段 private final Attribute<T, Serializable>[] queryAttributes; //数据库中所有字段
private String insertSQL; private final String insertSQL;
final Attribute<T, Serializable>[] insertAttributes; //数据库中所有可新增字段 final Attribute<T, Serializable>[] insertAttributes; //数据库中所有可新增字段
final String updateSQL; private final String updateSQL;
final Attribute<T, Serializable>[] updateAttributes; //数据库中所有可更新字段 final Attribute<T, Serializable>[] updateAttributes; //数据库中所有可更新字段
final String deleteSQL; private final String deleteSQL;
private final int logLevel; private final int logLevel;
@@ -254,8 +254,8 @@ public final class EntityInfo<T> {
if (updatesb.length() > 0) updatesb.append(", "); if (updatesb.length() > 0) updatesb.append(", ");
updatesb.append(col).append(" = ?"); updatesb.append(col).append(" = ?");
} }
this.updateSQL = "UPDATE " + table + " SET " + updatesb + " WHERE " + getPrimarySQLColumn(null) + " = ?"; this.updateSQL = "UPDATE " + (this.tableStrategy == null ? table : "${newtable}") + " SET " + updatesb + " WHERE " + getPrimarySQLColumn(null) + " = ?";
this.deleteSQL = "DELETE FROM " + table + " WHERE " + getPrimarySQLColumn(null) + " = ?"; this.deleteSQL = "DELETE FROM " + (this.tableStrategy == null ? table : "${newtable}") + " WHERE " + getPrimarySQLColumn(null) + " = ?";
this.querySQL = "SELECT * FROM " + table + " WHERE " + getPrimarySQLColumn(null) + " = ?"; this.querySQL = "SELECT * FROM " + table + " WHERE " + getPrimarySQLColumn(null) + " = ?";
} else { } else {
this.insertSQL = null; this.insertSQL = null;
@@ -320,6 +320,16 @@ public final class EntityInfo<T> {
return insertSQL.replace("${newtable}", getTable(bean)); return insertSQL.replace("${newtable}", getTable(bean));
} }
public String getUpdateSQL(T bean) {
if (this.tableStrategy == null) return updateSQL;
return updateSQL.replace("${newtable}", getTable(bean));
}
public String getDeleteSQL(T bean) {
if (this.tableStrategy == null) return deleteSQL;
return deleteSQL.replace("${newtable}", getTable(bean));
}
public String getTable(Serializable primary) { public String getTable(Serializable primary) {
if (tableStrategy == null) return table; if (tableStrategy == null) return table;
String t = tableStrategy.getTable(table, primary); String t = tableStrategy.getTable(table, primary);