DocSourceDAO代码:
- package com.jbcom.support.cms.dao;
- import com.jbcom.platform.spring.IBaseDao;
- /**
- * DocSource数据访问对象
- * @author Administrator
- *
- */
- public interface DocSourceDAO extends IBaseDao {
- public String getHQL_All();
- public String getHQL_RowCount();
- /**
- * 判断来源名称是否重复
- * @param docSourceId--来源标示
- * @param name--来源名称
- * @return T--重复 F--不重复
- */
- public boolean isNameExist(String docSourceId, String name);
- /**
- * 添加来源时判断来源名称是否重复
- * @param name--来源名称
- * @return isNameExist("0", name)方法的结果
- */
- public boolean isNameExist(String name);
- }
DocSourceDAOImpl代码:
- package com.jbcom.support.cms.dao.impl;
- import java.util.ArrayList;
- import java.util.List;
- import com.jbcom.platform.spring.BaseDaoImpl;
- import com.jbcom.support.cms.dao.DocSourceDAO;
- import com.jbcom.support.cms.hbm.DocSourceHBM;
- /**
- * DocSource数据访问对象
- * @author Administrator
- *
- */
- public class DocSourceDAOImpl extends BaseDaoImpl implements DocSourceDAO {
- public String getHQL_All() {
- return "from DocSourceHBM docSourceHBM";
- }
- public String getHQL_RowCount() {
- return "select count(*) from DocSourceHBM docSourceHBM";
- }
- protected Class getPersistentClass() {
- return DocSourceHBM.class;
- }
- /**
- * 判断来源名称是否重复
- * @param docSourceId--来源标示
- * @param name--来源名称
- * @return T--重复 F--不重复
- */
- public boolean isNameExist(String docSourceId,String name){
- List docSource ;
- docSource = new ArrayList();
- boolean reasult = false;
- if(!docSource.equals("0"))
- docSource = findWithHQL("FROM DocSourceHBM docSourceHBM where docSourceHBM.docSourceId<>'"
- + docSourceId
- + "' and docSourceHBM.name='"
- + name + "'");
- else
- docSource = findWithHQL("FROM DocSourceHBM docSourceHBM where docSourceHBM.name='"+name+"'");
- if (docSource.size() != 0)
- reasult = true;
- return reasult;
- }
- /**
- * 添加来源时判断来源名称是否重复
- * @param name--来源名称
- * @return isNameExist("0", name)方法的结果
- */
- public boolean isNameExist(String name){
- return isNameExist("0", name);
- }
- }
DocSourceEdit代码:
- package com.jbcom.support.cms.pages;
- import org.apache.tapestry.IRequestCycle;
- import org.apache.tapestry.valid.IValidationDelegate;
- import org.apache.tapestry.valid.ValidationConstraint;
- import com.jbcom.support.cms.dao.DocSourceDAO;
- import com.jbcom.support.cms.hbm.DocSourceHBM;
- import com.jbcom.support.cms.html.DocmentPage;
- import com.jbcom.support.tapestry.Visit;
- /**
- * 新增和修改来源
- *
- * @author Administrator
- */
- public abstract class DocSourceEdit extends DocmentPage {
- // 设定DAO类
- public abstract DocSourceDAO getDocSourceDAO();
- // 具体操作对象
- public abstract DocSourceHBM getDocSourceHBM();
- public abstract void setDocSourceHBM(DocSourceHBM docSourceHBM);
- /**
- * 来源信息的保存
- * @param cycle
- */
- public void save(IRequestCycle cycle) {
- IValidationDelegate validationDelegate = (IValidationDelegate) getBeans()
- .getBean("delegate");
- doValit(validationDelegate);
- if (validationDelegate.getHasErrors()){
- return;
- }
- DocSourceDAO dao = getDocSourceDAO();
- // 写入创建人
- getDocSourceHBM().setUser(((Visit)getVisit()).getLoginUser());
- dao.save(getDocSourceHBM());
- // 返回列表页
- DocSourceList nextPage = (DocSourceList) cycle.getPage("DocSourceList");
- cycle.activate(nextPage);
- }
- /**
- * 检验有效性
- * @param validationDelegate
- */
- private void doValit(IValidationDelegate validationDelegate) {
- if (validationDelegate.getHasErrors())
- return;
- DocSourceDAO docSourceDAO = getDocSourceDAO();
- String errorMessage = "";
- // 来源名称为空
- if (getDocSourceHBM().getName() == null
- || getDocSourceHBM().getName().trim().equals("")) {
- errorMessage = "请填写名称,名称不能为空!";
- validationDelegate.record(errorMessage,
- ValidationConstraint.CONSISTENCY);
- return;
- }
- // 来源名称重复
- boolean reasult;
- if(getDocSourceHBM().getDocSourceId()==null)
- reasult = docSourceDAO.isNameExist(getDocSourceHBM().getName());
- else
- reasult = docSourceDAO.isNameExist(getDocSourceHBM().getDocSourceId(),getDocSourceHBM().getName());
- if(reasult){
- errorMessage = "该名称已经被使用,请使用一个有效的名称!";
- validationDelegate.record(errorMessage,
- ValidationConstraint.CONSISTENCY);
- return;
- }
- // 标题过长
- if(getDocSourceHBM().getName().length() >= 50)
- {
- errorMessage = "名称过长!";
- validationDelegate.record(errorMessage,
- ValidationConstraint.CONSISTENCY);
- return;
- }
- // 描述过长
- if(getDocSourceHBM().getDescription()!=null){
- if(getDocSourceHBM().getDescription().length() >= 50)
- {
- errorMessage = "描述过长!";
- validationDelegate.record(errorMessage,
- ValidationConstraint.CONSISTENCY);
- return;
- }
- }
- // 来源链接地址为空
- if(getDocSourceHBM().getLink()==null ||getDocSourceHBM().getLink()=="" ){
- errorMessage = "请输入来源的链接地址!";
- validationDelegate.record(errorMessage,
- ValidationConstraint.CONSISTENCY);
- return;
- }
- // 链接过长
- if(getDocSourceHBM().getLink().length() >= 50)
- {
- errorMessage = "链接过长!";
- validationDelegate.record(errorMessage,
- ValidationConstraint.CONSISTENCY);
- return;
- }
- }
- }