通过代码生成机制的appfuse访问数据都通过GenericManager来实现,GenericManager默认提供了以下几个方法:

 1 package org.appfuse.service;
 2 
 3 import java.io.Serializable;
 4 import java.util.List;
 5 
 6 /**
 7  * Generic Manager that talks to GenericDao to CRUD POJOs.
 8  *
 9  * <p>Extend this interface if you want typesafe (no casting necessary) managers
10  * for your domain objects.
11  *
12  * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
13  *  Updated by jgarcia: added full text search + reindexing
14  * @param <T> a type variable
15  * @param <PK> the primary key for that type
16  */
17 public interface GenericManager<T, PK extends Serializable> {
18 
19     /**
20      * Generic method used to get all objects of a particular type. This
21      * is the same as lookup up all rows in a table.
22      * @return List of populated objects
23      */
24     List<T> getAll();
25 
26     /**
27      * Generic method to get an object based on class and identifier. An
28      * ObjectRetrievalFailureException Runtime Exception is thrown if
29      * nothing is found.
30      *
31      * @param id the identifier (primary key) of the object to get
32      * @return a populated object
33      * @see org.springframework.orm.ObjectRetrievalFailureException
34      */
35     T get(PK id);
36 
37     /**
38      * Checks for existence of an object of type T using the id arg.
39      * @param id the identifier (primary key) of the object to get
40      * @return - true if it exists, false if it doesn't
41      */
42     boolean exists(PK id);
43 
44     /**
45      * Generic method to save an object - handles both update and insert.
46      * @param object the object to save
47      * @return the updated object
48      */
49     T save(T object);
50 
51     /**
52      * Generic method to delete an object
53      * @param object the object to remove
54      */
55     void remove(T object);
56 
57     /**
58      * Generic method to delete an object based on class and id
59      * @param id the identifier (primary key) of the object to remove
60      */
61     void remove(PK id);
62 
63     /**
64      * Generic method to search for an object.
65      * @param searchTerm the search term
66      * @param clazz type of class to search for.
67      * @return a list of matched objects
68      */
69     List<T> search(String searchTerm, Class clazz);
70     /**
71      * Generic method to regenerate full text index of the persistent class T
72      */
73     void reindex();
74 
75     /**
76      * Generic method to regenerate full text index of all indexed classes
77      *
78      * @param async
79      *            true to perform the reindexing asynchronously
80      */
81     void reindexAll(boolean async);
82 }
GenericManager

相关文章: