com.geekologue.md4j.dao.hibernate
Class AbstractHbmDAO

java.lang.Object
  extended by com.geekologue.md4j.dao.AbstractDAO
      extended by com.geekologue.md4j.dao.hibernate.AbstractHbmDAO

public abstract class AbstractHbmDAO
extends AbstractDAO

Hibernate based DAO

Author:
manos

Field Summary
protected  org.hibernate.SessionFactory sf
           
 
Fields inherited from class com.geekologue.md4j.dao.AbstractDAO
daoClass, identifierName
 
Constructor Summary
AbstractHbmDAO(java.lang.Class clazz, java.lang.String idName)
           
 
Method Summary
abstract  void addParentOptions(java.util.Map map)
           
abstract  void copyProperties(java.util.Map from, java.lang.Object to)
          Copy the properties from the given Map to the target POJO object, converting the value type where appropriate.
protected  java.lang.Object createFromParams(java.util.Map map)
           
 void delete(java.io.Serializable pojo)
          Delete the object coresponding to the given identifier
 boolean exists(java.lang.String name, java.io.Serializable value, java.io.Serializable id)
          Checks whether a persisted instance exists with the given property/value pair.
protected  java.util.List findByExample(java.lang.Object exampleObject)
           
 java.lang.Object get(java.io.Serializable identifier)
          Retreive the object matching the class handled by this DAO and the given identifier or null if no match is found.
 java.util.Map get(java.io.Serializable identifier, java.util.Set projectionProperties)
          Retreive the properties of the object matching the given identifier as a Map of attribute-value pairs.
 java.util.Set getBrokenUConstraints(java.util.Map params, java.io.Serializable id)
          Get unique constraint violations before persisting new objects
 Page getPage(java.util.Map params, Order order, int pageNumber, int pageSize)
          Get a page of results.
 Page getPage(java.util.Set projectionProps, java.util.Map params, Order order, int pageNumber, int pageSize)
          Get a page of results.
protected  Page getPage(java.util.Set projectionProps, Order order, org.hibernate.Criteria criteria, int pageNumber, int pageSize)
          Create and return a Page of results.
 java.util.Map getParentOptions()
          Get data to populate drop downs refering to parent objects by many-to-one relationships.
abstract  java.util.Set getUniquePropertyNames()
          Get the property names for which unique constraints exis
 java.util.List listAll()
           
 java.lang.Object load(java.io.Serializable identifier)
          Retreive the object matching the class handled by this DAO and the given identifier.
protected abstract  void populateCriteria(java.util.Set projectionProps, java.util.Map params, org.hibernate.Criteria criteria)
           
 java.io.Serializable save(java.lang.Object pojo)
          Save the given object
 java.io.Serializable saveOrUpdate(java.lang.Object pojo)
           
 void update(java.util.Map map)
          Update the object matching the given identifier according to the property value pairs in the given map.
 void update(java.lang.Object pojo)
          Persist any changes to the given POJO
protected  java.lang.Object updateFromParams(java.util.Map map)
          Subclasses must override this method to obtain the persisted instance from here and update properties in their implementation of the method
 
Methods inherited from class com.geekologue.md4j.dao.AbstractDAO
getDaoClassInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sf

protected org.hibernate.SessionFactory sf
Constructor Detail

AbstractHbmDAO

public AbstractHbmDAO(java.lang.Class clazz,
                      java.lang.String idName)
Parameters:
clazz -
Method Detail

load

public java.lang.Object load(java.io.Serializable identifier)
                      throws DataAccessException
Retreive the object matching the class handled by this DAO and the given identifier. If the identifier is not match, an exception is thrown

Specified by:
load in class AbstractDAO
Parameters:
identifier -
Returns:
the maching pojo
Throws:
DataAccessException
See Also:
AbstractDAO.get(java.io.Serializable)

get

public java.lang.Object get(java.io.Serializable identifier)
                     throws DataAccessException
Retreive the object matching the class handled by this DAO and the given identifier or null if no match is found.

Specified by:
get in class AbstractDAO
Parameters:
identifier -
Returns:
the maching pojo if any, null otherwise
Throws:
DataAccessException
See Also:
AbstractDAO.get(java.io.Serializable)

get

public java.util.Map get(java.io.Serializable identifier,
                         java.util.Set projectionProperties)
Retreive the properties of the object matching the given identifier as a Map of attribute-value pairs.

Parameters:
identifier -
projectionProperties - the names of properties to retrieve
Returns:
the requested properties for the object matching the identifier, if any and if at least one projection property was supplied, null otherwise.
See Also:
com.geekologue.md4j.dao.AbstractDAO#get(Serializable, Set)

update

public void update(java.util.Map map)
            throws DataAccessException
Update the object matching the given identifier according to the property value pairs in the given map. If no match for the identifier is found, return null

Specified by:
update in class AbstractDAO
Parameters:
map - the map with the property value pairs to update
Throws:
DataAccessException
See Also:
com.geekologue.md4j.dao.AbstractDAO#update(java.util.Map, java.io.Serializable)

update

public void update(java.lang.Object pojo)
            throws DataAccessException
Description copied from class: AbstractDAO
Persist any changes to the given POJO

Specified by:
update in class AbstractDAO
Parameters:
pojo - the POJO to update
Throws:
DataAccessException
See Also:
com.geekologue.md4j.dao.AbstractDAO#update(java.util.Map, java.io.Serializable)

listAll

public java.util.List listAll()
                       throws DataAccessException
Throws:
DataAccessException
See Also:
com.geekologue.md4j.dao.AbstractDAO#listAll()

save

public java.io.Serializable save(java.lang.Object pojo)
                          throws DataAccessException
Description copied from class: AbstractDAO
Save the given object

Specified by:
save in class AbstractDAO
Parameters:
pojo - the POJO to save
Returns:
the saved pojo
Throws:
DataAccessException
See Also:
AbstractDAO.save(java.lang.Object)

saveOrUpdate

public java.io.Serializable saveOrUpdate(java.lang.Object pojo)
                                  throws DataAccessException
Throws:
DataAccessException
See Also:
com.geekologue.md4j.dao.AbstractDAO#saveOrUpdate(java.lang.Object)

findByExample

protected java.util.List findByExample(java.lang.Object exampleObject)
                                throws DataAccessException
Throws:
DataAccessException
See Also:
com.geekologue.md4j.dao.AbstractDAO#findByExample(java.lang.Object)

getPage

public Page getPage(java.util.Map params,
                    Order order,
                    int pageNumber,
                    int pageSize)
Description copied from class: AbstractDAO
Get a page of results.

Specified by:
getPage in class AbstractDAO
Parameters:
params - the attribute-value pairs the results have to match
pageNumber - the number of the page
pageSize - the number of results in the page
Returns:
a result page containing the matching entities
See Also:
AbstractDAO.getPage(Map, Order, int, int)

getPage

public Page getPage(java.util.Set projectionProps,
                    java.util.Map params,
                    Order order,
                    int pageNumber,
                    int pageSize)
Description copied from class: AbstractDAO
Get a page of results.

Specified by:
getPage in class AbstractDAO
Parameters:
projectionProps - the names of the property values to return
params - the attribute-value pairs the results have to match
pageNumber - the number of the page
pageSize - the number of results in the page
Returns:
a result page containing the property values of the matching entities
See Also:
AbstractDAO.getPage(Set, Map, Order, int, int)

populateCriteria

protected abstract void populateCriteria(java.util.Set projectionProps,
                                         java.util.Map params,
                                         org.hibernate.Criteria criteria)

getPage

protected Page getPage(java.util.Set projectionProps,
                       Order order,
                       org.hibernate.Criteria criteria,
                       int pageNumber,
                       int pageSize)
Create and return a Page of results.

Parameters:
sess - The Hibernate Session object to use for the search
projectionProps - The set of properties to return for each result
params - The set of search criteria to use
criteria - The criteria to use for the search, produced by each DAO in the object hierarchy using the params map
pageNumber - The page number to return
pageSize - The page size
Returns:
The resulting Page of results

delete

public void delete(java.io.Serializable pojo)
            throws DataAccessException
Description copied from class: AbstractDAO
Delete the object coresponding to the given identifier

Specified by:
delete in class AbstractDAO
Throws:
DataAccessException

createFromParams

protected java.lang.Object createFromParams(java.util.Map map)

updateFromParams

protected java.lang.Object updateFromParams(java.util.Map map)
Subclasses must override this method to obtain the persisted instance from here and update properties in their implementation of the method

Parameters:
map -
Returns:
Throws:
DataAccessException

exists

public boolean exists(java.lang.String name,
                      java.io.Serializable value,
                      java.io.Serializable id)
Checks whether a persisted instance exists with the given property/value pair. Used to check unique violation constraints before persisting new records. If an id is provided, the record matching it is excluded from the search, making the check valid for an update action.

Parameters:
name - the name of the property
value - the value to look for
id - the record to exclude from the search, usefull for checking constraints in case of an update (null may be provided)
Returns:
true if a match is found, false otherwise

getBrokenUConstraints

public java.util.Set getBrokenUConstraints(java.util.Map params,
                                           java.io.Serializable id)
Description copied from class: AbstractDAO
Get unique constraint violations before persisting new objects

Specified by:
getBrokenUConstraints in class AbstractDAO
Parameters:
params - the property value pairs to check
Returns:
a set of the broken property names

copyProperties

public abstract void copyProperties(java.util.Map from,
                                    java.lang.Object to)
Copy the properties from the given Map to the target POJO object, converting the value type where appropriate.

Parameters:
from -
to -

getUniquePropertyNames

public abstract java.util.Set getUniquePropertyNames()
Get the property names for which unique constraints exis

Returns:
the array of property names

getParentOptions

public java.util.Map getParentOptions()
Get data to populate drop downs refering to parent objects by many-to-one relationships.

Specified by:
getParentOptions in class AbstractDAO
Returns:
a Map where each key is the string name of the property for that parent object. The value for that key is yet another Map where the key value pair is used to the value and text (respectively) of HTML option elements
See Also:
AbstractDAO.getParentOptions()

addParentOptions

public abstract void addParentOptions(java.util.Map map)


Copyright © 2003-2007 Manos Batsis. All Rights Reserved.