01: /**
02: * com.mckoi.database.Function 11 Jul 2000
03: *
04: * Mckoi SQL Database ( http://www.mckoi.com/database )
05: * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * 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: */package com.mckoi.database;
24:
25: import java.util.List;
26:
27: /**
28: * Represents a function that is part of an expression to be evaluated. A
29: * function evaluates to a resultant Object. If the parameters of a function
30: * are not constant values, then the evaluation will require a lookup via a
31: * VariableResolver or GroupResolver. The GroupResolver helps evaluate an
32: * aggregate function.
33: *
34: * @author Tobias Downer
35: */
36:
37: public interface Function {
38:
39: /**
40: * Returns the name of the function. The name is a unique identifier that
41: * can be used to recreate this function. This identifier can be used to
42: * easily serialize the function when grouped with its parameters.
43: */
44: public String getName();
45:
46: /**
47: * Returns the list of Variable objects that this function uses as its
48: * parameters. If this returns an empty list, then the function must
49: * only have constant parameters. This information can be used to optimize
50: * evaluation because if all the parameters of a function are constant then
51: * we only need to evaluate the function once.
52: */
53: public List allVariables();
54:
55: /**
56: * Returns the list of all element objects that this function uses as its
57: * parameters. If this returns an empty list, then the function has no
58: * input elements at all. ( something like: upper(user()) )
59: */
60: public List allElements();
61:
62: /**
63: * Returns true if this function is an aggregate function. An aggregate
64: * function requires that the GroupResolver is not null when the evaluate
65: * method is called.
66: */
67: public boolean isAggregate(QueryContext context);
68:
69: /**
70: * Prepares the exressions that are the parameters of this function. This
71: * is intended to be used if we need to resolve aspects such as Variable
72: * references. For example, a variable reference to 'number' may become
73: * 'APP.Table.NUMBER'.
74: */
75: public void prepareParameters(ExpressionPreparer preparer)
76: throws DatabaseException;
77:
78: /**
79: * Evaluates the function and returns a TObject that represents the result
80: * of the function. The VariableResolver object should be used to look
81: * up variables in the parameter of the function. The 'FunctionTable'
82: * object should only be used when the function is a grouping function. For
83: * example, 'avg(value_of)'.
84: */
85: public TObject evaluate(GroupResolver group,
86: VariableResolver resolver, QueryContext context);
87:
88: /**
89: * The type of object this function returns. eg. TStringType,
90: * TBooleanType, etc. The VariableResolver points to a dummy row that can
91: * be used to dynamically determine the return type. For example, an
92: * implementation of SQL 'GREATEST' would return the same type as the
93: * list elements.
94: */
95: public TType returnTType(VariableResolver resolver,
96: QueryContext context);
97:
98: }
|