|
|
|
@ -10,7 +10,6 @@ import org.hibernate.NonUniqueResultException;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import javax.persistence.*;
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
@ -219,7 +218,6 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新参数汇总方法
|
|
|
|
|
*
|
|
|
|
|
* @param conditionName 条件属性名
|
|
|
|
|
* @param conditionValue 条件属性值
|
|
|
|
|
* @param propertyName 更新属性名
|
|
|
|
@ -480,22 +478,25 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public T getByProperty(DdlPackBean packBean) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
List<T> list = findByHqlWhere(packBean);
|
|
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
return list.size() != 0 ? list.get(0) : null;
|
|
|
|
|
}catch(NoResultException ne){
|
|
|
|
|
LOGGER.error("数据不存在,DdlPackBean:{}",packBean);
|
|
|
|
|
throw new RuntimeException("数据不存在");
|
|
|
|
|
} else if (list.size() > 1) {
|
|
|
|
|
return null;
|
|
|
|
|
}catch(NonUniqueResultException ex){
|
|
|
|
|
LOGGER.error("查询单条记录,但出现多条。packBean:{}",packBean);
|
|
|
|
|
throw new RuntimeException("存在多条记录");
|
|
|
|
|
throw new RuntimeException("存在多条记录:" + ex.getMessage());
|
|
|
|
|
}
|
|
|
|
|
return list.iterator().next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public T getByProperty(String propertyName, Object value) {
|
|
|
|
|
String queryString = "from " + persistentClass.getSimpleName() + " as model where model." + propertyName + "= :" + propertyName;
|
|
|
|
|
try {
|
|
|
|
|
return (T) entityManager.createQuery(queryString).setParameter(propertyName, value).getSingleResult();
|
|
|
|
|
List<T> list = entityManager.createQuery(queryString).setParameter(propertyName, value).getResultList();
|
|
|
|
|
return list.size() != 0 ? list.get(0) : null;
|
|
|
|
|
}catch(NoResultException ne){
|
|
|
|
|
LOGGER.error("数据不存在,prop:{},value:{}",propertyName,value,ne);
|
|
|
|
|
return null;
|
|
|
|
@ -532,7 +533,8 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
return (T) queryObject.getSingleResult();
|
|
|
|
|
List<T> list = queryObject.getResultList();
|
|
|
|
|
return list.size() != 0 ? list.get(0) : null;
|
|
|
|
|
}catch(NoResultException ne){
|
|
|
|
|
LOGGER.error("数据不存在",ne);
|
|
|
|
|
return null;
|
|
|
|
@ -1148,7 +1150,6 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存对象
|
|
|
|
|
*
|
|
|
|
|
* @param item 保存对象
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
@ -1212,7 +1213,6 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 对为赋值的属性进行赋值
|
|
|
|
|
*
|
|
|
|
|
* @param field
|
|
|
|
|
*/
|
|
|
|
|
private void fieldSetInitParam(T item,Field field) {
|
|
|
|
@ -1268,7 +1268,6 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量弱删除
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
@ -1291,7 +1290,6 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量弱删除
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
@ -1330,7 +1328,6 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量禁用
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
@ -1353,7 +1350,6 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量禁用
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|