org.zodiac.mybatisplus.binding.query.dynamic.ExtQueryWrapper Maven / Gradle / Ivy
package org.zodiac.mybatisplus.binding.query.dynamic;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
import org.zodiac.core.exception.IllegalUsageException;
import org.zodiac.mybatisplus.binding.helper.ServiceAdaptor;
import org.zodiac.mybatisplus.binding.parser.ParserCache;
import org.zodiac.mybatisplus.model.MyBatisPlusPagination;
import org.zodiac.mybatisplus.util.MyBatisPlusUtil;
public class ExtQueryWrapper extends QueryWrapper {
private static final long serialVersionUID = -6286866332919807523L;
/**
* 主实体class
*/
private Class mainEntityClass;
public ExtQueryWrapper() {
super();
}
public ExtQueryWrapper(T entity, String... columns) {
super(entity, columns);
}
public ExtQueryWrapper(T entity) {
super(entity);
}
public Class getMainEntityClass() {
return mainEntityClass;
}
public void setMainEntityClass(Class mainEntityClass) {
this.mainEntityClass = mainEntityClass;
}
public String getEntityTable() {
if (this.mainEntityClass == null) {
this.mainEntityClass = getEntityClass();
}
return ParserCache.getEntityTableName(this.mainEntityClass);
}
public T queryOne(Class entityClazz) {
this.mainEntityClass = entityClazz;
IService iService = MyBatisPlusUtil.getIServiceByEntity(this.mainEntityClass);
if (iService != null) {
return ServiceAdaptor.getSingleEntity(iService, this);
} else {
throw new IllegalUsageException("查询对象无BaseService/IService实现: " + this.mainEntityClass.getSimpleName());
}
}
public List queryList(Class entityClazz) {
this.mainEntityClass = entityClazz;
IService iService = MyBatisPlusUtil.getIServiceByEntity(entityClazz);
if (iService != null) {
return ServiceAdaptor.queryList(iService, this);
} else {
throw new IllegalUsageException("查询对象无BaseService/IService实现: " + entityClazz.getSimpleName());
}
}
public List queryList(Class entityClazz, MyBatisPlusPagination myBatisPlusPagination) {
this.mainEntityClass = entityClazz;
IService iService = MyBatisPlusUtil.getIServiceByEntity(entityClazz);
if (iService != null) {
return ServiceAdaptor.queryList(iService, this, myBatisPlusPagination, entityClazz);
} else {
throw new IllegalUsageException("查询对象无BaseService/IService实现: " + entityClazz.getSimpleName());
}
}
}