package com.opentravelsoft.service.impl;
import java.io.Serializable;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.opentravelsoft.providers.GenericDao;
import com.opentravelsoft.service.GenericManager;
/**
* This class serves as the Base class for all other Managers - 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.
*
* <p>To register this class in your Spring context file, use the following XML.
* <pre>
* <bean id="userManager" class="com.opentravelsoft.service.impl.GenericManagerImpl">
* <constructor-arg>
* <bean class="com.opentravelsoft.dao.hibernate.GenericDaoHibernate">
* <constructor-arg value="com.opentravelsoft.entity.User"/>
* <property name="sessionFactory" ref="sessionFactory"/>
* </bean>
* </constructor-arg>
* </bean>
* </pre>
*
*
* @param <T> a type variable
* @param <PK> the primary key for that type
*/
public class GenericManagerImpl<T, PK extends Serializable> implements GenericManager<T, PK> {
/**
* Log variable for all child classes. Uses LogFactory.getLog(getClass()) from Commons Logging
*/
protected final Log log = LogFactory.getLog(getClass());
/**
* GenericDao instance, set by constructor of child classes
*/
protected GenericDao<T, PK> dao;
public GenericManagerImpl() {}
public GenericManagerImpl(GenericDao<T, PK> genericDao) {
this.dao = genericDao;
}
/**
* {@inheritDoc}
*/
public List<T> getAll() {
return dao.getAll();
}
/**
* {@inheritDoc}
*/
public T get(PK id) {
return dao.get(id);
}
/**
* {@inheritDoc}
*/
public boolean exists(PK id) {
return dao.exists(id);
}
/**
* {@inheritDoc}
*/
public T save(T object) {
return dao.save(object);
}
/**
* {@inheritDoc}
*/
public void remove(PK id) {
dao.remove(id);
}
}