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