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 com.vividsolutions.jts.geom.Geometry;
19: import org.geotools.data.jdbc.DefaultSQLBuilder;
20: import org.geotools.data.jdbc.fidmapper.FIDMapper;
21: import org.geotools.feature.AttributeType;
22: import org.geotools.feature.FeatureType;
23: import org.geotools.filter.SQLEncoder;
24:
25: /**
26: * A HSQL-specific instance of DefaultSQLBuilder, which supports MySQL 4.1's
27: * geometric datatypes.
28: *
29: * @author Amr Alam, Refractions Research
30: * @author Gary Sheppard garysheppard@psu.edu
31: * @author Andrea Aime aaime@users.sourceforge.net
32: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/hsql/src/main/java/org/geotools/data/hsql/HsqlSQLBuilder.java $
33: */
34: public class HsqlSQLBuilder extends DefaultSQLBuilder {
35:
36: /**
37: * @deprecated use HsqlSQLBuilder(encoder, ft)
38: * @param encoder
39: */
40: public HsqlSQLBuilder(SQLEncoder encoder) {
41: super (encoder);
42: }
43:
44: public HsqlSQLBuilder(SQLEncoder encoder, FeatureType ft) {
45: super (encoder, ft, null);
46: }
47:
48: /**
49: * Produces the select information required.
50: *
51: * <p>
52: * The featureType, if known, is always requested.
53: * </p>
54: *
55: * <p>
56: * sql: <code>featureID (,attributeColumn)</code>
57: * </p>
58: *
59: * <p>
60: * We may need to provide AttributeReaders with a hook so they can request
61: * a wrapper function.
62: * </p>
63: *
64: * @param sql
65: * @param mapper
66: * @param attributes
67: */
68: public void sqlColumns(StringBuffer sql, FIDMapper mapper,
69: AttributeType[] attributes) {
70: for (int i = 0; i < mapper.getColumnCount(); i++) {
71: sql.append(mapper.getColumnName(i));
72:
73: if ((attributes.length > 0)
74: || (i < (mapper.getColumnCount() - 1))) {
75: sql.append(", ");
76: }
77: }
78:
79: for (int i = 0; i < attributes.length; i++) {
80: String colName = attributes[i].getName();
81:
82: //if (attributes[i].isGeometry()) {
83: if (Geometry.class
84: .isAssignableFrom(attributes[i].getType())) {
85: //Don't think we need this...geometries are stored as text in the DB
86: //sql.append("toText(" + attributes[i].getName() + ") AS " + attributes[i].getName());
87: sql.append(colName);
88: } else {
89: sql.append(colName);
90: }
91:
92: if (i < (attributes.length - 1)) {
93: sql.append(", ");
94: }
95: }
96: }
97: }
|