package net.supersoft.jpoll.persistence.hibernatedao;import java.util.List;
import net.supersoft.common.error.DaoError;
import net.supersoft.common.exception.DaoException;
import net.supersoft.common.exception.Debug;
import net.supersoft.dao.HibernateUtil;
import net.supersoft.jpoll.domain.Voter;
import net.supersoft.jpoll.persistence.iface.VoterDao;
import org.hibernate.*;public class VoterHibernateDao
implements VoterDao
{ public VoterHibernateDao()
{
} public Voter getVoter(String name)
throws Exception
{
Voter voter;
Exception exception;
voter = new Voter();
try
{
Session session = HibernateUtil.currentSession();
HibernateUtil.beginTransaction();
String HQL = "FROM Voter AS v WHERE v.voterName=:voterName";
Query query = session.createQuery(HQL);
query.setString("voterName", name);
List list = query.list();
if (list != null && list.size() != 0)
voter = (Voter)list.get(0);
}
catch (HibernateException ex)
{
HibernateUtil.rollbackTransaction();
Debug.printErr(this, "From getVoter(String name)\r\n" + ex.getMessage());
throw new DaoException(DaoError.NO_VOTER);
}
finally
{
HibernateUtil.closeSession();
}
HibernateUtil.closeSession();
//break MISSING_BLOCK_LABEL_131;
throw exception;
return voter;
} public void insertVoter(Voter voter)
throws DaoException
{
Exception exception;
try
{
Session session = HibernateUtil.currentSession();
HibernateUtil.beginTransaction();
session.save(voter);
HibernateUtil.commitTransaction();
}
catch (HibernateException ex)
{
HibernateUtil.rollbackTransaction();
Debug.printErr(this, DaoError.INSERT_VOTER_FAILED, "insertVoter(Voter voter)", ex);
throw new DaoException(DaoError.INSERT_VOTER_FAILED);
}
finally
{
HibernateUtil.closeSession();
}
HibernateUtil.closeSession();
break MISSING_BLOCK_LABEL_55;
throw exception;
} public void updateVoter(Voter voter)
throws DaoException
{
Exception exception;
try
{
Session session = HibernateUtil.currentSession();
HibernateUtil.beginTransaction();
session.update(voter);
HibernateUtil.commitTransaction();
}
catch (HibernateException ex)
{
HibernateUtil.rollbackTransaction();
Debug.printErr(this, DaoError.UPDATE_VOTER_FAILED, "updateVoter(Voter voter)", ex);
throw new DaoException(DaoError.UPDATE_VOTER_FAILED);
}
finally
{
HibernateUtil.closeSession();
}
HibernateUtil.closeSession();
break MISSING_BLOCK_LABEL_54;
throw exception;
} public Voter searchVoter(String ipAddress, int groupId)
throws DaoException
{
Voter voter;
Exception exception;
voter = null;
try
{
Session session = HibernateUtil.currentSession();
HibernateUtil.beginTransaction();
String HQL = "FROM Voter AS vr WHERE vr.voterIpaddress=:ipAddress AND vr.voterGroupId=:groupId";
Query query = session.createQuery(HQL);
query.setString("ipAddress", ipAddress);
query.setInteger("groupId", groupId);
voter = (Voter)query.uniqueResult();
HibernateUtil.commitTransaction();
}
catch (HibernateException ex)
{
HibernateUtil.rollbackTransaction();
Debug.printErr(this, DaoError.NO_VOTER, "searchVoter(String ipAddress,int voteId)", ex);
throw new DaoException(DaoError.NO_VOTER);
}
finally
{
HibernateUtil.closeSession();
}
HibernateUtil.closeSession();
break MISSING_BLOCK_LABEL_102;//
throw exception;//  这几行代码老是报错说label丢失是怎么回事
return voter;//
}
}