View Javadoc
1   /*******************************************************************************
2    *   Gisgraphy Project 
3    * 
4    *   This library is free software; you can redistribute it and/or
5    *   modify it under the terms of the GNU Lesser General Public
6    *   License as published by the Free Software Foundation; either
7    *   version 2.1 of the License, or (at your option) any later version.
8    * 
9    *   This library is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   *   Lesser General Public License for more details.
13   * 
14   *   You should have received a copy of the GNU Lesser General Public
15   *   License along with this library; if not, write to the Free Software
16   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
17   * 
18   *  Copyright 2008  Gisgraphy project 
19   *  David Masclet <davidmasclet@gisgraphy.com>
20   *  
21   *  
22   *******************************************************************************/
23  package com.gisgraphy.dao;
24  
25  import java.io.Serializable;
26  import java.util.List;
27  
28  /**
29   * Data Access Object (DAO) interface.
30   * 
31   * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
32   *         Modifications and comments by <a href="mailto:bwnoll@gmail.com">Bryan
33   *         Noll</a> This thing used to be named simply 'GenericDao' in versions
34   *         of appfuse prior to 2.0. It was renamed in an attempt to distinguish
35   *         and describe it as something different than GenericDao. GenericDao is
36   *         intended for subclassing, and was named Generic because 1) it has
37   *         very general functionality and 2) is 'generic' in the Java 5 sense of
38   *         the word... aka... it uses Generics. Implementations of this class
39   *         are not intended for subclassing. You most likely would want to
40   *         subclass GenericDao. The only real difference is that instances of
41   *         java.lang.Class are passed into the methods in this class, and they
42   *         are part of the constructor in the GenericDao, hence you'll have to
43   *         do some casting if you use this one.
44   * @see com.gisgraphy.dao.GenericDao
45   */
46  public interface UniversalDao {
47  
48      /**
49       * Generic method used to get all objects of a particular type. This is the
50       * same as lookup up all rows in a table.
51       * 
52       * @param clazz
53       *                the type of objects (a.k.a. while table) to get data from
54       * @return List of populated objects
55       */
56      List<?> getAll(Class<?> clazz);
57  
58      /**
59       * Generic method to get an object based on class and identifier. An
60       * ObjectRetrievalFailureException Runtime Exception is thrown if nothing is
61       * found.
62       * 
63       * @param clazz
64       *                model class to lookup
65       * @param id
66       *                the identifier (primary key) of the class
67       * @return a populated object
68       * @see org.springframework.orm.ObjectRetrievalFailureException
69       */
70      Object get(Class<?> clazz, Serializable id);
71  
72      /**
73       * Generic method to save an object - handles both update and insert.
74       * 
75       * @param o
76       *                the object to save
77       * @return a populated object
78       */
79      Object save(Object o);
80  
81      /**
82       * Generic method to delete an object based on class and id
83       * 
84       * @param clazz
85       *                model class to lookup
86       * @param id
87       *                the identifier (primary key) of the class
88       */
89      void remove(Class<?> clazz, Serializable id);
90  }