1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.mobility.push.dao;
17
18 import java.util.List;
19
20 import javax.persistence.EntityManager;
21 import javax.persistence.PersistenceContext;
22 import javax.persistence.Query;
23
24 import org.apache.log4j.Logger;
25 import org.kuali.mobility.push.entity.Push;
26 import org.kuali.mobility.push.entity.PushDeviceTuple;
27 import org.springframework.stereotype.Repository;
28 import org.springframework.transaction.annotation.Transactional;
29
30
31
32
33
34 @Repository
35 public class PushDeviceTupleDaoImpl implements PushDeviceTupleDao {
36
37
38 private static final Logger LOG = Logger.getLogger(DeviceDaoImpl.class);
39
40
41
42
43 @PersistenceContext
44 private EntityManager entityManager;
45
46
47
48
49 public PushDeviceTupleDaoImpl(){
50 }
51
52
53
54
55
56 public void markTupleAsSent(PushDeviceTuple tuple){
57 tuple.setSent();
58 this.saveTuple(tuple);
59 }
60
61
62
63
64
65 public Long saveTuple(PushDeviceTuple tuple){
66 Long id = null;
67 if(tuple != null){
68 if(tuple.getId() == null){
69 entityManager.persist(tuple);
70 }else{
71 entityManager.merge(tuple);
72 }
73 id = tuple.getId();
74 }
75 return id;
76 }
77
78
79
80
81
82
83 @SuppressWarnings("unchecked")
84 public List<PushDeviceTuple> findUnsentTuples(){
85 Query query = entityManager.createNamedQuery("PushDeviceTuple.findUnsent");
86 return query.getResultList();
87 }
88
89
90
91
92
93
94 @SuppressWarnings("unchecked")
95 public List<PushDeviceTuple> findTuplesForPush(Push push){
96 Query query = entityManager.createNamedQuery("PushDeviceTuple.findTuplesForPush");
97 query.setParameter("pushId", push.getPushId());
98 return query.getResultList();
99 }
100
101
102
103
104
105 @Transactional
106 public int removeTuplesForPush(Push push){
107 LOG.info("PDTDI.removeTuplesForPush");
108 int result = 0;
109 if(null == push){
110 return -1;
111 }
112 if(push.getPushId() != null){
113 String hql = "DELETE PushDeviceTuple t WHERE t.pushId = :pushId";
114 result = entityManager.createQuery(hql).setParameter("pushId", push.getPushId()).executeUpdate();
115 }else{
116 result = -1;
117 }
118 return result;
119 }
120
121
122
123
124
125 public EntityManager getEntityManager() {
126 return entityManager;
127 }
128
129
130
131
132
133 public void setEntityManager(EntityManager entityManager) {
134 this.entityManager = entityManager;
135 }
136 }