1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.documentlink.dao.impl; |
17 | |
|
18 | |
import java.util.List; |
19 | |
|
20 | |
import org.kuali.rice.kew.documentlink.DocumentLink; |
21 | |
import org.kuali.rice.kew.documentlink.dao.DocumentLinkDAO; |
22 | |
import org.apache.ojb.broker.query.Criteria; |
23 | |
import org.apache.ojb.broker.query.QueryByCriteria; |
24 | |
import org.kuali.rice.kew.notes.Note; |
25 | |
import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 0 | public class DocumentLinkDAOOjbImpl extends PersistenceBrokerDaoSupport implements DocumentLinkDAO{ |
34 | |
|
35 | |
public void saveDocumentLink(DocumentLink link) { |
36 | 0 | if(getLinkedDocument(link) == null) |
37 | 0 | this.getPersistenceBrokerTemplate().store(link); |
38 | |
|
39 | 0 | DocumentLink rLink = DocumentLinkDaoUtil.reverseLink(link); |
40 | 0 | if(getLinkedDocument(rLink) == null) |
41 | 0 | this.getPersistenceBrokerTemplate().store(rLink); |
42 | 0 | } |
43 | |
|
44 | |
public void deleteDocumentLink(DocumentLink link) { |
45 | 0 | deleteSingleLinkFromOrgnDoc(link); |
46 | 0 | deleteSingleLinkFromOrgnDoc(DocumentLinkDaoUtil.reverseLink(link)); |
47 | 0 | } |
48 | |
|
49 | |
|
50 | |
public void deleteDocmentLinksByDocId(Long docId){ |
51 | 0 | List<DocumentLink> links = getLinkedDocumentsByDocId(docId); |
52 | 0 | for(DocumentLink link: links){ |
53 | 0 | deleteDocumentLink(link); |
54 | |
} |
55 | |
|
56 | 0 | } |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
public List<DocumentLink> getLinkedDocumentsByDocId(Long docId) { |
64 | 0 | Criteria crit = new Criteria(); |
65 | 0 | crit.addEqualTo("orgnDocId", docId); |
66 | 0 | QueryByCriteria query = new QueryByCriteria(DocumentLink.class, crit); |
67 | 0 | query.addOrderByAscending("orgnDocId"); |
68 | 0 | return (List<DocumentLink>) this.getPersistenceBrokerTemplate().getCollectionByQuery(query); |
69 | |
} |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
public DocumentLink getLinkedDocument(DocumentLink link) { |
77 | 0 | Criteria crit = new Criteria(); |
78 | 0 | crit.addEqualTo("orgnDocId", link.getOrgnDocId()); |
79 | 0 | crit.addEqualTo("destDocId", link.getDestDocId()); |
80 | 0 | QueryByCriteria query = new QueryByCriteria(DocumentLink.class, crit); |
81 | 0 | query.addOrderByAscending("orgnDocId"); |
82 | 0 | return (DocumentLink) this.getPersistenceBrokerTemplate().getObjectByQuery(query); |
83 | |
} |
84 | |
|
85 | |
private void deleteSingleLinkFromOrgnDoc(DocumentLink link){ |
86 | 0 | Criteria crit = new Criteria(); |
87 | 0 | crit.addEqualTo("orgnDocId", link.getOrgnDocId()); |
88 | 0 | crit.addEqualTo("destDocId", link.getDestDocId()); |
89 | 0 | this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(DocumentLink.class, crit)); |
90 | 0 | } |
91 | |
|
92 | |
public void deleteSingleLinksByOrgnDocId(Long docId){ |
93 | 0 | Criteria crit = new Criteria(); |
94 | 0 | crit.addEqualTo("orgnDocId", docId); |
95 | 0 | this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(DocumentLink.class, crit)); |
96 | 0 | } |
97 | |
} |