添加update通过DdlPack

yun-zuoyi
alwaysfrin 6 years ago
parent b80cda2439
commit d0cac648f3

@ -105,6 +105,15 @@ public interface BaseRepository <T, ID extends Serializable> extends JpaReposito
int updateByProperties(String conditionName, Object conditionValue, String[] propertyName, Object[] propertyValue);
/**
*
* @param propertyName
* @param propertyValue
*/
int updateByProperties(String propertyName, Object propertyValue,DdlPackBean packBean);
int updateByProperties(String[] propertyName, Object[] propertyValue,DdlPackBean packBean);
/**
*
* @param conditionName
* @param conditionValue

@ -222,6 +222,40 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
}
@Override
public int updateByProperties(String propertyName, Object propertyValue,DdlPackBean packBean) {
return updateByProperties(new String[] { propertyName }, new Object[] { propertyValue },packBean);
}
@Override
public int updateByProperties(String[] propertyName, Object[] propertyValue,DdlPackBean packBean) {
if ((propertyName != null) && (propertyName.length > 0) && (propertyValue != null)
&& (propertyValue.length > 0) && (propertyName.length == propertyValue.length)) {
StringBuffer sb = new StringBuffer();
sb.append("update " + persistentClass.getName() + " model set ");
for (int i = 0; i < propertyName.length; i++) {
sb.append(propertyName[i] + " = :p_" + propertyName[i] + ",");
}
sb.deleteCharAt(sb.length() - 1);
sb.append(" where 1=1 " + packBean.getWhereAppend());
Query query = entityManager.createQuery(sb.toString());
//更新值
for (int i = 0; i < propertyName.length; i++) {
query.setParameter("p_" + propertyName[i], propertyValue[i]);
}
//查询条件
for (String key : packBean.getHqlPreparedMap().keySet()) {
query.setParameter(key,packBean.getHqlPreparedMap().get(key));
}
return query.executeUpdate();
} else {
throw new IllegalArgumentException("参数值错误!,propertyName:" + propertyName + ",propertyValue:" + propertyValue);
}
}
@Override
public int updateByHqlWhere(String hqlWhere, String propertyName, Object propertyValue) {
return updateByHqlWhere(hqlWhere, new String[]{propertyName}, new Object[]{propertyValue});
}

Loading…
Cancel
Save