📄 messengerdaoimpl.java
字号:
package com.briup.run.dao.impl;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import com.briup.run.common.util.HibernateSessionFactory;
import com.briup.run.dao.IMessengerDao;
import com.briup.run.dao.bean.BlackRecord;
import com.briup.run.dao.bean.FriendRecord;
import com.briup.run.dao.bean.MessageRecord;
public class MessengerDaoImpl implements IMessengerDao {
public void delBlackrecord(BlackRecord record) throws Exception {
Session session=HibernateSessionFactory.getSession();
session.delete(record);
}
public void delBlackrecord(Long recordid) throws Exception {
Session session=HibernateSessionFactory.getSession();
session.createQuery("delete from BlackRecord where id="+recordid).executeUpdate();
}
public void delFriendrecord(Long recordid) throws Exception {
Session session=HibernateSessionFactory.getSession();
session.createQuery("delete from FriendRecord where id="+recordid).executeUpdate();
}
public void delFriendrecord(FriendRecord record) throws Exception {
Session session=HibernateSessionFactory.getSession();
session.delete(record);
}
public void delMessage(MessageRecord record) throws Exception {
Session session=HibernateSessionFactory.getSession();
session.delete(record);
}
@SuppressWarnings("unchecked")
public List findAllBlacks(String selfname,int start,int end) throws Exception {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("from BlackRecord where selfName=?");
query.setString(0, selfname);
query.setFirstResult(start);
query.setMaxResults(end);
return query.list();
}
@SuppressWarnings("unchecked")
public List findAllFriends(String selfname,int start,int end) throws Exception {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("from FriendRecord where selfName=?");
query.setString(0, selfname);
query.setFirstResult(start);
query.setMaxResults(end);
return query.list();
}
public BlackRecord findBlackrecord(String selfname, String blackname) throws Exception {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("from BlackRecord where selfName=? and blackName=?");
query.setString(0, selfname);
query.setString(1, blackname);
return (BlackRecord)query.list().get(0);
}
public FriendRecord findFriendrecord(String selfname, String friendname) throws Exception {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("from FriendRecord where selfName=? and blackName=?");
query.setString(0, selfname);
query.setString(1, friendname);
return (FriendRecord)query.list().get(0);
}
public MessageRecord findMessageById(Long id) throws Exception {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("from MessageRecord where id=?");
query.setLong(0,id);
return (MessageRecord)query.uniqueResult();
}
@SuppressWarnings("unchecked")
public List findNewMessages(String nickname) throws Exception {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("from MessageRecord where receiver=? and status=? and receiverStatus=? order by sendDate");
query.setString(0,nickname);
query.setLong(1, 0l);
query.setLong(2, 0l);
return query.list();
}
@SuppressWarnings("unchecked")
public List findReMessages(String nickname,int start,int end) throws Exception {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("from MessageRecord where receiver=? and receiverStatus=? order by status,sendDate desc");
query.setString(0,nickname);
query.setLong(1, 0l);
query.setFirstResult(start);
query.setMaxResults(end);
return query.list();
}
@SuppressWarnings("unchecked")
public List findSeMessages(String nickname,int start,int end) throws Exception {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("from MessageRecord where sender=? and senderStatus=? order by sendDate desc");
query.setString(0,nickname);
query.setLong(1, 0l);
query.setFirstResult(start);
query.setMaxResults(end);
return query.list();
}
public int findUnreadedMessagesNumber(String nickname) throws Exception {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("from MessageRecord where receiver=? and receiverStatus=? and status=?");
query.setString(0,nickname);
query.setLong(1,0l);
query.setLong(2,0l);
return query.list().size();
}
public void saveBlackrecord(BlackRecord record) throws Exception {
Session session=HibernateSessionFactory.getSession();
session.save(record);
}
public void saveFriendrecord(FriendRecord record) throws Exception {
Session session=HibernateSessionFactory.getSession();
session.save(record);
}
public void saveMessage(MessageRecord record) throws Exception {
Session session=HibernateSessionFactory.getSession();
session.save(record);
}
public void delFriendRecord(String selfName, String friendName) throws Exception {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("delete from FriendRecord where selfName=? and friendName=?");
query.setString(0, selfName);
query.setString(1, friendName);
query.executeUpdate();
}
public void delBlackRecord(String selfName, String blackName) throws Exception {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("delete from BlackRecord where selfName=? and blackName=?");
query.setString(0, selfName);
query.setString(1, blackName);
query.executeUpdate();
}
@SuppressWarnings("unchecked")
public List findAllMember(int start, int end) throws Exception {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("from MemberInfo");
query.setFirstResult(start);
query.setMaxResults(end);
return query.list();
}
public Integer findReMessages(String nickname) throws Exception {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("from MessageRecord where receiver=? and receiverStatus=? ");
query.setString(0,nickname);
query.setLong(1, 0l);
return query.list().size();
}
public Integer findSeMessages(String nickname) throws Exception {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("from MessageRecord where sender=? and senderStatus=?");
query.setString(0,nickname);
query.setLong(1, 0l);
return query.list().size();
}
public Integer getAllFriendNum(String selfName) throws Exception {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("from FriendRecord where selfName=?");
query.setString(0, selfName);
return query.list().size();
}
public Integer getAllBlackNum(String selfName) throws Exception {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("from BlackRecord where selfName=?");
query.setString(0, selfName);
return query.list().size();
}
public List findFriendByName(String selfName) throws Exception {
Session session=HibernateSessionFactory.getSession();
Query query=session.createQuery("from FriendRecord where selfName=?");
query.setString(0, selfName);
return query.list();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -