This commit is contained in:
@@ -247,7 +247,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
if (values.length == 0) return;
|
||||
try {
|
||||
if (!info.isVirtualEntity()) {
|
||||
final String sql = info.getInsertSQL(values[0]);
|
||||
final String sql = info.getInsertPrepareSQL(values[0]);
|
||||
final Class primaryType = info.getPrimary().type();
|
||||
final Attribute primary = info.getPrimary();
|
||||
Attribute<T, Serializable>[] attrs = info.insertAttributes;
|
||||
@@ -623,7 +623,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
Class clazz = info.getType();
|
||||
int c = -1;
|
||||
if (!info.isVirtualEntity()) {
|
||||
final String updateSQL = info.getUpdateSQL(values[0]);
|
||||
final String updateSQL = info.getUpdatePrepareSQL(values[0]);
|
||||
final Attribute<T, Serializable> primary = info.getPrimary();
|
||||
conn.setReadOnly(false);
|
||||
final PreparedStatement prestmt = conn.prepareStatement(updateSQL);
|
||||
|
||||
@@ -91,25 +91,25 @@ public final class EntityInfo<T> {
|
||||
final DistributeTableStrategy<T> tableStrategy;
|
||||
|
||||
//根据主键查找单个对象的SQL, 含 ?
|
||||
final String querySQL;
|
||||
final String queryPrepareSQL;
|
||||
|
||||
//数据库中所有字段
|
||||
private final Attribute<T, Serializable>[] queryAttributes;
|
||||
|
||||
//新增SQL, 含 ?,即排除了自增长主键和标记为@Column(insertable=false)的字段
|
||||
private final String insertSQL;
|
||||
private final String insertPrepareSQL;
|
||||
|
||||
//数据库中所有可新增字段
|
||||
final Attribute<T, Serializable>[] insertAttributes;
|
||||
|
||||
//根据主键更新所有可更新字段的SQL,含 ?
|
||||
private final String updateSQL;
|
||||
private final String updatePrepareSQL;
|
||||
|
||||
//数据库中所有可更新字段
|
||||
final Attribute<T, Serializable>[] updateAttributes;
|
||||
|
||||
//根据主键删除记录的SQL,含 ?
|
||||
private final String deleteSQL;
|
||||
private final String deletePrepareSQL;
|
||||
|
||||
//日志级别,从LogLevel获取
|
||||
private final int logLevel;
|
||||
@@ -319,20 +319,20 @@ public final class EntityInfo<T> {
|
||||
if (insertsb2.length() > 0) insertsb2.append(',');
|
||||
insertsb2.append('?');
|
||||
}
|
||||
this.insertSQL = "INSERT INTO " + (this.tableStrategy == null ? table : "${newtable}") + "(" + insertsb + ") VALUES(" + insertsb2 + ")";
|
||||
this.insertPrepareSQL = "INSERT INTO " + (this.tableStrategy == null ? table : "${newtable}") + "(" + insertsb + ") VALUES(" + insertsb2 + ")";
|
||||
StringBuilder updatesb = new StringBuilder();
|
||||
for (String col : updatecols) {
|
||||
if (updatesb.length() > 0) updatesb.append(", ");
|
||||
updatesb.append(col).append(" = ?");
|
||||
}
|
||||
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) + " = ?";
|
||||
this.updatePrepareSQL = "UPDATE " + (this.tableStrategy == null ? table : "${newtable}") + " SET " + updatesb + " WHERE " + getPrimarySQLColumn(null) + " = ?";
|
||||
this.deletePrepareSQL = "DELETE FROM " + (this.tableStrategy == null ? table : "${newtable}") + " WHERE " + getPrimarySQLColumn(null) + " = ?";
|
||||
this.queryPrepareSQL = "SELECT * FROM " + table + " WHERE " + getPrimarySQLColumn(null) + " = ?";
|
||||
} else {
|
||||
this.insertSQL = null;
|
||||
this.updateSQL = null;
|
||||
this.deleteSQL = null;
|
||||
this.querySQL = null;
|
||||
this.insertPrepareSQL = null;
|
||||
this.updatePrepareSQL = null;
|
||||
this.deletePrepareSQL = null;
|
||||
this.queryPrepareSQL = null;
|
||||
}
|
||||
this.autoGenerated = auto;
|
||||
this.autouuid = uuid;
|
||||
@@ -412,9 +412,9 @@ public final class EntityInfo<T> {
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getInsertSQL(T bean) {
|
||||
if (this.tableStrategy == null) return insertSQL;
|
||||
return insertSQL.replace("${newtable}", getTable(bean));
|
||||
public String getInsertPrepareSQL(T bean) {
|
||||
if (this.tableStrategy == null) return insertPrepareSQL;
|
||||
return insertPrepareSQL.replace("${newtable}", getTable(bean));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -424,9 +424,9 @@ public final class EntityInfo<T> {
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getUpdateSQL(T bean) {
|
||||
if (this.tableStrategy == null) return updateSQL;
|
||||
return updateSQL.replace("${newtable}", getTable(bean));
|
||||
public String getUpdatePrepareSQL(T bean) {
|
||||
if (this.tableStrategy == null) return updatePrepareSQL;
|
||||
return updatePrepareSQL.replace("${newtable}", getTable(bean));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -436,9 +436,9 @@ public final class EntityInfo<T> {
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getDeleteSQL(T bean) {
|
||||
if (this.tableStrategy == null) return deleteSQL;
|
||||
return deleteSQL.replace("${newtable}", getTable(bean));
|
||||
public String getDeletePrepareSQL(T bean) {
|
||||
if (this.tableStrategy == null) return deletePrepareSQL;
|
||||
return deletePrepareSQL.replace("${newtable}", getTable(bean));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user