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.service;
24  
25  import java.io.Serializable;
26  import java.util.List;
27  
28  /**
29   * Generic Manager that talks to GenericDao to CRUD POJOs.
30   * <p>
31   * Extend this interface if you want typesafe (no casting necessary) managers
32   * for your domain objects.
33   * 
34   * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
35   * @param <T>
36   *                a type variable
37   * @param <PK>
38   *                the primary key for that type
39   */
40  public interface GenericManager<T, PK extends Serializable> {
41  
42      /**
43       * Generic method used to get all objects of a particular type. This is the
44       * same as lookup up all rows in a table.
45       * 
46       * @return List of populated objects
47       */
48      List<T> getAll();
49  
50      /**
51       * Generic method to get an object based on class and identifier. An
52       * ObjectRetrievalFailureException Runtime Exception is thrown if nothing is
53       * found.
54       * 
55       * @param id
56       *                the identifier (primary key) of the object to get
57       * @return a populated object
58       * @see org.springframework.orm.ObjectRetrievalFailureException
59       */
60      T get(PK id);
61  
62      /**
63       * Checks for existence of an object of type T using the id arg.
64       * 
65       * @param id
66       *                the identifier (primary key) of the object to get
67       * @return - true if it exists, false if it doesn't
68       */
69      boolean exists(PK id);
70  
71      /**
72       * Generic method to save an object - handles both update and insert.
73       * 
74       * @param object
75       *                the object to save
76       * @return the updated object
77       */
78      T save(T object);
79  
80      /**
81       * Generic method to delete an object based on class and id
82       * 
83       * @param id
84       *                the identifier (primary key) of the object to remove
85       */
86      void remove(PK id);
87  }