|
|
|
@ -651,6 +651,34 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int findByPropertyCountDemo(String[] propertyNames, Object[] values) {
|
|
|
|
|
if(propertyNames.length != values.length){
|
|
|
|
|
throw new IllegalArgumentException("参数错误数量和值个数不匹配!propertyNames:" + propertyNames.length + ",values:" + values.length);
|
|
|
|
|
}
|
|
|
|
|
StringBuffer queryString = new StringBuffer();
|
|
|
|
|
queryString.append("select count(*) from " + persistentClass.getName() + " as model where 1=1 ");
|
|
|
|
|
for (int i = 0; i < propertyNames.length; i++) {
|
|
|
|
|
if(values[i] != null) {
|
|
|
|
|
queryString.append(" and model." + propertyNames[i] + "= :" + propertyNames[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Query queryObject = entityManager.createQuery(queryString.toString(),Long.class);
|
|
|
|
|
for (int i = 0; i < propertyNames.length; i++) {
|
|
|
|
|
if(values[i] != null) {
|
|
|
|
|
queryObject.setParameter(propertyNames[i], values[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
Long count = (Long) queryObject.getSingleResult();
|
|
|
|
|
return count == null ? 0 : count.intValue();
|
|
|
|
|
}catch(NoResultException e){
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<T> findByPropertyPage(String propertyName, Object value, String orderByStuff, Pager pager) {
|
|
|
|
|
if(pager != null){
|
|
|
|
@ -1439,6 +1467,11 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isExitByPropertyDemo(String[] propertyNames, Object[] values) {
|
|
|
|
|
return findByPropertyCountDemo(propertyNames, values) > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isExitByHqlWhere(String hqlWhere, String[] propertyNames, Object[] values) {
|
|
|
|
|
return findByHqlWhereCount(hqlWhere,propertyNames,values) > 0;
|
|
|
|
|
}
|
|
|
|
|