public class GenIdKeyGenerator extends Object implements org.apache.ibatis.executor.keygen.KeyGenerator
| Constructor and Description |
|---|
GenIdKeyGenerator(GenId<?> genId,
EntityTable table,
EntityColumn column,
org.apache.ibatis.session.Configuration configuration,
boolean executeBefore) |
| Modifier and Type | Method and Description |
|---|---|
void |
genId(Object parameter) |
void |
prepare(Object parameter)
准备参数,当executeBefore=true时,需要在执行前生成主键,如果是在ms初始化前进来该方法,就没有生成id,这里需要补充执行一次
|
void |
processAfter(org.apache.ibatis.executor.Executor executor,
org.apache.ibatis.mapping.MappedStatement ms,
Statement stmt,
Object parameter) |
void |
processBefore(org.apache.ibatis.executor.Executor executor,
org.apache.ibatis.mapping.MappedStatement ms,
Statement stmt,
Object parameter) |
public GenIdKeyGenerator(GenId<?> genId, EntityTable table, EntityColumn column, org.apache.ibatis.session.Configuration configuration, boolean executeBefore)
public void processBefore(org.apache.ibatis.executor.Executor executor,
org.apache.ibatis.mapping.MappedStatement ms,
Statement stmt,
Object parameter)
processBefore in interface org.apache.ibatis.executor.keygen.KeyGeneratorpublic void processAfter(org.apache.ibatis.executor.Executor executor,
org.apache.ibatis.mapping.MappedStatement ms,
Statement stmt,
Object parameter)
processAfter in interface org.apache.ibatis.executor.keygen.KeyGeneratorpublic void genId(Object parameter)
public void prepare(Object parameter)
ms初始化之后再进来时,会按照selectKey的方式自动调用该方法,不需要再这里补充调用。
这里设置 CONCURRENCY 是为了避免后续ms正常后,这里判断为空会多此一举,所以设置一个阈值,超过阈值后就不再判断了。
只有当第一次出现并发插入超过 CONCURRENCY 值时,才可能会出现漏掉id的情况。
Copyright © 2023. All rights reserved.