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