This commit is contained in:
Looly
2023-04-18 22:40:05 +08:00
parent ff382aff85
commit 9d3551389e
5 changed files with 47 additions and 16 deletions

View File

@@ -145,9 +145,9 @@ public class DialectRunner implements Serializable {
* @throws DbRuntimeException SQL执行异常
*/
public int insertOrUpdate(final Connection conn, final Entity record, final String... keys) throws DbRuntimeException {
final Entity where = record.filter(keys);
final Entity where = record.filterNew(keys);
if (MapUtil.isNotEmpty(where) && count(conn, Query.of(where)) > 0) {
return update(conn, record, where);
return update(conn, record.removeNew(keys), where);
} else {
return insert(conn, record)[0];
}

View File

@@ -107,7 +107,10 @@ public class Entity extends Dict {
/* 字段名列表,用于限制加入的字段的值 */
private Set<String> fieldNames;
// --------------------------------------------------------------- Constructor start
// region ----- Constructor
/**
* 构造
*/
public Entity() {
}
@@ -132,7 +135,7 @@ public class Entity extends Dict {
super(caseInsensitive);
this.tableName = tableName;
}
// --------------------------------------------------------------- Constructor end
// endregion
// --------------------------------------------------------------- Getters and Setters start
@@ -259,7 +262,7 @@ public class Entity extends Dict {
* @since 4.0.10
*/
@Override
public Entity filter(final String... keys) {
public Entity filterNew(final String... keys) {
final Entity result = new Entity(this.tableName);
result.setFieldNames(this.fieldNames);
@@ -271,6 +274,11 @@ public class Entity extends Dict {
return result;
}
@Override
public Entity removeNew(final String... keys) {
return (Entity) super.removeNew(keys);
}
// -------------------------------------------------------------------- Put and Set start
@Override
public Entity set(final String field, final Object value) {