1 /** 2 * Copyright 2005-2011 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 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.krad.dao.MaintenanceDocumentDao; 26 import org.kuali.rice.krad.document.MaintenanceLock; 27 import org.kuali.rice.krad.util.KRADPropertyConstants; 28 29 /** 30 * This class is the OJB implementation of the MaintenanceDocumentDao interface. 31 */ 32 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.krad.dao.MaintenanceDocumentDao#getLockingDocumentNumber(java.lang.String, java.lang.String) 38 */ 39 public String getLockingDocumentNumber(String lockingRepresentation, String documentNumber) { 40 41 String lockingDocNumber = ""; 42 43 // build the query criteria 44 Criteria criteria = new Criteria(); 45 criteria.addEqualTo("lockingRepresentation", lockingRepresentation); 46 47 // if a docHeaderId is specified, then it will be excluded from the 48 // locking representation test. 49 if (StringUtils.isNotBlank(documentNumber)) { 50 criteria.addNotEqualTo(KRADPropertyConstants.DOCUMENT_NUMBER, documentNumber); 51 } 52 53 // attempt to retrieve a document based off this criteria 54 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 if (maintenanceLock != null) { 59 lockingDocNumber = maintenanceLock.getDocumentNumber(); 60 } 61 return lockingDocNumber; 62 } 63 64 // /** 65 // * Returns all pending maintenance documents locked by the given business object class. 66 // */ 67 // public Collection getPendingDocumentsForClass(Class dataObjectClass) { 68 // Criteria criteria = new Criteria(); 69 // criteria.addLike("lockingRepresentation", "%" + dataObjectClass.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 = KRADServiceLocatorInternal.getDataDictionaryService().getDataDictionary().getMaintenanceDocumentEntryForBusinessObjectClass(dataObjectClass); 83 // return getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(entry.getStandardDocumentBaseClass(), criteria)); 84 // } else { 85 // return maintenanceLocks; 86 // } 87 // } 88 89 /** 90 * @see org.kuali.rice.krad.dao.MaintenanceDocumentDao#deleteLocks(java.lang.String) 91 */ 92 public void deleteLocks(String documentNumber) { 93 Criteria criteria = new Criteria(); 94 criteria.addEqualTo("documentNumber", documentNumber); 95 QueryByCriteria query = new QueryByCriteria(MaintenanceLock.class, criteria); 96 getPersistenceBrokerTemplate().deleteByQuery(query); 97 } 98 99 /** 100 * @see org.kuali.rice.krad.dao.MaintenanceDocumentDao#storeLocks(java.util.List) 101 */ 102 public void storeLocks(List<MaintenanceLock> maintenanceLocks) { 103 for (MaintenanceLock maintenanceLock : maintenanceLocks) { 104 getPersistenceBrokerTemplate().store(maintenanceLock); 105 } 106 } 107 108 }