-
Notifications
You must be signed in to change notification settings - Fork 4
/
FriendDAOImpl.java
105 lines (88 loc) · 2.74 KB
/
FriendDAOImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package com.niit.dao;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.niit.model.Friend;
import com.niit.model.User;
@SuppressWarnings("deprecation")
@Repository(value = "FriendDAO")
public class FriendDAOImpl implements FriendDAO {
@Autowired
private SessionFactory sessionFactory;
public FriendDAOImpl(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
@Transactional
public boolean save(Friend friend) {
// TODO Auto-generated method stub
try {
sessionFactory.getCurrentSession().save(friend);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
@Transactional
public boolean update(Friend friend) {
// TODO Auto-generated method stub
try {
sessionFactory.getCurrentSession().update(friend);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
@Transactional
public boolean delete(int userID,int friendID) {
// TODO Auto-generated method stub
try {
Friend friend=new Friend();
friend.setFriend_id(friendID);
friend.setUser_id(userID);
sessionFactory.getCurrentSession().delete(friendID);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
@Transactional
public List<Friend> getMyFriends(int userID) {
// TODO Auto-generated method stub
String hql = "from Friend where user_id=" + userID ;
@SuppressWarnings("rawtypes")
Query query = sessionFactory.getCurrentSession().createQuery(hql);
@SuppressWarnings("unchecked")
List<Friend> list = (List<Friend>) query.list();
return list;
}
@Transactional
public Friend getName(String name) {
// TODO Auto-generated method stub
String hql = "from Friend where userID=" + "'" + name + "'";
@SuppressWarnings("rawtypes")
Query query = sessionFactory.getCurrentSession().createQuery(hql);
@SuppressWarnings("unchecked")
List<Friend> list = (List<Friend>) query.list();
if (list != null && !list.isEmpty()) {
System.out.println("username retrieved from DAOImpl");
return list.get(0);
} else {
return null;
}
}
@Transactional
public List<Friend> getMyNewFriendRequest(String userID){
String hql = "from Friend where userID=" + userID + "' and request_status = '" + "N";
@SuppressWarnings("rawtypes")
Query query = sessionFactory.getCurrentSession().createQuery(hql);
@SuppressWarnings("unchecked")
List<Friend> list = (List<Friend>) query.list();
return list;
}
}