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.apache.ojb.broker.query.Criteria; |
21 | |
import org.apache.ojb.broker.query.QueryByCriteria; |
22 | |
import org.kuali.rice.kew.documentlink.DocumentLink; |
23 | |
import org.kuali.rice.kew.documentlink.dao.DocumentLinkDAO; |
24 | |
import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | 0 | public class DocumentLinkDAOOjbImpl extends PersistenceBrokerDaoSupport implements DocumentLinkDAO{ |
33 | |
|
34 | |
public void saveDocumentLink(DocumentLink link) { |
35 | 0 | DocumentLink linkedDocument = getLinkedDocument(link); |
36 | 0 | if(linkedDocument == null) |
37 | 0 | this.getPersistenceBrokerTemplate().store(link); |
38 | |
else |
39 | 0 | link.setDocLinkId(linkedDocument.getDocLinkId()); |
40 | |
|
41 | 0 | DocumentLink rLink = DocumentLinkDaoUtil.reverseLink(link); |
42 | 0 | if(getLinkedDocument(rLink) == null) |
43 | 0 | this.getPersistenceBrokerTemplate().store(rLink); |
44 | 0 | } |
45 | |
|
46 | |
public void deleteDocumentLink(DocumentLink link) { |
47 | 0 | deleteSingleLinkFromOrgnDoc(link); |
48 | 0 | deleteSingleLinkFromOrgnDoc(DocumentLinkDaoUtil.reverseLink(link)); |
49 | 0 | } |
50 | |
|
51 | |
|
52 | |
public void deleteDocmentLinksByDocId(String docId){ |
53 | 0 | List<DocumentLink> links = getLinkedDocumentsByDocId(docId); |
54 | 0 | for(DocumentLink link: links){ |
55 | 0 | deleteDocumentLink(link); |
56 | |
} |
57 | |
|
58 | 0 | } |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public List<DocumentLink> getLinkedDocumentsByDocId(String docId) { |
66 | 0 | Criteria crit = new Criteria(); |
67 | 0 | crit.addEqualTo("orgnDocId", docId); |
68 | 0 | QueryByCriteria query = new QueryByCriteria(DocumentLink.class, crit); |
69 | 0 | query.addOrderByAscending("orgnDocId"); |
70 | 0 | return (List<DocumentLink>) this.getPersistenceBrokerTemplate().getCollectionByQuery(query); |
71 | |
} |
72 | |
|
73 | |
public List<DocumentLink> getOutgoingLinkedDocumentsByDocId(String docId) { |
74 | 0 | Criteria crit = new Criteria(); |
75 | 0 | crit.addEqualTo("destDocId", docId); |
76 | 0 | QueryByCriteria query = new QueryByCriteria(DocumentLink.class, crit); |
77 | 0 | query.addOrderByAscending("destDocId"); |
78 | 0 | return (List<DocumentLink>) this.getPersistenceBrokerTemplate().getCollectionByQuery(query); |
79 | |
} |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
public DocumentLink getLinkedDocument(DocumentLink link) { |
87 | 0 | Criteria crit = new Criteria(); |
88 | 0 | crit.addEqualTo("orgnDocId", link.getOrgnDocId()); |
89 | 0 | crit.addEqualTo("destDocId", link.getDestDocId()); |
90 | 0 | QueryByCriteria query = new QueryByCriteria(DocumentLink.class, crit); |
91 | 0 | query.addOrderByAscending("orgnDocId"); |
92 | 0 | return (DocumentLink) this.getPersistenceBrokerTemplate().getObjectByQuery(query); |
93 | |
} |
94 | |
|
95 | |
private void deleteSingleLinkFromOrgnDoc(DocumentLink link){ |
96 | 0 | Criteria crit = new Criteria(); |
97 | 0 | crit.addEqualTo("orgnDocId", link.getOrgnDocId()); |
98 | 0 | crit.addEqualTo("destDocId", link.getDestDocId()); |
99 | 0 | this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(DocumentLink.class, crit)); |
100 | 0 | } |
101 | |
|
102 | |
public void deleteSingleLinksByOrgnDocId(String docId){ |
103 | 0 | Criteria crit = new Criteria(); |
104 | 0 | crit.addEqualTo("orgnDocId", docId); |
105 | 0 | this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(DocumentLink.class, crit)); |
106 | 0 | } |
107 | |
|
108 | |
public DocumentLink getDocumentLink(Long documentLinkId) { |
109 | 0 | Criteria crit = new Criteria(); |
110 | 0 | crit.addEqualTo("docLinkId", documentLinkId); |
111 | 0 | return (DocumentLink) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(DocumentLink.class, crit)); |
112 | |
} |
113 | |
} |