fix: 修复自增主键并发线程问题
This commit is contained in:
@@ -56,13 +56,13 @@ public interface TableMapper {
|
||||
|
||||
int updateBatchByPk(@Param("sql")String sql);
|
||||
|
||||
void lockSequence(@Param("tableName")String tableName);
|
||||
int lockSequence(@Param("tableName")String tableName);
|
||||
|
||||
void unlockSequence(@Param("tableName") String tableName);
|
||||
int unlockSequence(@Param("tableName") String tableName);
|
||||
|
||||
void lockSequenceDm(@Param("tableName") String tableName);
|
||||
int lockSequenceDm(@Param("tableName") String tableName);
|
||||
|
||||
void unlockSequenceDm(@Param("tableName") String tableName);
|
||||
int unlockSequenceDm(@Param("tableName") String tableName);
|
||||
|
||||
void createSequenceSafeDm(@Param("tableName") String tableName, @Param("pkName") String pkName);
|
||||
int createSequenceSafeDm(@Param("tableName") String tableName, @Param("pkName") String pkName);
|
||||
}
|
||||
|
||||
@@ -178,18 +178,18 @@
|
||||
INCREMENT BY 1
|
||||
CACHE 1;
|
||||
</insert>
|
||||
<select id="setValForHighGoSequence">
|
||||
<update id="setValForHighGoSequence">
|
||||
SELECT setval( '${tableName}_seq', (SELECT COALESCE(MAX(${pkName}),0) + 1 FROM ${tableName}), false);
|
||||
</select>
|
||||
</update>
|
||||
<!-- 获取锁 -->
|
||||
<select id="lockSequence">
|
||||
<update id="lockSequence">
|
||||
SELECT pg_advisory_lock(hashtext('${tableName}_seq'));
|
||||
</select>
|
||||
</update>
|
||||
|
||||
<!-- 释放锁 -->
|
||||
<select id="unlockSequence" >
|
||||
<update id="unlockSequence" >
|
||||
SELECT pg_advisory_unlock(hashtext('${tableName}_seq'));
|
||||
</select>
|
||||
</update>
|
||||
<update id="lockSequenceDm">
|
||||
DECLARE
|
||||
result INT;
|
||||
|
||||
Reference in New Issue
Block a user