1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.dao.impl;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.UUID;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.apache.log4j.Logger;
24 import org.apache.ojb.broker.query.Criteria;
25 import org.apache.ojb.broker.query.QueryByCriteria;
26 import org.apache.ojb.broker.query.QueryFactory;
27 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
28 import org.kuali.rice.kns.service.KNSServiceLocator;
29 import org.kuali.rice.krad.bo.DataObjectBase;
30 import org.kuali.rice.krad.bo.PersistableBusinessObject;
31 import org.kuali.rice.krad.dao.BusinessObjectDao;
32 import org.kuali.rice.krad.dao.DocumentDao;
33 import org.kuali.rice.krad.document.Document;
34 import org.kuali.rice.krad.service.DocumentAdHocService;
35 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
36 import org.kuali.rice.krad.service.util.OjbCollectionAware;
37 import org.kuali.rice.krad.service.util.OjbCollectionHelper;
38 import org.kuali.rice.krad.util.KRADPropertyConstants;
39 import org.springframework.dao.DataAccessException;
40
41
42
43
44
45
46 @Deprecated
47 public class DocumentDaoOjb extends PlatformAwareDaoBaseOjb implements DocumentDao, OjbCollectionAware {
48 private static final Logger LOG = Logger.getLogger(DocumentDaoOjb.class);
49
50 protected BusinessObjectDao businessObjectDao;
51 protected DocumentAdHocService documentAdHocService;
52 private OjbCollectionHelper ojbCollectionHelper;
53
54
55 public DocumentDaoOjb(BusinessObjectDao businessObjectDao, DocumentAdHocService documentAdHocService) {
56 super();
57 this.businessObjectDao = businessObjectDao;
58 this.documentAdHocService = documentAdHocService;
59 }
60
61 @Override
62 public <T extends Document> T save(T document) throws DataAccessException {
63 if ( LOG.isDebugEnabled() ) {
64 LOG.debug( "About to store document: " + document, new Throwable() );
65 }
66 Document retrievedDocument = findByDocumentHeaderId(document.getClass(),document.getDocumentNumber());
67 if ( document instanceof PersistableBusinessObject ) {
68 if ( retrievedDocument != null && retrievedDocument instanceof PersistableBusinessObject ) {
69 getOjbCollectionHelper().processCollections(this, (PersistableBusinessObject)document, (PersistableBusinessObject)retrievedDocument);
70 }
71 }
72 if ( document instanceof DataObjectBase ) {
73 if (StringUtils.isEmpty(document.getObjectId())) {
74 ((DataObjectBase)document).setObjectId(UUID.randomUUID().toString());
75 }
76
77 document.setDocumentHeader( KRADServiceLocatorWeb.getDocumentHeaderService().saveDocumentHeader(document.getDocumentHeader()) );
78 }
79 this.getPersistenceBrokerTemplate().store(document);
80 return document;
81 }
82
83
84
85
86
87
88
89
90 @Override
91 public <T extends Document> T findByDocumentHeaderId(Class<T> clazz, String id) {
92 List<String> idList = new ArrayList<String>();
93 idList.add(id);
94
95 List<T> documentList = findByDocumentHeaderIds(clazz, idList);
96
97 T document = null;
98 if ((null != documentList) && (documentList.size() > 0)) {
99 document = documentList.get(0);
100 }
101
102 return document;
103 }
104
105
106
107
108
109
110
111
112 @Override
113 public <T extends Document> List<T> findByDocumentHeaderIds(Class<T> clazz, List<String> idList) {
114 Criteria criteria = new Criteria();
115 criteria.addIn(KRADPropertyConstants.DOCUMENT_NUMBER, idList);
116
117 QueryByCriteria query = QueryFactory.newQuery(clazz, criteria);
118
119
120 @SuppressWarnings("unchecked")
121 List<T> tempList = new ArrayList<T>(this.getPersistenceBrokerTemplate().getCollectionByQuery(query));
122
123 for (T doc : tempList) {
124 documentAdHocService.addAdHocs(doc);
125 }
126 return tempList;
127 }
128
129
130
131
132
133
134 @Override
135 public BusinessObjectDao getBusinessObjectDao() {
136 return businessObjectDao;
137 }
138
139
140
141
142
143 public void setBusinessObjectDao(BusinessObjectDao businessObjectDao) {
144 this.businessObjectDao = businessObjectDao;
145 }
146
147
148
149
150 @Override
151 public DocumentAdHocService getDocumentAdHocService() {
152 return this.documentAdHocService;
153 }
154
155
156
157
158
159 public void setDocumentAdHocService(DocumentAdHocService dahs) {
160 this.documentAdHocService = dahs;
161 }
162
163 protected OjbCollectionHelper getOjbCollectionHelper() {
164 if (ojbCollectionHelper == null) {
165 ojbCollectionHelper = KNSServiceLocator.getOjbCollectionHelper();
166 }
167
168 return ojbCollectionHelper;
169 }
170
171 public void setOjbCollectionHelper(OjbCollectionHelper ojbCollectionHelper) {
172 this.ojbCollectionHelper = ojbCollectionHelper;
173 }
174 }