/******************************************************************************* * 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.dao; import java.io.Serializable; import java.util.List; /** * Generic DAO (Data Access Object) with common methods to CRUD POJOs. * * Extend this interface if you want typesafe (no casting necessary) DAO's for * your domain objects. * * @author <a href="mailto:bwnoll@gmail.com">Bryan Noll</a> * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a> * @param <T> * a type variable * @param <PK> * the primary key for that type */ public interface GenericDao<T, PK extends Serializable> { /** * Generic method used to get all objects of a particular type. This is the * same as lookup up all rows in a table. * * @return List of populated objects */ List<T> getAll(); /** * Generic method to get an object based on class and identifier. An * ObjectRetrievalFailureException Runtime Exception is thrown if nothing is * found. * * @param id * the identifier (primary key) of the object to get * @return a populated object * @see org.springframework.orm.ObjectRetrievalFailureException */ T get(PK id); /** * Checks for existence of an object of type T using the id arg. * * @param id * the id of the entity * @return - true if it exists, false if it doesn't */ boolean exists(PK id); /** * Generic method to save an object - handles both update and insert. * * @param object * the object to save * @return the persisted object */ T save(T object); /** * Generic method to delete an object based on class and id * * @param id * the identifier (primary key) of the object to remove */ void remove(PK id); }