1 /*****************************************************************************
5 * Creation date 08.10.2012
8 *****************************************************************************/
10 package org.splat.dal.dao.kernel;
12 import java.io.Serializable;
14 import org.hibernate.Session;
15 import org.hibernate.SessionFactory;
16 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
19 * Generic DAO implementation.
21 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
24 * Persistent object class
28 public abstract class GenericDAOImpl<T, PK extends Serializable> extends HibernateDaoSupport implements
31 // * Hibernate session factory.
33 // private SessionFactory _sessionFactory;
36 * Persist the newInstance object into database.
39 * new object as a transient instance
40 * @return new primary key for the created persistent object
42 @SuppressWarnings("unchecked")
43 public PK create(T newInstance) {
44 return (PK) getSession().save(newInstance);
48 * Retrieve an object that was previously persisted to the database using the indicated id as primary key.
51 * primary key of an object to read
52 * @return an object found by the given key
54 @SuppressWarnings("unchecked")
55 public T read(PK id) {
56 return (T) getSession().get(getType(), id);
59 /** Save changes made to a persistent object.
60 * @param transientObject transient instance of the object to update
62 public void update(T transientObject) {
63 getSession().update(transientObject);
66 /** Remove an object from persistent storage in the database.
67 * @param persistentObject a persistent object to delete from the database
69 public void delete(T persistentObject) {
70 getSession().delete(persistentObject);
74 * Get persistent object type.
75 * @return Persistent object class to be processed by this DAO
77 abstract protected Class<T> getType();
80 // * Get the current hibernate session factory.
81 // * @return hibernate session
83 // private Session getSession() {
84 // return getSessionFactory().getCurrentSession();
88 // * Get the hibernate session factory.
89 // * @return the hibernate session factory
91 // public SessionFactory getSessionFactory() {
92 // return _sessionFactory;
96 // * Set the hibernate session factory.
97 // * @param sessionFactory the hibernate session factory to set
99 // public void setSessionFactory(SessionFactory sessionFactory) {
100 // _sessionFactory = sessionFactory;