]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAOImpl.java
Salome HOME
bc94999e82e44986c1ebc086528278a421b468dd
[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.springframework.orm.hibernate3.support.HibernateDaoSupport;
15
16 /**
17  * Generic DAO implementation.
18  * 
19  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
20  * 
21  * @param <T>
22  *            Persistent object class
23  * @param <PK>
24  *            Primary key class
25  */
26 public abstract class GenericDAOImpl<T, PK extends Serializable> extends HibernateDaoSupport implements
27                 GenericDAO<T, PK> {
28         /**
29          * Persist the newInstance object into database.
30          * 
31          * @param newInstance
32          *            new object as a transient instance
33          * @return new primary key for the created persistent object
34          */
35         @SuppressWarnings("unchecked")
36         public PK create(T newInstance) {
37                 return (PK) getSession().save(newInstance);
38         }
39
40         /**
41          * Retrieve an object that was previously persisted to the database using the indicated id as primary key.
42          * 
43          * @param id
44          *            primary key of an object to read
45          * @return an object found by the given key
46          */
47         @SuppressWarnings("unchecked")
48         public T get(PK id) {
49                 return (T) getSession().get(getType(), id);
50         }
51
52         /** Save changes made to a persistent object.
53          * @param transientObject transient instance of the object to update
54          */
55         public void update(T transientObject) {
56                 getSession().update(transientObject);
57         }
58
59         /** Remove an object from persistent storage in the database.
60          * @param persistentObject a persistent object to delete from the database
61          */
62         public void delete(T persistentObject) {
63                 getSession().delete(persistentObject);
64         }
65
66         /**
67          * Get persistent object type.
68          * @return Persistent object class to be processed by this DAO
69          */
70         abstract protected Class<T> getType();
71 }