Revision 44198 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

View differences:

DefaultExpressionBuilder.java
2 2

  
3 3
import java.text.MessageFormat;
4 4
import java.util.ArrayList;
5
import java.util.Collection;
6 5
import java.util.Collections;
7
import java.util.HashMap;
8 6
import java.util.HashSet;
9 7
import java.util.List;
10
import java.util.Map;
11 8
import java.util.Objects;
12 9
import java.util.Set;
13
import org.apache.commons.lang3.ObjectUtils;
14 10
import org.apache.commons.lang3.StringUtils;
15 11
import org.cresques.cts.IProjection;
12
import org.gvsig.expressionevaluator.Code;
16 13
import org.gvsig.fmap.geom.Geometry;
17 14
import org.gvsig.fmap.geom.primitive.Envelope;
18 15

  
19 16
import org.gvsig.expressionevaluator.ExpressionBuilder;
17
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;
20 21

  
21
@SuppressWarnings({"UseSpecificCatch","OverridableMethodCallInConstructor"})
22
@SuppressWarnings({"UseSpecificCatch" ,"OverridableMethodCallInConstructor"})
22 23
public class DefaultExpressionBuilder implements ExpressionBuilder {
24
    
25
    private static final String FORMAT_QUOTE_FOR_STRINGS = "'";
26
    private static final String FORMAT_QUOTE_FOR_IDENTIFIERS = "\"";
23 27

  
24
    public class ConfigBase implements Config {
28
    private static final String FORMAT_TRUE = "TRUE";
29
    private static final String FORMAT_FALSE = "FALSE";
25 30

  
26
        protected Map<String, Object> values;
31
    private static final String FORMAT_GROUP = "( {0} )";
27 32

  
28
        public ConfigBase() {
29
            this.values = new HashMap<>();
33
    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}))";
30 51

  
31
            this.set(Config.has_spatial_functions, true);
32
            this.set(Config.support_schemas, true);
33
            this.set(Config.constant_true, "(1=1)");
34
            this.set(Config.constant_false, "(1=2)");
35
            this.set(Config.quote_for_identifiers, "\"");
36
            this.set(Config.quote_for_strings, "'");
37
            this.set(Config.geometry_type_support, GeometrySupportType.WKB);
38
            this.set(Config.group, "( {0} )");
52
    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}) )";
39 55

  
40
            this.set(Config.ST_SRID, "ST_SRID({0})");
41
            this.set(Config.ST_AsText, "ST_AsText({0})");
42
            this.set(Config.ST_AsBinary, "ST_AsBinary({0})");
43
            this.set(Config.ST_AsEWKB, "ST_AsEWKB({0})");
44
            this.set(Config.ST_Contains, "ST_Contains(({0}), ({1}))");
45
            this.set(Config.ST_Crosses, "ST_Crosses(({0}), ({1}))");
46
            this.set(Config.ST_Disjoint, "ST_Disjoint(({0}), ({1}))");
47
            this.set(Config.ST_Equals, "ST_Equals(({0}), ({1}))");
48
            this.set(Config.ST_IsClosed, "ST_IsClosed({0})");
49
            this.set(Config.ST_Overlaps, "ST_Overlaps(({0}), ({1}))");
50
            this.set(Config.ST_Touches, "ST_Touches(({0}), ({1}))");
51
            this.set(Config.ST_Within, "ST_Within(({0}), ({1}))");
52
            this.set(Config.ST_Envelope, "ST_Envelope({0})");
53
            this.set(Config.ST_Intersects, "ST_Intersects(({0}), ({1}))");
54
            this.set(Config.ST_GeomFromText, "ST_GeomFromText({0}, ({1}))");
55
            this.set(Config.ST_GeomFromWKB, "ST_GeomFromWKB(({0}), ({1}))");
56
            this.set(Config.ST_GeomFromEWKB, "ST_GeomFromEWKB(({0}), ({1}))");
57
            
58
            // Por defecto no esta disponible la funcion ST_Simplify
59
            // this.set(Config.ST_Simplify, "ST_Simplify(({0}), ({1}))");
60
            this.remove_functionality(Config.ST_Simplify);
61
            
62
            this.set(Config.lcase, "LCASE({0})");
63
            this.set(Config.ucase, "UCASE({0})");
64
            this.set(Config.iif, "IIF({0},{1},{2})");
65
            this.set(Config.ifnull, "IFNULL({0},{1},{2})");
66
            
67
            this.set(Config.isNull, "( ({0}) IS NULL )");
68
            this.set(Config.notIsNull, "( ({0}) NOT IS NULL )");
69
            this.set(Config.operator_not, "( NOT ({0}) )");
56
    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}";
70 71

  
71
            this.set(Config.operator_AND, "{0} AND {1}");
72
            this.set(Config.operator_OR, "{0} OR {1}");
73
            this.set(Config.operator_EQ, "( ({0}) = ({1}) )");
74
            this.set(Config.operator_NE, "( ({0}) <> ({1}) )");
75
            this.set(Config.operator_GT, "( ({0}) > ({1}) )");
76
            this.set(Config.operator_GE, "( ({0}) >= ({1}) )");
77
            this.set(Config.operator_LT, "( ({0}) < ({1}) )");
78
            this.set(Config.operator_LE, "( ({0}) <= ({1}) )");
79
            this.set(Config.operator_LIKE, "( ({0}) LIKE ({1}) )");
80
            this.set(Config.operator_ILIKE, "( ({0}) ILIKE ({1}) )");
81

  
82
            this.set(Config.operator_add, "{0} + {1}");
83
            this.set(Config.operator_subst, "{0} - {1}");
84
            this.set(Config.operator_mult, "{0} * {1}");
85
            this.set(Config.operator_div, "{0} / {1}");
86
            this.set(Config.operator_concat, "{0} || {1}");
87

  
88
        }
89

  
90
        @Override
91
        public boolean has_functionality(String functionality) {
92
            Object x = this.values.get(functionality);
93
            if (x == null) {
94
                return false;
95
            }
96
            if (x instanceof CharSequence && StringUtils.isEmpty((CharSequence) x)) {
97
                return false;
98
            }
99
            return true;
100
        }
101

  
102
        @Override
103
        public void remove_functionality(String functionality) {
104
            this.values.remove(functionality);
105
        }
