001package com.randomnoun.common.jexl.sql;
002
003import java.util.*;
004
005import com.randomnoun.common.jexl.EvalFallbackException;
006import com.randomnoun.common.jexl.eval.*;
007
008/**
009 * A function which can be translated into SQL. These functions should be
010 * set in an SqlGenerator's context to allow expressions to use those functions.
011 *
012 * <p>This class defines a number of 'standard' functions, which can be used;
013 * they subclass the functions in EvalFunction of the same name, so that they can work
014 * in both the Evaluator and SqlGenerator AST visitors.
015 *
016 * 
017 * @author knoxg
018 */
019public interface SqlFunction {
020
021        /** All SQL functions must implement this method. It returns the SQL required for
022         *  the database to evaluate the function. evalContext can be used to get the
023         *  database type, if required.
024         *
025         * @param functionName The name of the function being translated
026         * @param evalContext  The evaluation context of the SqlGenerator doing the translation
027         * @param arguments    The arguments to the function
028         *
029         * @return the SQL representation of the function
030         * @throws EvalException If an exception occured during translation (e.g. missing arguments, arguments of wrong type, invalid arguments).
031         * @throws EvalFallbackException If this expression should be evaluated at runtime instead of being translated  
032         */
033        public abstract String toSql(String functionName, EvalContext evalContext, List<Object> arguments)
034                throws EvalException, EvalFallbackException;
035}