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 | 0 | 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 | 0 | super(); |
46 | 0 | this.businessObjectDao = businessObjectDao; |
47 | 0 | this.documentAdHocService = documentAdHocService; |
48 | 0 | } |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
@Override |
54 | |
public <T extends Document> T save(T document) throws DataAccessException { |
55 | 0 | if ( LOG.isDebugEnabled() ) { |
56 | 0 | LOG.debug( "About to store document: " + document, new Throwable() ); |
57 | |
} |
58 | 0 | Document retrievedDocument = findByDocumentHeaderId(document.getClass(),document.getDocumentNumber()); |
59 | 0 | KRADServiceLocatorInternal.getOjbCollectionHelper().processCollections(this, document, retrievedDocument); |
60 | 0 | this.getPersistenceBrokerTemplate().store(document); |
61 | 0 | 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 | 0 | List<String> idList = new ArrayList<String>(); |
74 | 0 | idList.add(id); |
75 | |
|
76 | 0 | List<T> documentList = findByDocumentHeaderIds(clazz, idList); |
77 | |
|
78 | 0 | T document = null; |
79 | 0 | if ((null != documentList) && (documentList.size() > 0)) { |
80 | 0 | document = documentList.get(0); |
81 | |
} |
82 | |
|
83 | 0 | 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 | 0 | Criteria criteria = new Criteria(); |
96 | 0 | criteria.addIn(KRADPropertyConstants.DOCUMENT_NUMBER, idList); |
97 | |
|
98 | 0 | QueryByCriteria query = QueryFactory.newQuery(clazz, criteria); |
99 | |
|
100 | |
|
101 | |
@SuppressWarnings("unchecked") |
102 | 0 | List<T> tempList = new ArrayList<T>(this.getPersistenceBrokerTemplate().getCollectionByQuery(query)); |
103 | |
|
104 | 0 | for (T doc : tempList) { |
105 | 0 | documentAdHocService.addAdHocs(doc); |
106 | |
} |
107 | 0 | return tempList; |
108 | |
} |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
@Override |
116 | |
public BusinessObjectDao getBusinessObjectDao() { |
117 | 0 | return businessObjectDao; |
118 | |
} |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
public void setBusinessObjectDao(BusinessObjectDao businessObjectDao) { |
125 | 0 | this.businessObjectDao = businessObjectDao; |
126 | 0 | } |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
@Override |
132 | |
public DocumentAdHocService getDocumentAdHocService() { |
133 | 0 | return this.documentAdHocService; |
134 | |
} |
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
public void setDocumentAdHocService(DocumentAdHocService dahs) { |
141 | 0 | this.documentAdHocService = dahs; |
142 | 0 | } |
143 | |
} |