106

  
107
        @Override
108
        public boolean has_spatial_functions() {
109
            return this.getBoolean(has_spatial_functions);
110
        }
111

  
112
        @Override
113
        public GeometrySupportType getGeometryTypeSupport() {
114
            return (GeometrySupportType) this.get(geometry_type_support);
115
        }
116

  
117
        @Override
118
        public boolean getBoolean(String name) {
119
            return (boolean) this.values.get(name);
120
        }
121

  
122
        @Override
123
        public String getString(String name) {
124
            return (String) this.values.get(name);
125
        }
126

  
127
        @Override
128
        public Object get(String name) {
129
            return this.values.get(name);
130
        }
131

  
132
        @Override
133
        public void set(String name, Object value) {
134
            this.values.put(name, value);
135
        }
136
    }
137

  
138
    public abstract class AbstractValue implements Value {
139

  
140
        @Override
141
        public void accept(Visitor visitor, VisitorFilter filter) {
142
            if (filter == null || filter.accept(this)) {
143
                visitor.visit(this);
144
            }
145
        }
146

  
147
    }
148

  
149
    public class ClassVisitorFilter implements VisitorFilter {
150

  
151
        private final Class classFilter;
152

  
153
        public ClassVisitorFilter(Class classFilter) {
154
            this.classFilter = classFilter;
155
        }
156

  
157
        @Override
158
        public boolean accept(Visitable visitable) {
159
            return classFilter.isInstance(visitable);
160
        }
161

  
162
    }
163

  
164 72
    public class GroupBase extends AbstractValue implements Group {
165 73

  
166 74
        protected Value value;
......
170 78
        }
171 79

  
172 80
        @Override
173
        public Value getValue() {
81
        public Value value() {
174 82
            return value;
175 83
        }
176 84

  
......
182 90

  
183 91
        @Override
184 92
        public String toString() {
185
            return MessageFormat.format(config.getString(Config.group), this.value.toString());
93
            return this.toString(EMPTY_FORMATTER);
186 94
        }
95
        
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
        }
187 103
    }
188 104

  
189 105
    public class VariableBase extends AbstractValue implements Variable {
......
195 111
        }
196 112

  
197 113
        @Override
198
        public String getName() {
114
        public String name() {
199 115
            return this.name;
200 116
        }
201 117

  
202 118
        @Override
203 119
        public String toString() {
120
            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
            }
204 128
            return identifier(this.name);
205 129
        }
206 130

  
207 131
        @Override
208 132
        public int compareTo(Variable o) {
209
            return this.name.compareTo(o.getName());
133
            return this.name.compareTo(o.name());
210 134
        }
211 135

  
212 136
        @Override
......
214 138
            if (!(obj instanceof Variable)) {
215 139
                return false;
216 140
            }
217
            return this.name.equals(((Variable) obj).getName());
141
            return this.name.equals(((Variable) obj).name());
218 142
        }
219 143

  
220 144
        @Override
......
232 156
        protected ParameterType type;
233 157
        protected Value srs;
234 158

  
159
        /*
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
        */
