forked from geotools/geotools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
PostGISPSDialect.java
239 lines (194 loc) · 7.9 KB
/
PostGISPSDialect.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2002-2009, 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.postgis;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Map;
import org.geotools.factory.Hints;
import org.geotools.jdbc.ColumnMetadata;
import org.geotools.jdbc.JDBCDataStore;
import org.geotools.jdbc.PreparedFilterToSQL;
import org.geotools.jdbc.PreparedStatementSQLDialect;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.GeometryDescriptor;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jts.io.WKBWriter;
/**
*
*
* @source $URL$
*/
public class PostGISPSDialect extends PreparedStatementSQLDialect {
private PostGISDialect delegate;
public PostGISPSDialect(JDBCDataStore store, PostGISDialect delegate) {
super(store);
this.delegate = delegate;
}
@Override
public boolean includeTable(String schemaName, String tableName, Connection cx)
throws SQLException {
return delegate.includeTable(schemaName, tableName, cx);
}
public Envelope decodeGeometryEnvelope(ResultSet rs, int column,
Connection cx) throws SQLException, IOException {
return delegate.decodeGeometryEnvelope(rs, column, cx);
}
@Override
public Geometry decodeGeometryValue(GeometryDescriptor descriptor, ResultSet rs, int column,
GeometryFactory factory, Connection cx) throws IOException, SQLException {
return delegate.decodeGeometryValue(descriptor, rs, column, factory, cx);
}
public Geometry decodeGeometryValue(GeometryDescriptor descriptor,
ResultSet rs, String column, GeometryFactory factory, Connection cx)
throws IOException, SQLException {
return delegate
.decodeGeometryValue(descriptor, rs, column, factory, cx);
}
@Override
public void encodeGeometryColumn(GeometryDescriptor gatt, String prefix, int srid,
StringBuffer sql) {
delegate.encodeGeometryColumn(gatt, prefix, srid, sql);
}
@Override
public void encodeGeometryColumn(GeometryDescriptor gatt, String prefix,
int srid, Hints hints, StringBuffer sql) {
delegate.encodeGeometryColumn(gatt, prefix, srid, hints, sql);
}
public void encodeGeometryEnvelope(String tableName, String geometryColumn,
StringBuffer sql) {
delegate.encodeGeometryEnvelope(tableName, geometryColumn, sql);
}
public void encodePrimaryKey(String column, StringBuffer sql) {
delegate.encodePrimaryKey(column, sql);
}
public Integer getGeometrySRID(String schemaName, String tableName,
String columnName, Connection cx) throws SQLException {
return delegate.getGeometrySRID(schemaName, tableName, columnName, cx);
}
public String getGeometryTypeName(Integer type) {
return delegate.getGeometryTypeName(type);
}
public Class<?> getMapping(ResultSet columnMetaData, Connection cx)
throws SQLException {
return delegate.getMapping(columnMetaData, cx);
}
@Override
public boolean lookupGeneratedValuesPostInsert() {
return delegate.lookupGeneratedValuesPostInsert();
}
public Object getNextAutoGeneratedValue(String schemaName,
String tableName, String columnName, Connection cx)
throws SQLException {
return delegate.getNextAutoGeneratedValue(schemaName, tableName,
columnName, cx);
}
@Override
public Object getLastAutoGeneratedValue(String schemaName, String tableName, String columnName,
Connection cx) throws SQLException {
return delegate.getLastAutoGeneratedValue(schemaName, tableName, columnName, cx);
}
public Object getNextSequenceValue(String schemaName, String sequenceName,
Connection cx) throws SQLException {
return delegate.getNextSequenceValue(schemaName, sequenceName, cx);
}
public String getSequenceForColumn(String schemaName, String tableName,
String columnName, Connection cx) throws SQLException {
return delegate.getSequenceForColumn(schemaName, tableName, columnName,
cx);
}
public boolean isLooseBBOXEnabled() {
return delegate.isLooseBBOXEnabled();
}
public void postCreateTable(String schemaName,
SimpleFeatureType featureType, Connection cx) throws SQLException {
delegate.postCreateTable(schemaName, featureType, cx);
}
@Override
public void preDropTable(String schemaName, SimpleFeatureType featureType, Connection cx)
throws SQLException {
delegate.preDropTable(schemaName, featureType, cx);
}
@Override
public void postDropTable(String schemaName, SimpleFeatureType featureType, Connection cx)
throws SQLException {
delegate.postDropTable(schemaName, featureType, cx);
}
public void registerClassToSqlMappings(Map<Class<?>, Integer> mappings) {
delegate.registerClassToSqlMappings(mappings);
}
public void registerSqlTypeNameToClassMappings(
Map<String, Class<?>> mappings) {
delegate.registerSqlTypeNameToClassMappings(mappings);
}
@Override
public void registerSqlTypeToSqlTypeNameOverrides(
Map<Integer, String> overrides) {
delegate.registerSqlTypeToSqlTypeNameOverrides(overrides);
}
@Override
public void handleUserDefinedType(ResultSet columnMetaData, ColumnMetadata metadata,
Connection cx) throws SQLException {
delegate.handleUserDefinedType(columnMetaData, metadata, cx);
}
public void setLooseBBOXEnabled(boolean looseBBOXEnabled) {
delegate.setLooseBBOXEnabled(looseBBOXEnabled);
}
@Override
public void prepareGeometryValue(Geometry g, int srid, Class binding,
StringBuffer sql) {
if (g != null) {
sql.append("ST_GeomFromWKB(?, " + srid + ")");
} else {
sql.append("?");
}
}
@Override
public void setGeometryValue(Geometry g, int srid, Class binding,
PreparedStatement ps, int column) throws SQLException {
if (g != null && !g.isEmpty()) {
if (g instanceof LinearRing ) {
//postgis does not handle linear rings, convert to just a line string
g = g.getFactory().createLineString(((LinearRing) g).getCoordinateSequence());
}
byte[] bytes = new WKBWriter().write(g);
ps.setBytes(column, bytes);
} else {
ps.setNull(column, Types.OTHER, "Geometry");
}
}
@Override
public PreparedFilterToSQL createPreparedFilterToSQL() {
PostgisPSFilterToSql fts = new PostgisPSFilterToSql(this);
fts.setLooseBBOXEnabled(delegate.isLooseBBOXEnabled());
return fts;
}
@Override
public boolean isLimitOffsetSupported() {
return delegate.isLimitOffsetSupported();
}
@Override
public void applyLimitOffset(StringBuffer sql, int limit, int offset) {
delegate.applyLimitOffset(sql, limit, offset);
}
}