io.github.dengchen2020.mybatis.methods.SelectByIdForUpdateMethod Maven / Gradle / Ivy
package io.github.dengchen2020.mybatis.methods;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import io.github.dengchen2020.mybatis.base.BaseMybatisRepository;
import org.apache.ibatis.mapping.MappedStatement;
import java.io.Serializable;
/**
* 根据id查询并加锁
* @author dengchen
* @since 2024/6/22
*/
public class SelectByIdForUpdateMethod extends AbstractMethod {
public SelectByIdForUpdateMethod(String methodName) {
super(methodName);
}
@Override
public MappedStatement injectMappedStatement(Class> mapperClass, Class> modelClass, TableInfo tableInfo) {
String sql = "SELECT "+tableInfo.getAllSqlSelect()+" FROM " + tableInfo.getTableName() + " WHERE id = #{id} FOR UPDATE";
return addSelectMappedStatementForTable(BaseMybatisRepository.class, languageDriver.createSqlSource(configuration, sql, Serializable.class), tableInfo);
}
}