This commit is contained in:
@@ -333,7 +333,7 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
if (values.length == 0) return;
|
||||
try {
|
||||
if (!info.isVirtualEntity()) {
|
||||
final String sql = info.getInsertSQL(values[0]);
|
||||
final String sql = info.getInsertSQL(values[0]);
|
||||
final PreparedStatement prestmt = info.autoGenerated
|
||||
? conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS) : conn.prepareStatement(sql);
|
||||
final Class primaryType = info.getPrimary().type();
|
||||
@@ -632,9 +632,10 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
try {
|
||||
Class clazz = info.getType();
|
||||
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 PreparedStatement prestmt = conn.prepareStatement(info.updateSQL);
|
||||
final PreparedStatement prestmt = conn.prepareStatement(updateSQL);
|
||||
Attribute<T, Serializable>[] attrs = info.updateAttributes;
|
||||
String[] sqls = null;
|
||||
if (writeListener == null) {
|
||||
@@ -647,7 +648,7 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
prestmt.addBatch();
|
||||
}
|
||||
} else {
|
||||
char[] sqlchars = info.updateSQL.toCharArray();
|
||||
char[] sqlchars = updateSQL.toCharArray();
|
||||
sqls = new String[values.length];
|
||||
CharSequence[] ps = new CharSequence[attrs.length];
|
||||
int index = 0;
|
||||
|
||||
@@ -74,15 +74,15 @@ public final class EntityInfo<T> {
|
||||
|
||||
private final Attribute<T, Serializable>[] queryAttributes; //数据库中所有字段
|
||||
|
||||
private String insertSQL;
|
||||
private final String insertSQL;
|
||||
|
||||
final Attribute<T, Serializable>[] insertAttributes; //数据库中所有可新增字段
|
||||
|
||||
final String updateSQL;
|
||||
private final String updateSQL;
|
||||
|
||||
final Attribute<T, Serializable>[] updateAttributes; //数据库中所有可更新字段
|
||||
|
||||
final String deleteSQL;
|
||||
private final String deleteSQL;
|
||||
|
||||
private final int logLevel;
|
||||
|
||||
@@ -254,8 +254,8 @@ public final class EntityInfo<T> {
|
||||
if (updatesb.length() > 0) updatesb.append(", ");
|
||||
updatesb.append(col).append(" = ?");
|
||||
}
|
||||
this.updateSQL = "UPDATE " + table + " SET " + updatesb + " WHERE " + getPrimarySQLColumn(null) + " = ?";
|
||||
this.deleteSQL = "DELETE FROM " + table + " WHERE " + getPrimarySQLColumn(null) + " = ?";
|
||||
this.updateSQL = "UPDATE " + (this.tableStrategy == null ? table : "${newtable}") + " SET " + updatesb + " WHERE " + getPrimarySQLColumn(null) + " = ?";
|
||||
this.deleteSQL = "DELETE FROM " + (this.tableStrategy == null ? table : "${newtable}") + " WHERE " + getPrimarySQLColumn(null) + " = ?";
|
||||
this.querySQL = "SELECT * FROM " + table + " WHERE " + getPrimarySQLColumn(null) + " = ?";
|
||||
} else {
|
||||
this.insertSQL = null;
|
||||
@@ -320,6 +320,16 @@ public final class EntityInfo<T> {
|
||||
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) {
|
||||
if (tableStrategy == null) return table;
|
||||
String t = tableStrategy.getTable(table, primary);
|
||||
|
||||
Reference in New Issue
Block a user