1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.mobility.xsl.dao;
17
18 import java.util.List;
19
20 import javax.persistence.EntityManager;
21 import javax.persistence.OptimisticLockException;
22 import javax.persistence.PersistenceContext;
23 import javax.persistence.Query;
24
25 import org.apache.log4j.Logger;
26 import org.kuali.mobility.xsl.entity.Xsl;
27 import org.springframework.stereotype.Repository;
28
29 @Repository
30 @Deprecated
31 public class XslDaoImpl implements XslDao {
32 private static final Logger LOG = Logger.getLogger(XslDaoImpl.class);
33
34 @PersistenceContext
35 private EntityManager entityManager;
36
37 public void deleteXslById(Long id) {
38 Query query = entityManager.createQuery("delete from Xsl x where x.xslId = :id");
39 query.setParameter("id", id);
40 query.executeUpdate();
41 }
42
43 @SuppressWarnings("unchecked")
44 public List<Xsl> findAllXsl() {
45 Query query = entityManager.createQuery("select x from Xsl x order by x.id");
46 return query.getResultList();
47 }
48
49 public Xsl findXslById(Long id) {
50 Query query = entityManager.createQuery("select x from Xsl x where x.xslId = :id");
51 query.setParameter("id", id);
52 return (Xsl) query.getSingleResult();
53 }
54
55 public Xsl findXslByCode(String code) {
56 Query query = entityManager.createQuery("select x from Xsl x where x.code = :code");
57 query.setParameter("code", code);
58 return (Xsl) query.getSingleResult();
59 }
60
61 public Long saveXsl(Xsl xsl) {
62 if (xsl == null) {
63 return null;
64 }
65 try {
66 if (xsl.getValue() != null) {
67 xsl.setValue(xsl.getValue().trim());
68 }
69 if (xsl.getXslId() == null) {
70 entityManager.persist(xsl);
71 } else {
72 entityManager.merge(xsl);
73 }
74 } catch( OptimisticLockException ole ) {
75 LOG.error(ole.getLocalizedMessage(),ole);
76 return null;
77 }
78 return xsl.getXslId();
79 }
80
81 public EntityManager getEntityManager() {
82 return entityManager;
83 }
84
85 public void setEntityManager(EntityManager entityManager) {
86 this.entityManager = entityManager;
87 }
88
89 }