View Javadoc

1   /*
2    * Copyright (c) 2004-2005, University Health Network.  All rights reserved. Distributed under the BSD 
3    * license (see http://opensource.org/licenses/bsd-license.php).
4    *  
5    * Created on 24-Nov-2004
6    */
7   package ca.uhn.cache.proxy;
8   
9   import ca.uhn.cache.CacheReasonEnum;
10  import ca.uhn.cache.IQuery;
11  
12  /***
13   * Adapts the arguments and return values of a particular Java method
14   * to work with a <code>ISemanticCache</code>.  It is assumed that the Java 
15   * method corresponds to some query, and the return value corresponds 
16   * to the results of the query, which are to be cached.   
17   *  
18   * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
19   * @version $Revision: 1.1 $ updated on $Date: 2005/01/24 22:53:24 $ by $Author: bryan_tripp $
20   */
21  public interface IMethodAdapter {
22      
23      /***
24       * @return the name of the adapted Java method
25       */
26      public String getMethodName();
27  
28      /***
29       * @return the argument types of the adapted Java method
30       */
31      public Class[] getArgTypes();
32      
33      /***
34       * @return the maximum number of calls to the source system (remainder queries)
35       *      that should be executed per single method call.  Generally, the more are allowed, 
36       *      the less they will span data that are already cached.    
37       */
38      public int getMaxGroups();
39  
40      /***
41       * @param theMethodArgs arguments of a query method call, constituting the query 
42       *      parameters expected by the underlying system 
43       * @return corresponding <code>IQuery</code> that defines the same scope of 
44       *      data as the method args, or an encompassing scope, but are in terms of 
45       *      a <code>IParamSpace</code> 
46       */
47      public IQuery getParamsFromArgs(Object[] theMethodArgs);
48  
49      /***
50       * Note that the query parameters returned by this method can be more general 
51       * than necessary, if extraneous data are filtered by includeInResults().  
52       *   
53       * @param theOriginalArgs the original arguments submitted by a caller to the  
54       *      query method
55       * @param theQuery defines the remainder query (i.e. data that 
56       *      are not in the cache)
57       * @return a new set of method arguments in the same form as the original ones, 
58       *      but with a new scope that corresponds to the remainder query  
59       */
60      public Object[] getArgs(Object[] theOriginalArgs, IQuery theQuery);
61      
62      /***
63       * The cache may return more data than needed.  This method is used to eliminate 
64       * extraneous data items from the results.  
65       * 
66       * @param theDataItem a candidate for a query result
67       * @param theMethodArgs method arguments defining query parameters 
68       * @return true iff the given candidate should be returned to the caller (judged 
69       *      according to args)
70       */
71      public boolean includeInResults(Object theDataItem, Object[] theMethodArgs);
72      
73      /***
74       * @param theMethodArgs method arguments defining query parameters 
75       * @return reason for caching data, if this can be determined from the args (defaults
76       *      to CacheReasonEnum.QUERY if nothing more specific is known)
77       */
78      public CacheReasonEnum getReason(Object[] theMethodArgs);
79      
80      /***
81       * @return a helper that knows things about data items 
82       */
83      public IDataInspector getDataInspector();
84      
85  }