1 /**
2 * Copyright 2005-2015 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.krad.dao.impl;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.ojb.broker.query.Criteria;
20 import org.apache.ojb.broker.query.QueryFactory;
21 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
22 import org.kuali.rice.krad.dao.MaintenanceDocumentDao;
23 import org.kuali.rice.krad.maintenance.MaintenanceLock;
24 import org.kuali.rice.krad.util.KRADPropertyConstants;
25
26 /**
27 * This class is the OJB implementation of the MaintenanceDocumentDao interface.
28 */
29 public class MaintenanceDocumentDaoOjb extends PlatformAwareDaoBaseOjb implements MaintenanceDocumentDao {
30
31 // private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MaintenanceDocumentDaoOjb.class);
32
33 /**
34 * @see org.kuali.rice.krad.dao.MaintenanceDocumentDao#getLockingDocumentNumber(java.lang.String, java.lang.String)
35 */
36 public String getLockingDocumentNumber(String lockingRepresentation, String documentNumber) {
37
38 String lockingDocNumber = "";
39
40 // build the query criteria
41 Criteria criteria = new Criteria();
42 criteria.addEqualTo("lockingRepresentation", lockingRepresentation);
43
44 // if a docHeaderId is specified, then it will be excluded from the
45 // locking representation test.
46 if (StringUtils.isNotBlank(documentNumber)) {
47 criteria.addNotEqualTo(KRADPropertyConstants.DOCUMENT_NUMBER, documentNumber);
48 }
49
50 // attempt to retrieve a document based off this criteria
51 MaintenanceLock maintenanceLock = (MaintenanceLock) getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(MaintenanceLock.class, criteria));
52
53 // if a document was found, then there's already one out there pending, and
54 // we consider it 'locked' and we return the docnumber.
55 if (maintenanceLock != null) {
56 lockingDocNumber = maintenanceLock.getDocumentNumber();
57 }
58 return lockingDocNumber;
59 }
60
61 }