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