1 package com.randomnoun.common.jexl.sql;
2
3 import java.util.*;
4
5 import com.randomnoun.common.jexl.EvalFallbackException;
6 import com.randomnoun.common.jexl.eval.*;
7
8 /**
9 * A function which can be translated into SQL. These functions should be
10 * set in an SqlGenerator's context to allow expressions to use those functions.
11 *
12 * <p>This class defines a number of 'standard' functions, which can be used;
13 * they subclass the functions in EvalFunction of the same name, so that they can work
14 * in both the Evaluator and SqlGenerator AST visitors.
15 *
16 *
17 * @author knoxg
18 */
19 public interface SqlFunction {
20
21 /** All SQL functions must implement this method. It returns the SQL required for
22 * the database to evaluate the function. evalContext can be used to get the
23 * database type, if required.
24 *
25 * @param functionName The name of the function being translated
26 * @param evalContext The evaluation context of the SqlGenerator doing the translation
27 * @param arguments The arguments to the function
28 *
29 * @return the SQL representation of the function
30 * @throws EvalException If an exception occured during translation (e.g. missing arguments, arguments of wrong type, invalid arguments).
31 * @throws EvalFallbackException If this expression should be evaluated at runtime instead of being translated
32 */
33 public abstract String toSql(String functionName, EvalContext evalContext, List<Object> arguments)
34 throws EvalException, EvalFallbackException;
35 }