info.joseluismartin.dao.ibatis
Class IBatisDao<T,PK extends Serializable>

java.lang.Object
  extended by org.springframework.dao.support.DaoSupport
      extended by org.springframework.orm.ibatis.support.SqlMapClientDaoSupport
          extended by info.joseluismartin.dao.ibatis.IBatisDao<T,PK>
All Implemented Interfaces:
Dao<T,PK>, PageableDataSource<T>, org.springframework.beans.factory.InitializingBean

public class IBatisDao<T,PK extends Serializable>
extends org.springframework.orm.ibatis.support.SqlMapClientDaoSupport
implements Dao<T,PK>

Dao implementation that use iBatis 2.x as ORM framework

Author:
Jose Luis Martin - (jlm@joseluismartin.info)

Field Summary
 
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
 
Constructor Summary
IBatisDao()
           
 
Method Summary
 void delete(T entity)
          Delete an entity
 void deleteById(PK id)
          Delete an object by primary key
 boolean exists(PK id)
          Checks for existence of an object of type T using the id arg.
 List<T> findByNamedQuery(String queryName, Map<String,Object> queryParams)
          Find a list of records by using a named query
 T get(PK id)
          Find object by id
<E> E
get(PK id, Class<E> clazz)
          
 List<T> getAll()
          Get all models
<E> List<E>
getAll(Class<E> clazz)
          
 List<T> getAllDistinct()
           
protected  String getDeleteQuery()
          Gets name of delete query in SqlMaps
 Class<T> getEntityClass()
           
protected  String getEntityName()
          Return de entity name for build query names
protected  String getInsertQuery()
          Gets name of insert query in SqlMaps
 List<Serializable> getKeys(Page<T> page)
          Gets a List with keys of page
protected  String getNewIdQuery()
          Gets name of new id query in SqlMaps
 Page<T> getPage(Page<T> page)
          Fill and return a page of data
protected  PK getPrimaryKey(T entity)
          Get the PK from entity
protected  String getPrimaryKeyPropertyName()
          Gets the PK property name
protected  String getUpdateQuery()
          Gets name of update query in SqlMaps
protected  String getValidateDuplicateQuery()
          Gets name of "validate duplicates" query in SqlMaps
 T initialize(T entity)
          Initalize entity at default depth
 T initialize(T entity, int depth)
          Initalize entity
 PK insert(T entity)
           
 void remove(PK id)
           
 T save(T entity)
          Save or update an object
 void setEntityClass(Class<T> entityClass)
           
 void update(T entity)
           
 
Methods inherited from class org.springframework.orm.ibatis.support.SqlMapClientDaoSupport
checkDaoConfig, getDataSource, getSqlMapClient, getSqlMapClientTemplate, setDataSource, setSqlMapClient, setSqlMapClientTemplate
 
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
 

Constructor Detail

IBatisDao

public IBatisDao()
Method Detail

getPage

public Page<T> getPage(Page<T> page)
Fill and return a page of data

Specified by:
getPage in interface PageableDataSource<T>
Returns:
the page

save

public T save(T entity)
Description copied from interface: Dao
Save or update an object

Specified by:
save in interface Dao<T,PK extends Serializable>
Parameters:
entity - the object to save
Returns:
the persisted object

insert

public PK insert(T entity)

update

public void update(T entity)

getPrimaryKey

protected PK getPrimaryKey(T entity)
Get the PK from entity

Parameters:
entity -
Returns:
PK

getPrimaryKeyPropertyName

protected String getPrimaryKeyPropertyName()
Gets the PK property name

Returns:
the property name of primary key

delete

public void delete(T entity)
Description copied from interface: Dao
Delete an entity

Specified by:
delete in interface Dao<T,PK extends Serializable>
Parameters:
entity - to delete

deleteById

public void deleteById(PK id)
Description copied from interface: Dao
Delete an object by primary key

Specified by:
deleteById in interface Dao<T,PK extends Serializable>
Parameters:
id - the primary key

get

public T get(PK id)
      throws org.springframework.dao.DataAccessException
Description copied from interface: Dao
Find object by id

Specified by:
get in interface Dao<T,PK extends Serializable>
Parameters:
id - the identifier (primary key) of the object to get
Returns:
entity or null if none
Throws:
org.springframework.dao.DataAccessException

getAll

public List<T> getAll()
               throws org.springframework.dao.DataAccessException
Description copied from interface: Dao
Get all models

Specified by:
getAll in interface Dao<T,PK extends Serializable>
Returns:
List of entities
Throws:
org.springframework.dao.DataAccessException

getInsertQuery

protected String getInsertQuery()
Gets name of insert query in SqlMaps

Returns:
the insert query name in SqlMaps

getValidateDuplicateQuery

protected String getValidateDuplicateQuery()
Gets name of "validate duplicates" query in SqlMaps

Returns:
the validate duplictes used in SqlMaps

getUpdateQuery

protected String getUpdateQuery()
Gets name of update query in SqlMaps

Returns:
the update query used in SqlMaps

getDeleteQuery

protected String getDeleteQuery()
Gets name of delete query in SqlMaps

Returns:
the delete query used in SqlMaps

getNewIdQuery

protected String getNewIdQuery()
Gets name of new id query in SqlMaps

Returns:
name of the newId query

getEntityName

protected String getEntityName()
Return de entity name for build query names

Returns:
the entity name used in SqlMaps

getEntityClass

public Class<T> getEntityClass()
Returns:
the entityClass

setEntityClass

public void setEntityClass(Class<T> entityClass)
Parameters:
entityClass - the entityClass to set

exists

public boolean exists(PK id)
Description copied from interface: Dao
Checks for existence of an object of type T using the id arg.

Specified by:
exists in interface Dao<T,PK extends Serializable>
Parameters:
id - the id of the entity
Returns:
- true if it exists, false if it doesn't

findByNamedQuery

public List<T> findByNamedQuery(String queryName,
                                Map<String,Object> queryParams)
Description copied from interface: Dao
Find a list of records by using a named query

Specified by:
findByNamedQuery in interface Dao<T,PK extends Serializable>
Parameters:
queryName - query name of the named query
queryParams - a map of the query names and the values
Returns:
a list of the records found

getAllDistinct

public List<T> getAllDistinct()

remove

public void remove(PK id)

getKeys

public List<Serializable> getKeys(Page<T> page)
Description copied from interface: PageableDataSource
Gets a List with keys of page

Specified by:
getKeys in interface PageableDataSource<T>
Returns:
List with keys

initialize

public T initialize(T entity)
Description copied from interface: Dao
Initalize entity at default depth

Specified by:
initialize in interface Dao<T,PK extends Serializable>
Parameters:
entity - to intialize
Returns:
intialized entity

initialize

public T initialize(T entity,
                    int depth)
Description copied from interface: Dao
Initalize entity

Specified by:
initialize in interface Dao<T,PK extends Serializable>
Parameters:
entity - to intialize
depth - to descend.
Returns:
intialized entity

get

public <E> E get(PK id,
                 Class<E> clazz)

Specified by:
get in interface Dao<T,PK extends Serializable>

getAll

public <E> List<E> getAll(Class<E> clazz)

Specified by:
getAll in interface Dao<T,PK extends Serializable>


Copyright © 2012 JDAL. All Rights Reserved.