diff --git a/src/org/redkale/source/DataDefaultSource.java b/src/org/redkale/source/DataDefaultSource.java index fc5858588..7f3dc0abe 100644 --- a/src/org/redkale/source/DataDefaultSource.java +++ b/src/org/redkale/source/DataDefaultSource.java @@ -313,6 +313,18 @@ public final class DataDefaultSource implements DataSource, Function void insert(T... values) { if (values.length == 0) return; + if (values.length > 1) { //检查对象是否都是同一个Entity类 + Class clazz = null; + for (T val : values) { + if (clazz == null) { + clazz = val.getClass(); + continue; + } + if (clazz != val.getClass()) { + throw new RuntimeException("DataSource.insert must the same Class Entity, but diff is " + clazz + " and " + val.getClass()); + } + } + } final EntityInfo info = loadEntityInfo((Class) values[0].getClass()); if (info.isVirtualEntity()) { insert(null, info, values); @@ -465,6 +477,18 @@ public final class DataDefaultSource implements DataSource, Function int delete(T... values) { if (values.length == 0) return -1; + if (values.length > 1) { //检查对象是否都是同一个Entity类 + Class clazz = null; + for (T val : values) { + if (clazz == null) { + clazz = val.getClass(); + continue; + } + if (clazz != val.getClass()) { + throw new RuntimeException("DataSource.delete must the same Class Entity, but diff is " + clazz + " and " + val.getClass()); + } + } + } final EntityInfo info = loadEntityInfo((Class) values[0].getClass()); if (info.isVirtualEntity()) { //虚拟表只更新缓存Cache return delete(null, info, values); @@ -625,6 +649,18 @@ public final class DataDefaultSource implements DataSource, Function int update(T... values) { if (values.length == 0) return 0; + if (values.length > 1) { //检查对象是否都是同一个Entity类 + Class clazz = null; + for (T val : values) { + if (clazz == null) { + clazz = val.getClass(); + continue; + } + if (clazz != val.getClass()) { + throw new RuntimeException("DataSource.update must the same Class Entity, but diff is " + clazz + " and " + val.getClass()); + } + } + } final EntityInfo info = loadEntityInfo((Class) values[0].getClass()); if (info.isVirtualEntity()) { return update(null, info, values); diff --git a/src/org/redkale/source/DataSource.java b/src/org/redkale/source/DataSource.java index 6d31c48c9..510d9ee2b 100644 --- a/src/org/redkale/source/DataSource.java +++ b/src/org/redkale/source/DataSource.java @@ -25,7 +25,7 @@ public interface DataSource { //----------------------insert----------------------------- /** - * 新增记录, 必须是Entity对象
+ * 新增记录, 多对象必须是同一个Entity类
* * @param 泛型 * @param values Entity对象 @@ -34,7 +34,7 @@ public interface DataSource { //-------------------------delete-------------------------- /** - * 删除指定主键值的记录, 必须是Entity对象
+ * 删除指定主键值的记录, 多对象必须是同一个Entity类
* 等价SQL: DELETE FROM {table} WHERE {primary} IN {values.id}
* * @param 泛型 @@ -84,7 +84,7 @@ public interface DataSource { //------------------------update--------------------------- /** - * 更新记录, 必须是Entity对象
+ * 更新记录, 多对象必须是同一个Entity类
* 等价SQL:
* UPDATE {table} SET column1 = value1, column2 = value2, ··· WHERE {primary} = {id1}
* UPDATE {table} SET column1 = value1, column2 = value2, ··· WHERE {primary} = {id2}