Package com.pugwoo.dbhelper.impl.part
Class P2_InsertOp
java.lang.Object
com.pugwoo.dbhelper.impl.part.P0_JdbcTemplateOp
com.pugwoo.dbhelper.impl.part.P1_QueryOp
com.pugwoo.dbhelper.impl.part.P2_InsertOp
- All Implemented Interfaces:
DBHelper,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware
- Direct Known Subclasses:
P3_UpdateOp
-
Field Summary
Fields inherited from class com.pugwoo.dbhelper.impl.part.P0_JdbcTemplateOp
applicationContext, features, fetchSize, interceptors, jdbcTemplate, LOGGER, maxPageSize, namedParameterJdbcTemplate, timeoutWarningValve -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintinsert(Collection<?> list) 批量插入多条记录,返回数据库实际修改的条数。
【说明】该方法没有事务,请在外层加事务。
【特别说明】因为需要获取自增主键,对于有自增id的插入,会降级为逐条插入,如果想提升性能,请使用insertBatchWithoutReturnId方法。<T> intinsert(T t) 插入一条记录
如果包含了自增id,则自增Id会被设置。
【注】只插入非null的值,如要需要插入null值,则用insertWithNull。intinsertBatchWithoutReturnId(String tableName, Collection<Map<String, Object>> list) 批量插入多条记录,返回数据库实际修改的条数。【不支持拦截器】intinsertBatchWithoutReturnId(String tableName, List<String> cols, Collection<Object[]> values) 以JDBCTemplate的batchUpdate方式,批量插入多条记录,返回数据库实际修改的条数。【不支持拦截器】<T> intinsertBatchWithoutReturnId(Collection<T> list) 批量插入多条记录,返回数据库实际修改的条数。
【重点】不会自动设置插入数据的返回自增ID(拦截器里也拿不到ID),也不会设置回数据库的默认值<T> intinsertWithNull(T t) 插入一条记录,返回数据库实际修改条数。
如果包含了自增id,则自增Id会被设置。Methods inherited from class com.pugwoo.dbhelper.impl.part.P1_QueryOp
getAll, getAll, getAllForStream, getAllForStream, getAllKey, getByExample, getByKey, getCount, getCount, getOne, getOne, getPage, getPage, getPageWithoutCount, getPageWithoutCount, getRaw, getRaw, getRawForStream, getRawForStream, getRawOne, getRawOne, handleRelatedColumn, handleRelatedColumn, handleRelatedColumn, handleRelatedColumn, isExist, isExistAtLeastMethods inherited from class com.pugwoo.dbhelper.impl.part.P0_JdbcTemplateOp
addComment, executeAfterCommit, getDatabaseType, getFeature, getJdbcTemplate, getNamedParameterJdbcTemplate, jdbcExecuteUpdate, log, logSlow, namedJdbcExecuteUpdate, namedJdbcExecuteUpdateWithLog, rollback, setApplicationContext, setFetchSize, setInterceptors, setJdbcTemplate, setMaxPageSize, setNamedParameterJdbcTemplate, setTimeoutWarningCallback, setTimeoutWarningValve, turnOffFeature, turnOnFeatureMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.pugwoo.dbhelper.DBHelper
delete, delete, delete, deleteHard, deleteHard, deleteHard, executeRaw, executeRaw, insertOrUpdate, insertOrUpdate, insertOrUpdateWithNull, update, update, update, updateAll, updateCustom, updateWithNull, updateWithNull
-
Constructor Details
-
P2_InsertOp
public P2_InsertOp()
-
-
Method Details
-
insert
public <T> int insert(T t) Description copied from interface:DBHelper插入一条记录
如果包含了自增id,则自增Id会被设置。
【注】只插入非null的值,如要需要插入null值,则用insertWithNull。- Parameters:
t- 需要插入的DO对象实例- Returns:
- 实际修改的条数
-
insert
Description copied from interface:DBHelper批量插入多条记录,返回数据库实际修改的条数。
【说明】该方法没有事务,请在外层加事务。
【特别说明】因为需要获取自增主键,对于有自增id的插入,会降级为逐条插入,如果想提升性能,请使用insertBatchWithoutReturnId方法。- Parameters:
list- 需要插入的DO对象实例列表- Returns:
- 实际修改的条数
-
insertBatchWithoutReturnId
Description copied from interface:DBHelper批量插入多条记录,返回数据库实际修改的条数。
【重点】不会自动设置插入数据的返回自增ID(拦截器里也拿不到ID),也不会设置回数据库的默认值- Parameters:
list- 需要插入的DO对象实例列表- Returns:
- 实际修改的条数
-
insertBatchWithoutReturnId
Description copied from interface:DBHelper批量插入多条记录,返回数据库实际修改的条数。【不支持拦截器】- Parameters:
tableName- 插入的表名list- 列名和值- Returns:
- 实际修改的条数
-
insertBatchWithoutReturnId
public int insertBatchWithoutReturnId(String tableName, List<String> cols, Collection<Object[]> values) Description copied from interface:DBHelper以JDBCTemplate的batchUpdate方式,批量插入多条记录,返回数据库实际修改的条数。【不支持拦截器】- Parameters:
tableName- 插入的表名cols- 列的列表values- 参数列表,每个元素是一条记录的值,按照cols的顺序,个数必须和cols的个数一致- Returns:
- 实际修改的条数
-
insertWithNull
public <T> int insertWithNull(T t) Description copied from interface:DBHelper插入一条记录,返回数据库实际修改条数。
如果包含了自增id,则自增Id会被设置。- Parameters:
t- 需要插入的DO对象实例- Returns:
- 实际修改的条数
-