/******************************************************************************* * Gisgraphy Project * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA * * Copyright 2008 Gisgraphy project * David Masclet <davidmasclet@gisgraphy.com> * * *******************************************************************************/ package com.gisgraphy.service.impl; import java.io.Serializable; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.gisgraphy.dao.GenericDao; import com.gisgraphy.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.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> * </pre> * * <p> * If you're using iBATIS instead of Hibernate, use: * * <pre> * <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> * </pre> * * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a> * @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 this class */ protected GenericDao<T, PK> genericDao; /** * Public constructor for creating a new GenericManagerImpl. * * @param genericDao * the GenericDao to use for persistence */ public GenericManagerImpl(final GenericDao<T, PK> genericDao) { this.genericDao = genericDao; } /** * {@inheritDoc} */ public List<T> getAll() { return genericDao.getAll(); } /** * {@inheritDoc} */ public T get(PK id) { return genericDao.get(id); } /** * {@inheritDoc} */ public boolean exists(PK id) { return genericDao.exists(id); } /** * {@inheritDoc} */ public T save(T object) { return genericDao.save(object); } /** * {@inheritDoc} */ public void remove(PK id) { genericDao.remove(id); } }