📄 bbsinfomanagedaohibernateimple.java
字号:
throw new WebBBSException("在数据库表中不存在指定bbsID="+bbsID+"的数据顶目!");
}
allBbsReplyInfosByOneBBS=oneBBSInfoPO.getBbsReplyInfosByBBS(); //只能在同一Session中获得对应的O/R Mapping对象
int bbsHitsCounter=oneBBSInfoPO.getHits();
oneBBSInfoPO.setHits(bbsHitsCounter+1);
tx.commit();
}
catch (HibernateException he)
{
throw new WebBBSException("在BBSInfoManageDAOHibernateImple类中的SelectBBSInfoByBBSID方法出现了HibernateException异常");
}
finally
{
HibernateUtil.closeSession();
}
return oneBBSInfoPO;
}
public ArrayList selectBBSInfoByBBSSendInfoTime(String sendInfoTime) throws WebBBSException
{
String HQLQuery="from com.px1987.webbbs.dao.BBSInfoPO as oneBBSInfoPO order by oneBBSInfoPO.hits desc where oneBBSInfoPO.sendInfoTime like '%"+sendInfoTime+"%'";
return selectSomeBBSInfo(HQLQuery);
}
public ArrayList selectBBSInfoByBBSTitle(String bbsTitleText) throws WebBBSException
{
String HQLQuery="from com.px1987.webbbs.dao.BBSInfoPO as oneBBSInfoPO order by oneBBSInfoPO.hits desc where oneBBSInfoPO.title='"+bbsTitleText+"'";
return selectSomeBBSInfo(HQLQuery);
}
public ArrayList selectBBSInfoByBBSTitleID(int bbsTitleID) throws WebBBSException
{
String HQLQuery="from com.px1987.webbbs.dao.BBSInfoPO as oneBBSInfoPO order by oneBBSInfoPO.hits desc where oneBBSInfoPO.bbsTitleID="+bbsTitleID;
return selectSomeBBSInfo(HQLQuery);
}
public ArrayList selectBBSInfoByUserID(String userID) throws WebBBSException
{
String HQLQuery="from com.px1987.webbbs.dao.BBSInfoPO as oneBBSInfoPO order by oneBBSInfoPO.hits desc where oneBBSInfoPO.userID='"+userID+"'";
return selectSomeBBSInfo(HQLQuery);
}
public ArrayList selectPageBBSInfoByLoginUserID(String userID,
int firstResult, int maxResults) throws WebBBSException
{
String hqlSelect="from com.px1987.webbbs.dao.BBSInfoPO as oneBBSInfoPO order by oneBBSInfoPO.hits desc where oneBBSInfoPO.userID='"+userID+"'";
return pageSelectDBData(hqlSelect, firstResult,maxResults);
}
public ArrayList selectPageBBSInfoByTitleID(int bbsTitleID,
int firstResult, int maxResults) throws WebBBSException
{
String hqlSelect="from com.px1987.webbbs.dao.BBSInfoPO as oneBBSInfoPO order by oneBBSInfoPO.hits desc where oneBBSInfoPO.bbsTitleID="+bbsTitleID;
return pageSelectDBData(hqlSelect, firstResult,maxResults);
}
public ArrayList selectPageBBSInfoByToday(int firstResult, int maxResults) throws WebBBSException
{
Date todayDate=new Date();
String todayDateString=(todayDate.getYear()+1900)+"-"+(todayDate.getMonth()+1)+"-"+todayDate.getDate();
String hqlSelect="from com.px1987.webbbs.dao.BBSInfoPO as oneBBSInfoPO order by oneBBSInfoPO.hits desc where oneBBSInfoPO.sendInfoTime like '%"+todayDateString+"%'";
return pageSelectDBData(hqlSelect, firstResult,maxResults);
}
public boolean updateBBSInfo(BBSInfoPO oneUpdatedBBSInfoPO) throws WebBBSException
{
boolean OKOrNot=false;
Session session=null;
Transaction tx=null;
BBSInfoPO oneReturnBBSInfoPO=null;
try
{
session = HibernateUtil.currentSession();
tx = session.beginTransaction();
oneReturnBBSInfoPO = (BBSInfoPO) session.get(BBSInfoPO.class, oneUpdatedBBSInfoPO.getId());
if(oneReturnBBSInfoPO==null)
{
throw new WebBBSException("在数据库表中不存在指定bbsID="+oneUpdatedBBSInfoPO.getId().toString()+"的数据顶目!");
}
oneReturnBBSInfoPO.setId(oneUpdatedBBSInfoPO.getId());
oneReturnBBSInfoPO.setAuthor(oneUpdatedBBSInfoPO.getAuthor());
oneReturnBBSInfoPO.setTitle(oneUpdatedBBSInfoPO.getTitle());
oneReturnBBSInfoPO.setReplay(oneUpdatedBBSInfoPO.getReplay());
oneReturnBBSInfoPO.setHits(oneUpdatedBBSInfoPO.getHits());
oneReturnBBSInfoPO.setSendInfoTime(oneUpdatedBBSInfoPO.getSendInfoTime());
oneReturnBBSInfoPO.setContent(oneUpdatedBBSInfoPO.getContent());
oneReturnBBSInfoPO.setMailto(oneUpdatedBBSInfoPO.getMailto());
oneReturnBBSInfoPO.setAbstractText(oneUpdatedBBSInfoPO.getAbstractText());
oneReturnBBSInfoPO.setLastUpdateTime(oneUpdatedBBSInfoPO.getLastUpdateTime());
oneReturnBBSInfoPO.setBbsIconID(oneUpdatedBBSInfoPO.getBbsIconID());
oneReturnBBSInfoPO.setBbsTypeID(oneUpdatedBBSInfoPO.getBbsTypeID());
oneReturnBBSInfoPO.setBbsTitleID(oneUpdatedBBSInfoPO.getBbsTitleID());
oneReturnBBSInfoPO.setUserID(oneUpdatedBBSInfoPO.getUserID());
session.flush();
tx.commit();
OKOrNot=true;
}
catch (HibernateException he)
{
throw new WebBBSException("在BBSInfoManageDAOHibernateImple类中的updateOneUserInfo方法出现了HibernateException异常");
}
finally
{
HibernateUtil.closeSession();
}
return OKOrNot;
}
public boolean updateBBSReplyCounterByBBSID(int bbsID) throws WebBBSException
{
boolean OKOrNot=false;
Session session=null;
Transaction tx=null;
String HQLQuery="update com.px1987.webbbs.dao.BBSInfoPO as oneBBSInfoPO set oneBBSInfoPO.replay=oneBBSInfoPO.replay+1 where oneBBSInfoPO.id="+bbsID;
try
{
session = HibernateUtil.currentSession();
tx = session.beginTransaction();
Query query = session.createQuery(HQLQuery);
query.executeUpdate();
tx.commit();
OKOrNot=true;
}
catch (HibernateException he)
{
throw new WebBBSException("在BBSInfoManageDAOHibernateImple类中的updateBBSReplyCounterByBBSID方法出现了HibernateException异常");
}
finally
{
HibernateUtil.closeSession();
}
return OKOrNot;
}
public boolean updateBBSInfoHitsByBbsID(int bbsID) throws WebBBSException
{
boolean OKOrNot=false;
Session session=null;
Transaction tx=null;
String HQLQuery="update com.px1987.webbbs.dao.BBSInfoPO as oneBBSInfoPO set oneBBSInfoPO.hits=oneBBSInfoPO.hits+1 where oneBBSInfoPO.id="+bbsID;
try
{
session = HibernateUtil.currentSession();
tx = session.beginTransaction();
Query query = session.createQuery(HQLQuery);
query.executeUpdate();
tx.commit();
OKOrNot=true;
}
catch (HibernateException he)
{
throw new WebBBSException("在BBSInfoManageDAOHibernateImple类中的updateBBSInfoHitsByBbsID方法出现了HibernateException异常");
}
finally
{
HibernateUtil.closeSession();
}
return OKOrNot;
}
public int getBBSInfoCounterBySendTime(String sendInfoTime) throws WebBBSException
{
String HQLQuery="select count(*) from com.px1987.webbbs.dao.BBSInfoPO as oneBBSInfoPO where oneBBSInfoPO.sendInfoTime like '%"+sendInfoTime+"%'";
return getBBSInfoTotalCounter(HQLQuery);
}
public int getBBSInfoTotalCounter(String HQLQuery) throws WebBBSException
{
int totalBBSInfoCounter;
Session session=null;
Transaction tx=null;
Query query =null;
try
{
session = HibernateUtil.currentSession();
tx = session.beginTransaction();
query = session.createQuery(HQLQuery);
Integer objectCounter=(Integer)query.uniqueResult();
totalBBSInfoCounter=objectCounter.intValue();
tx.commit();
}
catch (HibernateException he)
{
throw new WebBBSException("在BBSInfoManageDAOHibernateImple类中的getBBSInfoTotalCounter方法出现了HibernateException异常");
}
finally
{
HibernateUtil.closeSession();
}
return totalBBSInfoCounter;
}
public int getBBSInfoTotalCounter() throws WebBBSException
{
String HQLQuery="select count(*) from com.px1987.webbbs.dao.BBSInfoPO";
return getBBSInfoTotalCounter(HQLQuery);
}
public int getHotBBSInfoTotalCounter(int totalHits) throws WebBBSException
{
String HQLQuery="select count(*) from com.px1987.webbbs.dao.BBSInfoPO as oneBBSInfoPO where oneBBSInfoPO.hits >"+totalHits;
return getBBSInfoTotalCounter(HQLQuery);
}
public int getTotalBBSInfoCounterByUserID(String userID) throws WebBBSException
{
String HQLQuery="select count(*) from com.px1987.webbbs.dao.BBSInfoPO as oneBBSInfoPO where oneBBSInfoPO.userID='"+userID+"'";
return getBBSInfoTotalCounter(HQLQuery);
}
public int getBBSTotalCounterInOneBBSTitle(int bbsTitleID) throws WebBBSException
{
String HQLQuery="select count(*) from com.px1987.webbbs.dao.BBSInfoPO as oneBBSInfoPO where oneBBSInfoPO.bbsTitleID="+bbsTitleID;
return getBBSInfoTotalCounter(HQLQuery);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -