Biblioteca Java - Blame information for rev 9
Subversion Repositories:
(root)/Spring/SpringWebMVC/InventoryHibernate/src/main/java/com/linkscreens/inventory/dao/InventoryDaoImpl.java
Rev | Author | Line No. | Line |
---|---|---|---|
9 | mihai | 1 | package com.linkscreens.inventory.dao; |
2 | |||
3 | import com.linkscreens.inventory.entity.FilterParameters; | ||
4 | import com.linkscreens.inventory.entity.InventoryItem; | ||
5 | import org.hibernate.Query; | ||
6 | import org.hibernate.Session; | ||
7 | import org.hibernate.SessionFactory; | ||
8 | import org.slf4j.Logger; | ||
9 | import org.slf4j.LoggerFactory; | ||
10 | import org.springframework.stereotype.Repository; | ||
11 | |||
12 | import java.util.HashMap; | ||
13 | import java.util.List; | ||
14 | import java.util.Map; | ||
15 | |||
16 | /** | ||
17 | * | ||
18 | */ | ||
19 | @Repository | ||
20 | public class InventoryDaoImpl implements InventoryDao { | ||
21 | |||
22 | private static final Logger LOGGER = LoggerFactory.getLogger(InventoryDaoImpl.class); | ||
23 | |||
24 | private SessionFactory sessionFactory; | ||
25 | |||
26 | public void setSessionFactory(SessionFactory sf){ | ||
27 | this.sessionFactory = sf; | ||
28 | } | ||
29 | |||
30 | @Override | ||
31 | public void addNewInventoryItem(InventoryItem item) { | ||
32 | Session session = this.sessionFactory.getCurrentSession(); | ||
33 | session.persist(item); | ||
34 | LOGGER.info("Item saved successfully, Item Details=" + item); | ||
35 | } | ||
36 | |||
37 | @Override | ||
38 | public InventoryItem getItemById(Long itemId) { | ||
39 | Session session = this.sessionFactory.getCurrentSession(); | ||
40 | InventoryItem item = (InventoryItem) session.load(InventoryItem.class, itemId); | ||
41 | LOGGER.info("Item loaded successfully, Item details=" + item); | ||
42 | return item; | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public List<InventoryItem> getAllInventoryItems() { | ||
47 | Session session = this.sessionFactory.getCurrentSession(); | ||
48 | Query query = session.createQuery("FROM InventoryItem WHERE deleted IS NULL OR deleted = FALSE ORDER BY cont,anLunaAdaugare"); | ||
49 | List<InventoryItem> items = query.list(); | ||
50 | return items; | ||
51 | } | ||
52 | |||
53 | @Override | ||
54 | public List<InventoryItem> geFilteredInventoryItems(FilterParameters filter) { | ||
55 | Session session = this.sessionFactory.getCurrentSession(); | ||
56 | Query query = session.createQuery("FROM InventoryItem WHERE (deleted IS NULL OR deleted = FALSE) and (anLunaAdaugare >= :start" | ||
57 | + " AND anLunaAdaugare <= :end) ORDER BY cont,anLunaAdaugare"); | ||
58 | query.setParameter("start", filter.getStartYear() + "/" + filter.getStartMonth()); | ||
59 | query.setParameter("end", filter.getEndYear() + "/" + filter.getEndMonth()); | ||
60 | List<InventoryItem> items = query.list(); | ||
61 | return items; | ||
62 | } | ||
63 | |||
64 | @Override | ||
65 | public void updateInventoryItem(InventoryItem updatedItem) { | ||
66 | Session session = this.sessionFactory.getCurrentSession(); | ||
67 | session.update(updatedItem); | ||
68 | LOGGER.info("Item updated successfully, Item Details=" + updatedItem); | ||
69 | } | ||
70 | |||
71 | @Override | ||
72 | public void deleteItem(Long itemId) { | ||
73 | Session session = this.sessionFactory.getCurrentSession(); | ||
74 | InventoryItem item = (InventoryItem) session.load(InventoryItem.class, itemId); | ||
75 | if (null != item){ | ||
76 | item.setDeleted(true); | ||
77 | session.update(item); | ||
78 | } | ||
79 | LOGGER.info("Item deleted successfully, Item details=" + item); | ||
80 | } | ||
81 | } |