From ac294c58aebcc69168ce17d6c821a9c1de48a864 Mon Sep 17 00:00:00 2001 From: Redkale <8730487+redkale@users.noreply.github.com> Date: Wed, 16 Jan 2019 19:01:48 +0800 Subject: [PATCH] --- src/org/redkale/source/DataSource.java | 176 +++++++++++++++++++++++++ 1 file changed, 176 insertions(+) diff --git a/src/org/redkale/source/DataSource.java b/src/org/redkale/source/DataSource.java index dc37bc5e1..2f3ca886b 100644 --- a/src/org/redkale/source/DataSource.java +++ b/src/org/redkale/source/DataSource.java @@ -42,6 +42,32 @@ public interface DataSource { */ public int insert(final T... entitys); + /** + * 新增记录, 多对象必须是同一个Entity类且必须在同一张表中
+ * + * @param 泛型 + * @param entitys Entity对象 + * + * @return 影响的记录条数 + */ + default int insert(final Collection entitys) { + if (entitys == null || entitys.isEmpty()) return 0; + return insert(entitys.toArray()); + } + + /** + * 新增记录, 多对象必须是同一个Entity类且必须在同一张表中
+ * + * @param 泛型 + * @param entitys Entity对象 + * + * @return 影响的记录条数 + */ + default int insert(final Stream entitys) { + if (entitys == null) return 0; + return insert(entitys.toArray()); + } + /** * 新增记录, 多对象必须是同一个Entity类且必须在同一张表中
* @@ -52,6 +78,32 @@ public interface DataSource { */ public CompletableFuture insertAsync(final T... entitys); + /** + * 新增记录, 多对象必须是同一个Entity类且必须在同一张表中
+ * + * @param 泛型 + * @param entitys Entity对象 + * + * @return CompletableFuture + */ + default CompletableFuture insertAsync(final Collection entitys) { + if (entitys == null || entitys.isEmpty()) return CompletableFuture.completedFuture(0); + return insertAsync(entitys.toArray()); + } + + /** + * 新增记录, 多对象必须是同一个Entity类且必须在同一张表中
+ * + * @param 泛型 + * @param entitys Entity对象 + * + * @return CompletableFuture + */ + default CompletableFuture insertAsync(final Stream entitys) { + if (entitys == null) return CompletableFuture.completedFuture(0); + return insertAsync(entitys.toArray()); + } + //-------------------------deleteAsync-------------------------- /** * 删除指定主键值的记录, 多对象必须是同一个Entity类且必须在同一张表中
@@ -64,6 +116,34 @@ public interface DataSource { */ public int delete(final T... entitys); + /** + * 删除指定主键值的记录, 多对象必须是同一个Entity类且必须在同一张表中
+ * 等价SQL: DELETE FROM {table} WHERE {primary} IN {values.id}
+ * + * @param 泛型 + * @param entitys Entity对象 + * + * @return 影响的记录条数 + */ + default int delete(final Collection entitys) { + if (entitys == null || entitys.isEmpty()) return 0; + return delete(entitys.toArray()); + } + + /** + * 删除指定主键值的记录, 多对象必须是同一个Entity类且必须在同一张表中
+ * 等价SQL: DELETE FROM {table} WHERE {primary} IN {values.id}
+ * + * @param 泛型 + * @param entitys Entity对象 + * + * @return 影响的记录条数 + */ + default int delete(final Stream entitys) { + if (entitys == null) return 0; + return delete(entitys.toArray()); + } + /** * 删除指定主键值的记录, 多对象必须是同一个Entity类且必须在同一张表中
* 等价SQL: DELETE FROM {table} WHERE {primary} IN {values.id}
@@ -75,6 +155,34 @@ public interface DataSource { */ public CompletableFuture deleteAsync(final T... entitys); + /** + * 删除指定主键值的记录, 多对象必须是同一个Entity类且必须在同一张表中
+ * 等价SQL: DELETE FROM {table} WHERE {primary} IN {values.id}
+ * + * @param 泛型 + * @param entitys Entity对象 + * + * @return 影响的记录条数CompletableFuture + */ + default CompletableFuture deleteAsync(final Collection entitys) { + if (entitys == null || entitys.isEmpty()) return CompletableFuture.completedFuture(0); + return deleteAsync(entitys.toArray()); + } + + /** + * 删除指定主键值的记录, 多对象必须是同一个Entity类且必须在同一张表中
+ * 等价SQL: DELETE FROM {table} WHERE {primary} IN {values.id}
+ * + * @param 泛型 + * @param entitys Entity对象 + * + * @return 影响的记录条数CompletableFuture + */ + default CompletableFuture deleteAsync(final Stream entitys) { + if (entitys == null) return CompletableFuture.completedFuture(0); + return deleteAsync(entitys.toArray()); + } + /** * 删除指定主键值的记录,多主键值必须在同一张表中
* 等价SQL: DELETE FROM {table} WHERE {primary} IN {ids}
@@ -260,6 +368,40 @@ public interface DataSource { */ public int update(final T... entitys); + /** + * 更新记录, 多对象必须是同一个Entity类且必须在同一张表中
+ * 等价SQL:
+ * UPDATE {table} SET column1 = value1, column2 = value2, ··· WHERE {primary} = {id1}
+ * UPDATE {table} SET column1 = value1, column2 = value2, ··· WHERE {primary} = {id2}
+ * ···
+ * + * @param 泛型 + * @param entitys Entity对象 + * + * @return 影响的记录条数 + */ + default int update(final Collection entitys) { + if (entitys == null || entitys.isEmpty()) return 0; + return update(entitys.toArray()); + } + + /** + * 更新记录, 多对象必须是同一个Entity类且必须在同一张表中
+ * 等价SQL:
+ * UPDATE {table} SET column1 = value1, column2 = value2, ··· WHERE {primary} = {id1}
+ * UPDATE {table} SET column1 = value1, column2 = value2, ··· WHERE {primary} = {id2}
+ * ···
+ * + * @param 泛型 + * @param entitys Entity对象 + * + * @return 影响的记录条数 + */ + default int update(final Stream entitys) { + if (entitys == null) return 0; + return update(entitys.toArray()); + } + /** * 更新记录, 多对象必须是同一个Entity类且必须在同一张表中
* 等价SQL:
@@ -274,6 +416,40 @@ public interface DataSource { */ public CompletableFuture updateAsync(final T... entitys); + /** + * 更新记录, 多对象必须是同一个Entity类且必须在同一张表中
+ * 等价SQL:
+ * UPDATE {table} SET column1 = value1, column2 = value2, ··· WHERE {primary} = {id1}
+ * UPDATE {table} SET column1 = value1, column2 = value2, ··· WHERE {primary} = {id2}
+ * ···
+ * + * @param 泛型 + * @param entitys Entity对象 + * + * @return 影响的记录条数CompletableFuture + */ + default CompletableFuture updateAsync(final Collection entitys) { + if (entitys == null || entitys.isEmpty()) return CompletableFuture.completedFuture(0); + return updateAsync(entitys.toArray()); + } + + /** + * 更新记录, 多对象必须是同一个Entity类且必须在同一张表中
+ * 等价SQL:
+ * UPDATE {table} SET column1 = value1, column2 = value2, ··· WHERE {primary} = {id1}
+ * UPDATE {table} SET column1 = value1, column2 = value2, ··· WHERE {primary} = {id2}
+ * ···
+ * + * @param 泛型 + * @param entitys Entity对象 + * + * @return 影响的记录条数CompletableFuture + */ + default CompletableFuture updateAsync(final Stream entitys) { + if (entitys == null) return CompletableFuture.completedFuture(0); + return updateAsync(entitys.toArray()); + } + /** * 更新单个记录的单个字段
* 注意:即使字段标记为@Column(updatable=false)也会被更新