posts - 167,  comments - 30,  trackbacks - 0
           public List<CertInfoListView> getInfoList(CertInfoListView view) throws DAOException {
            List<CertInfoListView>  liinfo = new ArrayList<CertInfoListView>();
            String sql="select b.usercode,b.agentcode,i.sn,i.cert,i.certstate,i.endtime, i.ipasskeyno,b.id,b.addtime  from certbind b inner join certinfo i on b.ipasskeyno=i.ipasskeyno";
            Session session = HibernateTemplate.getInstance().getSession();
            StringBuffer sb = new StringBuffer(sql);
            sb.append(" where 1=1 ");
            if(!CheckEmpty.isEmpty(view.getIpasskeyno())){
             sb.append(" and i.ipasskeyno ='").append(view.getIpasskeyno()).append("'");
            }
            if(!CheckEmpty.isEmpty(view.getAgentcode())){
             sb.append(" and b.agentcode ='").append(view.getAgentcode()).append("'");
            }
            if(!CheckEmpty.isEmpty(view.getSn())){
             sb.append(" and i.sn ='").append(view.getSn()).append("'");
            }
            if(!CheckEmpty.isEmpty(view.getUsercode())){
             sb.append(" and b.usercode ='").append(view.getUsercode()).append("'");
            }
            if(view.getAddtime()!=null){
             sb.append(" and b.addtime=").append(view.getAddtime());
            }
            sb.append(" order by ipasskeyno ,addtime desc");
            Query q = session.createSQLQuery(sb.toString());
            int pageno = view.getPageno();
            int size = view.getPagesize();
            if(pageno!=0&&size!=0){
             q.setFirstResult((pageno-1)*size);
             q.setMaxResults(size);
            }
            List list = q.list();
            Iterator it = list.iterator();
            while(it.hasNext()){
             Object[] obj = (Object[])it.next();
             CertInfoListView c = new CertInfoListView();
             for(int i=0;i<obj.length;i++){
              if(!CheckEmpty.isEmpty((String)obj[0])){
               c.setUsercode((String)obj[0]);
              }
              if(!CheckEmpty.isEmpty((String)obj[1])){
               c.setAgentcode((String)obj[1]);
              }
              if(!CheckEmpty.isEmpty((String)obj[2])){
               c.setSn((String)obj[2]);
              }
              if(obj[3]!=null){
               SerializableClob sc = (SerializableClob)obj[3];
               String cc = null;
               if(sc!=null){
                try {
                 cc = sc.getSubString(1, (int)sc.length());
                } catch (SQLException e) {
                }
               }
               if(cc!=null)c.setCert(cc);
              }
              if(obj[4]!=null){
               BigDecimal b = (BigDecimal)obj[4];
               c.setCertstate(b.intValue());
              }
              if((obj[5])!=null){
               c.setEndtime(((Date)obj[5]));
              }
              if(!CheckEmpty.isEmpty((String)obj[6])){
               c.setIpasskeyno((String)obj[6]);
              }
              c.setCertbindid(Integer.parseInt((String)obj[7]));
              c.setAddtime((Date)obj[8]);
             }
             liinfo.add(c);
            }
            if(session!=null&&session.isConnected())session.close();
            return liinfo;
           }


          實現分頁的DAO
          /*
            * (non-Javadoc)
            *
            * @see com.cns.certservice.dao.CertBindTabDao#getCertBindList(com.cns.certservice.vo.CertBindView)
            */
           public List<CertBindView> getCertBindList(CertBindView view)
             throws DAOException {
            List<CertBindView> li = null;
            List<Certbind> lic = null;
            Session session = null;
            try {
             session = HibernateTemplate.getInstance().getSession();
             Criteria cri = session.createCriteria(Certbind.class);
             Certbind c = getCertBind(view);
             if (c.getAddtime() != null) {
              cri.add(Expression.eq("addtime", c.getAddtime()));
             }
             if (!CheckEmpty.isEmpty(c.getAgentcode())) {
              cri.add(Expression.eq("agentcode", c.getAgentcode()));
             }
             if(c.getId()!=0)cri.add(Expression.eq("id", c.getId()));
             if (!CheckEmpty.isEmpty(c.getIpasskeyno())) {
              cri.add(Expression.eq("ipasskeyno", c.getIpasskeyno()));
             }
             if (!CheckEmpty.isEmpty(c.getUsercode())) {
              cri.add(Expression.eq("usercode", c.getUsercode()));
             }
             if (!CheckEmpty.isEmpty(c.getExtend1())) {
              cri.add(Expression.eq("extend1", c.getExtend1()));
             }
             if (!CheckEmpty.isEmpty(c.getExtend2())) {
              cri.add(Expression.eq("extend2", c.getExtend2()));
             }
             if (c.getAgenttype() != 0) {
              cri.add(Expression.eq("agenttype", c.getAgenttype()));
             }
             int pageno = view.getPageno();
             int size = view.getPagesize();
             if(pageno!=0&&size!=0){
              cri.setFirstResult((pageno-1)*size);
              cri.setMaxResults(size);
             }
             lic = cri.list();
             if (lic != null) {
              li = new ArrayList<CertBindView>();
              for (Certbind cer : lic) {
               CertBindView v = getCertBindView(cer);
               li.add(v);
              }
             }
             
            } catch (HibernateException e) {
             log.error(e,e);
             throw new DAOException(e);
            }finally{
             if (session != null && session.isConnected())
              session.close();
            }
            return li;
           }
           public int getInfoListCount(CertBindView view) throws DAOException {
            int count = 0;
            Session session = null;
            try {
             session = HibernateTemplate.getInstance().getSession();
             Criteria cri = session.createCriteria(Certbind.class);
             Certbind c = getCertBind(view);
             if (c.getAddtime() != null) {
              cri.add(Expression.eq("addtime", c.getAddtime()));
             }
             if (!CheckEmpty.isEmpty(c.getAgentcode())) {
              cri.add(Expression.eq("agentcode", c.getAgentcode()));
             }
             if(c.getId()!=0)cri.add(Expression.eq("id", c.getId()));
             if (!CheckEmpty.isEmpty(c.getIpasskeyno())) {
              cri.add(Expression.eq("ipasskeyno", c.getIpasskeyno()));
             }
             if (!CheckEmpty.isEmpty(c.getUsercode())) {
              cri.add(Expression.eq("usercode", c.getUsercode()));
             }
             if (!CheckEmpty.isEmpty(c.getExtend1())) {
              cri.add(Expression.eq("extend1", c.getExtend1()));
             }
             if (!CheckEmpty.isEmpty(c.getExtend2())) {
              cri.add(Expression.eq("extend2", c.getExtend2()));
             }
             if (c.getAgenttype() != 0) {
              cri.add(Expression.eq("agenttype", c.getAgenttype()));
             }
             count = (Integer)cri.setProjection(Projections.rowCount()).uniqueResult();
             cri.setProjection(null);
            } catch (HibernateException e) {
             log.error(e,e);
             throw new DAOException(e);
            }finally{
             if (session != null && session.isConnected())
              session.close();
            }
            return count;
           }

          /*
            * (non-Javadoc)
            *
            * @see com.cns.certservice.dao.CertBindTabDao#updateCertBind(com.cns.certservice.vo.CertBindView)
            */
           public boolean updateCertBind(CertBindView view) throws DAOException {
            boolean res = false;
            if (view.getId()==0) {
             throw new DAOException("getId from CertBindView is null!");
            }
            Session session= null;
            try {
             session = HibernateTemplate.getInstance().getSession();
             Certbind c = (Certbind) session.get(Certbind.class, view.getId());
             if (!CheckEmpty.isEmpty(view.getAgentcode()))
              c.setAgentcode(view.getAgentcode());
             if (!CheckEmpty.isEmpty(view.getExtend1()))
              c.setExtend1(view.getExtend1());
             if (!CheckEmpty.isEmpty(view.getExtend2()))
              c.setExtend2(view.getExtend2());
             if (!CheckEmpty.isEmpty(view.getIpasskeyno()))
              c.setIpasskeyno(view.getIpasskeyno());
             if (!CheckEmpty.isEmpty(view.getUsercode()))
              c.setUsercode(view.getUsercode());
             if (view.getAgenttype() != 0)
              c.setAgenttype(view.getAgenttype());
             res = HibernateTemplate.getInstance().updateObject(c);
            } catch (HibernateException e) {
             log.error(e,e);
             throw new DAOException(e);
            }finally{
             if (session != null && session.isConnected())
              session.close();
            }
            return res;
           }


           private Certbind getCertBind(CertBindView view) {
            Certbind c = new Certbind();
            if (view.getAddtime() != null)
             c.setAddtime(view.getAddtime());
            if (!CheckEmpty.isEmpty(view.getAgentcode()))
             c.setAgentcode(view.getAgentcode());
            if (!CheckEmpty.isEmpty(view.getExtend1()))
             c.setExtend1(view.getExtend1());
            if (!CheckEmpty.isEmpty(view.getExtend2()))
             c.setExtend2(view.getExtend2());
            if (!CheckEmpty.isEmpty(view.getIpasskeyno()))
             c.setIpasskeyno(view.getIpasskeyno());
            if (!CheckEmpty.isEmpty(view.getUsercode()))
             c.setUsercode(view.getUsercode());
            if(view.getId()!=0)c.setId(view.getId());
            if (view.getAgenttype() != 0)
             c.setAgenttype(view.getAgenttype());
            return c;
           }

           private CertBindView getCertBindView(Certbind view) {
            CertBindView c = new CertBindView();
            if (view.getAddtime() != null)
             c.setAddtime(view.getAddtime());
            if (!CheckEmpty.isEmpty(view.getAgentcode()))
             c.setAgentcode(view.getAgentcode());
            if (!CheckEmpty.isEmpty(view.getExtend1()))
             c.setExtend1(view.getExtend1());
            if (!CheckEmpty.isEmpty(view.getExtend2()))
             c.setExtend2(view.getExtend2());
            if (!CheckEmpty.isEmpty(view.getIpasskeyno()))
             c.setIpasskeyno(view.getIpasskeyno());
            if (!CheckEmpty.isEmpty(view.getUsercode()))
             c.setUsercode(view.getUsercode());
            if(view.getId()!=0)c.setId(view.getId());
            if (view.getAgenttype() != 0)
             c.setAgenttype(view.getAgenttype());
            return c;
           }

          posted on 2009-08-20 13:37 David1228 閱讀(861) 評論(0)  編輯  收藏 所屬分類: Hibernate/ibatis

          <2009年8月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          文章檔案

          新聞分類

          新聞檔案

          相冊

          收藏夾

          Java

          Linux知識相關

          Spring相關

          云計算/Linux/虛擬化技術/

          友情博客

          多線程并發編程

          開源技術

          持久層技術相關

          搜索

          •  

          積分與排名

          • 積分 - 359875
          • 排名 - 154

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 左权县| 都昌县| 托克托县| 玉溪市| 广平县| 高尔夫| 老河口市| 浦县| 和平区| 探索| 如皋市| 樟树市| 龙口市| 阳东县| 宁南县| 九寨沟县| 柳江县| 安乡县| 宣汉县| 合山市| 呼玛县| 木里| 自贡市| 罗平县| 临颍县| 清水河县| 塔城市| 成都市| 抚顺市| 四会市| 阿城市| 镇平县| 旬阳县| 正镶白旗| 永昌县| 任丘市| 建阳市| 中方县| 内江市| 华容县| 玉溪市|