From 3c454b01954e34a531c286e88875ad849be05473 Mon Sep 17 00:00:00 2001 From: YuTian <2953516620@qq.com> Date: Wed, 17 Jul 2024 18:49:12 +0800 Subject: [PATCH] v1.4 --- .../aulib/sql/api/builder/InsertBuilder.java | 4 ++++ .../sql/builder/impl/InsertBuilderImpl.java | 16 ++++++++++++++-- .../yutian/aulib/sql/manager/SQLManagerImpl.java | 4 ++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/io/yutian/aulib/sql/api/builder/InsertBuilder.java b/src/main/java/com/io/yutian/aulib/sql/api/builder/InsertBuilder.java index 84a9673..b295cd0 100644 --- a/src/main/java/com/io/yutian/aulib/sql/api/builder/InsertBuilder.java +++ b/src/main/java/com/io/yutian/aulib/sql/api/builder/InsertBuilder.java @@ -9,6 +9,10 @@ public interface InsertBuilder> { String getTableName(); + boolean isIgnore(); + + InsertBuilder setIgnore(boolean ignore); + T setColumnNames(List columnNames); default T setColumnNames(String... columnNames) { diff --git a/src/main/java/com/io/yutian/aulib/sql/builder/impl/InsertBuilderImpl.java b/src/main/java/com/io/yutian/aulib/sql/builder/impl/InsertBuilderImpl.java index 972798d..1a82aac 100644 --- a/src/main/java/com/io/yutian/aulib/sql/builder/impl/InsertBuilderImpl.java +++ b/src/main/java/com/io/yutian/aulib/sql/builder/impl/InsertBuilderImpl.java @@ -16,6 +16,7 @@ public abstract class InsertBuilderImpl> extends AbstractSQLBuilder implements InsertBuilder { protected final String tableName; + protected boolean ignore; public InsertBuilderImpl(@NotNull SQLManagerImpl manager, String tableName) { super(manager); @@ -23,8 +24,19 @@ public abstract class InsertBuilderImpl> this.tableName = tableName; } - protected static String buildSQL(String tableName, List columnNames) { - return buildSQL("INSERT IGNORE INTO", tableName, columnNames); + @Override + public boolean isIgnore() { + return ignore; + } + + @Override + public InsertBuilder setIgnore(boolean ignore) { + this.ignore = ignore; + return this; + } + + protected static String buildSQL(String tableName, boolean ignore, List columnNames) { + return buildSQL("INSERT "+(ignore ? "IGNORE " : "")+"INTO", tableName, columnNames); } protected static String buildSQL(String sqlPrefix, String tableName, List columnNames) { diff --git a/src/main/java/com/io/yutian/aulib/sql/manager/SQLManagerImpl.java b/src/main/java/com/io/yutian/aulib/sql/manager/SQLManagerImpl.java index 59d62d6..32fa65d 100644 --- a/src/main/java/com/io/yutian/aulib/sql/manager/SQLManagerImpl.java +++ b/src/main/java/com/io/yutian/aulib/sql/manager/SQLManagerImpl.java @@ -204,7 +204,7 @@ public class SQLManagerImpl implements SQLManager { return new InsertBuilderImpl>(this, tableName) { @Override public PreparedSQLUpdateBatchAction setColumnNames(List columnNames) { - return new PreparedSQLBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames)); + return new PreparedSQLBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), isIgnore(), columnNames)); } }; } @@ -214,7 +214,7 @@ public class SQLManagerImpl implements SQLManager { return new InsertBuilderImpl>(this, tableName) { @Override public PreparedSQLUpdateAction setColumnNames(List columnNames) { - return new PreparedSQLUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames)); + return new PreparedSQLUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), isIgnore(), columnNames)); } }; }