View Javadoc

1   /*
2    * Copyright 2005-2007 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 org.apache.commons.lang.StringUtils;
21  import org.apache.ojb.broker.query.Criteria;
22  import org.apache.ojb.broker.query.QueryByCriteria;
23  import org.apache.ojb.broker.query.QueryFactory;
24  import org.kuali.rice.kns.dao.MaintenanceDocumentDao;
25  import org.kuali.rice.kns.document.MaintenanceLock;
26  import org.kuali.rice.kns.util.KNSPropertyConstants;
27  
28  /**
29   * This class is the OJB implementation of the MaintenanceDocumentDao interface.
30   */
31  public class MaintenanceDocumentDaoOjb extends PlatformAwareDaoBaseOjb implements MaintenanceDocumentDao {
32  
33  //    private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MaintenanceDocumentDaoOjb.class);
34  
35      /**
36       * @see org.kuali.rice.kns.dao.MaintenanceDocumentDao#getLockingDocumentNumber(java.lang.String, java.lang.String)
37       */
38      public String getLockingDocumentNumber(String lockingRepresentation, String documentNumber) {
39  
40          String lockingDocNumber = "";
41  
42          // build the query criteria
43          Criteria criteria = new Criteria();
44          criteria.addEqualTo("lockingRepresentation", lockingRepresentation);
45  
46          // if a docHeaderId is specified, then it will be excluded from the
47          // locking representation test.
48          if (StringUtils.isNotBlank(documentNumber)) {
49              criteria.addNotEqualTo(KNSPropertyConstants.DOCUMENT_NUMBER, documentNumber);
50          }
51  
52          // attempt to retrieve a document based off this criteria
53          MaintenanceLock maintenanceLock = (MaintenanceLock) getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(MaintenanceLock.class, criteria));
54  
55          // if a document was found, then there's already one out there pending, and
56          // we consider it 'locked' and we return the docnumber.
57          if (maintenanceLock != null) {
58              lockingDocNumber = maintenanceLock.getDocumentNumber();
59          }
60          return lockingDocNumber;
61      }
62  
63  //    /**
64  //     * Returns all pending maintenance documents locked by the given business object class.
65  //     */
66  //    public Collection getPendingDocumentsForClass(Class businessObjectClass) {
67  //        Criteria criteria = new Criteria();
68  //        criteria.addLike("lockingRepresentation", "%" + businessObjectClass.getName() + "%");
69  //
70  //        Collection maintenanceLocks = getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(MaintenanceLock.class, criteria));
71  //
72  //        if (!maintenanceLocks.isEmpty()) {
73  //            criteria = new Criteria();
74  //            Collection<String> documentNumbers = new ArrayList();
75  //
76  //            for (Object maintenanceLock : maintenanceLocks) {
77  //                documentNumbers.add(((MaintenanceLock) maintenanceLock).getDocumentNumber());
78  //            }
79  //            criteria.addIn("documentNumber", documentNumbers);
80  //
81  //            MaintenanceDocumentEntry entry = KNSServiceLocator.getDataDictionaryService().getDataDictionary().getMaintenanceDocumentEntryForBusinessObjectClass(businessObjectClass);
82  //            return getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(entry.getStandardDocumentBaseClass(), criteria));
83  //        } else {
84  //            return maintenanceLocks;
85  //        }
86  //    }
87  
88      /**
89       * @see org.kuali.rice.kns.dao.MaintenanceDocumentDao#deleteLocks(java.lang.String)
90       */
91      public void deleteLocks(String documentNumber) {
92          Criteria criteria = new Criteria();
93          criteria.addEqualTo("documentNumber", documentNumber);
94          QueryByCriteria query = new QueryByCriteria(MaintenanceLock.class, criteria);
95          getPersistenceBrokerTemplate().deleteByQuery(query);
96      }
97  
98      /**
99       * @see org.kuali.rice.kns.dao.MaintenanceDocumentDao#storeLocks(java.util.List)
100      */
101     public void storeLocks(List<MaintenanceLock> maintenanceLocks) {
102         for (MaintenanceLock maintenanceLock : maintenanceLocks) {
103             getPersistenceBrokerTemplate().store(maintenanceLock);
104         }
105     }
106 
107 }