From ab923285532b9d0100fc2c28fe914d12958df5fd Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Thu, 21 Nov 2024 15:20:41 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E8=BD=BD=20ParamBuilder#buildParams?= =?UTF-8?q?=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/xyz/zhouxy/jdbc/ParamBuilder.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/xyz/zhouxy/jdbc/ParamBuilder.java b/src/main/java/xyz/zhouxy/jdbc/ParamBuilder.java index 5bf9af0..12c23c5 100644 --- a/src/main/java/xyz/zhouxy/jdbc/ParamBuilder.java +++ b/src/main/java/xyz/zhouxy/jdbc/ParamBuilder.java @@ -68,6 +68,29 @@ public class ParamBuilder { .toArray(); } + public static Object[] buildParams(final Collection params) { + if (CollectionTools.isEmpty(params)) { + return EMPTY_OBJECT_ARRAY; + } + return params.stream() + .map(param -> { + if (param instanceof Optional) { + return OptionalTools.orElseNull((Optional) param); + } + if (param instanceof OptionalInt) { + return OptionalTools.toInteger(((OptionalInt) param)); + } + if (param instanceof OptionalLong) { + return OptionalTools.toLong(((OptionalLong) param)); + } + if (param instanceof OptionalDouble) { + return OptionalTools.toDouble(((OptionalDouble) param)); + } + return param; + }) + .toArray(); + } + public static List buildBatchParams(final Collection c, final Function func) { AssertTools.checkNotNull(c, "The collection can not be null."); AssertTools.checkNotNull(func, "The func can not be null.");