Salome HOME
Siman codebase is refactored. Spring beans are introduced in the context.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / dao / kernel / GenericDAOImpl.java
1 /*****************************************************************************
2  * Company         EURIWARE
3  * Application     SIMAN
4  * File            $Id$ 
5  * Creation date   08.10.2012
6  * @author         $Author$
7  * @version        $Revision$
8  *****************************************************************************/
9
10 package org.splat.dal.dao.kernel;
11
12 import java.io.Serializable;
13
14 import org.hibernate.Session;
15 import org.hibernate.SessionFactory;
16
17 /**
18  * @author rkv
19  * 
20  */
21 public abstract class GenericDAOImpl<T, PK extends Serializable> implements
22                 GenericDAO<T, PK> {
23         private SessionFactory _sessionFactory;
24
25         public PK create(T o) {
26                 return (PK) getSession().save(o);
27         }
28
29         public T read(PK id) {
30                 return (T) getSession().get(getType(), id);
31         }
32
33         public void update(T o) {
34                 getSession().update(o);
35         }
36
37         public void delete(T o) {
38                 getSession().delete(o);
39         }
40
41         abstract protected Class<T> getType();
42         /**
43          * @return hibernate session
44          */
45         private Session getSession() {
46                 return getSessionFactory().getCurrentSession();
47         }
48         
49         /**
50          * Get the sessionFactory.
51          * @return the sessionFactory
52          */
53         public SessionFactory getSessionFactory() {
54                 return _sessionFactory;
55         }
56
57         /**
58          * Set the sessionFactory.
59          * @param sessionFactory the sessionFactory to set
60          */
61         public void setSessionFactory(SessionFactory sessionFactory) {
62                 _sessionFactory = sessionFactory;
63         }
64 }