com.github.developframework.resource.spring.mybatis.MybatisResourceHandler Maven / Gradle / Ivy
The newest version!
package com.github.developframework.resource.spring.mybatis;
import com.github.developframework.resource.ResourceDefinition;
import com.github.developframework.resource.ResourceHandler;
import com.github.developframework.resource.Search;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
/**
* mybatis资源操作器
*
* @author qiushui on 2020-05-28.
*/
public class MybatisResourceHandler<
PO extends MPO,
ID extends Serializable,
DAOMAPPER extends BaseDaoMapper
> implements ResourceHandler {
protected final DAOMAPPER daoMapper;
protected final ResourceDefinition resourceDefinition;
public MybatisResourceHandler(DAOMAPPER daoMapper, ResourceDefinition resourceDefinition) {
this.daoMapper = daoMapper;
this.resourceDefinition = resourceDefinition;
}
@Override
public boolean existsById(ID id) {
return daoMapper.existsById(resourceDefinition.getEntityClass(), id);
}
@Override
public void insert(PO entity) {
daoMapper.insert(entity);
}
@Override
public void insertAll(Collection entities) {
daoMapper.insertAll(resourceDefinition.getEntityClass(), entities);
}
@Override
public boolean update(PO entity) {
return daoMapper.update(entity);
}
@Override
public void deleteById(ID id) {
daoMapper.deleteById(resourceDefinition.getEntityClass(), id);
}
@Override
public void delete(PO entity) {
daoMapper.deleteById(resourceDefinition.getEntityClass(), entity.getId());
}
@Override
public Optional queryById(ID id) {
return daoMapper.findById(resourceDefinition.getEntityClass(), id);
}
@Override
public Optional queryByIdForUpdate(ID id) {
return daoMapper.findByIdForUpdate(resourceDefinition.getEntityClass(), id);
}
@Override
public List query(Search search) {
return daoMapper.findList(resourceDefinition.getEntityClass(), (MybatisSearch) search, null, null);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy