
org.swiftboot.data.model.dao.impl.BaseCustomizeDaoImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swiftboot-data Show documentation
Show all versions of swiftboot-data Show documentation
Data access component based on Spring-Data-JPA
package org.swiftboot.data.model.dao.impl;
import org.apache.commons.lang3.StringUtils;
import org.swiftboot.data.model.entity.IdPersistable;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
/**
* 自定义 Jpa Dao 接口的基类
*
* @author swiftech
**/
public abstract class BaseCustomizeDaoImpl {
@PersistenceContext
protected EntityManager entityManager;
protected Class entityClass;
/**
* 创建一个单个字段查询的 CriteriaQuery 对象
*
* @param key
* @param value
* @return
*/
protected CriteriaQuery makeCriteriaQuery(String key, Object value) {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery(entityClass);
Root from = cq.from(entityClass);
cq.select(from);
if (StringUtils.isNotBlank(key) && value != null) {
cq.where(
cb.equal(from.get(key), value)
);
}
return cq;
}
public EntityManager getEntityManager() {
return entityManager;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy