01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2005-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.data.hsql;
17:
18: import java.io.IOException;
19:
20: import org.geotools.data.FeatureReader;
21: import org.geotools.data.jdbc.JDBCTextFeatureWriter;
22: import org.geotools.data.jdbc.QueryData;
23:
24: import com.vividsolutions.jts.geom.Geometry;
25: import com.vividsolutions.jts.io.WKTWriter;
26:
27: /**
28: * Feature writer handling specific geometric function from HSQL
29: *
30: * This essentially adds the DB in a box wrappers around various HSQL
31: * queries make them work.
32: *
33: * @author Amr Alam, Refractions Research
34: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/hsql/src/main/java/org/geotools/data/hsql/HsqlFeatureWriter.java $
35: */
36: public class HsqlFeatureWriter extends JDBCTextFeatureWriter {
37: private static WKTWriter geometryWriter = new WKTWriter();
38:
39: /**
40: * Creates a new instance of HsqlFeatureWriter
41: *
42: * @param fReader
43: * @param queryData
44: * @throws IOException
45: */
46: public HsqlFeatureWriter(FeatureReader fReader, QueryData queryData)
47: throws IOException {
48: super (fReader, queryData);
49: }
50:
51: /**
52: * @see org.geotools.data.jdbc.JDBCTextFeatureWriter#getGeometryInsertText(com.vividsolutions.jts.geom.Geometry,
53: * int)
54: */
55: protected String getGeometryInsertText(Geometry geom, int srid) {
56: if (geom == null) {
57: return "NULL";
58: }
59:
60: String geoText = geometryWriter.write(geom);
61: String sql = null;
62:
63: //HSQL doesn't support spatial types, and we're using 'DB in a box'
64: //which only has the 'geometry' type
65: sql = "GeomFromWKT";
66: // if (GeometryCollection.class.isAssignableFrom(geom.getClass())) {
67: // if (MultiPoint.class.isAssignableFrom(geom.getClass())) {
68: // sql = "MultiPointFromText";
69: // } else if (MultiLineString.class.isAssignableFrom(geom.getClass())) {
70: // sql = "MultiLineStringFromText";
71: // } else if (MultiPolygon.class.isAssignableFrom(geom.getClass())) {
72: // sql = "MultiPolygonFromText";
73: // } else {
74: // sql = "GeometryCollectionFromText";
75: // }
76: // } else {
77: // if (Point.class.isAssignableFrom(geom.getClass())) {
78: // sql = "PointFromText";
79: // } else if (LineString.class.isAssignableFrom(geom.getClass())) {
80: // sql = "LineStringFromText";
81: // } else if (Polygon.class.isAssignableFrom(geom.getClass())) {
82: // sql = "PolygonFromText";
83: // } else {
84: // sql = "GeometryFromText";
85: // }
86: // }
87:
88: sql += ("('" + geoText + "')");
89:
90: return sql;
91: }
92: }
|