?? messengerserviceimpl.java
字號:
package com.briup.run.service.impl;
import java.util.List;
import com.briup.run.common.exception.MemberServiceException;
import com.briup.run.common.exception.MessengerServiceException;
import com.briup.run.common.transaction.HibernateTransaction;
import com.briup.run.common.util.BeanFactory;
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;
import com.briup.run.service.IMessengerService;
public class MessengerServiceImpl implements IMessengerService {
public void AddBlack(BlackRecord record) throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
HibernateTransaction tran = new HibernateTransaction();
tran.beginTransaction();
try {
dao.saveBlackrecord(record);
tran.commit();
} catch (Exception e) {
tran.rollback();
throw new MessengerServiceException("The black's adding is failure");
}
}
@SuppressWarnings("unchecked")
public void addFriend(FriendRecord record) throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
HibernateTransaction tran = new HibernateTransaction();
tran.beginTransaction();
try {
List list=dao.findFriendByName(record.getSelfName());
for(Object obj:list){
FriendRecord fr=(FriendRecord)obj;
if (fr.getFriendName().equals(record.getFriendName()))
return;
}
dao.saveFriendrecord(record);
tran.commit();
} catch (Exception e) {
tran.rollback();
throw new MessengerServiceException("the friend's add is success!");
}
}
public void delBlackByRecordId(Long recordid)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
HibernateTransaction tran = new HibernateTransaction();
tran.beginTransaction();
try {
dao.delBlackrecord(recordid);
tran.commit();
} catch (Exception e) {
tran.rollback();
throw new MessengerServiceException("The black's delete failure");
}
}
public void delFriendByRecordId(Long recordid)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
HibernateTransaction tran = new HibernateTransaction();
tran.beginTransaction();
try {
dao.delFriendrecord(recordid);
tran.commit();
} catch (Exception e) {
tran.rollback();
throw new MessengerServiceException("The deleting of record's friend is failure");
}
}
public void delReMessage(Long id) throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
HibernateTransaction tran = new HibernateTransaction();
tran.beginTransaction();
try {
MessageRecord message = dao.findMessageById(id);
if (message.getSenderStatus() == 1) {
dao.delMessage(message);
} else {
message.setReceiverStatus(1l);
dao.saveMessage(message);
}
tran.commit();
} catch (Exception e) {
tran.rollback();
throw new MessengerServiceException("delete the recieve'message failure");
}
}
public void delSeMessage(Long id) throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
HibernateTransaction tran = new HibernateTransaction();
tran.beginTransaction();
try {
MessageRecord message = dao.findMessageById(id);
if (message.getReceiverStatus() == 1) {
dao.delMessage(message);
} else {
message.setReceiverStatus(1l);
dao.saveMessage(message);
}
tran.commit();
} catch (Exception e) {
tran.rollback();
throw new MessengerServiceException("delete the send's message failure");
}
}
@SuppressWarnings("unchecked")
public List findAllBlacks(String selfname, int start, int end)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
try {
List list = dao.findAllBlacks(selfname, start, end);
return list;
} catch (Exception e) {
e.printStackTrace();
throw new MessengerServiceException("find all black failure!");
}
}
@SuppressWarnings("unchecked")
public List findAllFriends(String selfname, int start, int end)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
try {
List list = dao.findAllFriends(selfname, start, end);
return list;
} catch (Exception e) {
e.printStackTrace();
throw new MessengerServiceException("find all of friends failure");
}
}
public MessageRecord findMessageDetail(Long messageid)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
HibernateTransaction tran = new HibernateTransaction();
tran.beginTransaction();
try {
MessageRecord record = dao.findMessageById(messageid);
record.setStatus(1l);
tran.commit();
return record;
} catch (Exception e) {
e.printStackTrace();
tran.rollback();
throw new MessengerServiceException("find the detail of message failure");
}
}
@SuppressWarnings("unchecked")
public List findNewMessages(String nickname)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
try {
List list = dao.findNewMessages(nickname);
return list;
} catch (Exception e) {
e.printStackTrace();
throw new MessengerServiceException("find the new message failure");
}
}
@SuppressWarnings("unchecked")
public List findReMessages(String nickname, int start, int end)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
try {
List list = dao.findReMessages(nickname, start, end);
return list;
} catch (Exception e) {
e.printStackTrace();
throw new MessengerServiceException("find the recieve message failure");
}
}
@SuppressWarnings("unchecked")
public List findSeMessages(String nickname, int start, int end)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
try {
List list = dao.findSeMessages(nickname, start, end);
return list;
} catch (Exception e) {
e.printStackTrace();
throw new MessengerServiceException("find the send message failure");
}
}
@SuppressWarnings("unchecked")
public int findUnreadedMessagesNumber(String nickname)
throws MemberServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
try {
List list = dao.findNewMessages(nickname);
return list.size();
} catch (Exception e) {
e.printStackTrace();
throw new MemberServiceException("find the message of unread failure");
}
}
public String sendMessage(MessageRecord record)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
HibernateTransaction tran = new HibernateTransaction();
tran.beginTransaction();
try {
dao.saveMessage(record);
tran.commit();
return new String("the message's sending is successful!");
} catch (Exception e) {
tran.rollback();
throw new MessengerServiceException("the message's sending is failure!");
}
}
public void delFriendRecord(String selfName, String friendName)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
HibernateTransaction tran = new HibernateTransaction();
tran.beginTransaction();
try {
dao.delFriendRecord(selfName, friendName);
tran.commit();
} catch (Exception e) {
tran.rollback();
throw new MessengerServiceException("delete the friend's record failure");
}
}
public void moveToBlackList(String selfName, String blackName)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
HibernateTransaction tran = new HibernateTransaction();
tran.beginTransaction();
try {
BlackRecord record = new BlackRecord();
record.setSelfName(selfName);
record.setBlackName(blackName);
dao.delFriendRecord(selfName, blackName);
dao.saveBlackrecord(record);
tran.commit();
} catch (Exception e) {
tran.rollback();
throw new MessengerServiceException("move to the blacklist failure");
}
}
public void delBlackRecord(String selfName, String blackName)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
HibernateTransaction tran = new HibernateTransaction();
tran.beginTransaction();
try {
dao.delBlackRecord(selfName, blackName);
tran.commit();
} catch (Exception e) {
tran.rollback();
throw new MessengerServiceException("delete the record of black failure");
}
}
public void moveToBuddyList(String selfName, String friendName)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
HibernateTransaction tran = new HibernateTransaction();
tran.beginTransaction();
try {
FriendRecord record = new FriendRecord();
record.setSelfName(selfName);
record.setFriendName(friendName);
dao.delBlackRecord(selfName, friendName);
dao.saveFriendrecord(record);
tran.commit();
} catch (Exception e) {
tran.rollback();
throw new MessengerServiceException("move to the buddy list failure");
}
}
@SuppressWarnings("unchecked")
public List findAllMember(int start, int end)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
try {
List list = dao.findAllMember(start, end);
return list;
} catch (Exception e) {
e.printStackTrace();
throw new MessengerServiceException("find all of members failure");
}
}
public Integer findReMessages(String nickname)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
try {
Integer num = dao.findReMessages(nickname);
return num;
} catch (Exception e) {
e.printStackTrace();
throw new MessengerServiceException("finding the message of recieve is failure");
}
}
public Integer findSeMessages(String nickname)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
try {
Integer num = dao.findSeMessages(nickname);
return num;
} catch (Exception e) {
e.printStackTrace();
throw new MessengerServiceException("finding the message of send is failure");
}
}
public Integer getAllBlackNum(String selfName)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
try {
Integer num = dao.getAllBlackNum(selfName);
return num;
} catch (Exception e) {
e.printStackTrace();
throw new MessengerServiceException("finding the number of black is failure");
}
}
public Integer getAllFriendNum(String selfName)
throws MessengerServiceException {
IMessengerDao dao = (IMessengerDao) BeanFactory.getBean("messengerDao");
try {
Integer num = dao.getAllFriendNum(selfName);
return num;
} catch (Exception e) {
e.printStackTrace();
throw new MessengerServiceException("finding the number of friend is failure");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -