svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.tools.evaluator.sqljep / src / main / java / org / gvsig / tools / evaluator / sqljep / SQLJEPEvaluator.java @ 42459
History | View | Annotate | Download (38 KB)
1 | 40560 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
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 for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | 40435 | jjdelcerro | package org.gvsig.tools.evaluator.sqljep; |
25 | |||
26 | import java.math.BigDecimal; |
||
27 | import java.util.Map; |
||
28 | import java.util.Map.Entry; |
||
29 | |||
30 | import org.gvsig.tools.evaluator.EvaluatorData; |
||
31 | import org.gvsig.tools.evaluator.EvaluatorException; |
||
32 | import org.gvsig.tools.evaluator.EvaluatorFieldsInfo; |
||
33 | import org.gvsig.tools.evaluator.EvaluatorParseException; |
||
34 | import org.gvsig.tools.evaluator.EvaluatorWithDescriptions; |
||
35 | import org.gvsig.tools.evaluator.sqljep.function.Boundary; |
||
36 | import org.gvsig.tools.evaluator.sqljep.function.Equals; |
||
37 | import org.gvsig.tools.evaluator.sqljep.function.GeomFromText; |
||
38 | import org.gvsig.tools.evaluator.sqljep.function.Intersects; |
||
39 | import org.gvsig.tools.evaluator.sqljep.function.Overlaps; |
||
40 | |||
41 | import org.medfoster.sqljep.ParseException; |
||
42 | import org.medfoster.sqljep.RowJEP; |
||
43 | import org.slf4j.Logger; |
||
44 | import org.slf4j.LoggerFactory; |
||
45 | |||
46 | public class SQLJEPEvaluator extends RowJEP |
||
47 | implements EvaluatorWithDescriptions {
|
||
48 | |||
49 | private static final Logger logger = |
||
50 | LoggerFactory.getLogger(SQLJEPEvaluator.class); |
||
51 | |||
52 | public static final String TODATE_FUNCTION_NAME = "to_timestamp"; |
||
53 | |||
54 | private String expresion; |
||
55 | private EvaluatorData data;
|
||
56 | private boolean not_parsed; |
||
57 | |||
58 | |||
59 | public SQLJEPEvaluator(String expresion) { |
||
60 | |||
61 | super(expresion);
|
||
62 | this.expresion = expresion;
|
||
63 | this.data = null; |
||
64 | not_parsed = true;
|
||
65 | } |
||
66 | |||
67 | public String getName() { |
||
68 | return "SQLJEP(" + expresion + ")"; |
||
69 | } |
||
70 | |||
71 | public String getSQL() { |
||
72 | return expresion;
|
||
73 | } |
||
74 | |||
75 | public String getDescription() { |
||
76 | return "SQLJEP-based evaluator"; |
||
77 | } |
||
78 | |||
79 | /*
|
||
80 | public EvaluatorFieldValue[] getFieldValues(String name) {
|
||
81 | return null;
|
||
82 | }
|
||
83 | */
|
||
84 | |||
85 | public Object evaluate(EvaluatorData data) throws EvaluatorException { |
||
86 | this.data = data;
|
||
87 | Object value = null; |
||
88 | try {
|
||
89 | if (not_parsed) {
|
||
90 | this.parseExpression();
|
||
91 | not_parsed = false;
|
||
92 | } |
||
93 | } catch (ParseException e) { |
||
94 | /*
|
||
95 | * Notify parse exception
|
||
96 | */
|
||
97 | throw new EvaluatorParseException(e); |
||
98 | } |
||
99 | |||
100 | try {
|
||
101 | value = this.getValue();
|
||
102 | } catch (Exception e) { |
||
103 | /*
|
||
104 | * Notify evaluation exception
|
||
105 | * (catching also runtime exceptions)
|
||
106 | */
|
||
107 | throw new EvaluatorException(e); |
||
108 | } |
||
109 | this.data = null; |
||
110 | return value;
|
||
111 | } |
||
112 | |||
113 | /*
|
||
114 | public int findColumn(String name) {
|
||
115 | return -1;
|
||
116 | }
|
||
117 | */
|
||
118 | |||
119 | /*
|
||
120 | public Comparable getColumnObject(int arg0) throws ParseException {
|
||
121 | return null;
|
||
122 | }
|
||
123 | */
|
||
124 | |||
125 | public Entry getVariable(String name) throws ParseException { |
||
126 | return new MyEntry(name); |
||
127 | } |
||
128 | |||
129 | private class MyEntry implements Map.Entry { |
||
130 | private String key; |
||
131 | |||
132 | public MyEntry(String key) { |
||
133 | this.key = key;
|
||
134 | } |
||
135 | |||
136 | public Object getKey() { |
||
137 | return this.key; |
||
138 | } |
||
139 | |||
140 | public Object getValue() { |
||
141 | |||
142 | Object resp = null; |
||
143 | |||
144 | if (data.hasDataValue(key)) {
|
||
145 | resp = data.getDataValue(key); |
||
146 | resp = fixDecimal(resp); |
||
147 | return resp;
|
||
148 | } |
||
149 | resp = data.getDataValue(key);; |
||
150 | resp = fixDecimal(resp); |
||
151 | return resp;
|
||
152 | } |
||
153 | |||
154 | /**
|
||
155 | * @param resp
|
||
156 | * @return
|
||
157 | */
|
||
158 | private Object fixDecimal(Object obj) { |
||
159 | |||
160 | if (obj instanceof Double) { |
||
161 | Double dou = (Double) obj; |
||
162 | String doustr = Double.toString(dou); |
||
163 | return new BigDecimal(doustr); |
||
164 | } else {
|
||
165 | if (obj instanceof Float) { |
||
166 | Float flo = (Float) obj; |
||
167 | String flostr = Float.toString(flo); |
||
168 | return new BigDecimal(flostr); |
||
169 | } else {
|
||
170 | return obj;
|
||
171 | } |
||
172 | } |
||
173 | } |
||
174 | |||
175 | public Object setValue(Object arg0) { |
||
176 | return null; |
||
177 | } |
||
178 | |||
179 | } |
||
180 | |||
181 | public EvaluatorFieldsInfo getFieldsInfo() {
|
||
182 | // TODO Auto-generated method stub
|
||
183 | return null; |
||
184 | } |
||
185 | |||
186 | private static Description[] available_operators; |
||
187 | private static Description[] available_functions; |
||
188 | |||
189 | public Description[] getAvailableOperators() { |
||
190 | |||
191 | if (available_operators == null) { |
||
192 | available_operators = new Description[] { |
||
193 | |||
194 | new DefaultDescription(
|
||
195 | "+",
|
||
196 | "Returns the sum (addition) of the left operand and"
|
||
197 | + " the right operand.",
|
||
198 | 42459 | jbadia | " + ",
|
199 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER), |
200 | new DefaultDescription(
|
||
201 | "-",
|
||
202 | "Returns the difference (subtraction) of the left operand minus"
|
||
203 | + " the right operand. It can be used as unary operator to"
|
||
204 | + " change the sign of the right operand.",
|
||
205 | 42459 | jbadia | " - ",
|
206 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER), |
207 | new DefaultDescription(
|
||
208 | "*",
|
||
209 | "Returns the product (multiplication) of the left operand by"
|
||
210 | + " the right operand.",
|
||
211 | 42459 | jbadia | " * ",
|
212 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER), |
213 | new DefaultDescription(
|
||
214 | "/",
|
||
215 | "Returns the division of the left operand by"
|
||
216 | + " the right operand.",
|
||
217 | 42459 | jbadia | " / ",
|
218 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER), |
219 | new DefaultDescription(
|
||
220 | ">",
|
||
221 | "Returns TRUE if the left operand is greater than "
|
||
222 | + "the right operand; FALSE otherwise.",
|
||
223 | 42459 | jbadia | " > ",
|
224 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER |
225 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING |
||
226 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME |
||
227 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
||
228 | new DefaultDescription(
|
||
229 | "<",
|
||
230 | "Returns TRUE if the left operand is smaller"
|
||
231 | + " than the right operand; FALSE otherwise.",
|
||
232 | 42459 | jbadia | " < ",
|
233 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER |
234 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING |
||
235 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME |
||
236 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
||
237 | new DefaultDescription(
|
||
238 | ">=",
|
||
239 | "Returns TRUE if the left operand is greater or "
|
||
240 | + "equal to the right operand; FALSE otherwise.",
|
||
241 | 42459 | jbadia | " >= ",
|
242 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER |
243 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING |
||
244 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME |
||
245 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
||
246 | new DefaultDescription(
|
||
247 | "<=",
|
||
248 | "Returns TRUE if the left operand is less or "
|
||
249 | + "equal to the right operand; FALSE otherwise.",
|
||
250 | 42459 | jbadia | " <= ",
|
251 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER |
252 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING |
||
253 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME |
||
254 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
||
255 | new DefaultDescription(
|
||
256 | 42459 | jbadia | "=",
|
257 | 40435 | jjdelcerro | "Returns TRUE if the left operand equals "
|
258 | + "the right operand; FALSE otherwise.",
|
||
259 | 42459 | jbadia | " = ",
|
260 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER |
261 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING |
||
262 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME |
||
263 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
||
264 | new DefaultDescription(
|
||
265 | "!=",
|
||
266 | "Returns TRUE if the left operand is not equal to "
|
||
267 | + "the right operand; FALSE otherwise.",
|
||
268 | 42459 | jbadia | " != ",
|
269 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER |
270 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING |
||
271 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME |
||
272 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
||
273 | new DefaultDescription(
|
||
274 | "And",
|
||
275 | "Returns TRUE if both operands are TRUE"
|
||
276 | + "; FALSE otherwise.",
|
||
277 | 42459 | jbadia | " and <Right_value>",
|
278 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
279 | new DefaultDescription(
|
||
280 | "Or",
|
||
281 | "Returns TRUE if the left operand is TRUE or the "
|
||
282 | + "right operand is TRUE; FALSE otherwise.",
|
||
283 | 42459 | jbadia | " or ",
|
284 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
285 | new DefaultDescription(
|
||
286 | "Not",
|
||
287 | "Returns the logical inverse of the right operand: TRUE if the right "
|
||
288 | + "operand is FALSE; FALSE otherwise.",
|
||
289 | 42459 | jbadia | "not ",
|
290 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
291 | new DefaultDescription(
|
||
292 | "In",
|
||
293 | "Returns TRUE if the left operand equals one of the comma-separated"
|
||
294 | + " values; FALSE otherwise.",
|
||
295 | 42459 | jbadia | " in ( <Comma_separated_values> )",
|
296 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER |
297 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING |
||
298 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME |
||
299 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
||
300 | new DefaultDescription(
|
||
301 | "Between",
|
||
302 | "Returns TRUE if the left operand is greater or equal than " +
|
||
303 | "the first right operand and less or equal than the second " +
|
||
304 | "right operand; FALSE otherwise.",
|
||
305 | 42459 | jbadia | " between <Right_value_1> and <Right_value_2>",
|
306 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER |
307 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING |
||
308 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME |
||
309 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
||
310 | new DefaultDescription(
|
||
311 | "Like",
|
||
312 | "Returns TRUE if the left operand matches the pattern expressed " +
|
||
313 | "by the right operand; FALSE otherwise. Use '%' as wildcard.",
|
||
314 | 42459 | jbadia | " like <Right_value>",
|
315 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
316 | new DefaultDescription(
|
||
317 | "Is Null",
|
||
318 | "Returns TRUE if the left operand has NULL value;" +
|
||
319 | " FALSE otherwise.",
|
||
320 | 42459 | jbadia | " is null",
|
321 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER |
322 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING |
||
323 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME |
||
324 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
||
325 | new DefaultDescription(
|
||
326 | "Is Not Null",
|
||
327 | "Returns TRUE if the left operand does not have NULL value;" +
|
||
328 | " FALSE otherwise.",
|
||
329 | 42459 | jbadia | " is not null",
|
330 | 40435 | jjdelcerro | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER |
331 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING |
||
332 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME |
||
333 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN) |
||
334 | |||
335 | |||
336 | |||
337 | }; |
||
338 | } |
||
339 | return available_operators;
|
||
340 | } |
||
341 | |||
342 | |||
343 | public Description[] getAvailableFunctions() { |
||
344 | |||
345 | if (available_functions == null) { |
||
346 | available_functions = new Description[] { |
||
347 | |||
348 | new DefaultDescription(
|
||
349 | "Equals",
|
||
350 | "Returns TRUE if the two input values are equal; "
|
||
351 | + "FALSE otherwise.",
|
||
352 | Equals.NAME + "( <Value_1> , <Value_2> )",
|
||
353 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER |
||
354 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING |
||
355 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME |
||
356 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_GEOMETRY), |
||
357 | new DefaultDescription(
|
||
358 | GeomFromText.NAME, |
||
359 | "Returns the geometry object equivalent to the "
|
||
360 | + "input WKT string (single quotes).",
|
||
361 | GeomFromText.NAME + "( <Geometry_in_WKT> )",
|
||
362 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING |
||
363 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_GEOMETRY), |
||
364 | new DefaultDescription(
|
||
365 | "Intersects",
|
||
366 | "Returns TRUE if the two input geometries intersect; "
|
||
367 | + "FALSE otherwise.",
|
||
368 | Intersects.NAME + "( <Geometry_1> , <Geometry_2> )",
|
||
369 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_GEOMETRY), |
||
370 | new DefaultDescription(
|
||
371 | "Overlaps",
|
||
372 | "Returns TRUE if the two input geometries overlap; "
|
||
373 | + "FALSE otherwise. Geometries overlap when they have some but "
|
||
374 | + "not all points in common, they have the same dimension, "
|
||
375 | + "and the intersection of the interiors of the two "
|
||
376 | + "geometries has the same dimension as the "
|
||
377 | + "geometries themselves.",
|
||
378 | Overlaps.NAME + "( <Geometry_1> , <Geometry_2> )",
|
||
379 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_GEOMETRY), |
||
380 | new DefaultDescription(
|
||
381 | "Boundary",
|
||
382 | "Returns a geometry which is the bounding box of the "
|
||
383 | + "input geometry.",
|
||
384 | Boundary.NAME + "( <Geometry> )",
|
||
385 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_GEOMETRY), |
||
386 | new DefaultDescription(
|
||
387 | "To_timestamp",
|
||
388 | "Converts the input value to the timestamp type.",
|
||
389 | "to_timestamp( <Value> )",
|
||
390 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
391 | // ===============================================
|
||
392 | // ===============================================
|
||
393 | // ===============================================
|
||
394 | |||
395 | new DefaultDescription(
|
||
396 | "Abs",
|
||
397 | "Returns the absolute value of the input numeric value.",
|
||
398 | "abs( <Numeric_value> )",
|
||
399 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER), |
||
400 | new DefaultDescription(
|
||
401 | "Power",
|
||
402 | "Takes two numeric inputs and returns numeric result as "
|
||
403 | + "first argument raised to second argument.",
|
||
404 | "power( <Base> , <Exponent> )",
|
||
405 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER), |
||
406 | new DefaultDescription(
|
||
407 | "Mod",
|
||
408 | "Returns the remainder of the first argument divided by "
|
||
409 | + "the second argument.",
|
||
410 | "mod( <Numeric_value_1> , <Numeric_value_2> )",
|
||
411 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER), |
||
412 | new DefaultDescription(
|
||
413 | "Substr",
|
||
414 | "Returns a substring of the first argument, starting at "
|
||
415 | + "the character indicated by the second argument. "
|
||
416 | + "The optional third argument indicates the length "
|
||
417 | + "of the result.",
|
||
418 | "substr( <String> , <Start_index> [ , <Length> ] )",
|
||
419 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
||
420 | new DefaultDescription(
|
||
421 | "Sign",
|
||
422 | "Returns 1 for positive input values, -1 for negative values"
|
||
423 | + " and 0 when input is 0.",
|
||
424 | "sign( <Numeric_value> )",
|
||
425 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER), |
||
426 | new DefaultDescription(
|
||
427 | "Ceil",
|
||
428 | "Returns the smallest whole number greater than or equal to "
|
||
429 | + "the input numeric value.",
|
||
430 | "ceil( <Numeric_value> )",
|
||
431 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER), |
||
432 | new DefaultDescription(
|
||
433 | "Floor",
|
||
434 | "Returns the largest whole number equal to or less than "
|
||
435 | + "the input numeric value.",
|
||
436 | "floor( <Numeric_value> )",
|
||
437 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER), |
||
438 | new DefaultDescription(
|
||
439 | "Trunc",
|
||
440 | "Returns the first argument truncated to as many decimal "
|
||
441 | + "places as indicated by the second optional argument "
|
||
442 | + "(defaults to zero).",
|
||
443 | "trunc( <Numeric_value> [ , <Integer_value> ] )",
|
||
444 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER), |
||
445 | new DefaultDescription(
|
||
446 | "Round",
|
||
447 | "Returns the first argument rounded to as many places "
|
||
448 | + "to the right of the decimal point as "
|
||
449 | + "indicated by the second optional argument "
|
||
450 | + "(defaults to zero).",
|
||
451 | "round( <Numeric_value> [ , <Integer_value> ] )",
|
||
452 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER), |
||
453 | new DefaultDescription(
|
||
454 | "Length",
|
||
455 | "Returns the length (number of characters) of the "
|
||
456 | + "input string.",
|
||
457 | "length( <String> )",
|
||
458 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
||
459 | new DefaultDescription(
|
||
460 | "Concat",
|
||
461 | "Returns the concatenation of the two input strings.",
|
||
462 | "concat( <String_1> , <String_2> )",
|
||
463 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
||
464 | new DefaultDescription(
|
||
465 | "Instr",
|
||
466 | "Searches for a string using some parameters (similar to " +
|
||
467 | "same function in Oracle).",
|
||
468 | "instr( <String_1> , <String_2> , <Int_1> , <Int_2> )",
|
||
469 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
||
470 | new DefaultDescription(
|
||
471 | "Trim",
|
||
472 | "Removes all leading and trailing spaces from the input" +
|
||
473 | " string.",
|
||
474 | "trim( <String> )",
|
||
475 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
||
476 | new DefaultDescription(
|
||
477 | "Rtrim",
|
||
478 | "Removes all trailing (right-hand) spaces from " +
|
||
479 | "the input string.",
|
||
480 | "Rtrim( <String> )",
|
||
481 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
||
482 | new DefaultDescription(
|
||
483 | "Ltrim",
|
||
484 | "Removes all leading (left-hand) spaces from " +
|
||
485 | "the input string.",
|
||
486 | "Ltrim( <String> )",
|
||
487 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
||
488 | new DefaultDescription(
|
||
489 | "Rpad",
|
||
490 | "Appends <String_2> to <String_1> as many times as needed to reach " +
|
||
491 | "length <L>. <String_2> defaults to a white space.",
|
||
492 | "rpad( <String_1> , <L> [ , <String_2> ] )",
|
||
493 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
||
494 | new DefaultDescription(
|
||
495 | "Lpad",
|
||
496 | "Prepends <String_2> to <String_1> as many times as needed to reach " +
|
||
497 | "length <L>. <String_2> defaults to a white space.",
|
||
498 | "lpad( <String_1> , <L> [ , <String_2> ] )",
|
||
499 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
||
500 | new DefaultDescription(
|
||
501 | "Upper",
|
||
502 | "Returns the input string in upper case.",
|
||
503 | "upper( <String> )",
|
||
504 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
||
505 | new DefaultDescription(
|
||
506 | "Lower",
|
||
507 | "Returns the input string in lower case.",
|
||
508 | "lower( <String> )",
|
||
509 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
||
510 | new DefaultDescription(
|
||
511 | "Translate",
|
||
512 | "Replaces characters following the order of the second and third" +
|
||
513 | " parameters.",
|
||
514 | "translate( <String_1> , <String_2> , <String_3> )",
|
||
515 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
||
516 | new DefaultDescription(
|
||
517 | "Replace",
|
||
518 | "Replaces in <String_1> the occurrences of <String_2>" +
|
||
519 | " with <String_3>.",
|
||
520 | "replace( <String_1> , <String_2> , <String_3> )",
|
||
521 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
||
522 | new DefaultDescription(
|
||
523 | "Initcap",
|
||
524 | "Sets the first character in each word to uppercase and the " +
|
||
525 | "rest to lowercase.",
|
||
526 | "initcap( <String> )",
|
||
527 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
||
528 | new DefaultDescription(
|
||
529 | "Value",
|
||
530 | "Returns the first non-null value from the input values. " +
|
||
531 | "Can be used to avoid null values in a field.",
|
||
532 | "value( <Value_1> , <Value_2> ... )",
|
||
533 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER |
||
534 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING |
||
535 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME |
||
536 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
||
537 | new DefaultDescription(
|
||
538 | "Decode",
|
||
539 | "This function works like a IF-THEN-ELSE block.",
|
||
540 | "decode( <Expression> , <Search> , <Result> ... )",
|
||
541 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER |
||
542 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING |
||
543 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME |
||
544 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
||
545 | new DefaultDescription(
|
||
546 | "To_char",
|
||
547 | "Converts the input value to string.",
|
||
548 | "to_char( <Value> )",
|
||
549 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER |
||
550 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING |
||
551 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME |
||
552 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
||
553 | new DefaultDescription(
|
||
554 | "To_number",
|
||
555 | "Converts the input string to a number.",
|
||
556 | "to_number( <String> )",
|
||
557 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER |
||
558 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
||
559 | new DefaultDescription(
|
||
560 | "Imatch",
|
||
561 | "Returns a string representing the phonetic value of the " +
|
||
562 | "input string. Similar to Soundex function in Oracle.",
|
||
563 | "imatch( <String> )",
|
||
564 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
||
565 | new DefaultDescription(
|
||
566 | "Case",
|
||
567 | "This function works like a CASE-WHEN block.",
|
||
568 | "case( <Expression> ... )",
|
||
569 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
||
570 | |||
571 | |||
572 | new DefaultDescription(
|
||
573 | "Index",
|
||
574 | "Returns the position of a substring in a string.",
|
||
575 | "index( <String> , <Substring> )",
|
||
576 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING), |
||
577 | new DefaultDescription(
|
||
578 | "Num",
|
||
579 | "Returns the numeric value of the input string.",
|
||
580 | "num( <String> )",
|
||
581 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
||
582 | new DefaultDescription(
|
||
583 | "Chr",
|
||
584 | "Converts the input value to string.",
|
||
585 | "chr( <Value> )",
|
||
586 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER |
||
587 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING |
||
588 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME |
||
589 | | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN), |
||
590 | /*
|
||
591 | * date
|
||
592 | */
|
||
593 | new DefaultDescription(
|
||
594 | "Months_between",
|
||
595 | "Returns the number of months (as a float-point value) between " +
|
||
596 | "<Earliest_date> and <Latest_date>.",
|
||
597 | "months_between( <Latest_date> , <Earliest_date> )",
|
||
598 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
599 | new DefaultDescription(
|
||
600 | "Add_months",
|
||
601 | "Adds a number of months to the input date.",
|
||
602 | "add_months( <Input_date> , <Number_of_months_integer>)",
|
||
603 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
604 | new DefaultDescription(
|
||
605 | "Last_day",
|
||
606 | "Returns the date corresponding to the last day of the month " +
|
||
607 | "of the input date.",
|
||
608 | "last_day( <Input_date> )",
|
||
609 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
610 | new DefaultDescription(
|
||
611 | "Next_day",
|
||
612 | "Returns the date of the first weekday named by the string " +
|
||
613 | "<Day_of_the_week> " +
|
||
614 | "that is later than <Input_date>.",
|
||
615 | "next_day( <Input_date> , <Day_of_the_week> )",
|
||
616 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
617 | new DefaultDescription(
|
||
618 | "To_date",
|
||
619 | "Converts the input string to a date following the" +
|
||
620 | " optional format.",
|
||
621 | "to_date( <Input_string> [ , <Format> ] )",
|
||
622 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
623 | new DefaultDescription(
|
||
624 | "Adddate",
|
||
625 | "Returns a date which is <Number_of_days> days after the" +
|
||
626 | " input date.",
|
||
627 | "adddate( <Input_date> , <Number_of_days> )",
|
||
628 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
629 | new DefaultDescription(
|
||
630 | "Subdate",
|
||
631 | "Returns a date which is <Number_of_days> days before the" +
|
||
632 | " input date.",
|
||
633 | "subdate( <Input_date> , <Number_of_days> )",
|
||
634 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
635 | new DefaultDescription(
|
||
636 | "Addtime",
|
||
637 | "Adds the second input time <Add_time> to the first " +
|
||
638 | "input time <Input_date>.",
|
||
639 | "addtime( <Input_time> , <Add_time> )",
|
||
640 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
641 | new DefaultDescription(
|
||
642 | "Subtime",
|
||
643 | "Subtracts the second input time <Sub_time> from the first " +
|
||
644 | "input time <Input_date>.",
|
||
645 | "subtime( <Input_time> , <Sub_time> )",
|
||
646 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
647 | new DefaultDescription(
|
||
648 | "Year",
|
||
649 | "Returns a numeric value representing the year of the " +
|
||
650 | "input date.",
|
||
651 | "year( <Input_date> )",
|
||
652 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
653 | new DefaultDescription(
|
||
654 | "Month",
|
||
655 | "Returns a numeric value representing the month of the " +
|
||
656 | "input date.",
|
||
657 | "month( <Input_date> )",
|
||
658 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
659 | new DefaultDescription(
|
||
660 | "Day",
|
||
661 | "Returns a numeric value representing the day of the " +
|
||
662 | "input date.",
|
||
663 | "day( <Input_date> )",
|
||
664 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
665 | new DefaultDescription(
|
||
666 | "Dayofmonth",
|
||
667 | "Returns a numeric value between 1 and 31 corresponding to " +
|
||
668 | "the day of the month of the input date.",
|
||
669 | "dayofmonth( <Input_date> )",
|
||
670 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
671 | new DefaultDescription(
|
||
672 | "Hour",
|
||
673 | "Returns a numeric value representing the number " +
|
||
674 | "of hours of the input time value.",
|
||
675 | "hour( <Time_value> )",
|
||
676 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
677 | new DefaultDescription(
|
||
678 | "Minute",
|
||
679 | "Returns a numeric value representing the number " +
|
||
680 | "of minutes of the input time value.",
|
||
681 | "minute( <Time_value> )",
|
||
682 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
683 | new DefaultDescription(
|
||
684 | "Second",
|
||
685 | "Returns a numeric value representing the number " +
|
||
686 | "of seconds of the input time value.",
|
||
687 | "second( <Time_value> )",
|
||
688 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
689 | new DefaultDescription(
|
||
690 | "Microsecond",
|
||
691 | "Returns the number of microseconds of the input " +
|
||
692 | "timestamp value",
|
||
693 | "microseconds( <Timestamp_value> )",
|
||
694 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
695 | new DefaultDescription(
|
||
696 | "Datediff",
|
||
697 | "Returns the number of days between the two input dates.",
|
||
698 | "datediff( <Date_1> , <Date_2> )",
|
||
699 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
700 | new DefaultDescription(
|
||
701 | "Dayofweek",
|
||
702 | "Returns a numeric value between 1 (Monday) and 7 " +
|
||
703 | "(Sunday) corresponding to " +
|
||
704 | "the day of the week of the input date.",
|
||
705 | "dayofweek( <Input_date> )",
|
||
706 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
707 | new DefaultDescription(
|
||
708 | "Weekofyear",
|
||
709 | "Returns a numeric value between 1 and 53 " +
|
||
710 | "corresponding to" +
|
||
711 | " the number of the week of the input date.",
|
||
712 | "weekofyear( <Input_date> )",
|
||
713 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
714 | new DefaultDescription(
|
||
715 | "Dayname",
|
||
716 | "Returns the name of the day corresponding to the input" +
|
||
717 | " date ('Sunday', 'Monday', etc).",
|
||
718 | "dayname( <Input_date> )",
|
||
719 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
720 | new DefaultDescription(
|
||
721 | "Monthname",
|
||
722 | "Returns the name of the month corresponding to the input" +
|
||
723 | " date ('January', 'February', etc).",
|
||
724 | "monthname( <Input_date> )",
|
||
725 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
726 | new DefaultDescription(
|
||
727 | "Makedate",
|
||
728 | "Returns a date corresponding to the day denoted by " +
|
||
729 | "<Day_integer> (between 1 and 366) of the year " +
|
||
730 | "<Year_integer>.",
|
||
731 | "makedate( <Year_integer> , <Day_integer> )",
|
||
732 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME), |
||
733 | new DefaultDescription(
|
||
734 | "Maketime",
|
||
735 | "Creates a time value with the input number of" +
|
||
736 | " hours, minutes and seconds.",
|
||
737 | "maketime( <Hours> , <Minutes> , <Seconds> )",
|
||
738 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME) |
||
739 | |||
740 | }; |
||
741 | } |
||
742 | return available_functions;
|
||
743 | } |
||
744 | |||
745 | // =======================================================
|
||
746 | // =======================================================
|
||
747 | // =======================================================
|
||
748 | |||
749 | private class DefaultDescription implements Description{ |
||
750 | |||
751 | private String name, desc, template; |
||
752 | private int categories; |
||
753 | |||
754 | public DefaultDescription(
|
||
755 | String name, String desc, String template, |
||
756 | int datatype_categories) {
|
||
757 | |||
758 | this.name = name;
|
||
759 | this.desc = desc;
|
||
760 | this.template = template;
|
||
761 | this.categories = datatype_categories;
|
||
762 | } |
||
763 | |||
764 | /* (non-Javadoc)
|
||
765 | * @see org.gvsig.tools.evaluator.EvaluatorWithDescriptions.Description#getName()
|
||
766 | */
|
||
767 | public String getName() { |
||
768 | return name;
|
||
769 | } |
||
770 | |||
771 | /* (non-Javadoc)
|
||
772 | * @see org.gvsig.tools.evaluator.EvaluatorWithDescriptions.Description#getDescription()
|
||
773 | */
|
||
774 | public String getDescription() { |
||
775 | return desc;
|
||
776 | } |
||
777 | |||
778 | /* (non-Javadoc)
|
||
779 | * @see org.gvsig.tools.evaluator.EvaluatorWithDescriptions.Description#getTemplate()
|
||
780 | */
|
||
781 | public String getTemplate() { |
||
782 | return template;
|
||
783 | } |
||
784 | |||
785 | /* (non-Javadoc)
|
||
786 | * @see org.gvsig.tools.evaluator.EvaluatorWithDescriptions.Description#getDataTypeCategories()
|
||
787 | */
|
||
788 | public int getDataTypeCategories() { |
||
789 | return this.categories; |
||
790 | } |
||
791 | |||
792 | } |
||
793 | } |