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