001    /**
002     * Copyright 2005-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.krad.dao.proxy;
017    
018    import java.util.List;
019    
020    import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
021    import org.kuali.rice.krad.dao.MaintenanceDocumentDao;
022    import org.kuali.rice.krad.maintenance.MaintenanceLock;
023    
024    public class MaintenanceDocumentDaoProxy implements MaintenanceDocumentDao {
025    
026        private MaintenanceDocumentDao maintenanceDocumentDaoJpa;
027        private MaintenanceDocumentDao maintenanceDocumentDaoOjb;
028            
029        @SuppressWarnings("unchecked")
030            private MaintenanceDocumentDao getDao(Class clazz) {
031            final String TMP_NM = clazz.getName();
032                    final int START_INDEX = TMP_NM.indexOf('.', TMP_NM.indexOf('.') + 1) + 1;
033            return (OrmUtils.isJpaAnnotated(clazz) && (OrmUtils.isJpaEnabled() || OrmUtils.isJpaEnabled("rice.krad"))) ?
034                                                    maintenanceDocumentDaoJpa : maintenanceDocumentDaoOjb; 
035        }
036        
037            public String getLockingDocumentNumber(String lockingRepresentation, String documentNumber) {
038                    return getDao(MaintenanceLock.class).getLockingDocumentNumber(lockingRepresentation, documentNumber);
039            }
040    
041    //      public Collection getPendingDocumentsForClass(Class dataObjectClass) {
042    //              return getDao(MaintenanceLock.class).getPendingDocumentsForClass(dataObjectClass);
043    //      }
044    
045            public void deleteLocks(String documentNumber) {
046                    getDao(MaintenanceLock.class).deleteLocks(documentNumber);
047            }
048    
049            public void storeLocks(List<MaintenanceLock> maintenanceLocks) {
050                    getDao(MaintenanceLock.class).storeLocks(maintenanceLocks);
051            }
052    
053            public void setMaintenanceDocumentDaoJpa(MaintenanceDocumentDao maintenanceDocumentDaoJpa) {
054                    this.maintenanceDocumentDaoJpa = maintenanceDocumentDaoJpa;
055            }
056    
057            public void setMaintenanceDocumentDaoOjb(MaintenanceDocumentDao maintenanceDocumentDaoOjb) {
058                    this.maintenanceDocumentDaoOjb = maintenanceDocumentDaoOjb;
059            }
060    
061    }