Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.spi / src / main / java / org / gvsig / fmap / dal / feature / spi / ExpressionBuilderBase.java @ 43034

History | View | Annotate | Download (32.2 KB)

1
package org.gvsig.fmap.dal.feature.spi;
2

    
3
import java.text.MessageFormat;
4
import java.util.ArrayList;
5
import java.util.Collections;
6
import java.util.HashMap;
7
import java.util.HashSet;
8
import java.util.List;
9
import java.util.Map;
10
import java.util.Objects;
11
import java.util.Set;
12
import org.apache.commons.lang3.ObjectUtils;
13
import org.apache.commons.lang3.StringUtils;
14
import org.cresques.cts.IProjection;
15
import org.gvsig.fmap.dal.ExpressionBuilder;
16
import org.gvsig.fmap.dal.ExpressionBuilder.BinaryOperator;
17
import org.gvsig.fmap.dal.ExpressionBuilder.Config;
18
import org.gvsig.fmap.dal.ExpressionBuilder.Constant;
19
import org.gvsig.fmap.dal.ExpressionBuilder.Custom;
20
import org.gvsig.fmap.dal.ExpressionBuilder.Function;
21
import org.gvsig.fmap.dal.ExpressionBuilder.GeometrySupportType;
22
import org.gvsig.fmap.dal.ExpressionBuilder.GeometryValue;
23
import org.gvsig.fmap.dal.ExpressionBuilder.Group;
24
import org.gvsig.fmap.dal.ExpressionBuilder.Parameter;
25
import org.gvsig.fmap.dal.ExpressionBuilder.ParameterType;
26
import org.gvsig.fmap.dal.ExpressionBuilder.Value;
27
import org.gvsig.fmap.dal.ExpressionBuilder.Variable;
28
import org.gvsig.fmap.dal.ExpressionBuilder.Visitable;
29
import org.gvsig.fmap.dal.ExpressionBuilder.Visitor;
30
import org.gvsig.fmap.dal.ExpressionBuilder.VisitorFilter;
31
import org.gvsig.fmap.geom.Geometry;
32
import org.gvsig.fmap.geom.primitive.Envelope;
33

    
34
public class ExpressionBuilderBase implements ExpressionBuilder {
35
    public class ConfigBase implements Config {
36

    
37
        protected Map<String,Object> values;
38
        
39
        public ConfigBase() {
40
            this.values = new HashMap<>();
41
            
42
            this.values.put(has_spatial_functions,false);
43
            this.values.put(constant_true, "(1=1)");
44
            this.values.put(constant_false, "(1=2)");
45
            this.values.put(quote_for_identifiers, "\"");
46
            this.values.put(quote_for_strings, "'");
47
            this.values.put(geometry_type_support, GeometrySupportType.WKT);
48
            this.values.put(group, "( {0} )");
49
            
50
            this.values.put(Find_SRID , "Find_SRID(({0}), ({1}), ({2}))");
51
            this.values.put(ST_SRID , "ST_SRID({0})");
52
            this.values.put(ST_AsText , "ST_AsText({0})");
53
            this.values.put(ST_AsBinary, "ST_AsBinary({0})");
54
            this.values.put(ST_AsEWKB, "ST_AsWKB({0})");
55
            this.values.put(ST_Contains, "ST_Contains(({0}), ({1}))");            
56
            this.values.put(ST_Crosses,  "ST_Crosses(({0}), ({1}))");
57
            this.values.put(ST_Disjoint ,  "ST_Disjoint(({0}), ({1}))");
58
            this.values.put(ST_Equals ,  "ST_Equals(({0}), ({1}))");
59
            this.values.put(ST_IsClosed,  "ST_IsClosed({0})");
60
            this.values.put(ST_Overlaps,  "ST_Overlaps(({0}), ({1}))");
61
            this.values.put(ST_Touches,  "ST_Touches(({0}), ({1}))");
62
            this.values.put(ST_Within, "ST_Within(({0}), ({1}))");            
63
            this.values.put(ST_Envelope, "ST_Envelope({0})");
64
            this.values.put(ST_Intersects, "ST_Intersects(({0}), ({1}))");
65
            this.values.put(ST_GeomFromText, "ST_GeomFromText({0}, ({1}))");
66
            this.values.put(ST_GeomFromWKB, "ST_GeomFromWKB(({0}), ({1}))");
67
            this.values.put(ST_GeomFromEWKB, "ST_GeomFromEWKB(({0}), ({1}))");
68
            this.values.put(lcase, "LCASE({0})");
69
            this.values.put(ucase, "UCASE({0})");
70
            this.values.put(isNull, "( ({0}) IS NULL )");
71
            this.values.put(notIsNull, "( ({0}) NOT IS NULL )");
72
            this.values.put(operator_not, "( NOT ({0}) )");
73
            
74
            this.values.put(operator_AND, "{0} AND {1}");
75
            this.values.put(operator_OR, "{0} OR {1}");
76
            this.values.put(operator_EQ, "( ({0}) = ({1}) )");
77
            this.values.put(operator_NE, "( ({0}) <> ({1}) )");
78
            this.values.put(operator_GT, "( ({0}) > ({1}) )");
79
            this.values.put(operator_GE, "( ({0}) >= ({1}) )");
80
            this.values.put(operator_LT, "( ({0}) < ({1}) )");
81
            this.values.put(operator_LE, "( ({0}) <= ({1}) )");
82
            this.values.put(operator_LIKE, "( ({0}) LIKE ({1}) )");
83
            this.values.put(operator_ILIKE, "( ({0}) ILIKE ({1}) )");
84

    
85
            this.values.put(operator_add, "{0} + {1}");
86
            this.values.put(operator_subst, "{0} - {1}");
87
            this.values.put(operator_mult, "{0} * {1}");
88
            this.values.put(operator_div, "{0} / {1}");
89
            this.values.put(operator_concat, "{0} || {1}");
90

    
91
        }
92

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

    
105
        @Override
106
        public void remove_functionality(String functionality) {
107
            this.values.remove(functionality);
108
        }
109

    
110
        @Override
111
        public boolean has_spatial_functions() {
112
            return this.getBoolean(has_spatial_functions);
113
        }
114

    
115
        @Override
116
        public GeometrySupportType getGeometryTypeSupport() {
117
            return (GeometrySupportType) this.get(geometry_type_support);
118
        }
119

    
120
        @Override
121
        public boolean getBoolean(String name) {
122
            return (boolean) this.values.get(name);
123
        }
124

    
125
        @Override
126
        public String getString(String name) {
127
            return (String) this.values.get(name);
128
        }
129

    
130
        @Override
131
        public Object get(String name) {
132
            return this.values.get(name);
133
        }
134

    
135
        @Override
136
        public void set(String name, Object value) {
137
            this.values.put(name,value);
138
        }
139
    }
140
    
141
    public abstract class AbstractValue implements Value {
142

    
143
        @Override
144
        public void accept(Visitor visitor, VisitorFilter filter) {
145
            if( filter == null || filter.accept(this) ) {
146
                visitor.visit(this);
147
            }
148
        }
149
        
150
    }
151

    
152
    public class ClassVisitorFilter implements VisitorFilter {
153

    
154
        private final Class classFilter;
155

    
156
        public ClassVisitorFilter(Class classFilter) {
157
            this.classFilter = classFilter;
158
        }
159
        
160
        @Override
161
        public boolean accept(Visitable visitable) {
162
            return classFilter.isInstance(visitable);
163
        }
164
        
165
    }
166
    
167
    public class GroupBase extends AbstractValue implements Group {
168
        protected Value value;
169
        
170
        public GroupBase(Value value) {
171
            this.value = value;
172
        }
173

    
174
        @Override
175
        public Value getValue() {
176
            return value;
177
        }
178

    
179
        @Override
180
        public void accept(Visitor visitor, VisitorFilter filter) {
181
            super.accept(visitor,filter);
182
            this.value.accept(visitor,filter);
183
        }
184
        
185
        @Override
186
        public String toString() {
187
            return MessageFormat.format(config.getString(Config.group), this.value.toString());
188
        }
189
    }
190

    
191
    public class VariableBase extends AbstractValue implements Variable {
192
        protected String name;
193
        
194
        public VariableBase(String name) {
195
            this.name = name;
196
        }
197
        
198
        @Override
199
        public String getName() {
200
            return this.name;
201
        }
202

    
203
        @Override
204
        public String toString() {
205
            return identifier(this.name);
206
        }
207

    
208
        @Override
209
        public int compareTo(Variable o) {
210
            return this.name.compareTo(o.getName());
211
        }
212

    
213
        @Override
214
        public boolean equals(Object obj) {
215
            if( ! (obj instanceof Variable) ) {
216
                return false;
217
            }
218
            return this.name.equals(((Variable)obj).getName());
219
        }
220

    
221
        @Override
222
        public int hashCode() {
223
            int hash = 7;
224
            hash = 37 * hash + Objects.hashCode(this.name);
225
            return hash;
226
        }
227
    }
228

    
229
    public class ParameterBase extends AbstractValue implements Parameter {
230
        protected Object value;
231
        protected ParameterType type;
232
        protected Value srs;
233
        
234
        public ParameterBase(Object value) {
235
            this.value = value;
236
            if( this.value instanceof String ) {
237
                this.type = ParameterType.Variable;
238
            } else {
239
                this.type = ParameterType.Constant;
240
            }
241
        }
242

    
243
        @Override
244
        public void accept(Visitor visitor, VisitorFilter filter) {
245
            super.accept(visitor, filter);
246
            if( this.srs != null ) {
247
                this.srs.accept(visitor, filter);
248
            }
249
        }
250
        
251
        @Override
252
        public Parameter as_geometry() {
253
            this.type = ParameterType.Geometry;
254
            return this;
255
        }
256
        
257
        @Override
258
        public Parameter as_constant() {
259
            this.type = ParameterType.Constant;
260
            return this;
261
        }
262
        
263
        @Override
264
        public Parameter as_variable() {
265
            this.type = ParameterType.Variable;
266
            return this;
267
        }
268
        
269
        @Override
270
        public Parameter srs(Value srs) {
271
            this.srs = srs;
272
            return this;
273
        }
274

    
275
        @Override
276
        public Parameter srs(IProjection srs) {
277
            this.srs = constant(getSRSId(srs));
278
            return this;
279
        }
280
 
281
        @Override
282
        public String getName() {
283
            switch(this.type) {
284
                case Variable:
285
                case Geometry:
286
                    return (String) this.value;
287
                case Constant:
288
                default:
289
                    return null;
290
            }
291
        }
292

    
293
        @Override
294
        public boolean is_constant() {
295
            return this.type == ParameterType.Constant;
296
        }
297

    
298
        @Override
299
        public boolean is_geometry_variable() {
300
            return this.type == ParameterType.Geometry;
301
        }
302

    
303
        @Override
304
        public boolean is_variable() {
305
            return this.type == ParameterType.Variable;
306
        }
307

    
308
        @Override
309
        public Object getValue() {
310
            try {
311
                switch(this.type) {
312
                    case Constant:
313
                        if( this.value instanceof Geometry ) {
314
                            switch( config.getGeometryTypeSupport() ) {
315
                                case EWKB:
316
                                    return bytearray(((Geometry)this.value).convertToEWKB());
317
                                case WKB:
318
                                    return bytearray(((Geometry)this.value).convertToWKB());
319
                                case WKT:
320
                                default:
321
                                    return ((Geometry)this.value).convertToWKT();
322
                            }
323
                        } else if( this.value instanceof IProjection ) {
324
                            return getSRSId((IProjection) this.value);
325
                        } 
326
                        return this.value;
327
                    case Variable:
328
                    case Geometry:
329
                    default:
330
                        return null;
331
                }
332
            } catch(Exception ex) {
333
                throw new RuntimeException("Can't get value from parameter.",ex);
334
            }
335
        }
336

    
337
        @Override
338
        public ParameterType getType() {
339
            return this.type;
340
        }
341
        
342
        @Override
343
        public Value getSRS() {
344
            return this.srs;
345
        }
346
        
347
        @Override
348
        public String toString() {
349
            switch(this.type) {
350
                case Constant:
351
                case Variable:
352
                default:
353
                    return "?";
354
                case Geometry:
355
                    switch( config.getGeometryTypeSupport() ) {
356
                        case EWKB:
357
                            return MessageFormat.format(
358
                                    config.getString(Config.ST_GeomFromEWKB),
359
                                    "?",
360
                                    String.valueOf(this.srs.toString())
361
                            );
362
                        case WKB:
363
                            return MessageFormat.format(
364
                                    config.getString(Config.ST_GeomFromWKB),
365
                                    "?",
366
                                    String.valueOf(this.srs.toString())
367
                            );
368
                        case WKT:
369
                        default:
370
                            return MessageFormat.format(
371
                                    config.getString(Config.ST_GeomFromText),
372
                                    "?",
373
                                    String.valueOf(this.srs.toString())
374
                            );                        
375
                    }                            
376
            }
377
        }        
378
    }
379

    
380
    public class ConstantBase extends AbstractValue implements Constant {
381
        
382
        protected Object value;
383
        
384
        public ConstantBase(Object value) {
385
            this.value = value;
386
        }
387
        
388
        @Override
389
        public Object getValue() {
390
            return this.value;
391
        }
392

    
393
        @Override
394
        public String toString() {
395
            if( this.value instanceof String ) {
396
                return string((String) this.value);
397
            }
398
            if( this.value instanceof Boolean ) {
399
                if( ((Boolean)this.value) ) {
400
                    return config.getString(Config.constant_true);
401
                } else {
402
                    return config.getString(Config.constant_false);
403
                }
404
            }
405
            return ObjectUtils.toString(this.value, "");
406
        }
407
    }
408

    
409
    public class CustomBase extends AbstractValue implements Custom {
410
        
411
        protected Object value;
412
        
413
        // Esto es para permitir declarar parametros y columnas en una seccion
414
        // custom.
415
        protected List<Value> values;
416
        
417
        public CustomBase(Object value) {
418
            this.value = value;
419
        }
420

    
421
        @Override
422
        public void accept(Visitor visitor, VisitorFilter filter) {
423
            super.accept(visitor, filter);
424
            if( this.values!=null ) {
425
                for (Value value : values) {
426
                    value.accept(visitor, filter);
427
                }
428
            }
429
        }
430
        
431
        @Override
432
        public Object getValue() {
433
            return this.value;
434
        }
435

    
436
        @Override
437
        public Custom add(Variable variable) {
438
            if( this.values==null ) {
439
                this.values = new ArrayList<>();
440
            }
441
            this.values.add(variable);
442
            return this;
443
        }
444

    
445
        @Override
446
        public Custom add(Parameter parameter) {
447
            if( this.values==null ) {
448
                this.values = new ArrayList<>();
449
            }
450
            this.values.add(parameter);
451
            return this;
452
        }
453

    
454
        @Override
455
        public String toString() {
456
            return ObjectUtils.toString(this.value, "");
457
        }
458
    }
459

    
460
    public class GeometryValueBase extends AbstractValue implements GeometryValue {
461

    
462
        protected Geometry geometry;
463
        protected IProjection projection;
464
        
465
        public GeometryValueBase(Geometry geometry, IProjection projection) {
466
            this.geometry = geometry;
467
            this.projection = projection;
468
        }
469
        
470
        @Override
471
        public Geometry getGeometry() {
472
            return this.geometry;
473
        }
474

    
475
        @Override
476
        public IProjection getSRS() {
477
            return this.projection;
478
        }
479

    
480
        @Override
481
        public String toString() {
482
            try {
483
                switch( config.getGeometryTypeSupport() ) {
484
                    case EWKB:
485
                        return MessageFormat.format(
486
                                config.getString(Config.ST_GeomFromEWKB),
487
                                bytearray(this.geometry.convertToEWKB()),
488
                                String.valueOf(getSRSId(this.projection))
489
                        );
490
                    case WKB:
491
                        return MessageFormat.format(
492
                                config.getString(Config.ST_GeomFromWKB),
493
                                bytearray(this.geometry.convertToWKB()),
494
                                String.valueOf(getSRSId(this.projection))
495
                        );
496
                    case WKT:
497
                    default:
498
                        return MessageFormat.format(
499
                                config.getString(Config.ST_GeomFromText),
500
                                string(this.geometry.convertToWKT()),
501
                                String.valueOf(getSRSId(this.projection))
502
                        );                        
503
                }
504
            } catch (Exception ex) {
505
                throw new RuntimeException("Can't convert geometry to string.",ex);
506
            }
507
        }
508
    } 
509

    
510
    public class FunctionBase extends AbstractValue implements Function {
511

    
512
        protected String name;
513
        protected String format;
514
        protected List<Value> parameters;
515
        
516
        public FunctionBase(String name, String format) {
517
            this.name = name;
518
            this.format = format;
519
        }
520
        
521
        @Override
522
        public List<Value> parameters() {
523
            if( this.parameters == null ) {
524
                this.parameters = new ArrayList<>();
525
            }
526
            return this.parameters;
527
        }        
528

    
529
        @Override
530
        public Function parameter(Value parameter) {
531
            this.parameters().add(parameter);
532
            return this;
533
        }
534

    
535
        @Override
536
        public String getName() {
537
            return this.name;
538
        }
539

    
540
        @Override
541
        public void accept(Visitor visitor, VisitorFilter filter) {
542
            super.accept(visitor,filter);
543
            for (Value value : this.parameters) {
544
                value.accept(visitor,filter);
545
            }
546
        }
547

    
548
        @Override
549
        public String toString() {
550
            if( this.parameters!=null && !this.parameters.isEmpty() ) {
551
                List<String> values = new ArrayList<>();
552
                for (Value value : this.parameters) {
553
                    values.add(value.toString());
554
                }
555
                return MessageFormat.format(format, values.toArray());
556
            } else {
557
                return this.format;
558
            }
559
        }
560
    }
561
    
562
    public class BinaryOperatorBase extends AbstractValue implements BinaryOperator {
563

    
564
        protected String name;
565
        protected String format;
566
        protected Value left;
567
        protected Value right;
568
        
569
        public BinaryOperatorBase(String name, String format) {
570
            this.name = name;
571
            this.format = format;
572
        }
573
        
574
        @Override
575
        public String getName() {
576
            return this.name;
577
        }
578

    
579
        @Override
580
        public void accept(Visitor visitor, VisitorFilter filter) {
581
            super.accept(visitor,filter);
582
            this.left.accept(visitor, filter);
583
            this.right.accept(visitor, filter);
584
        }
585

    
586
        @Override
587
        public BinaryOperator setLeft(Value operand) {
588
            this.left = operand;
589
            return this;
590
        }
591

    
592
        @Override
593
        public BinaryOperator setRight(Value operand) {
594
            this.right = operand;
595
            return this;
596
        }
597

    
598
        @Override
599
        public Value getLeft() {
600
            return this.left;
601
        }
602

    
603
        @Override
604
        public Value getRight() {
605
            return this.right;
606
        }
607
        
608
        @Override
609
        public String toString() {
610
            return MessageFormat.format(
611
                    format, 
612
                    this.left.toString(), 
613
                    this.right.toString()
614
            );
615
        }
616
    }
617

    
618
    protected Value value;
619
    protected Config config;
620
    
621
    public ExpressionBuilderBase() {
622
        this.config = new ConfigBase();
623
    }
624

    
625
    @Override
626
    public ExpressionBuilder createExpressionBuilder() {
627
        return new ExpressionBuilderBase();
628
    }
629
    
630
    @Override
631
    public Config getConfig() {
632
        return this.config;
633
    } 
634
    
635
    @Override
636
    public Value getValue() {
637
        return this.value;
638
    }
639
    
640
    @Override
641
    public ExpressionBuilder setValue(Value value) {
642
        this.value = value;
643
        return this;
644
    }
645

    
646
    @Override
647
    public String toString() {
648
        return this.value.toString();
649
    }
650

    
651
    @Override
652
    public void accept(Visitor visitor, VisitorFilter filter) {
653
        this.value.accept(visitor, filter);
654
    }
655
     
656
    @Override
657
    public boolean has_spatial_functions() {
658
        return this.config.getBoolean(Config.has_spatial_functions);
659
    }
660

    
661
    @Override
662
    public GeometrySupportType geometry_support_type() {
663
        return (GeometrySupportType) this.config.get(Config.geometry_type_support);
664
    }
665

    
666
    @Override
667
    public String string(String s) {
668
        String quote = this.config.getString(Config.quote_for_strings);
669
//        No se porque no esta disponible wrapIfMissing
670
//        return StringUtils.wrapIfMissing(s,quote);
671
        if (s.startsWith(quote)) {
672
            return s;
673
        }
674
        return quote + s + quote;
675
    }
676
    
677
    @Override
678
    public String identifier(String id) {
679
        String quote = this.config.getString(Config.quote_for_identifiers);
680
//        No se porque no esta disponible wrapIfMissing
681
//        return StringUtils.wrapIfMissing(id,quote);
682
        if (id.startsWith(quote)) {
683
            return id;
684
        }
685
        return quote + id + quote;
686
    }
687

    
688
    @Override
689
    public String bytearray(byte[] data) {
690
        StringBuilder builder = new StringBuilder();
691
        builder.append("0x");
692
        for (byte abyte : data) {
693
            int v = abyte & 0xff;
694
            builder.append(String.format("%02x", v));
695
        }
696
        return builder.toString();
697
    }
698

    
699
    @Override
700
    public int getSRSId(IProjection projection) {
701
        String abrev = projection.getAbrev();
702
        return Integer.valueOf(abrev.split(":")[1]);
703
    }
704
    
705
    @Override
706
    public Constant srs(IProjection projection) {
707
        return constant(getSRSId(projection));
708
    }
709

    
710
    @Override
711
    public Variable variable(String name) {
712
        return new VariableBase(name);
713
    }
714

    
715
    @Override
716
    public Variable column(String name) {
717
        return new VariableBase(name);
718
    }
719

    
720
    @Override
721
    public Parameter parameter(Object  value) {
722
        return new ParameterBase(value);
723
    }
724

    
725
    @Override
726
    public Constant constant(Object value) {
727
        return new ConstantBase(value);
728
    }
729

    
730
    @Override
731
    public Group group(Value value) {
732
        return new GroupBase(value);
733
    }
734
    
735
    @Override
736
    public GeometryValue geometry(Geometry geom, IProjection projection) {
737
        return new GeometryValueBase(geom, projection);
738
    }
739

    
740
    @Override
741
    public GeometryValue envelope(Envelope envelope, IProjection projection) {
742
        return new GeometryValueBase(envelope.getGeometry(), projection);
743
    }
744

    
745
    @Override
746
    public Custom custom(Object value) {
747
        return new CustomBase(value);
748
    }
749

    
750
    public Function function(String name, String format, Value...values) {
751
        FunctionBase func = new FunctionBase(name,format);
752
        for (Value value : values) {
753
            func.parameter(value);
754
        }
755
        return func;
756
    }
757
    
758
    public BinaryOperator binaryOperator(String name, String format, Value leftOperand, Value rightOperand) {
759
        BinaryOperator operator = new BinaryOperatorBase(name,format);
760
        operator.setLeft(leftOperand);
761
        operator.setRight(rightOperand);
762
        return operator;
763
    }
764
    
765
    @Override
766
    public List<Variable> getVariables() {
767
        final Set<Variable> vars = new HashSet<>();
768
        this.accept(new Visitor() {
769
            @Override
770
            public void visit(Visitable value) {
771
                vars.add((Variable)value);
772
            }
773
        }, new ClassVisitorFilter(Variable.class) );
774
        List<Variable> lvars = new ArrayList<>(vars);
775
        Collections.sort(lvars);
776
        return lvars;
777
    }
778
    
779
    @Override
780
    public List<Parameter> getParameters() {
781
        final List<Parameter> params = new ArrayList<>();
782
        this.accept(new Visitor() {
783
            @Override
784
            public void visit(Visitable value) {
785
                params.add((Parameter)value);
786
            }
787
        }, new ClassVisitorFilter(Parameter.class) );
788
        return params;
789
    }
790
    
791
    @Override
792
    public Function getAsGeometry(Value value) {
793
        return function("ST_AsBinary", config.getString(Config.ST_AsBinary), value);
794
    }
795

    
796
    @Override
797
    public ExpressionBuilder set(Value value) {
798
        this.value = value;
799
        return this;
800
    }
801

    
802
    @Override
803
    public ExpressionBuilder and(Value value) {
804
        if( this.value == null ) {
805
            return this.set(value);
806
        }
807
        BinaryOperator operator = binaryOperator("AND", config.getString(Config.operator_AND), this.value, value);
808
        this.value = operator;
809
        return this;
810
    }
811

    
812
    @Override
813
    public ExpressionBuilder or(Value value) {
814
        if( this.value == null ) {
815
            return this.set(value);
816
        }
817
        BinaryOperator operator = binaryOperator("OR", config.getString(Config.operator_OR), this.value, value);
818
        this.value = operator;
819
        return this;
820
    }
821

    
822
    @Override
823
    public Function Find_SRID(Value schema, Value table, Value column) {
824
        return function("Find_SRID", config.getString(Config.Find_SRID), schema, table, column);
825
    }
826

    
827
    @Override
828
    public Function ST_Intersects(Value geom1, Value geom2) {
829
        return function("ST_Intersects", config.getString(Config.ST_Intersects), geom1, geom2);
830
    }
831

    
832
    @Override
833
    public Function ST_SRID(Value geom) {
834
        return function("ST_SRID", config.getString(Config.ST_SRID), geom);
835
    }
836

    
837
    @Override
838
    public Function ST_Envelope(Value geom) {
839
        return function("ST_Envelope", config.getString(Config.ST_Envelope), geom);
840
    }
841

    
842
    @Override
843
    public Function ST_AsText(Value geom) {
844
        return function("ST_AsText", config.getString(Config.ST_AsText), geom);
845
    }
846

    
847
    @Override
848
    public Function ST_AsBinary(Value geom) {
849
        return function("ST_AsBinary", config.getString(Config.ST_AsBinary), geom);
850
    }
851

    
852
    @Override
853
    public Function ST_AsEWKB(Value geom) {
854
        return function("ST_AsEWKB", config.getString(Config.ST_AsEWKB), geom);
855
    }
856

    
857
    @Override
858
    public Function ST_GeomFromText(Value geom, Value crs) {
859
        return function("ST_GeomFromText", config.getString(Config.ST_GeomFromText), geom, crs);
860
    }
861

    
862
    @Override
863
    public Function ST_GeomFromWKB(Value geom, Value crs) {
864
        return function("ST_GeomFromWKB", config.getString(Config.ST_GeomFromWKB), geom, crs);
865
    }
866

    
867
    @Override
868
    public Function ST_GeomFromEWKB(Value geom, Value crs) {
869
        return function("ST_GeomFromEWKB", config.getString(Config.ST_GeomFromEWKB), geom, crs);
870
    }
871

    
872
    @Override
873
    public Function ST_Disjoint(Value geom1, Value geom2) {
874
        return function("ST_Disjoint", config.getString(Config.ST_Disjoint), geom1, geom2);
875
    }
876
    
877
    @Override
878
    public Function ST_Contains(Value geom1, Value geom2) {
879
        return function("ST_Contains", config.getString(Config.ST_Contains), geom1, geom2);
880
    }
881

    
882
    @Override
883
    public Function ST_Equals(Value geom1, Value geom2) {
884
        return function("ST_Equals", config.getString(Config.ST_Equals), geom1, geom2);
885
    }
886

    
887
    @Override
888
    public Function ST_Crosses(Value geom1, Value geom2) {
889
        return function("ST_Crosses", config.getString(Config.ST_Crosses), geom1, geom2);
890
    }
891

    
892
    @Override
893
    public Function ST_IsClosed(Value geom) {
894
        return function("ST_IsClosed", config.getString(Config.ST_IsClosed), geom);
895
    }
896

    
897
    @Override
898
    public Function ST_Overlaps(Value geom1, Value geom2) {
899
        return function("ST_Overlaps", config.getString(Config.ST_Overlaps), geom1, geom2);
900
    }
901

    
902
    @Override
903
    public Function ST_Touches(Value geom1, Value geom2) {
904
        return function("ST_Touches", config.getString(Config.ST_Touches), geom1, geom2);
905
    }
906

    
907
    @Override
908
    public Function ST_Within(Value geom1, Value geom2) {
909
        return function("ST_Within", config.getString(Config.ST_Within), geom1, geom2);
910
    }
911

    
912
    @Override
913
    public Function isNull(Value value) {
914
        return function("IS NULL", config.getString(Config.isNull), value);
915
    }
916

    
917
    @Override
918
    public Function notIsNull(Value value) {
919
        return function("NOT IS NULL", config.getString(Config.notIsNull), value);
920
    }
921

    
922
    @Override
923
    public Function not(Value value) {
924
        return function("NOT", config.getString(Config.operator_not), value);
925
    }
926

    
927
    @Override
928
    public Function lcase(Value s) {
929
        return function("LCASE", config.getString(Config.lcase), s);
930
    }
931

    
932
    @Override
933
    public Function ucase(Value s) {
934
        return function("UCASE", config.getString(Config.ucase), s);
935
    }
936

    
937

    
938
    @Override
939
    public BinaryOperator and(Value leftOperand, Value rightOperand) {
940
        return binaryOperator("AND", config.getString(Config.operator_AND), leftOperand, rightOperand);
941
    }
942

    
943
    @Override
944
    public BinaryOperator or(Value leftOperand, Value rightOperand) {
945
        return binaryOperator("OR", config.getString(Config.operator_OR), leftOperand, rightOperand);
946
    }
947

    
948
    @Override
949
    public BinaryOperator eq(Value leftOperand, Value rightOperand) {
950
        return binaryOperator("=", config.getString(Config.operator_EQ), leftOperand, rightOperand);
951
    }
952
    
953
    @Override
954
    public BinaryOperator ne(Value leftOperand, Value rightOperand) {
955
        return binaryOperator("<>", config.getString(Config.operator_NE), leftOperand, rightOperand);
956
    }    
957

    
958
    @Override
959
    public BinaryOperator gt(Value op1, Value op2) {
960
        return binaryOperator(">", config.getString(Config.operator_GT), op1, op2);
961
    }
962

    
963
    @Override
964
    public BinaryOperator ge(Value op1, Value op2) {
965
        return binaryOperator(">=", config.getString(Config.operator_GE), op1, op2);
966
    }
967

    
968
    @Override
969
    public BinaryOperator lt(Value op1, Value op2) {
970
        return binaryOperator("<", config.getString(Config.operator_LT), op1, op2);
971
    }
972

    
973
    @Override
974
    public BinaryOperator le(Value op1, Value op2) {
975
        return binaryOperator("<=", config.getString(Config.operator_LE), op1, op2);
976
    }
977

    
978
    @Override
979
    public BinaryOperator like(Value op1, Value op2) {
980
        return binaryOperator("LIKE", config.getString(Config.operator_LIKE), op1, op2);
981
    }
982

    
983
    @Override
984
    public BinaryOperator ilike(Value op1, Value op2) {
985
        return binaryOperator("ILIKE", config.getString(Config.operator_ILIKE), op1, op2);
986
    }
987

    
988
    @Override
989
    public BinaryOperator add(Value op1, Value op2) {
990
        return binaryOperator("ADD", config.getString(Config.operator_add), op1, op2);
991
    }
992

    
993
    @Override
994
    public BinaryOperator subst(Value op1, Value op2) {
995
        return binaryOperator("SUBST", config.getString(Config.operator_subst), op1, op2);
996
    }
997

    
998
    @Override
999
    public BinaryOperator mult(Value op1, Value op2) {
1000
        return binaryOperator("MULT", config.getString(Config.operator_mult), op1, op2);
1001
    }
1002

    
1003
    @Override
1004
    public BinaryOperator div(Value op1, Value op2) {
1005
        return binaryOperator("DIV", config.getString(Config.operator_div), op1, op2);
1006
    }
1007

    
1008
    @Override
1009
    public BinaryOperator concat(Value op1, Value op2) {
1010
        return binaryOperator("CONCAT", config.getString(Config.operator_concat), op1, op2);
1011
    }
1012
    
1013
}