DAO layer development summary 1 (comment version)

xiaoxiao2021-03-06  95

import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import net.sf.hibernate.Query; import java.util *;. import net.sf.hibernate.HibernateException; import new97. Pub.Base. *; Import new97.pub.util. *; import new97.pub.err. *; import new97.ejb.po. *; import new97.ejb.vo. *;

Public Class Partydao Extends Basedao {Private Static Log = logfactory.getlog (PartyDao.Class);

/ ** * Added participants * @Param vo partyvo * @throws sysexception * @throws APPEXCEPTION * /

Public void createparty (partvo vo) throws sysexception, APPEXCEPTION {

Party party = new party (); // Newly built a PO object party.setcreated ()); Party.SetAddress (VO.GETDRESS ()); // Read all properties from VO (corresponding database related Table) Deposit into the PO object, slightly try {CERTTYPE CERTTYPE = (CERTTYPE) session.load (CERTTYPE.CLASS, VO.GETCERTTTTYPE ()); Convert to PO objects according to VO

Party.setCertType (CERTTYPE); // In the set method in the set method, the properties of the PO are an object, which requires this, the following is the same as Area Area = (area) session.load (Area.class, Vo.getarea) ))); Party.setarea (area); localnet localnet = (localnet) session.load (localnet.class, vol.getlocalnet ()); Party.setLocalNet (localnet);} catch (hibernateException he) {he.printstacktrace () ; // throw a business error. No need to handle, only for the user. THROW New APPEXCEPTION ("80001", HE);} Try {session.save (party); // Hibernate action: Save session.flush (); if (log.isdebugeload ()) {log.debug ("flushsession" );}} Catch (hibernateException he) {throw new sysexception ("10009", he);}}

/ ** * Modify Participants * @Param Vo Partyvo * @Throws Sysexception * @throws APPEXCEPTION * /

Public void updateParty (Partyvo Vo) throws Sysexception, APPEXCEPTION {Party Party = null; // New a PO object try = (party) session.Load (Party.class, vol.getPartyId ()); // According to VO ID, pass the table LOAD to the PO object through Hibernate, PARTY.SETCREATEDATE (VO.GETCREATEDATE ()); // According to Vo, put the modified data set to the PO object, slightly part.setaddress (vol.getaddress () );} Catch (hibernateException he) {// throws a business error. No need to handle, only for the user. Throw New APPEXCEPTION ("80002", He);} Try {CERTTYPE CERTTYPE = (CERTTYPE) Session (CERTTYPE.CLASS, VO.GETCERTTTYPE ()); Party.setcertType (CERTTYPE); // In the PO in the set method Parameters, that is, the properties of the PO are an object, which needs to do this, the following as Area Area = (Area) Session.Load (Area.class, Vo.getarea ()); Party.Setarea (Area); localnet localnet = (localnet Session.Load (localnet.class (); Party.SetLocalNet (localnet);} catch (he.printstacktrace (); // throws a business error. No need to handle, only for the user. Throw New APPEXCEPTION ("80001", He);} Try {session.saveorUpdate (Party); // Hibernate Action: Save session.flush () after modification;} catch (he.printstacktrace (); Throw new SYSEXCEPTION ("10010", HE);

}

/ ** * Delete Participants * @Param Vo Partyvo * @throws SYSEXCEPTION * @Throws APPEXCEPTION * /

Public void deleteparty (long partyid) throws sysexception {party v1 = null; // New PO object try {v1 = (party) session.load (Party.class, partyid); // According to the parameter ID, use Hibernate to take the table to Load to PO} catch (HibernateException He) {throw new sysexception ("10013", he);} try {session.delete (v1); // Hibernate action: Delete table session.flush ();} catch (HibernateException HE) {Throw new sysexception ("10013", he);}}}

转载请注明原文地址:https://www.9cbs.com/read-123169.html

New Post(0)