| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.kew.notes.dao.impl; |
| 18 | |
|
| 19 | |
import java.util.List; |
| 20 | |
|
| 21 | |
import javax.persistence.EntityManager; |
| 22 | |
import javax.persistence.PersistenceContext; |
| 23 | |
import javax.persistence.Query; |
| 24 | |
|
| 25 | |
import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; |
| 26 | |
import org.kuali.rice.kew.notes.Attachment; |
| 27 | |
import org.kuali.rice.kew.notes.Note; |
| 28 | |
import org.kuali.rice.kew.notes.dao.NoteDAO; |
| 29 | |
|
| 30 | |
|
| 31 | 0 | public class NoteDAOJpaImpl implements NoteDAO { |
| 32 | |
|
| 33 | |
@PersistenceContext(unitName="kew-unit") |
| 34 | |
EntityManager entityManager; |
| 35 | |
|
| 36 | |
public Note getNoteByNoteId(String noteId) { |
| 37 | 0 | Query query = entityManager.createNamedQuery("KewNote.FindNoteByNoteId"); |
| 38 | 0 | query.setParameter("noteId", noteId); |
| 39 | 0 | return (Note) query.getSingleResult(); |
| 40 | |
} |
| 41 | |
|
| 42 | |
public List getNotesByDocumentId(String documentId) { |
| 43 | 0 | Query query = entityManager.createNamedQuery("KewNote.FindNoteByDocumentId"); |
| 44 | 0 | query.setParameter("documentId", documentId); |
| 45 | 0 | return (List) query.getResultList(); |
| 46 | |
} |
| 47 | |
|
| 48 | |
public void saveNote(Note note) { |
| 49 | 0 | if (note.getNoteId() == null){ |
| 50 | 0 | entityManager.persist(note); |
| 51 | |
} else { |
| 52 | 0 | entityManager.merge(note); |
| 53 | |
} |
| 54 | 0 | } |
| 55 | |
|
| 56 | |
public void deleteNote(Note note) { |
| 57 | 0 | Note n = getNoteByNoteId(note.getNoteId()); |
| 58 | 0 | OrmUtils.merge(entityManager, n); |
| 59 | 0 | entityManager.remove(n); |
| 60 | 0 | } |
| 61 | |
|
| 62 | |
public void deleteAttachment(Attachment attachment) { |
| 63 | 0 | Attachment a = findAttachment(attachment.getAttachmentId()); |
| 64 | 0 | entityManager.remove(a); |
| 65 | 0 | } |
| 66 | |
|
| 67 | |
|
| 68 | |
public Attachment findAttachment(String attachmentId) { |
| 69 | 0 | Query query = entityManager.createNamedQuery("Attachment.FindAttachmentById"); |
| 70 | 0 | query.setParameter("attachmentId", attachmentId); |
| 71 | 0 | return (Attachment)query.getSingleResult(); |
| 72 | |
} |
| 73 | |
|
| 74 | |
public EntityManager getEntityManager() { |
| 75 | 0 | return this.entityManager; |
| 76 | |
} |
| 77 | |
|
| 78 | |
public void setEntityManager(EntityManager entityManager) { |
| 79 | 0 | this.entityManager = entityManager; |
| 80 | 0 | } |
| 81 | |
|
| 82 | |
} |