Salome HOME
Id now is Long instead of Integer. First unit test is created. hibernate-3.5.jar...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / dao / kernel / GenericDAOImpl.java
index c19d1cfa837cb2f9b2d3d9f4bc742706cdaacd5b..f54184bc5b369c34cc5ed2de5ac4b8df843104ff 100644 (file)
@@ -13,52 +13,90 @@ import java.io.Serializable;
 
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
+import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
 
 /**
- * @author rkv
+ * Generic DAO implementation.
  * 
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ * 
+ * @param <T>
+ *            Persistent object class
+ * @param <PK>
+ *            Primary key class
  */
-public abstract class GenericDAOImpl<T, PK extends Serializable> implements
+public abstract class GenericDAOImpl<T, PK extends Serializable> extends HibernateDaoSupport implements
                GenericDAO<T, PK> {
-       private SessionFactory _sessionFactory;
+//     /**
+//      * Hibernate session factory.
+//      */
+//     private SessionFactory _sessionFactory;
 
-       public PK create(T o) {
-               return (PK) getSession().save(o);
+       /**
+        * Persist the newInstance object into database.
+        * 
+        * @param newInstance
+        *            new object as a transient instance
+        * @return new primary key for the created persistent object
+        */
+       @SuppressWarnings("unchecked")
+       public PK create(T newInstance) {
+               return (PK) getSession().save(newInstance);
        }
 
+       /**
+        * Retrieve an object that was previously persisted to the database using the indicated id as primary key.
+        * 
+        * @param id
+        *            primary key of an object to read
+        * @return an object found by the given key
+        */
+       @SuppressWarnings("unchecked")
        public T read(PK id) {
                return (T) getSession().get(getType(), id);
        }
 
-       public void update(T o) {
-               getSession().update(o);
-       }
-
-       public void delete(T o) {
-               getSession().delete(o);
-       }
-
-       abstract protected Class<T> getType();
-       /**
-        * @return hibernate session
+       /** Save changes made to a persistent object.
+        * @param transientObject transient instance of the object to update
         */
-       private Session getSession() {
-               return getSessionFactory().getCurrentSession();
+       public void update(T transientObject) {
+               getSession().update(transientObject);
        }
-       
-       /**
-        * Get the sessionFactory.
-        * @return the sessionFactory
+
+       /** Remove an object from persistent storage in the database.
+        * @param persistentObject a persistent object to delete from the database
         */
-       public SessionFactory getSessionFactory() {
-               return _sessionFactory;
+       public void delete(T persistentObject) {
+               getSession().delete(persistentObject);
        }
 
        /**
-        * Set the sessionFactory.
-        * @param sessionFactory the sessionFactory to set
+        * Get persistent object type.
+        * @return Persistent object class to be processed by this DAO
         */
-       public void setSessionFactory(SessionFactory sessionFactory) {
-               _sessionFactory = sessionFactory;
-       }
+       abstract protected Class<T> getType();
+       
+//     /**
+//      * Get the current hibernate session factory.
+//      * @return hibernate session
+//      */
+//     private Session getSession() {
+//             return getSessionFactory().getCurrentSession();
+//     }
+//     
+//     /**
+//      * Get the hibernate session factory.
+//      * @return the hibernate session factory
+//      */
+//     public SessionFactory getSessionFactory() {
+//             return _sessionFactory;
+//     }
+//
+//     /**
+//      * Set the hibernate session factory.
+//      * @param sessionFactory the hibernate session factory to set
+//      */
+//     public void setSessionFactory(SessionFactory sessionFactory) {
+//             _sessionFactory = sessionFactory;
+//     }
 }
\ No newline at end of file