1 /*****************************************************************************
5 * Creation date 08.10.2012
8 *****************************************************************************/
10 package org.splat.dal.dao.kernel;
12 import java.io.Serializable;
14 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
17 * Generic DAO implementation.
19 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
22 * Persistent object class
26 public abstract class GenericDAOImpl<T, PK extends Serializable> extends HibernateDaoSupport implements
29 * Persist the newInstance object into database.
32 * new object as a transient instance
33 * @return new primary key for the created persistent object
35 @SuppressWarnings("unchecked")
36 public PK create(T newInstance) {
37 return (PK) getSession().save(newInstance);
41 * Retrieve an object that was previously persisted to the database using the indicated id as primary key.
44 * primary key of an object to read
45 * @return an object found by the given key
47 @SuppressWarnings("unchecked")
49 return (T) getSession().get(getType(), id);
52 /** Save changes made to a persistent object.
53 * @param transientObject transient instance of the object to update
55 public void update(T transientObject) {
56 getSession().update(transientObject);
59 /** Remove an object from persistent storage in the database.
60 * @param persistentObject a persistent object to delete from the database
62 public void delete(T persistentObject) {
63 getSession().delete(persistentObject);
67 * Get persistent object type.
68 * @return Persistent object class to be processed by this DAO
70 abstract protected Class<T> getType();