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.kuali.mobility.push.entity.PushDeviceTuple;
25 import org.springframework.stereotype.Repository;
26
27 @Repository
28 public class PushDeviceTupleDaoImpl implements PushDeviceTupleDao {
29
30 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DeviceDaoImpl.class);
31 private String ME = this.getClass().getName();
32
33 @PersistenceContext
34 private EntityManager entityManager;
35
36 public PushDeviceTupleDaoImpl(){}
37
38 @SuppressWarnings("unchecked")
39 public void markTupleAsSent(PushDeviceTuple tuple){
40 tuple.setSent(true);
41 this.saveTuple(tuple);
42 }
43
44 @SuppressWarnings("unchecked")
45 public void saveTuple(PushDeviceTuple tuple){
46 if(tuple == null){
47 return;
48 }
49 if(tuple.getTupleId() == null){
50 entityManager.persist(tuple);
51 }else{
52 entityManager.merge(tuple);
53 }
54 }
55
56
57 @SuppressWarnings("unchecked")
58 public List<PushDeviceTuple> findUnsentTuples(){
59 Query query = entityManager.createQuery("select t from PushDeviceTuple t where t.sent = 'false'");
60 return query.getResultList();
61 }
62
63 public EntityManager getEntityManager() {
64 return entityManager;
65 }
66
67 public void setEntityManager(EntityManager entityManager) {
68 this.entityManager = entityManager;
69 }
70 }