mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-04 15:28:20 +08:00
feat(keys): 现在可以自定义返回的自增主键类型。
现在可以通过 returnGeneratedKey(Class<T> numberClass) 方法要求返回指定类型的自增主键。 BREAKING CHANGE: 移除了对于“是否返回主键”的选择,一旦定义了主键类型,就代表action将返回该类型的主键。
This commit is contained in:
+30
-14
@@ -12,22 +12,33 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PreparedSQLBatchUpdateActionImpl
|
||||
extends AbstractSQLAction<List<Long>>
|
||||
implements PreparedSQLUpdateBatchAction {
|
||||
public class PreparedSQLBatchUpdateActionImpl<T extends Number>
|
||||
extends AbstractSQLAction<List<T>>
|
||||
implements PreparedSQLUpdateBatchAction<T> {
|
||||
|
||||
boolean returnKeys = false;
|
||||
@NotNull List<Object[]> allParams;
|
||||
@NotNull List<Object[]> allParams = new ArrayList<>();
|
||||
|
||||
public PreparedSQLBatchUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
|
||||
protected final @NotNull Class<T> numberClass;
|
||||
|
||||
public PreparedSQLBatchUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
|
||||
@NotNull String sql) {
|
||||
super(manager, sql);
|
||||
this.numberClass = numberClass;
|
||||
this.allParams = new ArrayList<>();
|
||||
}
|
||||
|
||||
public PreparedSQLBatchUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
|
||||
@NotNull UUID uuid, @NotNull String sql) {
|
||||
super(manager, sql, uuid);
|
||||
this.numberClass = numberClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedSQLUpdateBatchAction setAllParams(Iterable<Object[]> allParams) {
|
||||
public PreparedSQLBatchUpdateActionImpl<T> setAllParams(Iterable<Object[]> allParams) {
|
||||
List<Object[]> paramsList = new ArrayList<>();
|
||||
allParams.forEach(paramsList::add);
|
||||
this.allParams = paramsList;
|
||||
@@ -35,35 +46,40 @@ public class PreparedSQLBatchUpdateActionImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedSQLUpdateBatchAction addParamsBatch(Object... params) {
|
||||
public PreparedSQLBatchUpdateActionImpl<T> addParamsBatch(Object... params) {
|
||||
this.allParams.add(params);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedSQLUpdateBatchAction setReturnGeneratedKeys(boolean returnGeneratedKey) {
|
||||
this.returnKeys = returnGeneratedKey;
|
||||
public PreparedSQLBatchUpdateActionImpl<T> returnGeneratedKeys() {
|
||||
this.returnKeys = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<Long> execute() throws SQLException {
|
||||
public <N extends Number> PreparedSQLBatchUpdateActionImpl<N> returnGeneratedKeys(Class<N> keyTypeClass) {
|
||||
return new PreparedSQLBatchUpdateActionImpl<>(getManager(), keyTypeClass, getActionUUID(), getSQLContent())
|
||||
.setAllParams(allParams).returnGeneratedKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<T> execute() throws SQLException {
|
||||
debugMessage(allParams);
|
||||
|
||||
try (Connection connection = getManager().getConnection()) {
|
||||
try (PreparedStatement statement = StatementUtil.createPrepareStatementBatch(
|
||||
connection, getSQLContent(), allParams, returnKeys
|
||||
)) {
|
||||
|
||||
int[] executed = statement.executeBatch();
|
||||
|
||||
if (!returnKeys) {
|
||||
return Arrays.stream(executed).mapToLong(Long::valueOf).boxed().collect(Collectors.toList());
|
||||
return Arrays.stream(executed).mapToObj(numberClass::cast).collect(Collectors.toList());
|
||||
} else {
|
||||
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
||||
List<Long> generatedKeys = new ArrayList<>();
|
||||
List<T> generatedKeys = new ArrayList<>();
|
||||
while (resultSet.next()) {
|
||||
generatedKeys.add(resultSet.getLong(1));
|
||||
generatedKeys.add(resultSet.getObject(1, numberClass));
|
||||
}
|
||||
return generatedKeys;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cc.carm.lib.easysql.action;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.SQLUpdateAction;
|
||||
import cc.carm.lib.easysql.manager.SQLManagerImpl;
|
||||
import cc.carm.lib.easysql.util.StatementUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -13,36 +14,45 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PreparedSQLUpdateActionImpl
|
||||
extends SQLUpdateActionImpl
|
||||
implements PreparedSQLUpdateAction {
|
||||
public class PreparedSQLUpdateActionImpl<T extends Number>
|
||||
extends SQLUpdateActionImpl<T>
|
||||
implements PreparedSQLUpdateAction<T> {
|
||||
|
||||
Object[] params;
|
||||
|
||||
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
|
||||
this(manager, sql, (Object[]) null);
|
||||
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
|
||||
@NotNull String sql) {
|
||||
this(manager, numberClass, sql, (Object[]) null);
|
||||
}
|
||||
|
||||
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql,
|
||||
@Nullable List<Object> params) {
|
||||
this(manager, sql, params == null ? null : params.toArray());
|
||||
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
|
||||
@NotNull String sql, @Nullable List<Object> params) {
|
||||
this(manager, numberClass, sql, params == null ? null : params.toArray());
|
||||
}
|
||||
|
||||
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql,
|
||||
@Nullable Object[] params) {
|
||||
super(manager, sql);
|
||||
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
|
||||
@NotNull String sql, @Nullable Object[] params) {
|
||||
super(manager, numberClass, sql);
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
|
||||
@NotNull UUID uuid, @NotNull String sql,
|
||||
Object[] params) {
|
||||
super(manager, numberClass, uuid, sql);
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedSQLUpdateActionImpl setParams(Object... params) {
|
||||
public PreparedSQLUpdateActionImpl<T> setParams(Object... params) {
|
||||
this.params = params;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedSQLUpdateAction setParams(@Nullable Iterable<Object> params) {
|
||||
public PreparedSQLUpdateActionImpl<T> setParams(@Nullable Iterable<Object> params) {
|
||||
if (params == null) {
|
||||
return setParams((Object[]) null);
|
||||
} else {
|
||||
@@ -53,7 +63,7 @@ public class PreparedSQLUpdateActionImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Long execute() throws SQLException {
|
||||
public @NotNull T execute() throws SQLException {
|
||||
debugMessage(Collections.singletonList(params));
|
||||
|
||||
try (Connection connection = getManager().getConnection()) {
|
||||
@@ -63,10 +73,10 @@ public class PreparedSQLUpdateActionImpl
|
||||
)) {
|
||||
|
||||
int changes = statement.executeUpdate();
|
||||
if (!returnGeneratedKeys) return (long) changes;
|
||||
if (!returnGeneratedKeys) return numberClass.cast(changes);
|
||||
else {
|
||||
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
||||
return resultSet.next() ? resultSet.getLong(1) : -1;
|
||||
return resultSet.next() ? resultSet.getObject(1, numberClass) : numberClass.cast(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,4 +85,10 @@ public class PreparedSQLUpdateActionImpl
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <N extends Number> SQLUpdateAction<N> returnGeneratedKey(Class<N> keyTypeClass) {
|
||||
PreparedSQLUpdateActionImpl<N> newAction = new PreparedSQLUpdateActionImpl<>(getManager(), keyTypeClass, getActionUUID(), getSQLContent(), params);
|
||||
newAction.returnGeneratedKey();
|
||||
return newAction;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,42 +9,57 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SQLUpdateActionImpl
|
||||
extends AbstractSQLAction<Long>
|
||||
implements SQLUpdateAction {
|
||||
public class SQLUpdateActionImpl<T extends Number>
|
||||
extends AbstractSQLAction<T>
|
||||
implements SQLUpdateAction<T> {
|
||||
|
||||
boolean returnGeneratedKeys = false;
|
||||
protected final @NotNull Class<T> numberClass;
|
||||
|
||||
public SQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
|
||||
protected boolean returnGeneratedKeys = false;
|
||||
|
||||
public SQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
|
||||
@NotNull String sql) {
|
||||
super(manager, sql);
|
||||
this.numberClass = numberClass;
|
||||
}
|
||||
|
||||
public SQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
|
||||
@NotNull UUID uuid, @NotNull String sql) {
|
||||
super(manager, sql, uuid);
|
||||
this.numberClass = numberClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Long execute() throws SQLException {
|
||||
public @NotNull T execute() throws SQLException {
|
||||
debugMessage(new ArrayList<>());
|
||||
|
||||
try (Connection connection = getManager().getConnection()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
|
||||
if (!returnGeneratedKeys) {
|
||||
return (long) statement.executeUpdate(getSQLContent());
|
||||
return numberClass.cast(statement.executeUpdate(getSQLContent()));
|
||||
} else {
|
||||
statement.executeUpdate(getSQLContent(), Statement.RETURN_GENERATED_KEYS);
|
||||
|
||||
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
||||
return resultSet.next() ? resultSet.getLong(1) : -1;
|
||||
return resultSet.next() ? resultSet.getObject(1, numberClass) : numberClass.cast(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SQLUpdateAction setReturnGeneratedKey(boolean returnGeneratedKey) {
|
||||
this.returnGeneratedKeys = returnGeneratedKey;
|
||||
public SQLUpdateAction<T> returnGeneratedKey() {
|
||||
this.returnGeneratedKeys = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <N extends Number> SQLUpdateAction<N> returnGeneratedKey(Class<N> keyTypeClass) {
|
||||
return new SQLUpdateActionImpl<>(getManager(), keyTypeClass, getActionUUID(), getSQLContent()).returnGeneratedKey();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Objects;
|
||||
import static cc.carm.lib.easysql.api.SQLBuilder.withBackQuote;
|
||||
|
||||
public class DeleteBuilderImpl
|
||||
extends AbstractConditionalBuilder<DeleteBuilder, SQLAction<Long>>
|
||||
extends AbstractConditionalBuilder<DeleteBuilder, SQLAction<Integer>>
|
||||
implements DeleteBuilder {
|
||||
|
||||
protected final String tableName;
|
||||
@@ -24,7 +24,7 @@ public class DeleteBuilderImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedSQLUpdateAction build() {
|
||||
public PreparedSQLUpdateAction<Integer> build() {
|
||||
|
||||
StringBuilder sqlBuilder = new StringBuilder();
|
||||
|
||||
@@ -33,9 +33,9 @@ public class DeleteBuilderImpl
|
||||
if (hasConditions()) sqlBuilder.append(" ").append(buildConditionSQL());
|
||||
if (limit > 0) sqlBuilder.append(" ").append(buildLimitSQL());
|
||||
|
||||
return new PreparedSQLUpdateActionImpl(
|
||||
getManager(), sqlBuilder.toString(),
|
||||
hasConditionParams() ? getConditionParams() : null
|
||||
return new PreparedSQLUpdateActionImpl<>(
|
||||
getManager(), Integer.class, sqlBuilder.toString(),
|
||||
(hasConditionParams() ? getConditionParams() : null)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,31 +28,25 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLAction<Long> renameTo(@NotNull String newTableName) {
|
||||
public SQLAction<Integer> renameTo(@NotNull String newTableName) {
|
||||
Objects.requireNonNull(newTableName, "table name could not be null");
|
||||
return new SQLUpdateActionImpl(getManager(),
|
||||
"ALTER TABLE " + withBackQuote(tableName) + " RENAME TO " + withBackQuote(newTableName)
|
||||
);
|
||||
return createAction("ALTER TABLE " + withBackQuote(tableName) + " RENAME TO " + withBackQuote(newTableName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLAction<Long> changeComment(@NotNull String newTableComment) {
|
||||
public SQLAction<Integer> changeComment(@NotNull String newTableComment) {
|
||||
Objects.requireNonNull(newTableComment, "table comment could not be null");
|
||||
return new SQLUpdateActionImpl(getManager(),
|
||||
"ALTER TABLE " + withBackQuote(getTableName()) + " COMMENT " + withQuote(newTableComment)
|
||||
);
|
||||
return createAction("ALTER TABLE " + withBackQuote(getTableName()) + " COMMENT " + withQuote(newTableComment));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLAction<Long> setAutoIncrementIndex(int index) {
|
||||
return new SQLUpdateActionImpl(getManager(),
|
||||
"ALTER TABLE " + withBackQuote(getTableName()) + " AUTO_INCREMENT=" + index
|
||||
);
|
||||
public SQLAction<Integer> setAutoIncrementIndex(int index) {
|
||||
return createAction("ALTER TABLE " + withBackQuote(getTableName()) + " AUTO_INCREMENT=" + index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLAction<Long> addIndex(@NotNull IndexType indexType, @Nullable String indexName,
|
||||
@NotNull String columnName, @NotNull String... moreColumns) {
|
||||
public SQLAction<Integer> addIndex(@NotNull IndexType indexType, @Nullable String indexName,
|
||||
@NotNull String columnName, @NotNull String... moreColumns) {
|
||||
Objects.requireNonNull(indexType, "indexType could not be null");
|
||||
Objects.requireNonNull(columnName, "column names could not be null");
|
||||
Objects.requireNonNull(moreColumns, "column names could not be null");
|
||||
@@ -63,7 +57,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLAction<Long> dropIndex(@NotNull String indexName) {
|
||||
public SQLAction<Integer> dropIndex(@NotNull String indexName) {
|
||||
Objects.requireNonNull(indexName, "indexName could not be null");
|
||||
return createAction(
|
||||
"ALTER TABLE " + withBackQuote(getTableName()) + " DROP INDEX " + withBackQuote(indexName)
|
||||
@@ -71,7 +65,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLAction<Long> dropForeignKey(@NotNull String keySymbol) {
|
||||
public SQLAction<Integer> dropForeignKey(@NotNull String keySymbol) {
|
||||
Objects.requireNonNull(keySymbol, "keySymbol could not be null");
|
||||
return createAction(
|
||||
"ALTER TABLE " + withBackQuote(getTableName()) + " DROP FOREIGN KEY " + withBackQuote(keySymbol)
|
||||
@@ -79,14 +73,14 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLAction<Long> dropPrimaryKey() {
|
||||
public SQLAction<Integer> dropPrimaryKey() {
|
||||
return createAction(
|
||||
"ALTER TABLE " + withBackQuote(getTableName()) + " DROP PRIMARY KEY"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLAction<Long> addColumn(@NotNull String columnName, @NotNull String settings, @Nullable String afterColumn) {
|
||||
public SQLAction<Integer> addColumn(@NotNull String columnName, @NotNull String settings, @Nullable String afterColumn) {
|
||||
Objects.requireNonNull(columnName, "columnName could not be null");
|
||||
Objects.requireNonNull(settings, "settings could not be null");
|
||||
String orderSettings = null;
|
||||
@@ -105,7 +99,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLAction<Long> renameColumn(@NotNull String columnName, @NotNull String newName) {
|
||||
public SQLAction<Integer> renameColumn(@NotNull String columnName, @NotNull String newName) {
|
||||
Objects.requireNonNull(columnName, "columnName could not be null");
|
||||
Objects.requireNonNull(newName, "please specify new column name");
|
||||
return createAction(
|
||||
@@ -114,7 +108,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLAction<Long> modifyColumn(@NotNull String columnName, @NotNull String settings) {
|
||||
public SQLAction<Integer> modifyColumn(@NotNull String columnName, @NotNull String settings) {
|
||||
Objects.requireNonNull(columnName, "columnName could not be null");
|
||||
Objects.requireNonNull(settings, "please specify new column settings");
|
||||
return createAction(
|
||||
@@ -123,7 +117,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLAction<Long> removeColumn(@NotNull String columnName) {
|
||||
public SQLAction<Integer> removeColumn(@NotNull String columnName) {
|
||||
Objects.requireNonNull(columnName, "columnName could not be null");
|
||||
return createAction(
|
||||
"ALTER TABLE " + withBackQuote(getTableName()) + " DROP " + withBackQuote(columnName)
|
||||
@@ -131,7 +125,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLAction<Long> setColumnDefault(@NotNull String columnName, @NotNull String defaultValue) {
|
||||
public SQLAction<Integer> setColumnDefault(@NotNull String columnName, @NotNull String defaultValue) {
|
||||
Objects.requireNonNull(columnName, "columnName could not be null");
|
||||
Objects.requireNonNull(defaultValue, "defaultValue could not be null, if you need to remove the default value, please use #removeColumnDefault().");
|
||||
return createAction(
|
||||
@@ -140,14 +134,14 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLAction<Long> removeColumnDefault(@NotNull String columnName) {
|
||||
public SQLAction<Integer> removeColumnDefault(@NotNull String columnName) {
|
||||
Objects.requireNonNull(columnName, "columnName could not be null");
|
||||
return createAction(
|
||||
"ALTER TABLE " + withBackQuote(getTableName()) + " ALTER " + withBackQuote(columnName) + " DROP DEFAULT"
|
||||
);
|
||||
}
|
||||
|
||||
private SQLUpdateActionImpl createAction(@NotNull String sql) {
|
||||
return new SQLUpdateActionImpl(getManager(), sql);
|
||||
private SQLUpdateActionImpl<Integer> createAction(@NotNull String sql) {
|
||||
return new SQLUpdateActionImpl<>(getManager(), Integer.class, sql);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class TableCreateBuilderImpl extends AbstractSQLBuilder implements TableC
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLUpdateAction build() {
|
||||
public SQLUpdateAction<Integer> build() {
|
||||
StringBuilder createSQL = new StringBuilder();
|
||||
createSQL.append("CREATE TABLE IF NOT EXISTS ").append(withBackQuote(tableName));
|
||||
createSQL.append("(");
|
||||
@@ -94,7 +94,7 @@ public class TableCreateBuilderImpl extends AbstractSQLBuilder implements TableC
|
||||
createSQL.append(" COMMENT ").append(withQuote(tableComment));
|
||||
}
|
||||
|
||||
return new SQLUpdateActionImpl(getManager(), createSQL.toString());
|
||||
return new SQLUpdateActionImpl<>(getManager(), Integer.class, createSQL.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.*;
|
||||
import static cc.carm.lib.easysql.api.SQLBuilder.withBackQuote;
|
||||
|
||||
public class UpdateBuilderImpl
|
||||
extends AbstractConditionalBuilder<UpdateBuilder, SQLAction<Long>>
|
||||
extends AbstractConditionalBuilder<UpdateBuilder, SQLAction<Integer>>
|
||||
implements UpdateBuilder {
|
||||
|
||||
protected final @NotNull String tableName;
|
||||
@@ -27,7 +27,7 @@ public class UpdateBuilderImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedSQLUpdateAction build() {
|
||||
public PreparedSQLUpdateAction<Integer> build() {
|
||||
|
||||
StringBuilder sqlBuilder = new StringBuilder();
|
||||
|
||||
@@ -47,7 +47,7 @@ public class UpdateBuilderImpl
|
||||
|
||||
if (limit > 0) sqlBuilder.append(" ").append(buildLimitSQL());
|
||||
|
||||
return new PreparedSQLUpdateActionImpl(getManager(), sqlBuilder.toString(), allParams);
|
||||
return new PreparedSQLUpdateActionImpl<>(getManager(), Integer.class, sqlBuilder.toString(), allParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -120,20 +120,18 @@ public class SQLManagerImpl implements SQLManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long executeSQL(String sql) {
|
||||
return new SQLUpdateActionImpl(this, sql).execute(null);
|
||||
public Integer executeSQL(String sql) {
|
||||
return new SQLUpdateActionImpl<>(this, Integer.class, sql).execute(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long executeSQL(String sql, Object[] params) {
|
||||
return new PreparedSQLUpdateActionImpl(this, sql, params).execute(null);
|
||||
public Integer executeSQL(String sql, Object[] params) {
|
||||
return new PreparedSQLUpdateActionImpl<>(this, Integer.class, sql, params).execute(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch) {
|
||||
return new PreparedSQLBatchUpdateActionImpl(this, sql)
|
||||
.setAllParams(paramsBatch)
|
||||
.execute(null);
|
||||
public List<Integer> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch) {
|
||||
return new PreparedSQLBatchUpdateActionImpl<>(this, Integer.class, sql).setAllParams(paramsBatch).execute(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -174,41 +172,41 @@ public class SQLManagerImpl implements SQLManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InsertBuilder<PreparedSQLUpdateBatchAction> createInsertBatch(@NotNull String tableName) {
|
||||
return new InsertBuilderImpl<PreparedSQLUpdateBatchAction>(this, tableName) {
|
||||
public InsertBuilder<PreparedSQLUpdateBatchAction<Integer>> createInsertBatch(@NotNull String tableName) {
|
||||
return new InsertBuilderImpl<PreparedSQLUpdateBatchAction<Integer>>(this, tableName) {
|
||||
@Override
|
||||
public PreparedSQLUpdateBatchAction setColumnNames(List<String> columnNames) {
|
||||
return new PreparedSQLBatchUpdateActionImpl(getManager(), buildSQL(getTableName(), columnNames));
|
||||
public PreparedSQLUpdateBatchAction<Integer> setColumnNames(List<String> columnNames) {
|
||||
return new PreparedSQLBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public InsertBuilder<PreparedSQLUpdateAction> createInsert(@NotNull String tableName) {
|
||||
return new InsertBuilderImpl<PreparedSQLUpdateAction>(this, tableName) {
|
||||
public InsertBuilder<PreparedSQLUpdateAction<Integer>> createInsert(@NotNull String tableName) {
|
||||
return new InsertBuilderImpl<PreparedSQLUpdateAction<Integer>>(this, tableName) {
|
||||
@Override
|
||||
public PreparedSQLUpdateAction setColumnNames(List<String> columnNames) {
|
||||
return new PreparedSQLUpdateActionImpl(getManager(), buildSQL(getTableName(), columnNames));
|
||||
public PreparedSQLUpdateAction<Integer> setColumnNames(List<String> columnNames) {
|
||||
return new PreparedSQLUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReplaceBuilder<PreparedSQLUpdateBatchAction> createReplaceBatch(@NotNull String tableName) {
|
||||
return new ReplaceBuilderImpl<PreparedSQLUpdateBatchAction>(this, tableName) {
|
||||
public ReplaceBuilder<PreparedSQLUpdateBatchAction<Integer>> createReplaceBatch(@NotNull String tableName) {
|
||||
return new ReplaceBuilderImpl<PreparedSQLUpdateBatchAction<Integer>>(this, tableName) {
|
||||
@Override
|
||||
public PreparedSQLUpdateBatchAction setColumnNames(List<String> columnNames) {
|
||||
return new PreparedSQLBatchUpdateActionImpl(getManager(), buildSQL(getTableName(), columnNames));
|
||||
public PreparedSQLUpdateBatchAction<Integer> setColumnNames(List<String> columnNames) {
|
||||
return new PreparedSQLBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReplaceBuilder<PreparedSQLUpdateAction> createReplace(@NotNull String tableName) {
|
||||
return new ReplaceBuilderImpl<PreparedSQLUpdateAction>(this, tableName) {
|
||||
public ReplaceBuilder<PreparedSQLUpdateAction<Integer>> createReplace(@NotNull String tableName) {
|
||||
return new ReplaceBuilderImpl<PreparedSQLUpdateAction<Integer>>(this, tableName) {
|
||||
@Override
|
||||
public PreparedSQLUpdateAction setColumnNames(List<String> columnNames) {
|
||||
return new PreparedSQLUpdateActionImpl(getManager(), buildSQL(getTableName(), columnNames));
|
||||
public PreparedSQLUpdateAction<Integer> setColumnNames(List<String> columnNames) {
|
||||
return new PreparedSQLUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user