1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.mobility.library.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.library.entity.Library;
26 import org.kuali.mobility.library.entity.LibraryHourPeriod;
27 import org.kuali.mobility.library.entity.LibraryHourSet;
28 import org.springframework.stereotype.Repository;
29 import org.springframework.transaction.annotation.Transactional;
30
31
32
33
34
35
36 @Repository
37 public class LibraryDaoImpl implements LibraryDao {
38
39
40
41
42 private static final Logger LOG = Logger.getLogger( LibraryDaoImpl.class );
43
44
45
46
47 @PersistenceContext
48 private EntityManager entityManager;
49
50
51
52
53
54
55 @Override
56 public List<Library> getLibraries(){
57 String nq = "Library.getLibraries";
58 Query query = getEntityManager().createNamedQuery(nq);
59 return query.getResultList();
60 }
61
62
63
64
65
66 @Override
67 public Library getLibrary(long libraryId) {
68 return this.entityManager.find(Library.class, libraryId);
69 }
70
71
72
73
74
75 @Override
76 @Transactional
77 public Library saveLibrary(Library library) {
78 if (library.getId() == null){
79 this.entityManager.persist(library);
80 }
81 else {
82 library = this.entityManager.merge(library);
83 }
84 return library;
85 }
86
87
88
89
90
91 @Override
92 public List<LibraryHourSet> getLibraryHourSets(long libraryId) {
93 Query q = this.entityManager.createNamedQuery("LibraryHourSet.getHourSets");
94 q.setParameter("libraryId", libraryId);
95 return q.getResultList();
96 }
97
98
99
100
101
102 @Override
103 @Transactional
104 public LibraryHourSet saveLibraryHourSets(LibraryHourSet lhs) {
105 if (lhs.getId() == null){
106 this.entityManager.persist(lhs);
107 return lhs;
108 }
109 else {
110 return this.entityManager.merge(lhs);
111 }
112 }
113
114
115
116
117
118
119
120 public EntityManager getEntityManager() {
121 return entityManager;
122 }
123
124
125
126
127
128 public void setEntityManager(EntityManager entityManager) {
129 this.entityManager = entityManager;
130 }
131
132
133
134
135 @Override
136 public List<Library> getLibariesForCampus(String campusCode) {
137 Query query = getEntityManager().createNamedQuery("Library.getLibariesForCampus");
138 query.setParameter("campusCode", campusCode);
139 return query.getResultList();
140 }
141
142
143
144
145 @Override
146 public List<String> getCampusWithLibraries() {
147 Query query = getEntityManager().createNamedQuery("Library.getCampusWithLibraries");
148 return query.getResultList();
149 }
150
151
152
153
154 @Override
155 @Transactional
156 public LibraryHourPeriod saveLibraryHourPeriod(LibraryHourPeriod libraryHourPeriod) {
157
158 if (libraryHourPeriod.getId() == null){
159 getEntityManager().persist(libraryHourPeriod);
160 return libraryHourPeriod;
161 }
162 else {
163 return getEntityManager().merge(libraryHourPeriod);
164 }
165 }
166
167 }