1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.edl.impl.extract.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.framework.persistence.jpa.OrmUtils;
24 import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria;
25 import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria;
26 import org.kuali.rice.edl.impl.extract.Dump;
27 import org.kuali.rice.edl.impl.extract.Fields;
28 import org.kuali.rice.edl.impl.extract.dao.ExtractDAO;
29 import org.kuali.rice.kew.notes.Note;
30
31 public class ExtractDAOJpaImpl implements ExtractDAO {
32
33 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ExtractDAOJpaImpl.class);
34
35 @PersistenceContext(unitName = "kew-unit")
36 private EntityManager entityManager;
37
38 public Dump getDumpByDocumentId(String docId) {
39 LOG.debug("finding Document Extract by documentId " + docId);
40 Criteria crit = new Criteria(Dump.class.getName());
41 crit.eq("docId", docId);
42 return (Dump) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult();
43 }
44
45 public List<Fields> getFieldsByDocumentId(String docId) {
46 LOG.debug("finding Extract Fileds by documentId " + docId);
47 Criteria crit = new Criteria(Fields.class.getName());
48 crit.eq("documentId", docId);
49 crit.orderBy("docId", true);
50
51 return (List<Fields>) new QueryByCriteria(entityManager, crit).toQuery().getResultList();
52 }
53
54 public void saveDump(Dump dump) {
55 LOG.debug("check for null values in Extract document");
56 checkNull(dump.getDocId(), "Document ID");
57 checkNull(dump.getDocCreationDate(), "Creation Date");
58 checkNull(dump.getDocCurrentNodeName(), "Current Node Name");
59 checkNull(dump.getDocModificationDate(), "Modification Date");
60 checkNull(dump.getDocRouteStatusCode(), "Route Status Code");
61 checkNull(dump.getDocInitiatorId(), "Initiator ID");
62 checkNull(dump.getDocTypeName(), "Doc Type Name");
63 LOG.debug("saving EDocLite document: routeHeader " + dump.getDocId());
64 if (dump.getDocId() == null) {
65 entityManager.persist(dump);
66 } else {
67 OrmUtils.merge(entityManager, dump);
68 }
69 }
70
71 public void saveField(Fields field) {
72 LOG.debug("saving EDocLite Extract fields");
73 checkNull(field.getDocId(), "Document ID");
74 checkNull(field.getFieldValue(), "Field Value");
75 checkNull(field.getFiledName(), "Field Name");
76 LOG.debug("saving Fields: routeHeader " + field.getFieldId());
77
78 if (field.getFieldId() == null) {
79 entityManager.persist(field);
80 } else {
81 OrmUtils.merge(entityManager, field);
82 }
83 }
84
85 private void checkNull(Object value, String valueName) throws RuntimeException {
86 if (value == null) {
87 throw new RuntimeException("Null value for " + valueName);
88 }
89 }
90
91 public void deleteDump(String documentId) {
92 LOG.debug("deleting record form Extract Dump table");
93 entityManager.remove(entityManager.find(Note.class, documentId));
94 }
95
96 public EntityManager getEntityManager() {
97 return this.entityManager;
98 }
99
100 public void setEntityManager(EntityManager entityManager) {
101 this.entityManager = entityManager;
102 }
103 }