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 org.apache.log4j.Logger;
19 import org.apache.ojb.broker.query.Criteria;
20 import org.apache.ojb.broker.query.QueryByCriteria;
21 import org.apache.ojb.broker.query.QueryFactory;
22 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
23 import org.kuali.rice.krad.dao.BusinessObjectDao;
24 import org.kuali.rice.krad.dao.DocumentDao;
25 import org.kuali.rice.krad.document.Document;
26 import org.kuali.rice.krad.service.DocumentAdHocService;
27 import org.kuali.rice.krad.service.KRADServiceLocatorInternal;
28 import org.kuali.rice.krad.util.KRADPropertyConstants;
29 import org.kuali.rice.krad.util.OjbCollectionAware;
30 import org.springframework.dao.DataAccessException;
31
32 import java.util.ArrayList;
33 import java.util.List;
34
35
36
37
38 public class DocumentDaoOjb extends PlatformAwareDaoBaseOjb implements DocumentDao, OjbCollectionAware{
39 private static final Logger LOG = Logger.getLogger(DocumentDaoOjb.class);
40 protected BusinessObjectDao businessObjectDao;
41 protected DocumentAdHocService documentAdHocService;
42
43
44 public DocumentDaoOjb(BusinessObjectDao businessObjectDao, DocumentAdHocService documentAdHocService) {
45 super();
46 this.businessObjectDao = businessObjectDao;
47 this.documentAdHocService = documentAdHocService;
48 }
49
50
51
52
53 @Override
54 public <T extends Document> T save(T document) throws DataAccessException {
55 if ( LOG.isDebugEnabled() ) {
56 LOG.debug( "About to store document: " + document, new Throwable() );
57 }
58 Document retrievedDocument = findByDocumentHeaderId(document.getClass(),document.getDocumentNumber());
59 KRADServiceLocatorInternal.getOjbCollectionHelper().processCollections(this, document, retrievedDocument);
60 this.getPersistenceBrokerTemplate().store(document);
61 return document;
62 }
63
64
65
66
67
68
69
70
71 @Override
72 public <T extends Document> T findByDocumentHeaderId(Class<T> clazz, String id) {
73 List<String> idList = new ArrayList<String>();
74 idList.add(id);
75
76 List<T> documentList = findByDocumentHeaderIds(clazz, idList);
77
78 T document = null;
79 if ((null != documentList) && (documentList.size() > 0)) {
80 document = documentList.get(0);
81 }
82
83 return document;
84 }
85
86
87
88
89
90
91
92
93 @Override
94 public <T extends Document> List<T> findByDocumentHeaderIds(Class<T> clazz, List<String> idList) {
95 Criteria criteria = new Criteria();
96 criteria.addIn(KRADPropertyConstants.DOCUMENT_NUMBER, idList);
97
98 QueryByCriteria query = QueryFactory.newQuery(clazz, criteria);
99
100
101 @SuppressWarnings("unchecked")
102 List<T> tempList = new ArrayList<T>(this.getPersistenceBrokerTemplate().getCollectionByQuery(query));
103
104 for (T doc : tempList) {
105 documentAdHocService.addAdHocs(doc);
106 }
107 return tempList;
108 }
109
110
111
112
113
114
115 @Override
116 public BusinessObjectDao getBusinessObjectDao() {
117 return businessObjectDao;
118 }
119
120
121
122
123
124 public void setBusinessObjectDao(BusinessObjectDao businessObjectDao) {
125 this.businessObjectDao = businessObjectDao;
126 }
127
128
129
130
131 @Override
132 public DocumentAdHocService getDocumentAdHocService() {
133 return this.documentAdHocService;
134 }
135
136
137
138
139
140 public void setDocumentAdHocService(DocumentAdHocService dahs) {
141 this.documentAdHocService = dahs;
142 }
143 }