All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.org.atool.fluent.mybatis.base.dao.BaseDao Maven / Gradle / Ivy

package cn.org.atool.fluent.mybatis.base.dao;

import cn.org.atool.fluent.mybatis.base.IBaseDao;
import cn.org.atool.fluent.mybatis.base.IEntity;
import cn.org.atool.fluent.mybatis.base.crud.IQuery;
import cn.org.atool.fluent.mybatis.base.crud.IUpdate;

import java.util.ArrayList;
import java.util.List;

/**
 * BaseDaoImpl
 *
 * @param  实体类
 * @author darui.wu
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public abstract class BaseDao implements IBaseDao, IProtectedDao {

    /**
     * 无任何条件的查询
     *
     * @return IQuery
     */
    protected abstract IQuery query();

    /**
     * 无任何设置的更新器
     *
     * @return IUpdate
     */
    protected abstract IUpdate updater();

    /**
     * 构造默认查询条件
     *
     * @return IQuery
     */
    protected abstract > Q defaultQuery();

    /**
     * 构造默认更新条件
     *
     * @return IUpdate
     */
    protected abstract > U defaultUpdater();

    @Override
    public boolean updateEntityByIds(E... entities) {
        List updates = new ArrayList<>(entities.length);
        for (IEntity entity : entities) {
            IUpdate update = DaoHelper.buildUpdateEntityById(this::updater, entity);
            updates.add(update);
        }
        int count = this.mapper().updateBy(updates.toArray(new IUpdate[0]));
        return count > 0;
    }

    @Override
    public int updateBy(E updateNoN, E whereNoN) {
        IUpdate updater = DaoHelper.buildUpdateByEntityNoN(this::defaultUpdater, updateNoN, whereNoN);
        return this.updateBy(updater);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy