net.sf.shineframework.server.dal.dao
Class BaseDao<T extends DalObject>

java.lang.Object
  extended by org.springframework.dao.support.DaoSupport
      extended by org.springframework.orm.jpa.support.JpaDaoSupport
          extended by net.sf.shineframework.server.dal.dao.BaseDao<T>
All Implemented Interfaces:
Dao<T>, org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
BaseFwDao, BaseNamedDao

public class BaseDao<T extends DalObject>
extends org.springframework.orm.jpa.support.JpaDaoSupport
implements Dao<T>

A basic data access object. This object offers two functionalities in addition to the infrastructure wrapping of the spring and jpa (at the moment, in the future may be jpa) functionalities:


The managed class is the class the DAO actually retrieves from the DB.
If all you need from your managed object is to retrieve it by pk, or to get all instances from the DB then you DO NOT NEED TO EXTEND this base DAO, you can simply instantiate it from a spring configuration and inject the managed class name to the constructor.

Author:
amirk

Field Summary
protected  org.apache.log4j.Logger logger
           
protected  java.lang.Class<? extends DalObject> managedClass
           
protected  java.lang.String shortName
           
 
Constructor Summary
BaseDao()
           
 
Method Summary
 void delete(T o)
          deletes an object from the database
protected  java.util.Collection<T> find(java.lang.String query)
           
protected  java.util.Collection<T> find(java.lang.String query, int firstResult, int maxResult)
           
protected  java.util.Collection<T> find(java.lang.String query, int firstResult, int maxResult, java.lang.Object... params)
           
protected  java.util.Collection<T> find(java.lang.String query, java.lang.Object... params)
           
protected  java.util.Collection<T> findByNamedParam(java.lang.String query, int firstResult, int maxResult, java.util.Map<java.lang.String,? extends java.lang.Object> params)
           
protected  java.util.Collection<T> findByNamedParam(java.lang.String query, java.util.Map<java.lang.String,? extends java.lang.Object> params)
           
protected  java.util.Collection<T> findByNamedQuery(java.lang.String queryName)
           
protected  java.util.Collection<T> findByNamedQuery(java.lang.String queryName, int firstResult, int maxResult)
           
protected  java.util.Collection<T> findByNamedQuery(java.lang.String queryName, int firstResult, int maxResult, java.lang.Object... params)
           
protected  java.util.Collection<T> findByNamedQuery(java.lang.String queryName, java.util.Map<java.lang.String,? extends java.lang.Object> params)
           
protected  java.util.Collection<T> findByProperties(T dm, java.lang.Object... names)
           
 java.util.Collection<T> getAll()
          retrieves all objects of the managed type from the database
protected  java.util.Collection<T> getAllObjects()
          Retrieves all objects.
 T getByBusinessKey(T dm)
          retrieves an object that matches the business key properties in the dm.
 T getByPk(java.io.Serializable pk)
          retrieves an object from the database by its primary key
 java.util.Collection<T> getByProperties(T dm, java.lang.Object... names)
          retrieves all objects that match the properties.
 T getByUniqueProperties(T dm)
          retrieves an object that matches the unique properties of the provided dm.
 java.lang.Class<? extends DalObject> getManagedClass()
           
static boolean isNamedQuery(java.lang.Class<? extends DalObject> managedClass, java.lang.String queryName)
           
protected  T load(java.lang.Class<? extends DalObject> c, java.io.Serializable pk)
           
protected  T load(java.io.Serializable pk)
           
protected  T load(java.lang.String queryName, java.util.Map<java.lang.String,? extends java.lang.Object> params)
          the difference between this method and findByNamedQuery is that this query returns a unique result (or null), and the find method returns a collection
protected  T load(java.lang.String queryName, java.lang.Object... params)
           
 T merge(T o)
          merges an object to the database.
 T save(T o)
          saves an object to the database
 void setManagedClass(java.lang.Class<? extends DalObject> managedClass)
           
 void setManagedClassName(java.lang.String managedClassName)
           
 
Methods inherited from class org.springframework.orm.jpa.support.JpaDaoSupport
checkDaoConfig, createJpaTemplate, createJpaTemplate, getJpaTemplate, setEntityManager, setEntityManagerFactory, setJpaTemplate
 
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

logger

protected org.apache.log4j.Logger logger

managedClass

protected java.lang.Class<? extends DalObject> managedClass

shortName

protected java.lang.String shortName
Constructor Detail

BaseDao

public BaseDao()
Method Detail

isNamedQuery

public static boolean isNamedQuery(java.lang.Class<? extends DalObject> managedClass,
                                   java.lang.String queryName)

delete

public void delete(T o)
Description copied from interface: Dao
deletes an object from the database

Specified by:
delete in interface Dao<T extends DalObject>
Parameters:
o - DalObject to delete

find

protected java.util.Collection<T> find(java.lang.String query)

find

protected java.util.Collection<T> find(java.lang.String query,
                                       int firstResult,
                                       int maxResult)

find

protected java.util.Collection<T> find(java.lang.String query,
                                       int firstResult,
                                       int maxResult,
                                       java.lang.Object... params)

find

protected java.util.Collection<T> find(java.lang.String query,
                                       java.lang.Object... params)

findByNamedParam

protected java.util.Collection<T> findByNamedParam(java.lang.String query,
                                                   int firstResult,
                                                   int maxResult,
                                                   java.util.Map<java.lang.String,? extends java.lang.Object> params)

findByNamedParam

protected java.util.Collection<T> findByNamedParam(java.lang.String query,
                                                   java.util.Map<java.lang.String,? extends java.lang.Object> params)

findByNamedQuery

protected java.util.Collection<T> findByNamedQuery(java.lang.String queryName)

findByNamedQuery

protected java.util.Collection<T> findByNamedQuery(java.lang.String queryName,
                                                   int firstResult,
                                                   int maxResult)

findByNamedQuery

protected java.util.Collection<T> findByNamedQuery(java.lang.String queryName,
                                                   int firstResult,
                                                   int maxResult,
                                                   java.lang.Object... params)

findByNamedQuery

protected java.util.Collection<T> findByNamedQuery(java.lang.String queryName,
                                                   java.util.Map<java.lang.String,? extends java.lang.Object> params)

findByProperties

protected java.util.Collection<T> findByProperties(T dm,
                                                   java.lang.Object... names)

getAll

public java.util.Collection<T> getAll()
Description copied from interface: Dao
retrieves all objects of the managed type from the database

Specified by:
getAll in interface Dao<T extends DalObject>
Returns:
all objects of the managed type from the database

getAllObjects

protected java.util.Collection<T> getAllObjects()
                                                           throws org.springframework.dao.DataAccessException
Retrieves all objects. This method attempt to locate a ManagedClass.all query in your managed class (for example: Employee.all). this allows you to override the default query that executes ("from ManagedClass").
This is highly useful when trying to use the retrieved objects out of the transaction scope.

Returns:
Throws:
org.springframework.dao.DataAccessException

getByBusinessKey

public T getByBusinessKey(T dm)
Description copied from interface: Dao
retrieves an object that matches the business key properties in the dm. The business key properties are determined by the BusinessKey annotation.

Specified by:
getByBusinessKey in interface Dao<T extends DalObject>
Parameters:
dm - example domain object
Returns:
an object that matches the business key criteria in the example dm

getByPk

public T getByPk(java.io.Serializable pk)
                            throws org.springframework.dao.DataAccessException
Description copied from interface: Dao
retrieves an object from the database by its primary key

Specified by:
getByPk in interface Dao<T extends DalObject>
Parameters:
pk - primary key
Returns:
the object (or null when no match found)
Throws:
org.springframework.dao.DataAccessException

getByProperties

public java.util.Collection<T> getByProperties(T dm,
                                               java.lang.Object... names)
Description copied from interface: Dao
retrieves all objects that match the properties. Use the dm as an "example" object on which properties named names are being considered in the query

Specified by:
getByProperties in interface Dao<T extends DalObject>
Parameters:
dm - example domain object
names - property named to fetch by
Returns:
all objects that match the properties in the example domain object

getByUniqueProperties

public T getByUniqueProperties(T dm)
Description copied from interface: Dao
retrieves an object that matches the unique properties of the provided dm. The unique properties are defined by the Column(unique=true) persistence annotation.

Specified by:
getByUniqueProperties in interface Dao<T extends DalObject>
Parameters:
dm - example domain object
Returns:
an object that matches the unique criteria in the example dm

getManagedClass

public java.lang.Class<? extends DalObject> getManagedClass()

load

protected T load(java.lang.Class<? extends DalObject> c,
                 java.io.Serializable pk)

load

protected T load(java.io.Serializable pk)

load

protected T load(java.lang.String queryName,
                 java.util.Map<java.lang.String,? extends java.lang.Object> params)
                            throws org.springframework.dao.DataAccessException
the difference between this method and findByNamedQuery is that this query returns a unique result (or null), and the find method returns a collection

Parameters:
queryName -
names -
params -
Returns:
Throws:
DataAcessException
org.springframework.dao.DataAccessException

load

protected T load(java.lang.String queryName,
                 java.lang.Object... params)
                            throws org.springframework.dao.DataAccessException
Throws:
org.springframework.dao.DataAccessException

merge

public T merge(T o)
Description copied from interface: Dao
merges an object to the database. Use this method to update objects

Specified by:
merge in interface Dao<T extends DalObject>
Parameters:
o - DalObject to merge
Returns:
the merged object (attached to the session)

save

public T save(T o)
Description copied from interface: Dao
saves an object to the database

Specified by:
save in interface Dao<T extends DalObject>
Parameters:
o - DalObject to save
Returns:
the saved object (with a freshly-created primary key)

setManagedClass

public void setManagedClass(java.lang.Class<? extends DalObject> managedClass)

setManagedClassName

public void setManagedClassName(java.lang.String managedClassName)


Copyright © 2007 sourceforge.net. All Rights Reserved.