1 24 25 package com.mckoi.database; 26 27 37 38 public final class FunctionDef implements java.io.Serializable , Cloneable { 39 40 static final long serialVersionUID = 3339781003247956829L; 41 42 45 private String name; 46 47 50 private Expression[] params; 51 52 56 private transient Function cached_function; 57 58 59 62 public FunctionDef(String name, Expression[] params) { 63 this.name = name; 64 this.params = params; 65 } 66 67 70 public String getName() { 71 return name; 72 } 73 74 79 public Expression[] getParameters() { 80 return params; 81 } 82 83 88 public boolean isAggregate(QueryContext context) { 89 FunctionLookup fun_lookup = context.getFunctionLookup(); 90 boolean is_aggregate = fun_lookup.isAggregate(this); 91 if (is_aggregate) { 92 return true; 93 } 94 Expression[] params = getParameters(); 96 for (int i = 0; i < params.length; ++i) { 97 is_aggregate = params[i].hasAggregateFunction(context); 98 if (is_aggregate) { 99 return true; 100 } 101 } 102 return false; 104 } 105 106 112 public Function getFunction(QueryContext context) { 113 if (cached_function != null) { 114 return cached_function; 115 } 116 else { 117 FunctionLookup lookup = context.getFunctionLookup(); 118 cached_function = lookup.generateFunction(this); 119 if (cached_function == null) { 120 throw new StatementException("Function '" + getName() + 121 "' doesn't exist."); 122 } 123 return cached_function; 124 } 125 } 126 127 130 public Object clone() throws CloneNotSupportedException { 131 FunctionDef v = (FunctionDef) super.clone(); 132 Expression[] exps = (Expression[]) ((Expression[]) v.params).clone(); 134 for (int n = 0; n < exps.length; ++n) { 136 exps[n] = (Expression) exps[n].clone(); 137 } 138 v.params = exps; 139 v.cached_function = null; 140 return v; 141 } 142 143 146 public String toString() { 147 StringBuffer buf = new StringBuffer (); 148 buf.append(name); 149 buf.append('('); 150 for (int i = 0; i < params.length; ++i) { 151 buf.append(params[i].text().toString()); 152 if (i < params.length - 1) { 153 buf.append(','); 154 } 155 } 156 buf.append(')'); 157 return new String (buf); 158 } 159 160 } 161 | Popular Tags |