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