| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kns.dao.impl; |
| 17 | |
|
| 18 | |
import java.util.ArrayList; |
| 19 | |
import java.util.HashMap; |
| 20 | |
import java.util.List; |
| 21 | |
|
| 22 | |
import javax.persistence.EntityManager; |
| 23 | |
import javax.persistence.PersistenceContext; |
| 24 | |
import javax.persistence.PersistenceException; |
| 25 | |
|
| 26 | |
import org.apache.commons.beanutils.BeanUtils; |
| 27 | |
import org.apache.log4j.Logger; |
| 28 | |
import org.kuali.rice.core.util.OrmUtils; |
| 29 | |
import org.kuali.rice.kim.bo.Group; |
| 30 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
| 31 | |
import org.kuali.rice.kns.bo.AdHocRoutePerson; |
| 32 | |
import org.kuali.rice.kns.bo.AdHocRouteWorkgroup; |
| 33 | |
import org.kuali.rice.kns.bo.PersistableBusinessObject; |
| 34 | |
import org.kuali.rice.kns.dao.BusinessObjectDao; |
| 35 | |
import org.kuali.rice.kns.dao.DocumentDao; |
| 36 | |
import org.kuali.rice.kns.document.Document; |
| 37 | |
import org.kuali.rice.kns.service.DocumentAdHocService; |
| 38 | |
import org.kuali.rice.kns.util.KNSPropertyConstants; |
| 39 | |
import org.springframework.dao.DataAccessException; |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
public class DocumentDaoJpa implements DocumentDao { |
| 45 | 0 | private static Logger LOG = Logger.getLogger(DocumentDaoJpa.class); |
| 46 | |
private BusinessObjectDao businessObjectDao; |
| 47 | |
private DocumentAdHocService documentAdHocService; |
| 48 | |
|
| 49 | |
@PersistenceContext |
| 50 | |
private EntityManager entityManager; |
| 51 | |
|
| 52 | |
public DocumentDaoJpa(EntityManager entityManager, BusinessObjectDao businessObjectDao, DocumentAdHocService documentAdHocService) { |
| 53 | 0 | super(); |
| 54 | 0 | this.entityManager = entityManager; |
| 55 | 0 | this.businessObjectDao = businessObjectDao; |
| 56 | 0 | this.documentAdHocService = documentAdHocService; |
| 57 | 0 | } |
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
public void save(Document document) throws DataAccessException { |
| 65 | 0 | Document attachedDoc = findByDocumentHeaderId(document.getClass(),document.getDocumentNumber()); |
| 66 | 0 | if (attachedDoc == null) { |
| 67 | 0 | entityManager.persist(document); |
| 68 | |
} else { |
| 69 | 0 | OrmUtils.reattach(attachedDoc, document); |
| 70 | 0 | entityManager.merge(attachedDoc); |
| 71 | |
} |
| 72 | 0 | } |
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
public Document findByDocumentHeaderId(Class clazz, String id) throws DataAccessException { |
| 82 | 0 | List idList = new ArrayList(); |
| 83 | 0 | idList.add(id); |
| 84 | |
|
| 85 | 0 | List documentList = findByDocumentHeaderIds(clazz, idList); |
| 86 | |
|
| 87 | 0 | Document document = null; |
| 88 | 0 | if ((null != documentList) && (documentList.size() > 0)) { |
| 89 | 0 | document = (Document) documentList.get(0); |
| 90 | |
} |
| 91 | |
|
| 92 | 0 | return document; |
| 93 | |
} |
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
public List findByDocumentHeaderIds(Class clazz, List idList) throws DataAccessException { |
| 103 | 0 | org.kuali.rice.core.jpa.criteria.Criteria criteria = new org.kuali.rice.core.jpa.criteria.Criteria(clazz.getName()); |
| 104 | 0 | criteria.in(KNSPropertyConstants.DOCUMENT_NUMBER, (List) idList); |
| 105 | 0 | List<Document> list = new ArrayList<Document>(); |
| 106 | |
try { |
| 107 | 0 | list = new org.kuali.rice.core.jpa.criteria.QueryByCriteria(entityManager, criteria).toQuery().getResultList(); |
| 108 | 0 | } catch (PersistenceException e) { |
| 109 | 0 | e.printStackTrace(); |
| 110 | 0 | } |
| 111 | 0 | for (Document doc : list) { |
| 112 | 0 | documentAdHocService.addAdHocs(doc); |
| 113 | 0 | entityManager.refresh(doc); |
| 114 | |
} |
| 115 | 0 | return list; |
| 116 | |
} |
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
@Deprecated |
| 124 | |
public void saveMaintainableBusinessObject(PersistableBusinessObject businessObject) { |
| 125 | 0 | throw new UnsupportedOperationException("Don't use this depricated method."); |
| 126 | |
} |
| 127 | |
|
| 128 | |
public BusinessObjectDao getBusinessObjectDao() { |
| 129 | 0 | return businessObjectDao; |
| 130 | |
} |
| 131 | |
|
| 132 | |
public void setBusinessObjectDao(BusinessObjectDao businessObjectDao) { |
| 133 | 0 | this.businessObjectDao = businessObjectDao; |
| 134 | 0 | } |
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
public EntityManager getEntityManager() { |
| 140 | 0 | return this.entityManager; |
| 141 | |
} |
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
public void setEntityManager(EntityManager entityManager) { |
| 147 | 0 | this.entityManager = entityManager; |
| 148 | 0 | } |
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
public DocumentAdHocService getDocumentAdHocService() { |
| 154 | 0 | return this.documentAdHocService; |
| 155 | |
} |
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
public void setDocumentAdHocService(DocumentAdHocService dahs) { |
| 162 | 0 | this.documentAdHocService = dahs; |
| 163 | 0 | } |
| 164 | |
|
| 165 | |
} |