Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MaintenanceDocumentDaoJpa |
|
| 1.6;1.6 |
1 | /* | |
2 | * Copyright 2005-2008 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl2.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.kuali.rice.kns.dao.impl; | |
17 | ||
18 | import java.util.List; | |
19 | ||
20 | import javax.persistence.EntityManager; | |
21 | import javax.persistence.PersistenceContext; | |
22 | ||
23 | import org.apache.commons.lang.StringUtils; | |
24 | import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria; | |
25 | import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria; | |
26 | import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria.QueryByCriteriaType; | |
27 | import org.kuali.rice.kns.dao.MaintenanceDocumentDao; | |
28 | import org.kuali.rice.kns.document.MaintenanceLock; | |
29 | import org.kuali.rice.kns.util.KNSPropertyConstants; | |
30 | ||
31 | /** | |
32 | * This class is the JPA implementation of the MaintenanceDocumentDao interface. | |
33 | */ | |
34 | 0 | public class MaintenanceDocumentDaoJpa implements MaintenanceDocumentDao { |
35 | ||
36 | // private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MaintenanceDocumentDaoJpa.class); | |
37 | ||
38 | @PersistenceContext | |
39 | private EntityManager entityManager; | |
40 | ||
41 | /** | |
42 | * @see org.kuali.rice.kns.dao.MaintenanceDocumentDao#getLockingDocumentNumber(java.lang.String, java.lang.String) | |
43 | */ | |
44 | public String getLockingDocumentNumber(String lockingRepresentation, String documentNumber) { | |
45 | 0 | String lockingDocNumber = ""; |
46 | ||
47 | // build the query criteria | |
48 | 0 | Criteria criteria = new Criteria(MaintenanceLock.class.getName()); |
49 | 0 | criteria.eq("lockingRepresentation", lockingRepresentation); |
50 | ||
51 | // if a docHeaderId is specified, then it will be excluded from the | |
52 | // locking representation test. | |
53 | 0 | if (StringUtils.isNotBlank(documentNumber)) { |
54 | 0 | criteria.ne(KNSPropertyConstants.DOCUMENT_NUMBER, documentNumber); |
55 | } | |
56 | ||
57 | // attempt to retrieve a document based off this criteria | |
58 | 0 | MaintenanceLock maintenanceLock = (MaintenanceLock) new QueryByCriteria(entityManager, criteria).toQuery().getSingleResult(); |
59 | ||
60 | // if a document was found, then there's already one out there pending, | |
61 | // and we consider it 'locked' and we return the docnumber. | |
62 | 0 | if (maintenanceLock != null) { |
63 | 0 | lockingDocNumber = maintenanceLock.getDocumentNumber(); |
64 | } | |
65 | 0 | return lockingDocNumber; |
66 | } | |
67 | ||
68 | // /** | |
69 | // * Returns all pending maintenance documents locked by the given business object class. | |
70 | // */ | |
71 | // public Collection getPendingDocumentsForClass(Class businessObjectClass) { | |
72 | // Criteria criteria = new Criteria(MaintenanceLock.class.getName()); | |
73 | // criteria.like("lockingRepresentation", "%" + businessObjectClass.getName() + "%"); | |
74 | // | |
75 | // Collection maintenanceLocks = new QueryByCriteria(entityManager, criteria).toQuery().getResultList(); | |
76 | // if (!maintenanceLocks.isEmpty()) { | |
77 | // criteria = new Criteria(MaintenanceDocumentBase.class.getName()); | |
78 | // List<String> documentNumbers = new ArrayList<String>(); | |
79 | // | |
80 | // for (Object maintenanceLock : maintenanceLocks) { | |
81 | // documentNumbers.add(((MaintenanceLock) maintenanceLock).getDocumentNumber()); | |
82 | // } | |
83 | // criteria.in("documentNumber", documentNumbers); | |
84 | // | |
85 | // return new QueryByCriteria(entityManager, criteria).toQuery().getResultList(); | |
86 | // } else { | |
87 | // return maintenanceLocks; | |
88 | // } | |
89 | // } | |
90 | ||
91 | /** | |
92 | * @see org.kuali.rice.kns.dao.MaintenanceDocumentDao#deleteLocks(java.lang.String) | |
93 | */ | |
94 | public void deleteLocks(String documentNumber) { | |
95 | 0 | Criteria criteria = new Criteria(MaintenanceLock.class.getName()); |
96 | 0 | criteria.eq("documentNumber", documentNumber); |
97 | 0 | new QueryByCriteria(entityManager, criteria, QueryByCriteriaType.DELETE).toQuery().executeUpdate(); |
98 | 0 | } |
99 | ||
100 | /** | |
101 | * @see org.kuali.rice.kns.dao.MaintenanceDocumentDao#storeLocks(java.util.List) | |
102 | */ | |
103 | public void storeLocks(List<MaintenanceLock> maintenanceLocks) { | |
104 | 0 | for (MaintenanceLock maintenanceLock : maintenanceLocks) { |
105 | 0 | entityManager.merge(maintenanceLock); |
106 | } | |
107 | 0 | } |
108 | ||
109 | /** | |
110 | * @return the entityManager | |
111 | */ | |
112 | public EntityManager getEntityManager() { | |
113 | 0 | return this.entityManager; |
114 | } | |
115 | ||
116 | /** | |
117 | * @param entityManager the entityManager to set | |
118 | */ | |
119 | public void setEntityManager(EntityManager entityManager) { | |
120 | 0 | this.entityManager = entityManager; |
121 | 0 | } |
122 | ||
123 | } |