235 168
        public ParameterBase() {
236 169
            this.type = ParameterType.Constant;
237 170
            this.name = null;
......
284 217

  
285 218
        @Override
286 219
        public Parameter srs(IProjection srs) {
287
            this.srs = constant(getSRSId(srs));
220
            this.srs = constant(srs_id(srs));
288 221
            if( this.type == ParameterType.Variable ) {
289 222
                this.type = ParameterType.Geometry;
290 223
            }
......
292 225
        }
293 226

  
294 227
        @Override
295
        public String getName() {
228
        public String name() {
296 229
            switch (this.type) {
297 230
                case Variable:
298 231
                case Geometry:
......
330 263

  
331 264
        @Override
332 265
        public Parameter value(Object value) {
266
            if( value instanceof Geometry ) {
267
                if( this.srs == null ) {
268
                    IProjection proj = ((Geometry)value).getProjection();
269
                    this.srs(parameter().value(proj));
270
                }
271
            }
333 272
            this.value = value;
334 273
            return this;
335 274
        }
......
342 281
        }
343 282

  
344 283
        @Override
345
        public Object getValue() {
284
        public Object value() {
346 285
            try {
347 286
                switch (this.type) {
348 287
                    case Constant:
349
                        if (this.value instanceof Geometry) {
350
                            switch (config.getGeometryTypeSupport()) {
288
                        if( this.value instanceof Geometry ) {
289
                            Geometry geometry = (Geometry) this.value;
290
                            switch (geometry_support_type()) {
351 291
                                case EWKB:
352
                                    return bytearray(((Geometry) this.value).convertToEWKB());
353
                                case NATIVE:
292
                                    return GeometryUtils.toEWKB(geometry);
354 293
                                case WKB:
355
                                    return bytearray(((Geometry) this.value).convertToWKB());
294
                                    return GeometryUtils.toWKB(geometry);
356 295
                                case WKT:
357 296
                                default:
358
                                    return ((Geometry) this.value).convertToWKT();
297
                                    return GeometryUtils.toWKT(geometry);
359 298
                            }
360 299
                        } else if (this.value instanceof IProjection) {
361
                            return getSRSId((IProjection) this.value);
300
                            return srs_id((IProjection) this.value);
362 301
                        }
363 302
                        return this.value;
364 303
                    case Variable:
......
372 311
        }
373 312

  
374 313
        @Override
375
        public ParameterType getType() {
314
        public ParameterType type() {
376 315
            return this.type;
377 316
        }
378 317

  
379 318
        @Override
380
        public Value getSRS() {
319
        public Value srs() {
381 320
            return this.srs;
382 321
        }
383 322

  
384 323
        @Override
385 324
        public String toString() {
325
            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
            }
386 333
            switch (this.type) {
387 334
                case Constant:
335
                    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
                    }
388 358
                case Variable:
389 359
                default:
390 360
                    return "?";
391 361
                case Geometry:
392
                    switch (config.getGeometryTypeSupport()) {
362
                    switch (geometry_support_type()) {
393 363
                        case EWKB:
394 364
                            return MessageFormat.format(
395
                                    config.getString(Config.ST_GeomFromEWKB),
396
                                    "?",
397
                                    String.valueOf(this.srs.toString())
365
                                FORMAT_ST_GEOMFROMEWKB,
366
                                "?",
367
                                getSRS(formatter)
398 368
                            );
399 369
                        case WKB:
400 370
                            return MessageFormat.format(
401
                                    config.getString(Config.ST_GeomFromWKB),
402
                                    "?",
403
                                    String.valueOf(this.srs.toString())
371
                                FORMAT_ST_GEOMFROMWKB,
372
                                "?",
373
                                getSRS(formatter)
404 374
                            );
405 375
                        case WKT:
406 376
                        default:
407 377
                            return MessageFormat.format(
408
                                    config.getString(Config.ST_GeomFromText),
409
                                    "?",
410
                                    String.valueOf(this.srs.toString())
378
                                FORMAT_ST_GEOMFROMTEXT,
379
                                "?",
380
                                getSRS(formatter)
411 381
                            );
412 382
                    }
413 383
            }
414 384
        }
385
        
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
        }
415 400
    }
416 401

  
417 402
    public class ConstantBase extends AbstractValue implements Constant {
......
423 408
        }
424 409

  
425 410
        @Override
426
        public Object getValue() {
411
        public Object value() {
427 412
            return this.value;
428 413
        }
429 414

  
430 415
        @Override
431 416
        public String toString() {
417
            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
            }
432 431
            if (this.value instanceof String) {
433 432
                return string((String) this.value);
434 433
            }
434
            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
            }
435 461
            if (this.value instanceof Boolean) {
436 462
                if (((Boolean) this.value)) {
437
                    return config.getString(Config.constant_true);
463
                    return FORMAT_TRUE;
438 464
                } else {
439
                    return config.getString(Config.constant_false);
465
                    return FORMAT_FALSE;
440 466
                }
441 467
            }
442
            return ObjectUtils.toString(this.value, "");
468
            return Objects.toString(this.value, "");
443 469
        }
444 470
    }
445 471

  
......
466 492
        }
467 493

  
468 494
        @Override
469
        public Object getValue() {
495
        public Object value() {
470 496
            return this.value;
471 497
        }
472 498

  
......
490 516

  
491 517
        @Override
492 518
        public String toString() {
493
            return ObjectUtils.toString(this.value, "");
519
            return this.toString(EMPTY_FORMATTER);
494 520
        }
495
    }
496

  
497
    public class GeometryValueBase extends AbstractValue implements GeometryValue {
498

  
499
        protected Geometry geometry;
500
        protected IProjection projection;
501

  
502
        public GeometryValueBase(Geometry geometry, IProjection projection) {
503
            this.geometry = geometry;
504
            this.projection = projection;
505
        }
506

  
521
        
507 522
        @Override
508
        public Geometry getGeometry() {
509
            return this.geometry;
510
        }
511

  
512
        @Override
513
        public IProjection getSRS() {
514
            return this.projection;
515
        }
516

  
517
        @Override
518
        public String toString() {
519
            try {
520
                switch (config.getGeometryTypeSupport()) {
521
                    case EWKB:
522
                        return MessageFormat.format(
523
                                config.getString(Config.ST_GeomFromEWKB),
524
                                bytearray(this.geometry.convertToEWKB()),
525
                                String.valueOf(getSRSId(this.projection))
526
                        );
527
                    case WKB:
528
                        return MessageFormat.format(
529
                                config.getString(Config.ST_GeomFromWKB),
530
                                bytearray(this.geometry.convertToWKB()),
531
                                String.valueOf(getSRSId(this.projection))
532
                        );
533
                    case WKT:
534
                    default:
535
                        return MessageFormat.format(
536
                                config.getString(Config.ST_GeomFromText),
537
                                string(this.geometry.convertToWKT()),
538
                                String.valueOf(getSRSId(this.projection))
539
                        );
540
                }
541
            } catch (Exception ex) {
542
                throw new RuntimeException("Can't convert geometry to string.", ex);
523
        public String toString(Formatter<Value> formatter) {
524
            if( formatter.canApply(this) ) {
525
                return formatter.format(this);
543 526
            }
527
            return Objects.toString(this.value, "");
544 528
        }
545 529
    }
546 530

  
......
574 558
        }
575 559

  
576 560
        @Override
577
        public String getName() {
561
        public String name() {
578 562
            return this.name;
579 563
        }
580 564

  
......
588 572

  
589 573
        @Override
590 574
        public String toString() {
575
            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
            }
591 583
            if( this.format==null ) {
592 584
                StringBuilder builder = new StringBuilder();
593 585
                builder.append(name);
......
597 589
                    for (Value value : this.parameters) {
598 590
                        if( first ) {
599 591
                            first=false;
600
                            builder.append(value.toString());
592
                            builder.append(value.toString(formatter));
601 593
                        } else {
602 594
                            builder.append(", ");
603
                            builder.append(value.toString());
595
                            builder.append(value.toString(formatter));
604 596
                        }
605 597
                    }
606 598
                }
......
610 602
            if (this.parameters != null && !this.parameters.isEmpty()) {
611 603
                List<String> values = new ArrayList<>();
612 604
                for (Value value : this.parameters) {
613
                    values.add(value.toString());
605
                    values.add(value.toString(formatter));
614 606
                }
615 607
                return MessageFormat.format(format, values.toArray());
616 608
            } else {
......
619 611
        }
620 612
    }
621 613

  
614
    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

  
622 662
    public class BinaryOperatorBase extends AbstractValue implements BinaryOperator {
623 663

  
624 664
        protected String name;
......
632 672
        }
633 673

  
634 674
        @Override
635
        public String getName() {
675
        public String name() {
636 676
            return this.name;
637 677
        }
638 678

  
......
644 684
        }
645 685

  
646 686
        @Override
647
        public BinaryOperator setLeft(Value operand) {
687
        public BinaryOperator left(Value operand) {
648 688
            this.left = operand;
649 689
            return this;
650 690
        }
651 691

  
652 692
        @Override
653
        public BinaryOperator setRight(Value operand) {
693
        public BinaryOperator right(Value operand) {
654 694
            this.right = operand;
655 695
            return this;
656 696
        }
657 697

  
658 698
        @Override
659
        public Value getLeft() {
699
        public Value left() {
660 700
            return this.left;
661 701
        }
662 702

  
663 703
        @Override
664
        public Value getRight() {
704
        public Value right() {
665 705
            return this.right;
666 706
        }
667 707

  
668 708
        @Override
669 709
        public String toString() {
670
            return MessageFormat.format(
671
                    format,
672
                    this.left.toString(),
673
                    this.right.toString()
674
            );
710
            return this.toString(EMPTY_FORMATTER);
675 711
        }
712
        
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
        }
676 736
    }
677 737

  
738
    protected GeometrySupportType geometrySupportType;
678 739
    protected Value value;
679
    protected Config config;
680 740

  
681 741
    public DefaultExpressionBuilder() {
682
        this.config = new ConfigBase();
742
        this.geometrySupportType = GeometrySupportType.WKB;
683 743
    }
684 744

  
685 745
    @Override
......
688 748
    }
689 749

  
690 750
    @Override
691
    public Config getConfig() {
692
        return this.config;
751
    public GeometrySupportType geometry_support_type() {
752
        return this.geometrySupportType;
693 753
    }
694 754

  
695 755
    @Override
696
    public Value getValue() {
756
    public ExpressionBuilder geometry_support_type(GeometrySupportType geometrySupportType) {
757
        this.geometrySupportType = geometrySupportType;
758
        return this;
759
    }
760

  
761
    @Override
762
    public Value value() {
697 763
        return this.value;
698 764
    }
699 765

  
700 766
    @Override
701
    public ExpressionBuilder setValue(Value value) {
767
    public ExpressionBuilder value(Value value) {
702 768
        this.value = value;
703 769
        return this;
704 770
    }
......
709 775
    }
710 776

  
711 777
    @Override
778
    public String toString(Formatter<Value> formatter) {
779
        return this.value.toString(formatter);
780
    }
781

  
782
    @Override
783
    public Value toValue(String expression) {
784
        try {
785
            Code code = ExpressionUtils.compile(expression);
786
            return code.toValue(this);
787
        } catch(Throwable ex) {
788
            return custom(expression);
789
        }
790
    }
791

  
792
    @Override
712 793
    public void accept(Visitor visitor, VisitorFilter filter) {
713 794
        if( this.value == null) {
714 795
            return;
......
717 798
    }
718 799

  
719 800
    @Override
720
    public boolean has_spatial_functions() {
721
        return this.config.getBoolean(Config.has_spatial_functions);
801
    public String quote_for_identifiers() {
802
        return FORMAT_QUOTE_FOR_IDENTIFIERS;
722 803
    }
723

  
804
    
724 805
    @Override
725
    public GeometrySupportType geometry_support_type() {
726
        return (GeometrySupportType) this.config.get(Config.geometry_type_support);
806
    public String quote_for_strings() {
807
        return FORMAT_QUOTE_FOR_STRINGS;
727 808
    }
728

  
809
       
729 810
    @Override
730 811
    public String string(String s) {
731
        String quote = this.config.getString(Config.quote_for_strings);
812
        String quote = this.quote_for_strings();
732 813
//        No se porque no esta disponible wrapIfMissing
733 814
//        return StringUtils.wrapIfMissing(s,quote);
734 815
        if (s.startsWith(quote)) {
735 816
            return s;
736 817
        }
737
        return quote + s + quote;
818
        return quote + StringUtils.replace(s,quote,quote+quote) + quote;
738 819
    }
739 820

  
740 821
    @Override
741 822
    public String identifier(String id) {
742
        String quote = this.config.getString(Config.quote_for_identifiers);
823
        String quote = this.quote_for_identifiers();
743 824
//        No se porque no esta disponible wrapIfMissing
744 825
//        return StringUtils.wrapIfMissing(id,quote);
745 826
        if (id.startsWith(quote)) {
......
749 830
    }
750 831

  
751 832
    @Override
752
    public String bytearray(byte[] data) {
753
        return "DECODE('"+bytearray_hex(data)+"','hex')";
754
    }
755
    
756
    @Override
757 833
    public String bytearray_hex(byte[] data) {
758 834
        StringBuilder builder = new StringBuilder();
759 835
        for (byte abyte : data) {
......
774 850
    }
775 851
    
776 852
    @Override
777
    public Object getSRSId(IProjection projection) {
853
    public Object srs_id(IProjection projection) {
778 854
        if( projection==null ) {
779 855
            return 0;
780 856
        }
......
782 858
    }
783 859

  
784 860
    @Override
861
    public Constant bytearray(byte[] data) {
862
        return new ConstantBase(data);
863
    }
864
    
865
    @Override
785 866
    public Constant srs(IProjection projection) {
786
        return constant(getSRSId(projection));
867
        return constant(projection);
787 868
    }
788 869

  
789 870
    @Override
......
798 879
    
799 880
    @Override
800 881
    public Parameter parameter(String name) {
801
        Parameters parameters = this.getParameters();
802
        Parameter parameter = parameters.get(name);
803
        if( parameter != null ) {
804
            return parameter;
882
        List<Parameter> parameters = this.parameters();
883
        for (Parameter parameter : parameters) {
884
            if( StringUtils.equalsIgnoreCase(name, parameter.name()) ) {
885
                return parameter;
886
            }
805 887
        }
806
        parameter = this.parameter();
888
        Parameter parameter = this.parameter();
807 889
        parameter.name(name);
808 890
        return parameter;
809 891
    }
......
824 906
    }
825 907

  
826 908
    @Override
827
    public GeometryValue geometry(Geometry geom, IProjection projection) {
828
        return new GeometryValueBase(geom, projection);
909
    public Constant geometry(Geometry geom, IProjection projection) {
910
        geom.setProjection(projection);
911
        return new ConstantBase(geom);
829 912
    }
830 913

  
831 914
    @Override
832
    public GeometryValue geometry(Geometry geom) {
915
    public Constant geometry(Geometry geom) {
833 916
        if( geom.getProjection()==null ) {
834 917
            throw new IllegalArgumentException("The geometry does not have an associated projection. Use 'geometry(Geometry, IProjection)'.");
835 918
        }
836
        return new GeometryValueBase(geom, geom.getProjection());
919
        return new ConstantBase(geom);
837 920
    }
838 921

  
839 922
    @Override
840
    public GeometryValue envelope(Envelope envelope, IProjection projection) {
841
        return new GeometryValueBase(envelope.getGeometry(), projection);
923
    public Constant envelope(Envelope envelope, IProjection projection) {
924
        Geometry geom = envelope.getGeometry();
925
        geom.setProjection(projection);
926
        return new ConstantBase(geom);
842 927
    }
843 928

  
844 929
    @Override
845
    public GeometryValue envelope(Envelope envelope) {
930
    public Constant envelope(Envelope envelope) {
846 931
        if( envelope.getProjection()==null ) {
847 932
            throw new IllegalArgumentException("The envelope does not have an associated projection. Use 'envelope(Geometry, IProjection)'.");
848 933
        }
849
        return new GeometryValueBase(envelope.getGeometry(), envelope.getProjection());
934
        Geometry geom = envelope.getGeometry();
935
        return new ConstantBase(geom);
850 936
    }
851 937

  
852 938
    @Override
......
854 940
        return new CustomBase(value);
855 941
    }
856 942

  
943
    @Override
944
    public Method method(Value instance, String name, Value... values) {
945
        MethodBase method = new MethodBase(instance, name);
946
        for (Value theValue : values) {
947
            method.parameter(theValue);
948
        }
949
        return method;
950
    }
951
    
952
    @Override
857 953
    public Function function(String name, Value... values) {
858 954
        FunctionBase func = new FunctionBase(name);
859 955
        for (Value theValue : values) {
......
870 966
        return func;
871 967
    }
872 968

  
969
    @Override
970
    public BinaryOperator binaryOperator(String name, Value leftOperand, Value rightOperand) {
971
        return binaryOperator(name, null, leftOperand, rightOperand);
972
    }
973
    
873 974
    public BinaryOperator binaryOperator(String name, String format, Value leftOperand, Value rightOperand) {
874 975
        BinaryOperator operator = new BinaryOperatorBase(name, format);
875
        operator.setLeft(leftOperand);
876
        operator.setRight(rightOperand);
976
        operator.left(leftOperand);
977
        operator.right(rightOperand);
877 978
        return operator;
878 979
    }
879 980

  
880 981
    @Override
881
    public List<Variable> getVariables() {
982
    public List<Variable> variables() {
882 983
        final Set<Variable> vars = new HashSet<>();
883 984
        this.accept(new Visitor() {
884 985
            @Override
885 986
            public void visit(Visitable value) {
886
                vars.add((Variable) value);
987
                if( !vars.contains((Variable)value) ) {
988
                    vars.add((Variable)value);
989
                }
887 990
            }
888 991
        }, new ClassVisitorFilter(Variable.class));
889 992
        List<Variable> lvars = new ArrayList<>(vars);
......
891 994
        return lvars;
892 995
    }
893 996

  
894
    private static class ParametersBase extends ArrayList<Parameter> implements Parameters {
895

  
896
        private static final long serialVersionUID = -2188534574151780470L;
897

  
898
        public ParametersBase() {
899
            super();
900
        }
901

  
902
        public ParametersBase(Collection parameters) {
903
            super(parameters);
904
        }
905

  
906
        @Override
907
        public Parameter get(String name) {
908
            if( name == null ) {
909
                return null;
910
            }
911
            for (Parameter param : this) {
912
                if( param.is_variable() || param.is_geometry_variable() ) {
913
                    if( name.equalsIgnoreCase(param.getName()) ) {
914
                        return param;
915
                    }
916
                }
917
            }
918
            return null;
919
        }
920

  
921
        
922
        @Override
923
        public String toString() {
924
            boolean first = true;
925
            StringBuilder builder = new StringBuilder();
926
            builder.append("{ ");
927
            for (Parameter param : this) {
928
                if (!first) {
929
                    builder.append(", ");
930
                } else {
931
                    first = false;
932
                }
933
                String s;
934
                Object value = param.getValue();
935
                if (value == null) {
936
                    s = "null";
937
                } else if (value instanceof String) {
938
                    s = "'" + (String) value + "'";
939
                } else {
940
                    s = value.toString();
941
                }
942
                switch (param.getType()) {
943
                    case Constant:
944
                        builder.append(s);
945
                        break;
946
                    case Geometry:
947
                        builder.append("(Geometry)");
948
                    case Variable:
949
                    default:
950
                        builder.append(param.getName());
951
                        builder.append(": ");
952
                        builder.append(s);
953
                }
954
            }
955
            builder.append(" }");
956
            return builder.toString();
957
        }
958
    }
959

  
960 997
    @Override
961
    public Parameters getParameters() {
962
        final Parameters params = new ParametersBase();
998
    public List<Parameter> parameters() {
999
        final List<Parameter>  params = new ArrayList<>();
963 1000
        this.accept(new Visitor() {
964 1001
            @Override
965 1002
            public void visit(Visitable value) {
......
968 1005
        }, new ClassVisitorFilter(Parameter.class));
969 1006
        return params;
970 1007
    }
971

  
1008
    
972 1009
    @Override
973
    public Function getAsGeometry(Value value) {
974
        return builtin_function("ST_AsBinary", config.getString(Config.ST_AsBinary), value);
1010
    public List<String> parameters_names() {
1011
        List<String> params = new ArrayList<>();
1012
        for (Parameter param : parameters()) {
1013
            Object theValue = param.value();
1014
            String s;
1015
            switch(param.type()) {
1016
                case Constant:
1017
                    if( theValue==null ) {
1018
                        s = "NULL";
1019
                    } else if( theValue instanceof String ) {
1020
                        s = "'" + (String)theValue + "'";
1021
                        
1022
                    } else if( theValue instanceof byte[] ) {
1023
                        s = bytearray_0x((byte[]) theValue);
1024
                        
1025
                    } else {
1026
                        s = theValue.toString();
1027
                    }    
1028
                    break;
1029
                case Geometry:
1030
                    if( param.name()==null ) {
1031
                        s = bytearray_0x((byte[]) theValue);
1032
                    } else {
1033
                        s = "\"" + param.name() + "\"";
1034
                    }
1035
                    break;
1036
                case Variable:
1037
                default:
1038
                    s = "\"" + param.name() + "\"";
1039
            }
1040
//            if( !params.contains(s) ) { // Ojo que deben ir todos, incluso duplicados.
1041
                params.add(s);
1042
//            }
1043
        }
1044
        // Collections.sort(params); Ojo, no deben ordenarse.
1045
        return params;
975 1046
    }
1047
    
1048
    @Override
1049
    public List<String> variables_names() {
1050
        List<String> vars = new ArrayList<>();
1051
        for (Variable var : this.variables()) {
1052
            vars.add(var.name());
1053
        }
1054
        Collections.sort(vars);
1055
        return vars;
1056
    }
1057
    
1058
    @Override
1059
    public Function as_geometry(Value value) {
1060
        return builtin_function(FUNCTION_ST_ASBINARY, FORMAT_ST_ASBINARY, value);
1061
    }
976 1062

  
977 1063
    @Override
978 1064
    public ExpressionBuilder set(Value value) {
......
985 1071
        if (this.value == null) {
986 1072
            return this.set(value);
987 1073
        }
988
        BinaryOperator operator = binaryOperator("AND", config.getString(Config.operator_AND), this.value, value);
1074
        BinaryOperator operator = binaryOperator(OPERATOR_AND, FORMAT_OPERATOR_AND, this.value, value);
989 1075
        this.value = operator;
990 1076
        return this;
991 1077
    }
......
995 1081
        if (this.value == null) {
996 1082
            return this.set(value);
997 1083
        }
998
        BinaryOperator operator = binaryOperator("OR", config.getString(Config.operator_OR), this.value, value);
1084
        BinaryOperator operator = binaryOperator(OPERATOR_OR, FORMAT_OPERATOR_OR, this.value, value);
999 1085
        this.value = operator;
1000 1086
        return this;
1001 1087
    }
1002 1088

  
1003 1089
    @Override
1004 1090
    public Function ST_Intersects(Value geom1, Value geom2) {
1005
        return builtin_function("ST_Intersects", config.getString(Config.ST_Intersects), geom1, geom2);
1091
        return builtin_function(FUNCTION_ST_INTERSECTS, FORMAT_ST_INTERSECTS, geom1, geom2);
1006 1092
    }
1007 1093

  
1008 1094
    @Override
1009 1095
    public Function ST_SRID(Value geom) {
1010
        return builtin_function("ST_SRID", config.getString(Config.ST_SRID), geom);
1096
        return builtin_function(FUNCTION_ST_SRID, FORMAT_ST_SRID, geom);
1011 1097
    }
1012 1098

  
1013 1099
    @Override
1014 1100
    public Function ST_Envelope(Value geom) {
1015
        return builtin_function("ST_Envelope", config.getString(Config.ST_Envelope), geom);
1101
        return builtin_function(FUNCTION_ST_ENVELOPE, FORMAT_ST_ENVELOPE, geom);
1016 1102
    }
1017 1103

  
1018 1104
    @Override
1019 1105
    public Function ST_AsText(Value geom) {
1020
        return builtin_function("ST_AsText", config.getString(Config.ST_AsText), geom);
1106
        return builtin_function(FUNCTION_ST_ASTEXT, FORMAT_ST_ASTEXT, geom);
1021 1107
    }
1022 1108

  
1023 1109
    @Override
1024 1110
    public Function ST_AsBinary(Value geom) {
1025
        return builtin_function("ST_AsBinary", config.getString(Config.ST_AsBinary), geom);
1111
        return builtin_function(FUNCTION_ST_ASBINARY, FORMAT_ST_ASBINARY, geom);
1026 1112
    }
1027 1113

  
1028 1114
    @Override
1029 1115
    public Function ST_AsEWKB(Value geom) {
1030
        return builtin_function("ST_AsEWKB", config.getString(Config.ST_AsEWKB), geom);
1116
        return builtin_function(FUNCTION_ST_ASEWKB, FORMAT_ST_ASEWKB, geom);
1031 1117
    }
1032 1118

  
1033 1119
    @Override
1034 1120
    public Function ST_GeomFromText(Value geom, Value crs) {
1035
        return builtin_function("ST_GeomFromText", config.getString(Config.ST_GeomFromText), geom, crs);
1121
        return builtin_function(FUNCTION_ST_GEOMFROMTEXT, FORMAT_ST_GEOMFROMTEXT, geom, crs);
1036 1122
    }
1037 1123

  
1038 1124
    @Override
1039 1125
    public Function ST_GeomFromWKB(Value geom, Value crs) {
1040
        return builtin_function("ST_GeomFromWKB", config.getString(Config.ST_GeomFromWKB), geom, crs);
1126
        return builtin_function(FUNCTION_ST_GEOMFROMWKB, FORMAT_ST_GEOMFROMWKB, geom, crs);
1041 1127
    }
1042 1128

  
1043 1129
    @Override
1044 1130
    public Function ST_GeomFromEWKB(Value geom, Value crs) {
1045
        return builtin_function("ST_GeomFromEWKB", config.getString(Config.ST_GeomFromEWKB), geom, crs);
1131
        return builtin_function(FUNCTION_ST_GEOMFROMEWKB, FORMAT_ST_GEOMFROMEWKB, geom, crs);
1046 1132
    }
1047 1133

  
1048 1134
    @Override
1049 1135
    public Function ST_Simplify(Value geom, Value tolerance) {
1050
        return builtin_function("ST_Simplify", config.getString(Config.ST_Simplify), tolerance);
1136
        return builtin_function(FUNCTION_ST_SIMPLIFY, FORMAT_ST_SIMPLIFY, tolerance);
1051 1137
    }
1052 1138

  
1053 1139
    @Override
1054 1140
    public Function ST_Disjoint(Value geom1, Value geom2) {
1055
        return builtin_function("ST_Disjoint", config.getString(Config.ST_Disjoint), geom1, geom2);
1141
        return builtin_function(FUNCTION_ST_DISJOINT, FORMAT_ST_DISJOINT, geom1, geom2);
1056 1142
    }
1057 1143

  
1058 1144
    @Override
1059 1145
    public Function ST_Contains(Value geom1, Value geom2) {
1060
        return builtin_function("ST_Contains", config.getString(Config.ST_Contains), geom1, geom2);
1146
        return builtin_function(FUNCTION_ST_CONTAINS, FORMAT_ST_CONTAINS, geom1, geom2);
1061 1147
    }
1062 1148

  
1063 1149
    @Override
1064 1150
    public Function ST_Equals(Value geom1, Value geom2) {
1065
        return builtin_function("ST_Equals", config.getString(Config.ST_Equals), geom1, geom2);
1151
        return builtin_function(FUNCTION_ST_EQUALS, FORMAT_ST_EQUALS, geom1, geom2);
1066 1152
    }
1067 1153

  
1068 1154
    @Override
1069 1155
    public Function ST_Crosses(Value geom1, Value geom2) {
1070
        return builtin_function("ST_Crosses", config.getString(Config.ST_Crosses), geom1, geom2);
1156
        return builtin_function(FUNCTION_ST_CROSSES, FORMAT_ST_CROSSES, geom1, geom2);
1071 1157
    }
1072 1158

  
1073 1159
    @Override
1074 1160
    public Function ST_IsClosed(Value geom) {
1075
        return builtin_function("ST_IsClosed", config.getString(Config.ST_IsClosed), geom);
1161
        return builtin_function(FUNCTION_ST_ISCLOSED, FORMAT_ST_ISCLOSED, geom);
1076 1162
    }
1077 1163

  
1078 1164
    @Override
1079 1165
    public Function ST_Overlaps(Value geom1, Value geom2) {
1080
        return builtin_function("ST_Overlaps", config.getString(Config.ST_Overlaps), geom1, geom2);
1166
        return builtin_function(FUNCTION_ST_OVERLAPS, FORMAT_ST_OVERLAPS, geom1, geom2);
1081 1167
    }
1082 1168

  
1083 1169
    @Override
1084 1170
    public Function ST_Touches(Value geom1, Value geom2) {
1085
        return builtin_function("ST_Touches", config.getString(Config.ST_Touches), geom1, geom2);
1171
        return builtin_function(FUNCTION_ST_TOUCHES, FORMAT_ST_TOUCHES, geom1, geom2);
1086 1172
    }
1087 1173

  
1088 1174
    @Override
1089 1175
    public Function ST_Within(Value geom1, Value geom2) {
1090
        return builtin_function("ST_Within", config.getString(Config.ST_Within), geom1, geom2);
1176
        return builtin_function("ST_Within", FORMAT_ST_WITHIN, geom1, geom2);
1091 1177
    }
1092 1178

  
1093 1179
    @Override
1094
    public Function isNull(Value value) {
1095
        return builtin_function("IS NULL", config.getString(Config.isNull), value);
1180
    public Function is_null(Value value) {
1181
        return builtin_function("IS NULL", FORMAT_ISNULL, value);
1096 1182
    }
1097 1183

  
1098 1184
    @Override
1099
    public Function notIsNull(Value value) {
1100
        return builtin_function("NOT IS NULL", config.getString(Config.notIsNull), value);
1185
    public Function not_is_null(Value value) {
1186
        return builtin_function("NOT IS NULL", FORMAT_NOTISNULL, value);
1101 1187
    }
1102 1188

  
1103 1189
    @Override
1104 1190
    public Function not(Value value) {
1105
        return builtin_function("NOT", config.getString(Config.operator_not), value);
1191
        return builtin_function(OPERATOR_NOT, FORMAT_OPERATOR_NOT, value);
1106 1192
    }
1107 1193

  
1108 1194
    @Override
1109
    public Function lcase(Value s) {
1110
        return builtin_function("LCASE", config.getString(Config.lcase), s);
1111
    }
1112

  
1113
    @Override
1114
    public Function ucase(Value s) {
1115
        return builtin_function("UCASE", config.getString(Config.ucase), s);
1116
    }
1117

  
1118
    @Override
1119 1195
    public BinaryOperator and(Value leftOperand, Value rightOperand) {
1120
        return binaryOperator("AND", config.getString(Config.operator_AND), leftOperand, rightOperand);
1196
        return binaryOperator(OPERATOR_AND, FORMAT_OPERATOR_AND, leftOperand, rightOperand);
1121 1197
    }
1122 1198

  
1123 1199
    @Override
1124 1200
    public BinaryOperator or(Value leftOperand, Value rightOperand) {
1125
        return binaryOperator("OR", config.getString(Config.operator_OR), leftOperand, rightOperand);
1201
        return binaryOperator(OPERATOR_OR, FORMAT_OPERATOR_OR, leftOperand, rightOperand);
1126 1202
    }
1127 1203

  
1128 1204
    @Override
1129 1205
    public BinaryOperator eq(Value leftOperand, Value rightOperand) {
1130
        return binaryOperator("=", config.getString(Config.operator_EQ), leftOperand, rightOperand);
1206
        return binaryOperator("=", FORMAT_OPERATOR_EQ, leftOperand, rightOperand);
1131 1207
    }
1132 1208

  
1133 1209
    @Override
1134 1210
    public BinaryOperator ne(Value leftOperand, Value rightOperand) {
1135
        return binaryOperator("<>", config.getString(Config.operator_NE), leftOperand, rightOperand);
1211
        return binaryOperator("<>", FORMAT_OPERATOR_NE, leftOperand, rightOperand);
1136 1212
    }
1137 1213

  
1138 1214
    @Override
1139 1215
    public BinaryOperator gt(Value op1, Value op2) {
1140
        return binaryOperator(">", config.getString(Config.operator_GT), op1, op2);
1216
        return binaryOperator(">", FORMAT_OPERATOR_GT, op1, op2);
1141 1217
    }
1142 1218

  
1143 1219
    @Override
1144 1220
    public BinaryOperator ge(Value op1, Value op2) {
1145
        return binaryOperator(">=", config.getString(Config.operator_GE), op1, op2);
1221
        return binaryOperator(">=", FORMAT_OPERATOR_GE, op1, op2);
1146 1222
    }
1147 1223

  
1148 1224
    @Override
1149 1225
    public BinaryOperator lt(Value op1, Value op2) {
1150
        return binaryOperator("<", config.getString(Config.operator_LT), op1, op2);
1226
        return binaryOperator("<", FORMAT_OPERATOR_LT, op1, op2);
1151 1227
    }
1152 1228

  
1153 1229
    @Override
1154 1230
    public BinaryOperator le(Value op1, Value op2) {
1155
        return binaryOperator("<=", config.getString(Config.operator_LE), op1, op2);
1231
        return binaryOperator("<=", FORMAT_OPERATOR_LE, op1, op2);
1156 1232
    }
1157 1233

  
1158 1234
    @Override
1159 1235
    public BinaryOperator like(Value op1, Value op2) {
1160
        return binaryOperator("LIKE", config.getString(Config.operator_LIKE), op1, op2);
1236
        return binaryOperator(OPERATOR_LIKE, FORMAT_OPERATOR_LIKE, op1, op2);
1161 1237
    }
1162 1238

  
1163 1239
    @Override
1164 1240
    public BinaryOperator ilike(Value op1, Value op2) {
1165
        return binaryOperator("ILIKE", config.getString(Config.operator_ILIKE), op1, op2);
1241
        return binaryOperator(OPERATOR_ILIKE, FORMAT_OPERATOR_ILIKE, op1, op2);
1166 1242
    }
1167 1243

  
1168 1244
    @Override
1169 1245
    public BinaryOperator add(Value op1, Value op2) {
1170
        return binaryOperator("ADD", config.getString(Config.operator_add), op1, op2);
1246
        return binaryOperator(OPERATOR_ADD, FORMAT_OPERATOR_ADD, op1, op2);
1171 1247
    }
1172 1248

  
1173 1249
    @Override
1174 1250
    public BinaryOperator subst(Value op1, Value op2) {
1175
        return binaryOperator("SUBST", config.getString(Config.operator_subst), op1, op2);
1251
        return binaryOperator(OPERATOR_SUBST, FORMAT_OPERATOR_SUBST, op1, op2);
1176 1252
    }
1177 1253

  
1178 1254
    @Override
1179 1255
    public BinaryOperator mult(Value op1, Value op2) {
1180
        return binaryOperator("MULT", config.getString(Config.operator_mult), op1, op2);
1256
        return binaryOperator(OPERATOR_MULT, FORMAT_OPERATOR_MULT, op1, op2);
1181 1257
    }
1182 1258

  
1183 1259
    @Override
1184 1260
    public BinaryOperator div(Value op1, Value op2) {
1185
        return binaryOperator("DIV", config.getString(Config.operator_div), op1, op2);
1261
        return binaryOperator(OPERATOR_DIV, FORMAT_OPERATOR_DIV, op1, op2);
1186 1262
    }
1187 1263

  
1188 1264
    @Override
1189 1265
    public BinaryOperator concat(Value op1, Value op2) {
1190
        return binaryOperator("CONCAT", config.getString(Config.operator_concat), op1, op2);
1266
        return binaryOperator(OPERATOR_CONCAT, FORMAT_OPERATOR_CONCAT, op1, op2);
1191 1267
    }
1192 1268
    
1193 1269
    @Override
1194 1270
    public Function iif(Value condition, Value iftrue, Value iffalse) {
1195
        return builtin_function("IIF", config.getString(Config.iif), condition, iftrue, iffalse);
1271
        return function(FUNCTION_IIF, condition, iftrue, iffalse);
1196 1272
    }
1197 1273

  
1198 1274
    @Override
1199 1275
    public Function ifnull(Value value, Value iftrue, Value iffalse) {
1200
        return builtin_function("IFNULL", config.getString(Config.ifnull), value, iftrue, iffalse);
1276
        return function(FUNCTION_IFNULL, value, iftrue, iffalse);
1201 1277
    }
1202 1278
    
1203 1279
    @Override
1204 1280
    public Function left(Value str, Value size) {
1205
       return function("left", str, size);
1206
       // return builtin_function("left", "left({1})",str,size);
1281
       return function(FUNCTION_LEFT, str, size);
1207 1282
    }
1208 1283
    
1209 1284
    @Override
1210 1285
    public Function right(Value str, Value len) {
1211
       return function("right", str, len);
1286
       return function(FUNCTION_RIGHT, str, len);
1212 1287
    }
1213 1288
    
1214 1289
    @Override
1215 1290
    public Function locate(Value search, Value str, Value start) {
1216
       return function("locate", search, str, start);
1291
       return function(FUNCTION_LOCATE, search, str, start);
1217 1292
    }
1218 1293
    
1219 1294
    @Override
1220 1295
    public Function position(Value search, Value str) {
1221
       return function("position", search, str);
1296
       return function(FUNCTION_POSITION, search, str);
1222 1297
    }
1223 1298
    
1224 1299
    @Override
1225 1300
    public Function lpad(Value str, Value len, Value padstr) {
1226
       return function("lpad", str, len, padstr);
1301
       return function(FUNCTION_LPAD, str, len, padstr);
1227 1302
    }
1228 1303
    
1229 1304
    @Override
1230 1305
    public Function rpad(Value str, Value len, Value padstr) {
1231
       return function("rpad", str, len, padstr);
1306
       return function(FUNCTION_RPAD, str, len, padstr);
1232 1307
    }
1233 1308
    
1234 1309
    @Override
1235 1310
    public Function ltrim(Value str) {
1236
       return function("ltrim", str);
1311
       return function(FUNCTION_LTRIM, str);
1237 1312
    }
1238 1313
    
1239 1314
    @Override
1240 1315
    public Function rtrim(Value str) {
1241
       return function("rtrim", str);
1316
       return function(FUNCTION_RTRIM, str);
1242 1317
    }
1243 1318
    
1244 1319
    @Override
1245 1320
    public Function trim(Value str) {
1246
       return function("trim", str);
1321
       return function(FUNCTION_TRIM, str);
1247 1322
    }
1248 1323
    
1249 1324
    @Override
1250 1325
    public Function repeat(Value str, Value size) {
1251
       return function("repeat", str, size);
1326
       return function(FUNCTION_REPEAT, str, size);
1252 1327
    }
1253 1328
    
1254 1329
    @Override
1255 1330
    public Function replace(Value str, Value search, Value replstr) {
1256
       return function("replace", str, search, replstr);
1331
       return function(FUNCTION_REPLACE, str, search, replstr);
1257 1332
    }
1258 1333
    
1259 1334
    @Override
1260 1335
    public Function ascii(Value str) {
1261
       return function("ascii", str);
1336
       return function(FUNCTION_ASCII, str);
1262 1337
    }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff