forked from geotools/geotools
/
RecnoFilterToSQL.java
78 lines (71 loc) · 2.45 KB
/
RecnoFilterToSQL.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2002-2015, Open Source Geospatial Foundation (OSGeo)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
package org.geotools.data.shapefile;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import org.geotools.data.jdbc.FilterToSQL;
import org.geotools.filter.FilterCapabilities;
/**
* Encodes a filter into a SQL WHERE statement for the JDBC providers used with the optional RECNO field index.
*
* @author Alvaro Huarte - Tracasa / ahuarte@tracasa.es
*/
public class RecnoFilterToSQL extends FilterToSQL
{
public RecnoFilterToSQL(FilterCapabilities filterCapabilities)
{
this.filterCapabilities = filterCapabilities;
}
@Override
protected FilterCapabilities createFilterCapabilities()
{
FilterCapabilities caps = new FilterCapabilities();
caps.addAll(filterCapabilities);
return caps;
}
private FilterCapabilities filterCapabilities;
static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
static {
// Set DATE_FORMAT time zone to GMT, as Date's are always in GMT internaly. Otherwise we'll
// get a local timezone encoding regardless of the actual Date value
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
}
static SimpleDateFormat DATETIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Override
protected void writeLiteral(Object literal) throws IOException
{
if (literal instanceof Date)
{
out.write("'");
if (literal instanceof java.sql.Date)
{
out.write(DATE_FORMAT.format(literal));
}
else
{
out.write(DATETIME_FORMAT.format(literal));
}
out.write("'");
}
else
{
super.writeLiteral(literal);
}
}
}