KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > database > Function


1 /**
2  * com.mckoi.database.Function 11 Jul 2000
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * Version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License Version 2 for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * Version 2 along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Change Log:
21  *
22  *
23  */

24
25 package com.mckoi.database;
26
27 import java.util.List JavaDoc;
28
29 /**
30  * Represents a function that is part of an expression to be evaluated. A
31  * function evaluates to a resultant Object. If the parameters of a function
32  * are not constant values, then the evaluation will require a lookup via a
33  * VariableResolver or GroupResolver. The GroupResolver helps evaluate an
34  * aggregate function.
35  *
36  * @author Tobias Downer
37  */

38
39 public interface Function {
40
41   /**
42    * Returns the name of the function. The name is a unique identifier that
43    * can be used to recreate this function. This identifier can be used to
44    * easily serialize the function when grouped with its parameters.
45    */

46   public String JavaDoc getName();
47
48   /**
49    * Returns the list of Variable objects that this function uses as its
50    * parameters. If this returns an empty list, then the function must
51    * only have constant parameters. This information can be used to optimize
52    * evaluation because if all the parameters of a function are constant then
53    * we only need to evaluate the function once.
54    */

55   public List JavaDoc allVariables();
56
57   /**
58    * Returns the list of all element objects that this function uses as its
59    * parameters. If this returns an empty list, then the function has no
60    * input elements at all. ( something like: upper(user()) )
61    */

62   public List JavaDoc allElements();
63
64   /**
65    * Returns true if this function is an aggregate function. An aggregate
66    * function requires that the GroupResolver is not null when the evaluate
67    * method is called.
68    */

69   public boolean isAggregate(QueryContext context);
70
71   /**
72    * Prepares the exressions that are the parameters of this function. This
73    * is intended to be used if we need to resolve aspects such as Variable
74    * references. For example, a variable reference to 'number' may become
75    * 'APP.Table.NUMBER'.
76    */

77   public void prepareParameters(ExpressionPreparer preparer)
78                                                   throws DatabaseException;
79
80   /**
81    * Evaluates the function and returns a TObject that represents the result
82    * of the function. The VariableResolver object should be used to look
83    * up variables in the parameter of the function. The 'FunctionTable'
84    * object should only be used when the function is a grouping function. For
85    * example, 'avg(value_of)'.
86    */

87   public TObject evaluate(GroupResolver group, VariableResolver resolver,
88                           QueryContext context);
89
90   /**
91    * The type of object this function returns. eg. TStringType,
92    * TBooleanType, etc. The VariableResolver points to a dummy row that can
93    * be used to dynamically determine the return type. For example, an
94    * implementation of SQL 'GREATEST' would return the same type as the
95    * list elements.
96    */

97   public TType returnTType(VariableResolver resolver, QueryContext context);
98
99 }
100
Popular Tags