| 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 javax.persistence.EntityManager; |
| 21 | |
import javax.persistence.PersistenceContext; |
| 22 | |
|
| 23 | |
import org.kuali.rice.core.jpa.criteria.Criteria; |
| 24 | |
import org.kuali.rice.core.jpa.criteria.QueryByCriteria; |
| 25 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
| 26 | |
import org.kuali.rice.kew.documentlink.DocumentLink; |
| 27 | |
import org.kuali.rice.kew.documentlink.dao.DocumentLinkDAO; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | 0 | public class DocumentLinkDAOJpaImpl implements DocumentLinkDAO { |
| 36 | |
|
| 37 | |
|
| 38 | |
@PersistenceContext(unitName = "kew-unit") |
| 39 | |
private EntityManager entityManager; |
| 40 | |
|
| 41 | |
public EntityManager getEntityManager() { |
| 42 | 0 | return this.entityManager; |
| 43 | |
} |
| 44 | |
|
| 45 | |
public void setEntityManager(EntityManager entityManager) { |
| 46 | 0 | this.entityManager = entityManager; |
| 47 | 0 | } |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
public void deleteDocmentLinksByDocId(Long docId) { |
| 55 | 0 | List<DocumentLink> links = getLinkedDocumentsByDocId(docId); |
| 56 | 0 | for(DocumentLink link: links){ |
| 57 | 0 | deleteDocumentLink(link); |
| 58 | |
} |
| 59 | 0 | } |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
public void deleteDocumentLink(DocumentLink link) { |
| 67 | 0 | deleteSingleLinkFromOrgnDoc(link); |
| 68 | 0 | deleteSingleLinkFromOrgnDoc(DocumentLinkDaoUtil.reverseLink(link)); |
| 69 | 0 | } |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
public DocumentLink getLinkedDocument(DocumentLink link) { |
| 77 | 0 | Criteria crit = new Criteria(DocumentLink.class.getName()); |
| 78 | 0 | crit.eq("orgnDocId", link.getOrgnDocId()); |
| 79 | 0 | crit.eq("destDocId", link.getDestDocId()); |
| 80 | 0 | return (DocumentLink) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult(); |
| 81 | |
} |
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
public List<DocumentLink> getLinkedDocumentsByDocId(Long docId) { |
| 89 | 0 | Criteria crit = new Criteria(DocumentLink.class.getName()); |
| 90 | 0 | crit.eq("orgnDocId", docId); |
| 91 | 0 | return (List<DocumentLink>) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult(); |
| 92 | |
|
| 93 | |
} |
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
public void saveDocumentLink(DocumentLink link) { |
| 101 | 0 | if(getLinkedDocument(link) == null) |
| 102 | 0 | entityManager.persist(link); |
| 103 | |
|
| 104 | 0 | DocumentLink rLink = DocumentLinkDaoUtil.reverseLink(link); |
| 105 | 0 | if(getLinkedDocument(rLink) == null) |
| 106 | 0 | entityManager.persist(link); |
| 107 | |
|
| 108 | 0 | } |
| 109 | |
|
| 110 | |
private void deleteSingleLinkFromOrgnDoc(DocumentLink link){ |
| 111 | 0 | DocumentLink cur = getLinkedDocument(link); |
| 112 | 0 | entityManager.remove(cur) ; |
| 113 | 0 | } |
| 114 | |
|
| 115 | |
} |