T
- a type variablePK
- the primary key for that typepublic class GenericManagerImpl<T,PK extends Serializable> extends Object implements GenericManager<T,PK>
To register this class in your Spring context file, use the following XML.
<bean id="userManager" class="com.gisgraphy.service.impl.GenericManagerImpl"> <constructor-arg> <bean class="com.gisgraphy.dao.hibernate.GenericDaoHibernate"> <constructor-arg value="com.gisgraphy.model.User"/> <property name="sessionFactory" ref="sessionFactory"/> </bean> </constructor-arg> </bean>
If you're using iBATIS instead of Hibernate, use:
<bean id="userManager" class="com.gisgraphy.service.impl.GenericManagerImpl"> <constructor-arg> <bean class="com.gisgraphy.dao.ibatis.GenericDaoiBatis"> <constructor-arg value="com.gisgraphy.model.User"/> <property name="dataSource" ref="dataSource"/> <property name="sqlMapClient" ref="sqlMapClient"/> </bean> </constructor-arg> </bean>
Modifier and Type | Field and Description |
---|---|
protected GenericDao<T,PK> |
genericDao
GenericDao instance, set by constructor of this class
|
protected org.apache.commons.logging.Log |
log
Log variable for all child classes.
|
Constructor and Description |
---|
GenericManagerImpl(GenericDao<T,PK> genericDao)
Public constructor for creating a new GenericManagerImpl.
|
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.
|
protected final org.apache.commons.logging.Log log
protected GenericDao<T,PK extends Serializable> genericDao
public GenericManagerImpl(GenericDao<T,PK> genericDao)
genericDao
- the GenericDao to use for persistencepublic List<T> getAll()
getAll
in interface GenericManager<T,PK extends Serializable>
public T get(PK id)
get
in interface GenericManager<T,PK extends Serializable>
id
- the identifier (primary key) of the object to getObjectRetrievalFailureException
public boolean exists(PK id)
exists
in interface GenericManager<T,PK extends Serializable>
id
- the identifier (primary key) of the object to getpublic T save(T object)
save
in interface GenericManager<T,PK extends Serializable>
object
- the object to savepublic void remove(PK id)
remove
in interface GenericManager<T,PK extends Serializable>
id
- the identifier (primary key) of the object to removeCopyright © 2015. All rights reserved.