Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / main / java / org / gvsig / expressionevaluator / impl / DefaultExpressionBuilder.java @ 44259

History | View | Annotate | Download (48.4 KB)

1 44006 jjdelcerro
package org.gvsig.expressionevaluator.impl;
2 43020 jjdelcerro
3
import java.text.MessageFormat;
4
import java.util.ArrayList;
5
import java.util.Collections;
6
import java.util.HashSet;
7
import java.util.List;
8
import java.util.Objects;
9
import java.util.Set;
10
import org.apache.commons.lang3.StringUtils;
11
import org.cresques.cts.IProjection;
12 44198 jjdelcerro
import org.gvsig.expressionevaluator.Code;
13 43020 jjdelcerro
import org.gvsig.fmap.geom.Geometry;
14 43034 jjdelcerro
import org.gvsig.fmap.geom.primitive.Envelope;
15 43020 jjdelcerro
16 44006 jjdelcerro
import org.gvsig.expressionevaluator.ExpressionBuilder;
17 44198 jjdelcerro
import static org.gvsig.expressionevaluator.ExpressionBuilder.EMPTY_FORMATTER;
18
import org.gvsig.expressionevaluator.ExpressionUtils;
19
import org.gvsig.expressionevaluator.Formatter;
20
import org.gvsig.fmap.geom.GeometryUtils;
21 43093 jjdelcerro
22 44198 jjdelcerro
@SuppressWarnings({"UseSpecificCatch" ,"OverridableMethodCallInConstructor"})
23 44006 jjdelcerro
public class DefaultExpressionBuilder implements ExpressionBuilder {
24 44198 jjdelcerro
25
    private static final String FORMAT_QUOTE_FOR_STRINGS = "'";
26
    private static final String FORMAT_QUOTE_FOR_IDENTIFIERS = "\"";
27 44006 jjdelcerro
28 44198 jjdelcerro
    private static final String FORMAT_TRUE = "TRUE";
29
    private static final String FORMAT_FALSE = "FALSE";
30 43020 jjdelcerro
31 44198 jjdelcerro
    private static final String FORMAT_GROUP = "( {0} )";
32 43093 jjdelcerro
33 44198 jjdelcerro
    private static final String FORMAT_ST_SRID = "ST_SRID({0})";
34
    private static final String FORMAT_ST_ASTEXT = "ST_AsText({0})";
35
    private static final String FORMAT_ST_ASBINARY = "ST_AsBinary({0})";
36
    private static final String FORMAT_ST_ASEWKB = "ST_AsEWKB({0})";
37
    private static final String FORMAT_ST_CONTAINS = "ST_Contains(({0}), ({1}))";
38
    private static final String FORMAT_ST_CROSSES = "ST_Crosses(({0}), ({1}))";
39
    private static final String FORMAT_ST_DISJOINT = "ST_Disjoint(({0}), ({1}))";
40
    private static final String FORMAT_ST_EQUALS = "ST_Equals(({0}), ({1}))";
41
    private static final String FORMAT_ST_ISCLOSED = "ST_IsClosed({0})";
42
    private static final String FORMAT_ST_OVERLAPS = "ST_Overlaps(({0}), ({1}))";
43
    private static final String FORMAT_ST_TOUCHES = "ST_Touches(({0}), ({1}))";
44
    private static final String FORMAT_ST_WITHIN = "ST_Within(({0}), ({1}))";
45
    private static final String FORMAT_ST_ENVELOPE = "ST_Envelope({0})";
46
    private static final String FORMAT_ST_INTERSECTS = "ST_Intersects(({0}), ({1}))";
47
    private static final String FORMAT_ST_GEOMFROMTEXT = "ST_GeomFromText(({0}), ({1}))";
48
    private static final String FORMAT_ST_GEOMFROMWKB = "ST_GeomFromWKB(({0}), ({1}))";
49
    private static final String FORMAT_ST_GEOMFROMEWKB = "ST_GeomFromEWKB(({0}), ({1}))";
50
    private static final String FORMAT_ST_SIMPLIFY = "ST_Simplify(({0}), ({1}))";
51 43093 jjdelcerro
52 44198 jjdelcerro
    private static final String FORMAT_ISNULL = "( ({0}) IS NULL )";
53
    private static final String FORMAT_NOTISNULL = "( ({0}) NOT IS NULL )";
54
    private static final String FORMAT_OPERATOR_NOT = "( NOT ({0}) )";
55 43093 jjdelcerro
56 44198 jjdelcerro
    private static final String FORMAT_OPERATOR_AND = "{0} AND {1}";
57
    private static final String FORMAT_OPERATOR_OR = "{0} OR {1}";
58
    private static final String FORMAT_OPERATOR_EQ = "( ({0}) = ({1}) )";
59
    private static final String FORMAT_OPERATOR_NE = "( ({0}) <> ({1}) )";
60
    private static final String FORMAT_OPERATOR_GT = "( ({0}) > ({1}) )";
61
    private static final String FORMAT_OPERATOR_GE = "( ({0}) >= ({1}) )";
62
    private static final String FORMAT_OPERATOR_LT = "( ({0}) < ({1}) )";
63
    private static final String FORMAT_OPERATOR_LE = "( ({0}) <= ({1}) )";
64
    private static final String FORMAT_OPERATOR_LIKE = "( ({0}) LIKE ({1}) )";
65
    private static final String FORMAT_OPERATOR_ILIKE = "( ({0}) ILIKE ({1}) )";
66
    private static final String FORMAT_OPERATOR_ADD = "{0} + {1}";
67
    private static final String FORMAT_OPERATOR_SUBST = "{0} - {1}";
68
    private static final String FORMAT_OPERATOR_MULT = "{0} * {1}";
69
    private static final String FORMAT_OPERATOR_DIV = "{0} / {1}";
70
    private static final String FORMAT_OPERATOR_CONCAT = "{0} || {1}";
71 43093 jjdelcerro
72 43020 jjdelcerro
    public class GroupBase extends AbstractValue implements Group {
73 43093 jjdelcerro
74 43020 jjdelcerro
        protected Value value;
75 43093 jjdelcerro
76 43020 jjdelcerro
        public GroupBase(Value value) {
77
            this.value = value;
78
        }
79
80
        @Override
81 44198 jjdelcerro
        public Value value() {
82 43020 jjdelcerro
            return value;
83
        }
84
85
        @Override
86
        public void accept(Visitor visitor, VisitorFilter filter) {
87 43093 jjdelcerro
            super.accept(visitor, filter);
88
            this.value.accept(visitor, filter);
89 43020 jjdelcerro
        }
90 43093 jjdelcerro
91 43020 jjdelcerro
        @Override
92
        public String toString() {
93 44198 jjdelcerro
            return this.toString(EMPTY_FORMATTER);
94 43020 jjdelcerro
        }
95 44198 jjdelcerro
96
        @Override
97
        public String toString(Formatter<Value> formatter) {
98
            if( formatter.canApply(this) ) {
99
                return formatter.format(this);
100
            }
101
            return MessageFormat.format(FORMAT_GROUP, this.value.toString());
102
        }
103 43020 jjdelcerro
    }
104
105
    public class VariableBase extends AbstractValue implements Variable {
106 43093 jjdelcerro
107 43020 jjdelcerro
        protected String name;
108 43093 jjdelcerro
109 43020 jjdelcerro
        public VariableBase(String name) {
110
            this.name = name;
111
        }
112 43093 jjdelcerro
113 43020 jjdelcerro
        @Override
114 44198 jjdelcerro
        public String name() {
115 43020 jjdelcerro
            return this.name;
116
        }
117
118
        @Override
119
        public String toString() {
120 44198 jjdelcerro
            return this.toString(EMPTY_FORMATTER);
121
        }
122
123
        @Override
124
        public String toString(Formatter<Value> formatter) {
125
            if( formatter.canApply(this) ) {
126
                return formatter.format(this);
127
            }
128 43020 jjdelcerro
            return identifier(this.name);
129
        }
130
131
        @Override
132
        public int compareTo(Variable o) {
133 44198 jjdelcerro
            return this.name.compareTo(o.name());
134 43020 jjdelcerro
        }
135
136
        @Override
137
        public boolean equals(Object obj) {
138 43093 jjdelcerro
            if (!(obj instanceof Variable)) {
139 43020 jjdelcerro
                return false;
140
            }
141 44198 jjdelcerro
            return this.name.equals(((Variable) obj).name());
142 43020 jjdelcerro
        }
143
144
        @Override
145
        public int hashCode() {
146
            int hash = 7;
147
            hash = 37 * hash + Objects.hashCode(this.name);
148
            return hash;
149
        }
150
    }
151
152
    public class ParameterBase extends AbstractValue implements Parameter {
153 43093 jjdelcerro
154
        protected String name;
155 43020 jjdelcerro
        protected Object value;
156
        protected ParameterType type;
157
        protected Value srs;
158 43093 jjdelcerro
159 44198 jjdelcerro
        /*
160
        Para un parametre de tipo Geometria, el srs sera siempre un Constant
161
        excepto cuando se le asigne una geometria contante al parametro y esta
162
        tenga un SRS asignado. En este caso, tanto la geometria como el SRS
163
        se trataran como parametros.
164

165
        Si se quiere que el SRS sea un Parameter, se construira como tal y se
166
        asignara a traves del metodo srs(Value srs).
167
        */
168 43093 jjdelcerro
        public ParameterBase() {
169
            this.type = ParameterType.Constant;
170
            this.name = null;
171
            this.value = null;
172 43020 jjdelcerro
        }
173
174
        @Override
175
        public void accept(Visitor visitor, VisitorFilter filter) {
176
            super.accept(visitor, filter);
177 43093 jjdelcerro
            if (this.srs != null) {
178 43020 jjdelcerro
                this.srs.accept(visitor, filter);
179
            }
180
        }
181 43093 jjdelcerro
182 43020 jjdelcerro
        @Override
183 43093 jjdelcerro
        public Parameter as_geometry_variable() {
184 43020 jjdelcerro
            this.type = ParameterType.Geometry;
185 43093 jjdelcerro
            if (this.value == null && this.name != null) {
186
                this.value = this.name;
187
            }
188 43020 jjdelcerro
            return this;
189
        }
190 43093 jjdelcerro
191 43020 jjdelcerro
        @Override
192
        public Parameter as_constant() {
193
            this.type = ParameterType.Constant;
194 43093 jjdelcerro
            if (this.value == null && this.name != null) {
195
                this.value = this.name;
196
            }
197 43020 jjdelcerro
            return this;
198
        }
199 43093 jjdelcerro
200 43020 jjdelcerro
        @Override
201
        public Parameter as_variable() {
202
            this.type = ParameterType.Variable;
203 43093 jjdelcerro
            if (this.value != null && this.name == null) {
204
                this.name = (String) this.value;
205
            }
206 43020 jjdelcerro
            return this;
207
        }
208 43093 jjdelcerro
209 43020 jjdelcerro
        @Override
210
        public Parameter srs(Value srs) {
211
            this.srs = srs;
212 43093 jjdelcerro
            if( this.type == ParameterType.Variable ) {
213
                this.type = ParameterType.Geometry;
214
            }
215 43020 jjdelcerro
            return this;
216
        }
217
218
        @Override
219
        public Parameter srs(IProjection srs) {
220 44198 jjdelcerro
            this.srs = constant(srs_id(srs));
221 43093 jjdelcerro
            if( this.type == ParameterType.Variable ) {
222
                this.type = ParameterType.Geometry;
223
            }
224 43020 jjdelcerro
            return this;
225
        }
226 43093 jjdelcerro
227 43020 jjdelcerro
        @Override
228 44198 jjdelcerro
        public String name() {
229 43093 jjdelcerro
            switch (this.type) {
230 43020 jjdelcerro
                case Variable:
231
                case Geometry:
232 43093 jjdelcerro
                    return this.name;
233 43020 jjdelcerro
                case Constant:
234 43093 jjdelcerro
                    if (this.value == null) {
235
                        return null;
236
                    }
237
                    return this.value.toString();
238 43020 jjdelcerro
                default:
239 43093 jjdelcerro
                    if (this.name != null) {
240
                        return this.name;
241
                    }
242
                    if (this.value != null) {
243
                        return this.value.toString();
244
                    }
245 43020 jjdelcerro
                    return null;
246
            }
247
        }
248
249
        @Override
250
        public boolean is_constant() {
251
            return this.type == ParameterType.Constant;
252
        }
253
254
        @Override
255
        public boolean is_geometry_variable() {
256
            return this.type == ParameterType.Geometry;
257
        }
258
259
        @Override
260
        public boolean is_variable() {
261
            return this.type == ParameterType.Variable;
262
        }
263
264
        @Override
265 43093 jjdelcerro
        public Parameter value(Object value) {
266 44198 jjdelcerro
            if( value instanceof Geometry ) {
267
                if( this.srs == null ) {
268
                    IProjection proj = ((Geometry)value).getProjection();
269
                    this.srs(parameter().value(proj));
270
                }
271
            }
272 43093 jjdelcerro
            this.value = value;
273
            return this;
274
        }
275
276
        @Override
277
        public Parameter name(String name) {
278
            this.type = ParameterType.Variable;
279
            this.name = name;
280
            return this;
281
        }
282
283
        @Override
284 44198 jjdelcerro
        public Object value() {
285 43020 jjdelcerro
            try {
286 43093 jjdelcerro
                switch (this.type) {
287 43020 jjdelcerro
                    case Constant:
288 44198 jjdelcerro
                        if( this.value instanceof Geometry ) {
289
                            Geometry geometry = (Geometry) this.value;
290
                            switch (geometry_support_type()) {
291 43020 jjdelcerro
                                case EWKB:
292 44198 jjdelcerro
                                    return GeometryUtils.toEWKB(geometry);
293 43020 jjdelcerro
                                case WKB:
294 44198 jjdelcerro
                                    return GeometryUtils.toWKB(geometry);
295 43020 jjdelcerro
                                case WKT:
296
                                default:
297 44198 jjdelcerro
                                    return GeometryUtils.toWKT(geometry);
298 43020 jjdelcerro
                            }
299 43093 jjdelcerro
                        } else if (this.value instanceof IProjection) {
300 44198 jjdelcerro
                            return srs_id((IProjection) this.value);
301 43093 jjdelcerro
                        }
302 43020 jjdelcerro
                        return this.value;
303
                    case Variable:
304
                    case Geometry:
305
                    default:
306 43093 jjdelcerro
                        return this.value;
307 43020 jjdelcerro
                }
308 43093 jjdelcerro
            } catch (Exception ex) {
309
                throw new RuntimeException("Can't get value from parameter.", ex);
310 43020 jjdelcerro
            }
311
        }
312
313
        @Override
314 44198 jjdelcerro
        public ParameterType type() {
315 43020 jjdelcerro
            return this.type;
316
        }
317 43093 jjdelcerro
318 43020 jjdelcerro
        @Override
319 44198 jjdelcerro
        public Value srs() {
320 43020 jjdelcerro
            return this.srs;
321
        }
322 43093 jjdelcerro
323 43020 jjdelcerro
        @Override
324
        public String toString() {
325 44198 jjdelcerro
            return this.toString(EMPTY_FORMATTER);
326
        }
327
328
        @Override
329
        public String toString(Formatter<Value> formatter) {
330
            if( formatter.canApply(this) ) {
331
                return formatter.format(this);
332
            }
333 43093 jjdelcerro
            switch (this.type) {
334 43020 jjdelcerro
                case Constant:
335 44198 jjdelcerro
                    if( value instanceof Geometry ) {
336
                        switch (geometry_support_type()) {
337
                            case EWKB:
338
                                return MessageFormat.format(
339
                                    FORMAT_ST_GEOMFROMEWKB,
340
                                    "?",
341
                                    getSRS(formatter)
342
                                );
343
                            case WKB:
344
                                return MessageFormat.format(
345
                                    FORMAT_ST_GEOMFROMWKB,
346
                                    "?",
347
                                    getSRS(formatter)
348
                                );
349
                            case WKT:
350
                            default:
351
                                return MessageFormat.format(
352
                                    FORMAT_ST_GEOMFROMTEXT,
353
                                    "?",
354
                                    getSRS(formatter)
355
                                );
356
                        }
357
                    }
358 43020 jjdelcerro
                case Variable:
359
                default:
360
                    return "?";
361
                case Geometry:
362 44198 jjdelcerro
                    switch (geometry_support_type()) {
363 43020 jjdelcerro
                        case EWKB:
364
                            return MessageFormat.format(
365 44198 jjdelcerro
                                FORMAT_ST_GEOMFROMEWKB,
366
                                "?",
367
                                getSRS(formatter)
368 43020 jjdelcerro
                            );
369
                        case WKB:
370
                            return MessageFormat.format(
371 44198 jjdelcerro
                                FORMAT_ST_GEOMFROMWKB,
372
                                "?",
373
                                getSRS(formatter)
374 43020 jjdelcerro
                            );
375
                        case WKT:
376
                        default:
377
                            return MessageFormat.format(
378 44198 jjdelcerro
                                FORMAT_ST_GEOMFROMTEXT,
379
                                "?",
380
                                getSRS(formatter)
381 43093 jjdelcerro
                            );
382
                    }
383 43020 jjdelcerro
            }
384 43093 jjdelcerro
        }
385 44198 jjdelcerro
386
        private String getSRS(Formatter formatter) {
387
            if( this.srs!=null ) {
388
                return this.srs.toString(formatter);
389
            }
390
            if( this.value instanceof Geometry ) {
391
                IProjection proj = ((Geometry)this.value).getProjection();
392
                Object s = srs_id(proj);
393
                if( s == null ) {
394
                    throw new IllegalArgumentException("A parameter of type Geometry with an invalid SRS.");
395
                }
396
                return s.toString();
397
            }
398
            throw new IllegalArgumentException("The parameter of type Geometry need a SRS.");
399
        }
400 43020 jjdelcerro
    }
401
402
    public class ConstantBase extends AbstractValue implements Constant {
403 43093 jjdelcerro
404 43020 jjdelcerro
        protected Object value;
405 43093 jjdelcerro
406 43020 jjdelcerro
        public ConstantBase(Object value) {
407
            this.value = value;
408
        }
409 43093 jjdelcerro
410 43020 jjdelcerro
        @Override
411 44198 jjdelcerro
        public Object value() {
412 43020 jjdelcerro
            return this.value;
413
        }
414
415
        @Override
416
        public String toString() {
417 44198 jjdelcerro
            return this.toString(EMPTY_FORMATTER);
418
        }
419
420
        @Override
421
        public String toString(Formatter<Value> formatter) {
422
            if( formatter.canApply(this) ) {
423
                return formatter.format(this);
424
            }
425
            if( this.value==null ) {
426
                return "NULL";
427
            }
428
            if( this.value instanceof byte[] ) {
429
                return "DECODE('"+bytearray_hex((byte[])this.value)+"','hex')";
430
            }
431 43093 jjdelcerro
            if (this.value instanceof String) {
432 43020 jjdelcerro
                return string((String) this.value);
433
            }
434 44198 jjdelcerro
            if( this.value instanceof Geometry ) {
435
                Geometry geometry = (Geometry) this.value;
436
                switch (geometry_support_type()) {
437
                    case EWKB:
438
                        return MessageFormat.format(
439
                                FORMAT_ST_GEOMFROMEWKB,
440
                                "DECODE('"+bytearray_hex(GeometryUtils.toEWKB(geometry))+"','hex')",
441
                                String.valueOf(srs_id(geometry.getProjection()))
442
                        );
443
                    case WKB:
444
                        return MessageFormat.format(
445
                                FORMAT_ST_GEOMFROMWKB,
446
                                "DECODE('"+bytearray_hex(GeometryUtils.toWKB(geometry))+"','hex')",
447
                                String.valueOf(srs_id(geometry.getProjection()))
448
                        );
449
                    case WKT:
450
                    default:
451
                        return MessageFormat.format(
452
                                FORMAT_ST_GEOMFROMTEXT,
453
                                string(GeometryUtils.toWKT(geometry)),
454
                                String.valueOf(srs_id(geometry.getProjection()))
455
                        );
456
                }
457
            }
458
            if( this.value instanceof IProjection ) {
459
                return Objects.toString(srs_id((IProjection)(this.value)));
460
            }
461 43093 jjdelcerro
            if (this.value instanceof Boolean) {
462
                if (((Boolean) this.value)) {
463 44198 jjdelcerro
                    return FORMAT_TRUE;
464 43020 jjdelcerro
                } else {
465 44198 jjdelcerro
                    return FORMAT_FALSE;
466 43020 jjdelcerro
                }
467
            }
468 44198 jjdelcerro
            return Objects.toString(this.value, "");
469 43020 jjdelcerro
        }
470
    }
471
472
    public class CustomBase extends AbstractValue implements Custom {
473 43093 jjdelcerro
474 43020 jjdelcerro
        protected Object value;
475 43093 jjdelcerro
476 43020 jjdelcerro
        // Esto es para permitir declarar parametros y columnas en una seccion
477
        // custom.
478
        protected List<Value> values;
479 43093 jjdelcerro
480 43020 jjdelcerro
        public CustomBase(Object value) {
481
            this.value = value;
482
        }
483
484
        @Override
485
        public void accept(Visitor visitor, VisitorFilter filter) {
486
            super.accept(visitor, filter);
487 43093 jjdelcerro
            if (this.values != null) {
488 44006 jjdelcerro
                for (Value theValue : values) {
489
                    theValue.accept(visitor, filter);
490 43020 jjdelcerro
                }
491
            }
492
        }
493 43093 jjdelcerro
494 43020 jjdelcerro
        @Override
495 44198 jjdelcerro
        public Object value() {
496 43020 jjdelcerro
            return this.value;
497
        }
498
499
        @Override
500
        public Custom add(Variable variable) {
501 43093 jjdelcerro
            if (this.values == null) {
502 43020 jjdelcerro
                this.values = new ArrayList<>();
503
            }
504
            this.values.add(variable);
505
            return this;
506
        }
507
508
        @Override
509
        public Custom add(Parameter parameter) {
510 43093 jjdelcerro
            if (this.values == null) {
511 43020 jjdelcerro
                this.values = new ArrayList<>();
512
            }
513
            this.values.add(parameter);
514
            return this;
515
        }
516
517
        @Override
518
        public String toString() {
519 44198 jjdelcerro
            return this.toString(EMPTY_FORMATTER);
520 43020 jjdelcerro
        }
521 44198 jjdelcerro
522 43020 jjdelcerro
        @Override
523 44198 jjdelcerro
        public String toString(Formatter<Value> formatter) {
524
            if( formatter.canApply(this) ) {
525
                return formatter.format(this);
526 43020 jjdelcerro
            }
527 44198 jjdelcerro
            return Objects.toString(this.value, "");
528 43020 jjdelcerro
        }
529 43093 jjdelcerro
    }
530 43020 jjdelcerro
531
    public class FunctionBase extends AbstractValue implements Function {
532
533
        protected String name;
534
        protected String format;
535
        protected List<Value> parameters;
536 43093 jjdelcerro
537 43020 jjdelcerro
        public FunctionBase(String name, String format) {
538
            this.name = name;
539
            this.format = format;
540
        }
541 43093 jjdelcerro
542 44020 jjdelcerro
        public FunctionBase(String name) {
543
            this(name,null);
544
        }
545
546 43020 jjdelcerro
        @Override
547
        public List<Value> parameters() {
548 43093 jjdelcerro
            if (this.parameters == null) {
549 43020 jjdelcerro
                this.parameters = new ArrayList<>();
550
            }
551
            return this.parameters;
552 43093 jjdelcerro
        }
553 43020 jjdelcerro
554
        @Override
555
        public Function parameter(Value parameter) {
556
            this.parameters().add(parameter);
557
            return this;
558
        }
559
560
        @Override
561 44198 jjdelcerro
        public String name() {
562 43020 jjdelcerro
            return this.name;
563
        }
564
565
        @Override
566
        public void accept(Visitor visitor, VisitorFilter filter) {
567 43093 jjdelcerro
            super.accept(visitor, filter);
568 43020 jjdelcerro
            for (Value value : this.parameters) {
569 43093 jjdelcerro
                value.accept(visitor, filter);
570 43020 jjdelcerro
            }
571
        }
572
573
        @Override
574
        public String toString() {
575 44198 jjdelcerro
            return this.toString(EMPTY_FORMATTER);
576
        }
577
578
        @Override
579
        public String toString(Formatter<Value> formatter) {
580
            if( formatter.canApply(this) ) {
581
                return formatter.format(this);
582
            }
583 44020 jjdelcerro
            if( this.format==null ) {
584
                StringBuilder builder = new StringBuilder();
585
                builder.append(name);
586
                builder.append("(");
587
                if (this.parameters != null && !this.parameters.isEmpty()) {
588
                    boolean first = true;
589
                    for (Value value : this.parameters) {
590
                        if( first ) {
591
                            first=false;
592 44198 jjdelcerro
                            builder.append(value.toString(formatter));
593 44020 jjdelcerro
                        } else {
594
                            builder.append(", ");
595 44198 jjdelcerro
                            builder.append(value.toString(formatter));
596 44020 jjdelcerro
                        }
597
                    }
598
                }
599
                builder.append(")");
600
                return builder.toString();
601
            }
602 43093 jjdelcerro
            if (this.parameters != null && !this.parameters.isEmpty()) {
603 43020 jjdelcerro
                List<String> values = new ArrayList<>();
604
                for (Value value : this.parameters) {
605 44198 jjdelcerro
                    values.add(value.toString(formatter));
606 43020 jjdelcerro
                }
607
                return MessageFormat.format(format, values.toArray());
608
            } else {
609
                return this.format;
610
            }
611
        }
612
    }
613 43093 jjdelcerro
614 44198 jjdelcerro
    public class MethodBase extends FunctionBase implements Method {
615
616
        private final Value instance;
617
618
        public MethodBase(Value instance, String name) {
619
            super(name);
620
            this.instance = instance;
621
        }
622
623
        @Override
624
        public Value instance() {
625
            return this.instance;
626
        }
627
628
        @Override
629
        public void accept(Visitor visitor, VisitorFilter filter) {
630
            this.instance.accept(visitor, filter);
631
            super.accept(visitor, filter);
632
        }
633
634
        @Override
635
        public String toString(Formatter<Value> formatter) {
636
            if( formatter.canApply(this) ) {
637
                return formatter.format(this);
638
            }
639
            StringBuilder builder = new StringBuilder();
640
            builder.append(this.instance.toString(formatter));
641
            builder.append("->");
642
            builder.append(this.name());
643
            builder.append(name);
644
            builder.append("(");
645
            if (this.parameters != null && !this.parameters.isEmpty()) {
646
                boolean first = true;
647
                for (Value value : this.parameters) {
648
                    if( first ) {
649
                        first=false;
650
                        builder.append(value.toString(formatter));
651
                    } else {
652
                        builder.append(", ");
653
                        builder.append(value.toString(formatter));
654
                    }
655
                }
656
            }
657
            builder.append(")");
658
            return builder.toString();
659
        }
660
    }
661
662 43020 jjdelcerro
    public class BinaryOperatorBase extends AbstractValue implements BinaryOperator {
663
664
        protected String name;
665
        protected String format;
666
        protected Value left;
667
        protected Value right;
668 43093 jjdelcerro
669 43020 jjdelcerro
        public BinaryOperatorBase(String name, String format) {
670
            this.name = name;
671
            this.format = format;
672
        }
673 43093 jjdelcerro
674 43020 jjdelcerro
        @Override
675 44198 jjdelcerro
        public String name() {
676 43020 jjdelcerro
            return this.name;
677
        }
678
679
        @Override
680
        public void accept(Visitor visitor, VisitorFilter filter) {
681 43093 jjdelcerro
            super.accept(visitor, filter);
682 43020 jjdelcerro
            this.left.accept(visitor, filter);
683
            this.right.accept(visitor, filter);
684
        }
685
686
        @Override
687 44198 jjdelcerro
        public BinaryOperator left(Value operand) {
688 43020 jjdelcerro
            this.left = operand;
689
            return this;
690
        }
691
692
        @Override
693 44198 jjdelcerro
        public BinaryOperator right(Value operand) {
694 43020 jjdelcerro
            this.right = operand;
695
            return this;
696
        }
697
698
        @Override
699 44198 jjdelcerro
        public Value left() {
700 43020 jjdelcerro
            return this.left;
701
        }
702
703
        @Override
704 44198 jjdelcerro
        public Value right() {
705 43020 jjdelcerro
            return this.right;
706
        }
707 43093 jjdelcerro
708 43020 jjdelcerro
        @Override
709
        public String toString() {
710 44198 jjdelcerro
            return this.toString(EMPTY_FORMATTER);
711 43020 jjdelcerro
        }
712 44198 jjdelcerro
713
        @Override
714
        public String toString(Formatter<Value> formatter) {
715
            if( formatter.canApply(this) ) {
716
                return formatter.format(this);
717
            }
718
            if( this.format==null ) {
719
                StringBuilder builder = new StringBuilder();
720
                builder.append("(");
721
                builder.append(this.left.toString(formatter));
722
                builder.append(" ");
723
                builder.append(this.name);
724
                builder.append(" ");
725
                builder.append(this.right.toString(formatter));
726
                builder.append(")");
727
                return builder.toString();
728
            } else {
729
                return MessageFormat.format(
730
                        format,
731
                        this.left.toString(formatter),
732
                        this.right.toString(formatter)
733
                );
734
            }
735
        }
736 43020 jjdelcerro
    }
737
738 44198 jjdelcerro
    protected GeometrySupportType geometrySupportType;
739 43020 jjdelcerro
    protected Value value;
740 43093 jjdelcerro
741 44006 jjdelcerro
    public DefaultExpressionBuilder() {
742 44198 jjdelcerro
        this.geometrySupportType = GeometrySupportType.WKB;
743 43020 jjdelcerro
    }
744
745
    @Override
746 44259 jjdelcerro
    public boolean isEmpty() {
747
        return value == null;
748
    }
749
750
    @Override
751 43020 jjdelcerro
    public ExpressionBuilder createExpressionBuilder() {
752 44006 jjdelcerro
        return new DefaultExpressionBuilder();
753 43020 jjdelcerro
    }
754 43093 jjdelcerro
755 43020 jjdelcerro
    @Override
756 44198 jjdelcerro
    public GeometrySupportType geometry_support_type() {
757
        return this.geometrySupportType;
758 43093 jjdelcerro
    }
759
760 43020 jjdelcerro
    @Override
761 44198 jjdelcerro
    public ExpressionBuilder geometry_support_type(GeometrySupportType geometrySupportType) {
762
        this.geometrySupportType = geometrySupportType;
763
        return this;
764
    }
765
766
    @Override
767
    public Value value() {
768 43020 jjdelcerro
        return this.value;
769
    }
770 43093 jjdelcerro
771 43020 jjdelcerro
    @Override
772 44198 jjdelcerro
    public ExpressionBuilder value(Value value) {
773 43020 jjdelcerro
        this.value = value;
774
        return this;
775
    }
776
777
    @Override
778
    public String toString() {
779
        return this.value.toString();
780
    }
781
782
    @Override
783 44198 jjdelcerro
    public String toString(Formatter<Value> formatter) {
784
        return this.value.toString(formatter);
785
    }
786
787
    @Override
788
    public Value toValue(String expression) {
789
        try {
790
            Code code = ExpressionUtils.compile(expression);
791
            return code.toValue(this);
792
        } catch(Throwable ex) {
793
            return custom(expression);
794
        }
795
    }
796
797
    @Override
798 43020 jjdelcerro
    public void accept(Visitor visitor, VisitorFilter filter) {
799 43093 jjdelcerro
        if( this.value == null) {
800
            return;
801
        }
802 43020 jjdelcerro
        this.value.accept(visitor, filter);
803
    }
804 43093 jjdelcerro
805 43020 jjdelcerro
    @Override
806 44198 jjdelcerro
    public String quote_for_identifiers() {
807
        return FORMAT_QUOTE_FOR_IDENTIFIERS;
808 43020 jjdelcerro
    }
809 44198 jjdelcerro
810 43020 jjdelcerro
    @Override
811 44198 jjdelcerro
    public String quote_for_strings() {
812
        return FORMAT_QUOTE_FOR_STRINGS;
813 43020 jjdelcerro
    }
814 44198 jjdelcerro
815 43020 jjdelcerro
    @Override
816
    public String string(String s) {
817 44198 jjdelcerro
        String quote = this.quote_for_strings();
818 43034 jjdelcerro
//        No se porque no esta disponible wrapIfMissing
819
//        return StringUtils.wrapIfMissing(s,quote);
820 43020 jjdelcerro
        if (s.startsWith(quote)) {
821
            return s;
822
        }
823 44198 jjdelcerro
        return quote + StringUtils.replace(s,quote,quote+quote) + quote;
824 43020 jjdelcerro
    }
825 43093 jjdelcerro
826 43020 jjdelcerro
    @Override
827
    public String identifier(String id) {
828 44198 jjdelcerro
        String quote = this.quote_for_identifiers();
829 43034 jjdelcerro
//        No se porque no esta disponible wrapIfMissing
830
//        return StringUtils.wrapIfMissing(id,quote);
831 43020 jjdelcerro
        if (id.startsWith(quote)) {
832
            return id;
833
        }
834
        return quote + id + quote;
835
    }
836
837
    @Override
838 44006 jjdelcerro
    public String bytearray_hex(byte[] data) {
839 43020 jjdelcerro
        StringBuilder builder = new StringBuilder();
840
        for (byte abyte : data) {
841
            int v = abyte & 0xff;
842
            builder.append(String.format("%02x", v));
843
        }
844
        return builder.toString();
845
    }
846
847 44006 jjdelcerro
    @Override
848
    public String bytearray_0x(byte[] data) {
849 43355 jjdelcerro
        return "0x" + bytearray_hex(data);
850
    }
851
852 44006 jjdelcerro
    @Override
853
    public String bytearray_x(byte[] data) {
854 43355 jjdelcerro
        return "x'" + bytearray_hex(data) + "'";
855 43302 jjdelcerro
    }
856
857 43020 jjdelcerro
    @Override
858 44198 jjdelcerro
    public Object srs_id(IProjection projection) {
859 44006 jjdelcerro
        if( projection==null ) {
860
            return 0;
861
        }
862
        return ProjectionUtils.getCode(projection);
863 43020 jjdelcerro
    }
864 43093 jjdelcerro
865 43020 jjdelcerro
    @Override
866 44198 jjdelcerro
    public Constant bytearray(byte[] data) {
867
        return new ConstantBase(data);
868
    }
869
870
    @Override
871 43020 jjdelcerro
    public Constant srs(IProjection projection) {
872 44198 jjdelcerro
        return constant(projection);
873 43020 jjdelcerro
    }
874
875
    @Override
876
    public Variable variable(String name) {
877
        return new VariableBase(name);
878
    }
879
880
    @Override
881
    public Variable column(String name) {
882
        return new VariableBase(name);
883
    }
884 43739 jjdelcerro
885 43020 jjdelcerro
    @Override
886 43093 jjdelcerro
    public Parameter parameter(String name) {
887 44198 jjdelcerro
        List<Parameter> parameters = this.parameters();
888
        for (Parameter parameter : parameters) {
889
            if( StringUtils.equalsIgnoreCase(name, parameter.name()) ) {
890
                return parameter;
891
            }
892 43093 jjdelcerro
        }
893 44198 jjdelcerro
        Parameter parameter = this.parameter();
894 43093 jjdelcerro
        parameter.name(name);
895
        return parameter;
896 43020 jjdelcerro
    }
897 43093 jjdelcerro
898 43687 jjdelcerro
    @Override
899 43093 jjdelcerro
    public Parameter parameter() {
900
        return new ParameterBase();
901
    }
902
903 43020 jjdelcerro
    @Override
904
    public Constant constant(Object value) {
905
        return new ConstantBase(value);
906
    }
907
908
    @Override
909
    public Group group(Value value) {
910
        return new GroupBase(value);
911
    }
912 43093 jjdelcerro
913 43020 jjdelcerro
    @Override
914 44198 jjdelcerro
    public Constant geometry(Geometry geom, IProjection projection) {
915
        geom.setProjection(projection);
916
        return new ConstantBase(geom);
917 43020 jjdelcerro
    }
918
919
    @Override
920 44198 jjdelcerro
    public Constant geometry(Geometry geom) {
921 44006 jjdelcerro
        if( geom.getProjection()==null ) {
922
            throw new IllegalArgumentException("The geometry does not have an associated projection. Use 'geometry(Geometry, IProjection)'.");
923
        }
924 44198 jjdelcerro
        return new ConstantBase(geom);
925 44006 jjdelcerro
    }
926
927
    @Override
928 44198 jjdelcerro
    public Constant envelope(Envelope envelope, IProjection projection) {
929
        Geometry geom = envelope.getGeometry();
930
        geom.setProjection(projection);
931
        return new ConstantBase(geom);
932 43034 jjdelcerro
    }
933
934
    @Override
935 44198 jjdelcerro
    public Constant envelope(Envelope envelope) {
936 44006 jjdelcerro
        if( envelope.getProjection()==null ) {
937
            throw new IllegalArgumentException("The envelope does not have an associated projection. Use 'envelope(Geometry, IProjection)'.");
938
        }
939 44198 jjdelcerro
        Geometry geom = envelope.getGeometry();
940
        return new ConstantBase(geom);
941 44006 jjdelcerro
    }
942
943
    @Override
944 43020 jjdelcerro
    public Custom custom(Object value) {
945
        return new CustomBase(value);
946
    }
947
948 44198 jjdelcerro
    @Override
949
    public Method method(Value instance, String name, Value... values) {
950
        MethodBase method = new MethodBase(instance, name);
951
        for (Value theValue : values) {
952
            method.parameter(theValue);
953
        }
954
        return method;
955
    }
956
957
    @Override
958 44020 jjdelcerro
    public Function function(String name, Value... values) {
959
        FunctionBase func = new FunctionBase(name);
960
        for (Value theValue : values) {
961
            func.parameter(theValue);
962
        }
963
        return func;
964
    }
965
966
    public Function builtin_function(String name, String format, Value... values) {
967 43093 jjdelcerro
        FunctionBase func = new FunctionBase(name, format);
968 44006 jjdelcerro
        for (Value theValue : values) {
969
            func.parameter(theValue);
970 43020 jjdelcerro
        }
971
        return func;
972
    }
973 43093 jjdelcerro
974 44198 jjdelcerro
    @Override
975
    public BinaryOperator binaryOperator(String name, Value leftOperand, Value rightOperand) {
976
        return binaryOperator(name, null, leftOperand, rightOperand);
977
    }
978
979 43020 jjdelcerro
    public BinaryOperator binaryOperator(String name, String format, Value leftOperand, Value rightOperand) {
980 43093 jjdelcerro
        BinaryOperator operator = new BinaryOperatorBase(name, format);
981 44198 jjdelcerro
        operator.left(leftOperand);
982
        operator.right(rightOperand);
983 43020 jjdelcerro
        return operator;
984
    }
985 43093 jjdelcerro
986 43020 jjdelcerro
    @Override
987 44198 jjdelcerro
    public List<Variable> variables() {
988 43020 jjdelcerro
        final Set<Variable> vars = new HashSet<>();
989
        this.accept(new Visitor() {
990
            @Override
991
            public void visit(Visitable value) {
992 44198 jjdelcerro
                if( !vars.contains((Variable)value) ) {
993
                    vars.add((Variable)value);
994
                }
995 43020 jjdelcerro
            }
996 43093 jjdelcerro
        }, new ClassVisitorFilter(Variable.class));
997 43020 jjdelcerro
        List<Variable> lvars = new ArrayList<>(vars);
998
        Collections.sort(lvars);
999
        return lvars;
1000
    }
1001 43093 jjdelcerro
1002 43020 jjdelcerro
    @Override
1003 44198 jjdelcerro
    public List<Parameter> parameters() {
1004
        final List<Parameter>  params = new ArrayList<>();
1005 43020 jjdelcerro
        this.accept(new Visitor() {
1006
            @Override
1007
            public void visit(Visitable value) {
1008 43093 jjdelcerro
                params.add((Parameter) value);
1009 43020 jjdelcerro
            }
1010 43093 jjdelcerro
        }, new ClassVisitorFilter(Parameter.class));
1011 43020 jjdelcerro
        return params;
1012
    }
1013 44198 jjdelcerro
1014 43020 jjdelcerro
    @Override
1015 44198 jjdelcerro
    public List<String> parameters_names() {
1016
        List<String> params = new ArrayList<>();
1017
        for (Parameter param : parameters()) {
1018
            Object theValue = param.value();
1019
            String s;
1020
            switch(param.type()) {
1021
                case Constant:
1022
                    if( theValue==null ) {
1023
                        s = "NULL";
1024
                    } else if( theValue instanceof String ) {
1025
                        s = "'" + (String)theValue + "'";
1026
1027
                    } else if( theValue instanceof byte[] ) {
1028
                        s = bytearray_0x((byte[]) theValue);
1029
1030
                    } else {
1031
                        s = theValue.toString();
1032
                    }
1033
                    break;
1034
                case Geometry:
1035
                    if( param.name()==null ) {
1036
                        s = bytearray_0x((byte[]) theValue);
1037
                    } else {
1038
                        s = "\"" + param.name() + "\"";
1039
                    }
1040
                    break;
1041
                case Variable:
1042
                default:
1043
                    s = "\"" + param.name() + "\"";
1044
            }
1045
//            if( !params.contains(s) ) { // Ojo que deben ir todos, incluso duplicados.
1046
                params.add(s);
1047
//            }
1048
        }
1049
        // Collections.sort(params); Ojo, no deben ordenarse.
1050
        return params;
1051 43020 jjdelcerro
    }
1052 44198 jjdelcerro
1053
    @Override
1054
    public List<String> variables_names() {
1055
        List<String> vars = new ArrayList<>();
1056
        for (Variable var : this.variables()) {
1057
            vars.add(var.name());
1058
        }
1059
        Collections.sort(vars);
1060
        return vars;
1061
    }
1062
1063
    @Override
1064
    public Function as_geometry(Value value) {
1065
        return builtin_function(FUNCTION_ST_ASBINARY, FORMAT_ST_ASBINARY, value);
1066
    }
1067 43020 jjdelcerro
1068
    @Override
1069
    public ExpressionBuilder set(Value value) {
1070
        this.value = value;
1071
        return this;
1072
    }
1073
1074
    @Override
1075
    public ExpressionBuilder and(Value value) {
1076 43093 jjdelcerro
        if (this.value == null) {
1077 43020 jjdelcerro
            return this.set(value);
1078
        }
1079 44198 jjdelcerro
        BinaryOperator operator = binaryOperator(OPERATOR_AND, FORMAT_OPERATOR_AND, this.value, value);
1080 43020 jjdelcerro
        this.value = operator;
1081
        return this;
1082
    }
1083
1084
    @Override
1085
    public ExpressionBuilder or(Value value) {
1086 43093 jjdelcerro
        if (this.value == null) {
1087 43020 jjdelcerro
            return this.set(value);
1088
        }
1089 44198 jjdelcerro
        BinaryOperator operator = binaryOperator(OPERATOR_OR, FORMAT_OPERATOR_OR, this.value, value);
1090 43020 jjdelcerro
        this.value = operator;
1091
        return this;
1092
    }
1093
1094
    @Override
1095
    public Function ST_Intersects(Value geom1, Value geom2) {
1096 44198 jjdelcerro
        return builtin_function(FUNCTION_ST_INTERSECTS, FORMAT_ST_INTERSECTS, geom1, geom2);
1097 43020 jjdelcerro
    }
1098
1099
    @Override
1100
    public Function ST_SRID(Value geom) {
1101 44198 jjdelcerro
        return builtin_function(FUNCTION_ST_SRID, FORMAT_ST_SRID, geom);
1102 43020 jjdelcerro
    }
1103
1104
    @Override
1105
    public Function ST_Envelope(Value geom) {
1106 44198 jjdelcerro
        return builtin_function(FUNCTION_ST_ENVELOPE, FORMAT_ST_ENVELOPE, geom);
1107 43020 jjdelcerro
    }
1108
1109
    @Override
1110
    public Function ST_AsText(Value geom) {
1111 44198 jjdelcerro
        return builtin_function(FUNCTION_ST_ASTEXT, FORMAT_ST_ASTEXT, geom);
1112 43020 jjdelcerro
    }
1113
1114
    @Override
1115
    public Function ST_AsBinary(Value geom) {
1116 44198 jjdelcerro
        return builtin_function(FUNCTION_ST_ASBINARY, FORMAT_ST_ASBINARY, geom);
1117 43020 jjdelcerro
    }
1118
1119
    @Override
1120
    public Function ST_AsEWKB(Value geom) {
1121 44198 jjdelcerro
        return builtin_function(FUNCTION_ST_ASEWKB, FORMAT_ST_ASEWKB, geom);
1122 43020 jjdelcerro
    }
1123
1124
    @Override
1125
    public Function ST_GeomFromText(Value geom, Value crs) {
1126 44198 jjdelcerro
        return builtin_function(FUNCTION_ST_GEOMFROMTEXT, FORMAT_ST_GEOMFROMTEXT, geom, crs);
1127 43020 jjdelcerro
    }
1128
1129
    @Override
1130
    public Function ST_GeomFromWKB(Value geom, Value crs) {
1131 44198 jjdelcerro
        return builtin_function(FUNCTION_ST_GEOMFROMWKB, FORMAT_ST_GEOMFROMWKB, geom, crs);
1132 43020 jjdelcerro
    }
1133
1134
    @Override
1135
    public Function ST_GeomFromEWKB(Value geom, Value crs) {
1136 44198 jjdelcerro
        return builtin_function(FUNCTION_ST_GEOMFROMEWKB, FORMAT_ST_GEOMFROMEWKB, geom, crs);
1137 43020 jjdelcerro
    }
1138
1139
    @Override
1140 43355 jjdelcerro
    public Function ST_Simplify(Value geom, Value tolerance) {
1141 44198 jjdelcerro
        return builtin_function(FUNCTION_ST_SIMPLIFY, FORMAT_ST_SIMPLIFY, tolerance);
1142 43355 jjdelcerro
    }
1143
1144
    @Override
1145 43034 jjdelcerro
    public Function ST_Disjoint(Value geom1, Value geom2) {
1146 44198 jjdelcerro
        return builtin_function(FUNCTION_ST_DISJOINT, FORMAT_ST_DISJOINT, geom1, geom2);
1147 43034 jjdelcerro
    }
1148 43093 jjdelcerro
1149 43034 jjdelcerro
    @Override
1150 43020 jjdelcerro
    public Function ST_Contains(Value geom1, Value geom2) {
1151 44198 jjdelcerro
        return builtin_function(FUNCTION_ST_CONTAINS, FORMAT_ST_CONTAINS, geom1, geom2);
1152 43020 jjdelcerro
    }
1153
1154
    @Override
1155 43034 jjdelcerro
    public Function ST_Equals(Value geom1, Value geom2) {
1156 44198 jjdelcerro
        return builtin_function(FUNCTION_ST_EQUALS, FORMAT_ST_EQUALS, geom1, geom2);
1157 43034 jjdelcerro
    }
1158
1159
    @Override
1160 43020 jjdelcerro
    public Function ST_Crosses(Value geom1, Value geom2) {
1161 44198 jjdelcerro
        return builtin_function(FUNCTION_ST_CROSSES, FORMAT_ST_CROSSES, geom1, geom2);
1162 43020 jjdelcerro
    }
1163
1164
    @Override
1165
    public Function ST_IsClosed(Value geom) {
1166 44198 jjdelcerro
        return builtin_function(FUNCTION_ST_ISCLOSED, FORMAT_ST_ISCLOSED, geom);
1167 43020 jjdelcerro
    }
1168
1169
    @Override
1170
    public Function ST_Overlaps(Value geom1, Value geom2) {
1171 44198 jjdelcerro
        return builtin_function(FUNCTION_ST_OVERLAPS, FORMAT_ST_OVERLAPS, geom1, geom2);
1172 43020 jjdelcerro
    }
1173
1174
    @Override
1175
    public Function ST_Touches(Value geom1, Value geom2) {
1176 44198 jjdelcerro
        return builtin_function(FUNCTION_ST_TOUCHES, FORMAT_ST_TOUCHES, geom1, geom2);
1177 43020 jjdelcerro
    }
1178
1179
    @Override
1180
    public Function ST_Within(Value geom1, Value geom2) {
1181 44198 jjdelcerro
        return builtin_function("ST_Within", FORMAT_ST_WITHIN, geom1, geom2);
1182 43020 jjdelcerro
    }
1183
1184
    @Override
1185 44198 jjdelcerro
    public Function is_null(Value value) {
1186
        return builtin_function("IS NULL", FORMAT_ISNULL, value);
1187 43020 jjdelcerro
    }
1188
1189
    @Override
1190 44198 jjdelcerro
    public Function not_is_null(Value value) {
1191
        return builtin_function("NOT IS NULL", FORMAT_NOTISNULL, value);
1192 43020 jjdelcerro
    }
1193
1194
    @Override
1195
    public Function not(Value value) {
1196 44198 jjdelcerro
        return builtin_function(OPERATOR_NOT, FORMAT_OPERATOR_NOT, value);
1197 43020 jjdelcerro
    }
1198
1199
    @Override
1200
    public BinaryOperator and(Value leftOperand, Value rightOperand) {
1201 44198 jjdelcerro
        return binaryOperator(OPERATOR_AND, FORMAT_OPERATOR_AND, leftOperand, rightOperand);
1202 43020 jjdelcerro
    }
1203
1204
    @Override
1205
    public BinaryOperator or(Value leftOperand, Value rightOperand) {
1206 44198 jjdelcerro
        return binaryOperator(OPERATOR_OR, FORMAT_OPERATOR_OR, leftOperand, rightOperand);
1207 43020 jjdelcerro
    }
1208
1209
    @Override
1210
    public BinaryOperator eq(Value leftOperand, Value rightOperand) {
1211 44198 jjdelcerro
        return binaryOperator("=", FORMAT_OPERATOR_EQ, leftOperand, rightOperand);
1212 43020 jjdelcerro
    }
1213 43093 jjdelcerro
1214 43020 jjdelcerro
    @Override
1215
    public BinaryOperator ne(Value leftOperand, Value rightOperand) {
1216 44198 jjdelcerro
        return binaryOperator("<>", FORMAT_OPERATOR_NE, leftOperand, rightOperand);
1217 43093 jjdelcerro
    }
1218 43020 jjdelcerro
1219
    @Override
1220
    public BinaryOperator gt(Value op1, Value op2) {
1221 44198 jjdelcerro
        return binaryOperator(">", FORMAT_OPERATOR_GT, op1, op2);
1222 43020 jjdelcerro
    }
1223
1224
    @Override
1225
    public BinaryOperator ge(Value op1, Value op2) {
1226 44198 jjdelcerro
        return binaryOperator(">=", FORMAT_OPERATOR_GE, op1, op2);
1227 43020 jjdelcerro
    }
1228
1229
    @Override
1230
    public BinaryOperator lt(Value op1, Value op2) {
1231 44198 jjdelcerro
        return binaryOperator("<", FORMAT_OPERATOR_LT, op1, op2);
1232 43020 jjdelcerro
    }
1233
1234
    @Override
1235
    public BinaryOperator le(Value op1, Value op2) {
1236 44198 jjdelcerro
        return binaryOperator("<=", FORMAT_OPERATOR_LE, op1, op2);
1237 43020 jjdelcerro
    }
1238
1239
    @Override
1240
    public BinaryOperator like(Value op1, Value op2) {
1241 44198 jjdelcerro
        return binaryOperator(OPERATOR_LIKE, FORMAT_OPERATOR_LIKE, op1, op2);
1242 43020 jjdelcerro
    }
1243
1244
    @Override
1245
    public BinaryOperator ilike(Value op1, Value op2) {
1246 44198 jjdelcerro
        return binaryOperator(OPERATOR_ILIKE, FORMAT_OPERATOR_ILIKE, op1, op2);
1247 43020 jjdelcerro
    }
1248
1249
    @Override
1250
    public BinaryOperator add(Value op1, Value op2) {
1251 44198 jjdelcerro
        return binaryOperator(OPERATOR_ADD, FORMAT_OPERATOR_ADD, op1, op2);
1252 43020 jjdelcerro
    }
1253
1254
    @Override
1255
    public BinaryOperator subst(Value op1, Value op2) {
1256 44198 jjdelcerro
        return binaryOperator(OPERATOR_SUBST, FORMAT_OPERATOR_SUBST, op1, op2);
1257 43020 jjdelcerro
    }
1258
1259
    @Override
1260
    public BinaryOperator mult(Value op1, Value op2) {
1261 44198 jjdelcerro
        return binaryOperator(OPERATOR_MULT, FORMAT_OPERATOR_MULT, op1, op2);
1262 43020 jjdelcerro
    }
1263
1264
    @Override
1265
    public BinaryOperator div(Value op1, Value op2) {
1266 44198 jjdelcerro
        return binaryOperator(OPERATOR_DIV, FORMAT_OPERATOR_DIV, op1, op2);
1267 43020 jjdelcerro
    }
1268
1269
    @Override
1270
    public BinaryOperator concat(Value op1, Value op2) {
1271 44198 jjdelcerro
        return binaryOperator(OPERATOR_CONCAT, FORMAT_OPERATOR_CONCAT, op1, op2);
1272 43020 jjdelcerro
    }
1273 44051 omartinez
1274
    @Override
1275 44038 jjdelcerro
    public Function iif(Value condition, Value iftrue, Value iffalse) {
1276 44198 jjdelcerro
        return function(FUNCTION_IIF, condition, iftrue, iffalse);
1277 44038 jjdelcerro
    }
1278
1279 44051 omartinez
    @Override
1280 44038 jjdelcerro
    public Function ifnull(Value value, Value iftrue, Value iffalse) {
1281 44198 jjdelcerro
        return function(FUNCTION_IFNULL, value, iftrue, iffalse);
1282 44038 jjdelcerro
    }
1283 44051 omartinez
1284
    @Override
1285
    public Function left(Value str, Value size) {
1286 44198 jjdelcerro
       return function(FUNCTION_LEFT, str, size);
1287 44051 omartinez
    }
1288
1289
    @Override
1290
    public Function right(Value str, Value len) {
1291 44198 jjdelcerro
       return function(FUNCTION_RIGHT, str, len);
1292 44051 omartinez
    }
1293
1294
    @Override
1295
    public Function locate(Value search, Value str, Value start) {
1296 44198 jjdelcerro
       return function(FUNCTION_LOCATE, search, str, start);
1297 44051 omartinez
    }
1298
1299
    @Override
1300
    public Function position(Value search, Value str) {
1301 44198 jjdelcerro
       return function(FUNCTION_POSITION, search, str);
1302 44051 omartinez
    }
1303
1304
    @Override
1305
    public Function lpad(Value str, Value len, Value padstr) {
1306 44198 jjdelcerro
       return function(FUNCTION_LPAD, str, len, padstr);
1307 44051 omartinez
    }
1308
1309
    @Override
1310
    public Function rpad(Value str, Value len, Value padstr) {
1311 44198 jjdelcerro
       return function(FUNCTION_RPAD, str, len, padstr);
1312 44051 omartinez
    }
1313
1314
    @Override
1315
    public Function ltrim(Value str) {
1316 44198 jjdelcerro
       return function(FUNCTION_LTRIM, str);
1317 44051 omartinez
    }
1318
1319
    @Override
1320
    public Function rtrim(Value str) {
1321 44198 jjdelcerro
       return function(FUNCTION_RTRIM, str);
1322 44051 omartinez
    }
1323
1324
    @Override
1325
    public Function trim(Value str) {
1326 44198 jjdelcerro
       return function(FUNCTION_TRIM, str);
1327 44051 omartinez
    }
1328
1329
    @Override
1330
    public Function repeat(Value str, Value size) {
1331 44198 jjdelcerro
       return function(FUNCTION_REPEAT, str, size);
1332 44051 omartinez
    }
1333
1334
    @Override
1335
    public Function replace(Value str, Value search, Value replstr) {
1336 44198 jjdelcerro
       return function(FUNCTION_REPLACE, str, search, replstr);
1337 44051 omartinez
    }
1338
1339
    @Override
1340
    public Function ascii(Value str) {
1341 44198 jjdelcerro
       return function(FUNCTION_ASCII, str);
1342 44051 omartinez
    }
1343
1344
    @Override
1345
    public Function lenght(Value str) {
1346 44198 jjdelcerro
       return function(FUNCTION_LENGHT, str);
1347 44051 omartinez
    }
1348
1349
    @Override
1350
    public Function instr(Value str, Value search, Value start) {
1351 44198 jjdelcerro
       return function(FUNCTION_INSTR, str, search, start);
1352 44051 omartinez
    }
1353
1354
    @Override
1355
    public Function lower(Value str) {
1356 44198 jjdelcerro
       return function(FUNCTION_LOWER, str);
1357 44051 omartinez
    }
1358
1359
    @Override
1360
    public Function upper(Value str) {
1361 44198 jjdelcerro
       return function(FUNCTION_UPPER, str);
1362 44051 omartinez
    }
1363
1364
    @Override
1365
    public Function space(Value size) {
1366 44198 jjdelcerro
       return function(FUNCTION_SPACE, size);
1367 44051 omartinez
    }
1368
1369
    @Override
1370
    public Function substring(Value str, Value start, Value len) {
1371 44198 jjdelcerro
       return function(FUNCTION_SUBSTRING, str, start, len);
1372 44051 omartinez
    }
1373
1374
    @Override
1375
    public Function acos(Value num) {
1376 44198 jjdelcerro
       return function(FUNCTION_ACOS, num);
1377 44051 omartinez
    }
1378
1379
    @Override
1380
    public Function asin(Value num) {
1381 44198 jjdelcerro
       return function(FUNCTION_ASIN, num);
1382 44051 omartinez
    }
1383
1384
    @Override
1385
    public Function atan(Value num) {
1386 44198 jjdelcerro
       return function(FUNCTION_ATAN, num);
1387 44051 omartinez
    }
1388
1389
    @Override
1390
    public Function cos(Value num) {
1391 44198 jjdelcerro
       return function(FUNCTION_COS, num);
1392 44051 omartinez
    }
1393
1394
    @Override
1395
    public Function cosh(Value num) {
1396 44198 jjdelcerro
       return function(FUNCTION_COSH, num);
1397 44051 omartinez
    }
1398
1399
    @Override
1400
    public Function cot(Value num) {
1401 44198 jjdelcerro
       return function(FUNCTION_COT, num);
1402 44051 omartinez
    }
1403
1404
    @Override
1405
    public Function bitand(Value num1, Value num2) {
1406 44198 jjdelcerro
       return function(FUNCTION_BITAND, num1, num2);
1407 44051 omartinez
    }
1408
1409
    @Override
1410
    public Function bitor(Value num1, Value num2) {
1411 44198 jjdelcerro
       return function(FUNCTION_BITOR, num1, num2);
1412 44051 omartinez
    }
1413
1414
    @Override
1415
    public Function bitxor(Value num1, Value num2) {
1416 44198 jjdelcerro
       return function(FUNCTION_BITXOR, num1, num2);
1417 44051 omartinez
    }
1418
1419
    @Override
1420
    public Function ceil(Value num) {
1421 44198 jjdelcerro
       return function(FUNCTION_CEIL, num);
1422 44051 omartinez
    }
1423
1424
    @Override
1425
    public Function degrees(Value num) {
1426 44198 jjdelcerro
       return function(FUNCTION_DEGREES, num);
1427 44051 omartinez
    }
1428
1429
    @Override
1430
    public Function exp(Value num) {
1431 44198 jjdelcerro
       return function(FUNCTION_EXP, num);
1432 44051 omartinez
    }
1433
1434
    @Override
1435
    public Function floor(Value num) {
1436 44198 jjdelcerro
       return function(FUNCTION_FLOOR, num);
1437 44051 omartinez
    }
1438
1439
    @Override
1440
    public Function log(Value num) {
1441 44198 jjdelcerro
       return function(FUNCTION_LOG, num);
1442 44051 omartinez
    }
1443
1444
    @Override
1445
    public Function log10(Value num) {
1446 44198 jjdelcerro
       return function(FUNCTION_LOG10, num);
1447 44051 omartinez
    }
1448
1449
    @Override
1450
    public Function pi(Value num) {
1451 44198 jjdelcerro
       return function(FUNCTION_PI, num);
1452 44051 omartinez
    }
1453
1454
    @Override
1455
    public Function power(Value num) {
1456 44198 jjdelcerro
       return function(FUNCTION_POWER, num);
1457 44051 omartinez
    }
1458
1459
    @Override
1460
    public Function radians(Value num) {
1461 44198 jjdelcerro
       return function(FUNCTION_RADIANS, num);
1462 44051 omartinez
    }
1463
1464
    @Override
1465
    public Function rand(Value num) {
1466 44198 jjdelcerro
       return function(FUNCTION_RAND, num);
1467 44051 omartinez
    }
1468
1469
    @Override
1470
    public Function round(Value num) {
1471 44198 jjdelcerro
       return function(FUNCTION_ROUND, num);
1472 44051 omartinez
    }
1473
1474
    @Override
1475
    public Function sqrt(Value num) {
1476 44198 jjdelcerro
       return function(FUNCTION_SQRT, num);
1477 44051 omartinez
    }
1478
1479
    @Override
1480
    public Function sign(Value num) {
1481 44198 jjdelcerro
       return function(FUNCTION_SIGN, num);
1482 44051 omartinez
    }
1483
1484
    @Override
1485
    public Function sin(Value num) {
1486 44198 jjdelcerro
       return function(FUNCTION_SIN, num);
1487 44051 omartinez
    }
1488
1489
    @Override
1490
    public Function sinh(Value num) {
1491 44198 jjdelcerro
       return function(FUNCTION_SINH, num);
1492 44051 omartinez
    }
1493
1494
    @Override
1495
    public Function tan(Value num) {
1496 44198 jjdelcerro
       return function(FUNCTION_TAN, num);
1497 44051 omartinez
    }
1498
    @Override
1499
    public Function tanh(Value num) {
1500 44198 jjdelcerro
       return function(FUNCTION_TANH, num);
1501 44051 omartinez
    }
1502
1503
    @Override
1504
    public Function zero() {
1505 44198 jjdelcerro
       return function(FUNCTION_ZERO);
1506 44051 omartinez
    }
1507 44053 omartinez
1508
    @Override
1509
    public Function chr(Value num) {
1510 44198 jjdelcerro
       return function(FUNCTION_CHR, num);
1511
    }
1512
1513
    @Override
1514
    public Function ST_ExtentAggregate(Value geom) {
1515
       return function(FUNCTION_ST_EXTENTAGGREGATE, geom);
1516 44053 omartinez
    }
1517 44198 jjdelcerro
1518
    @Override
1519
    public Function ST_UnionAggregate(Value geom) {
1520
       return function(FUNCTION_ST_UNIONAGGREGATE, geom);
1521
    }
1522
1523
    @Override
1524
    public Function cast(Value object, Value typeName) {
1525
       return function(FUNCTION_CAST, object, typeName);
1526
    }
1527
1528
    @Override
1529
    public Function decode(Value value, Value format) {
1530
       return function(FUNCTION_DECODE, value, format);
1531
    }
1532
1533
    @Override
1534
    public Function toDouble(Value num) {
1535
       return function(FUNCTION_TODOUBLE, num);
1536
    }
1537
1538
    @Override
1539
    public Function toFloat(Value num) {
1540
       return function(FUNCTION_TOFLOAT, num);
1541
    }
1542
1543
    @Override
1544
    public Function toLong(Value num) {
1545
       return function(FUNCTION_TOLONG, num);
1546
    }
1547
1548
    @Override
1549
    public Function toInteger(Value num) {
1550
       return function(FUNCTION_TOINTEGER, num);
1551
    }
1552
1553
    @Override
1554
    public Function toStr(Value object) {
1555
       return function(FUNCTION_TOSTR, object);
1556
    }
1557
1558 44253 jjdelcerro
    @Override
1559
    public Function ST_Point(Value x, Value y) {
1560
       return function(FUNCTION_ST_POINT, x, y);
1561
    }
1562 44198 jjdelcerro
1563 44253 jjdelcerro
    @Override
1564
    public Function ST_SetSRID(Value geom, Value srid) {
1565
       return function(FUNCTION_ST_POINT, geom, srid);
1566
    }
1567 43020 jjdelcerro
}