3 import java.lang.reflect.Method;
4 import java.sql.SQLException;
6 import java.util.Locale;
7 import java.util.concurrent.ConcurrentHashMap;
8 import java.util.concurrent.ConcurrentMap;
18 Method[] methods = HeavyAIEscapeFunctions.class.getMethods();
19 ConcurrentMap<String, Method> functionMap =
20 new ConcurrentHashMap<String, Method>(methods.length * 2);
21 for (Method method : methods) {
22 if (method.getName().startsWith(prefix)) {
24 method.getName().
substring(prefix.length()).toLowerCase(Locale.US),
38 Method method = FUNCTION_MAP.get(functionName);
43 String nameLower = functionName.toLowerCase(Locale.US);
44 if (nameLower.equals(functionName)) {
48 method = FUNCTION_MAP.get(nameLower);
53 FUNCTION_MAP.putIfAbsent(functionName, method);
68 List<? extends CharSequence> parsedArgs)
throws SQLException {
80 List<? extends CharSequence> parsedArgs)
throws SQLException {
93 List<? extends CharSequence> parsedArgs)
throws SQLException {
94 if (parsedArgs.size() != 1) {
95 throw new RuntimeException(
96 "Syntax error function 'dayofweek' takes one and only one argument.");
98 appendCall(buf,
"extract(dow from ",
",",
")+1", parsedArgs);
109 List<? extends CharSequence> parsedArgs)
throws SQLException {
120 public static void sqlhour(StringBuilder buf, List<? extends CharSequence> parsedArgs)
121 throws SQLException {
132 public static void sqlminute(StringBuilder buf, List<? extends CharSequence> parsedArgs)
133 throws SQLException {
144 public static void sqlmonth(StringBuilder buf, List<? extends CharSequence> parsedArgs)
145 throws SQLException {
157 List<? extends CharSequence> parsedArgs)
throws SQLException {
168 public static void sqlsecond(StringBuilder buf, List<? extends CharSequence> parsedArgs)
169 throws SQLException {
180 public static void sqlweek(StringBuilder buf, List<? extends CharSequence> parsedArgs)
181 throws SQLException {
192 public static void sqlyear(StringBuilder buf, List<? extends CharSequence> parsedArgs)
193 throws SQLException {
200 List<? extends CharSequence> parsedArgs) {
201 if (parsedArgs.size() != 1) {
202 throw new RuntimeException(
203 "Syntax error " + functionName +
" takes one and only one argument.");
205 CharSequence arg0 = parsedArgs.get(0);
206 buf.ensureCapacity(buf.length() + call.length() + arg0.length() + 1);
207 buf.append(call).
append(arg0).append(
')');
224 List<? extends CharSequence>
args) {
225 int size = begin.length();
231 int numberOfArguments = args.size();
232 for (
int i = 0; i < numberOfArguments; i++) {
233 size += args.get(i).length();
235 size += separator.length() * (numberOfArguments - 1);
236 sb.ensureCapacity(sb.length() + size + 1);
238 for (
int i = 0; i < numberOfArguments; i++) {
242 sb.append(args.get(i));
size_t append(FILE *f, const size_t size, const int8_t *buf)
Appends the specified number of bytes to the end of the file f from buf.
static Method getFunction(String functionName)
static final ConcurrentMap< String, Method > FUNCTION_MAP
static void sqlminute(StringBuilder buf, List<?extends CharSequence > parsedArgs)
static void sqlweek(StringBuilder buf, List<?extends CharSequence > parsedArgs)
static void sqlceiling(StringBuilder buf, List<?extends CharSequence > parsedArgs)
static void sqlsecond(StringBuilder buf, List<?extends CharSequence > parsedArgs)
static void sqlyear(StringBuilder buf, List<?extends CharSequence > parsedArgs)
static void appendCall(StringBuilder sb, String begin, String separator, String end, List<?extends CharSequence > args)
static void sqldayofyear(StringBuilder buf, List<?extends CharSequence > parsedArgs)
static void sqldayofweek(StringBuilder buf, List<?extends CharSequence > parsedArgs)
static void sqlquarter(StringBuilder buf, List<?extends CharSequence > parsedArgs)
static void sqlhour(StringBuilder buf, List<?extends CharSequence > parsedArgs)
static void singleArgumentFunctionCall(StringBuilder buf, String call, String functionName, List<?extends CharSequence > parsedArgs)
static void sqlmonth(StringBuilder buf, List<?extends CharSequence > parsedArgs)
static void sqldayofmonth(StringBuilder buf, List<?extends CharSequence > parsedArgs)
static ConcurrentMap< String, Method > createFunctionMap(String prefix)