org.apache.ibatis.binding.MapperMethod Java Examples

The following examples show how to use org.apache.ibatis.binding.MapperMethod. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseServiceImpl.java    From cola-cloud with MIT License 6 votes vote down vote up
/**
 * 根据主键ID进行批量修改
 *
 * @param entityList 实体对象列表
 * @param batchSize  批量刷新个数
 * @param selective  是否滤掉空字段
 * @return boolean
 */
private boolean updateBatchById(List<T> entityList, int batchSize, boolean selective) {
    if (com.baomidou.mybatisplus.toolkit.CollectionUtils.isEmpty(entityList)) {
        throw new IllegalArgumentException("Error: entityList must not be empty");
    }
    try (SqlSession batchSqlSession = sqlSessionBatch()) {
        int size = entityList.size();
        SqlMethod sqlMethod = selective ? SqlMethod.UPDATE_BY_ID : SqlMethod.UPDATE_ALL_COLUMN_BY_ID;
        String sqlStatement = sqlStatement(sqlMethod);
        for (int i = 0; i < size; i++) {
            MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>();
            param.put("et", entityList.get(i));
            batchSqlSession.update(sqlStatement, param);
            if (i >= 1 && i % batchSize == 0) {
                batchSqlSession.flushStatements();
            }
        }
        batchSqlSession.flushStatements();
    } catch (Throwable e) {
        throw new MybatisPlusException("Error: Cannot execute updateBatchById Method. Cause", e);
    }
    return true;
}
 
Example #2
Source File: PaginationMapperProxy.java    From Shop-for-JavaWeb with MIT License 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    if (isObjectMethod(method)) {
        return null;
    }
    final Class<?> declaringInterface = findDeclaringInterface(proxy, method);
    if (Page.class.isAssignableFrom(method.getReturnType())) {
        // 分页处理
        return new PaginationMapperMethod(declaringInterface, method, sqlSession).execute(args);
    }
    // 原处理方式
    final MapperMethod mapperMethod = new MapperMethod(declaringInterface, method, sqlSession.getConfiguration());
    final Object result = mapperMethod.execute(sqlSession, args);
    if (result == null && method.getReturnType().isPrimitive()) {
        throw new BindingException(
                "Mapper method '"
                        + method.getName()
                        + "' ("
                        + method.getDeclaringClass()
                        + ") attempted to return null from a method with a primitive return type ("
                        + method.getReturnType() + ").");
    }
    return result;
}