docs: 补充 ParamBuilder 和 SimpleJdbcTemplate 的文档注释
This commit is contained in:
@@ -45,8 +45,26 @@ import xyz.zhouxy.plusone.commons.util.OptionalTools;
|
|||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public class ParamBuilder {
|
public class ParamBuilder {
|
||||||
|
/**
|
||||||
|
* 空参数数组常量
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* 用于表示无参数的 SQL 操作
|
||||||
|
*/
|
||||||
public static final Object[] EMPTY_OBJECT_ARRAY = {};
|
public static final Object[] EMPTY_OBJECT_ARRAY = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建 SQL 参数数组
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* 将传入的参数转换为 {@code Object[]},用于 {@link PreparedStatement} 的参数填充。
|
||||||
|
* 支持自动拆箱 {@link Optional}、{@link OptionalInt}、{@link OptionalLong}、{@link OptionalDouble}。
|
||||||
|
* 对于 {@link CharSequence}、{@link Number}、{@link Boolean}、{@link Temporal} 类型不做转换直接透传。
|
||||||
|
* 如果传入的 {@code params} 为 {@code null} 或空,则返回 {@link #EMPTY_OBJECT_ARRAY}。
|
||||||
|
*
|
||||||
|
* @param params SQL 参数列表(可变参数)
|
||||||
|
* @return 参数数组
|
||||||
|
*/
|
||||||
public static Object[] buildParams(final Object... params) {
|
public static Object[] buildParams(final Object... params) {
|
||||||
if (ArrayTools.isEmpty(params)) {
|
if (ArrayTools.isEmpty(params)) {
|
||||||
return EMPTY_OBJECT_ARRAY;
|
return EMPTY_OBJECT_ARRAY;
|
||||||
@@ -87,6 +105,19 @@ public class ParamBuilder {
|
|||||||
return param;
|
return param;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量构建参数列表
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* 将集合中的每个元素通过 {@code func} 映射为 {@code Object[]},
|
||||||
|
* 最终返回 {@code List<Object[]>},用于 {@link #batchUpdate} 批量操作。
|
||||||
|
*
|
||||||
|
* @param <T> 集合元素类型
|
||||||
|
* @param c 待转换的集合
|
||||||
|
* @param func 转换函数,将集合元素转换为参数数组
|
||||||
|
* @return 参数数组列表
|
||||||
|
* @throws NullPointerException 如果 {@code c} 或 {@code func} 为 {@code null}
|
||||||
|
*/
|
||||||
public static <T> List<Object[]> buildBatchParams(final Collection<T> c, final Function<T, Object[]> func) {
|
public static <T> List<Object[]> buildBatchParams(final Collection<T> c, final Function<T, Object[]> func) {
|
||||||
AssertTools.checkNotNull(c, "The collection can not be null.");
|
AssertTools.checkNotNull(c, "The collection can not be null.");
|
||||||
AssertTools.checkNotNull(func, "The func can not be null.");
|
AssertTools.checkNotNull(func, "The func can not be null.");
|
||||||
|
|||||||
@@ -59,6 +59,11 @@ public class SimpleJdbcTemplate implements JdbcOperations {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
private final TransactionTemplate transactionTemplate;
|
private final TransactionTemplate transactionTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造一个 {@code SimpleJdbcTemplate} 实例
|
||||||
|
*
|
||||||
|
* @param dataSource 数据源,用于获取数据库连接;不可为 {@code null}
|
||||||
|
*/
|
||||||
public SimpleJdbcTemplate(@Nonnull DataSource dataSource) {
|
public SimpleJdbcTemplate(@Nonnull DataSource dataSource) {
|
||||||
AssertTools.checkNotNull(dataSource);
|
AssertTools.checkNotNull(dataSource);
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
@@ -199,6 +204,14 @@ public class SimpleJdbcTemplate implements JdbcOperations {
|
|||||||
|
|
||||||
// #region - transaction
|
// #region - transaction
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取事务模板
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* 返回的 {@link TransactionTemplate} 与当前模板共享同一个 {@link DataSource}。
|
||||||
|
*
|
||||||
|
* @return 事务模板
|
||||||
|
*/
|
||||||
public TransactionTemplate transaction() {
|
public TransactionTemplate transaction() {
|
||||||
return this.transactionTemplate;
|
return this.transactionTemplate;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user