com.gisgraphy.dao.hibernate

## Class GenericDaoHibernate<T,PK extends Serializable>

- java.lang.Object
- - org.springframework.dao.support.DaoSupport
  - - org.springframework.orm.hibernate3.support.HibernateDaoSupport
    - - com.gisgraphy.dao.hibernate.GenericDaoHibernate<T,PK>

- Type Parameters:
    `T` - a type variable
    `PK` - the primary key for that type
  All Implemented Interfaces:
    GenericDao<T,PK>, org.springframework.beans.factory.InitializingBean
  Direct Known Subclasses:
    RoleDaoHibernate, UserDaoHibernate

      public class GenericDaoHibernate<T,PK extends Serializable>
      extends org.springframework.orm.hibernate3.support.HibernateDaoSupport
      implements GenericDao<T,PK>

  This class serves as the Base class for all other DAOs - namely to hold common CRUD methods that they might all use. You should only need to extend this class when your require custom CRUD logic.

  To register this class in your Spring context file, use the following XML.

            <bean id="fooDao" class="com.gisgraphy.dao.hibernate.GenericDaoHibernate">
                <constructor-arg value="com.gisgraphy.model.Foo"/>
                <property name="sessionFactory" ref="sessionFactory"/>
            </bean>

  Author:
    Bryan Noll

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected org.apache.commons.logging.Log` | `log` Log variable for all child classes.

    - ### Fields inherited from class org.springframework.dao.support.DaoSupport

      `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `GenericDaoHibernate(Class<T> persistentClass)` Constructor that takes in a class to see which type of entity to persist

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `exists(PK id)` Checks for existence of an object of type T using the id arg.
    `T` | `get(PK id)` Generic method to get an object based on class and identifier.
    `List<T>` | `getAll()` Generic method used to get all objects of a particular type.
    `void` | `remove(PK id)` Generic method to delete an object based on class and id
    `T` | `save(T object)` Generic method to save an object - handles both update and insert.

    - ### Methods inherited from class org.springframework.orm.hibernate3.support.HibernateDaoSupport

      `checkDaoConfig, convertHibernateAccessException, createHibernateTemplate, getHibernateTemplate, getSession, getSession, getSessionFactory, releaseSession, setHibernateTemplate, setSessionFactory`

    - ### Methods inherited from class org.springframework.dao.support.DaoSupport

      `afterPropertiesSet, initDao`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### log

          protected final org.apache.commons.logging.Log log

      Log variable for all child classes. Uses LogFactory.getLog(getClass()) from Commons Logging

  - ### Constructor Detail

    - #### GenericDaoHibernate

          public GenericDaoHibernate(Class<T> persistentClass)

      Constructor that takes in a class to see which type of entity to persist
      Parameters:
        `persistentClass` - the class type you'd like to persist

  - ### Method Detail

    - #### getAll

          public List<T> getAll()

      Generic method used to get all objects of a particular type. This is the same as lookup up all rows in a table.
      Specified by:
        `getAll` in interface `GenericDao<T,PK extends Serializable>`
      Returns:
        List of populated objects

    - #### get

          public T get(PK id)

      Generic method to get an object based on class and identifier. An ObjectRetrievalFailureException Runtime Exception is thrown if nothing is found.
      Specified by:
        `get` in interface `GenericDao<T,PK extends Serializable>`
      Parameters:
        `id` - the identifier (primary key) of the object to get
      Returns:
        a populated object
      See Also:
        `ObjectRetrievalFailureException`

    - #### exists

          public boolean exists(PK id)

      Checks for existence of an object of type T using the id arg.
      Specified by:
        `exists` in interface `GenericDao<T,PK extends Serializable>`
      Parameters:
        `id` - the id of the entity
      Returns:
        - true if it exists, false if it doesn't

    - #### save

          public T save(T object)

      Generic method to save an object - handles both update and insert.
      Specified by:
        `save` in interface `GenericDao<T,PK extends Serializable>`
      Parameters:
        `object` - the object to save
      Returns:
        the persisted object

    - #### remove

          public void remove(PK id)

      Generic method to delete an object based on class and id
      Specified by:
        `remove` in interface `GenericDao<T,PK extends Serializable>`
      Parameters:
        `id` - the identifier (primary key) of the object to remove

Copyright © 2015. All rights reserved.