01: /*
02: * Geotools2 - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002, 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: */
17: package org.geotools.data.geometryless;
18:
19: import java.util.logging.Logger;
20:
21: // import org.geotools.data.jdbc.DefaultSQLBuilder;
22: import org.geotools.data.jdbc.GeoAPISQLBuilder;
23: import org.geotools.data.jdbc.fidmapper.FIDMapper;
24: import org.geotools.feature.AttributeType;
25: import org.geotools.feature.GeometryAttributeType; // import org.geotools.filter.SQLEncoder;
26: import org.geotools.data.jdbc.FilterToSQL;
27: import org.opengis.feature.type.Name;
28:
29: /**
30: * A Geometryless-specific instance of DefaultSQLBuilder, which supports geometries created form standard data types
31: * @author Rob Atkinson rob@socialchange.net.au
32: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/geometryless/src/main/java/org/geotools/data/geometryless/GeometrylessSQLBuilder.java $
33: */
34: public class GeometrylessSQLBuilder extends GeoAPISQLBuilder {
35:
36: /** The logger for the mysql module. */
37: private static final Logger LOGGER = org.geotools.util.logging.Logging
38: .getLogger("org.geotools.data.geometryless");
39:
40: public GeometrylessSQLBuilder(FilterToSQL encoder) {
41: super (encoder, null, null);
42:
43: }
44:
45: /**
46: * Produces the select information required.
47: *
48: * <p>
49: * The featureType, if known, is always requested.
50: * </p>
51: *
52: * <p>
53: * sql: <code>featureID (,attributeColumn)</code>
54: * </p>
55: *
56: * <p>
57: * We may need to provide AttributeReaders with a hook so they can request
58: * a wrapper function.
59: * </p>
60: *
61: * @param sql
62: * @param fidColumnName
63: * @param attributes
64: */
65: public void sqlColumns(StringBuffer sql, FIDMapper mapper,
66: AttributeType[] attributes) {
67:
68: for (int i = 0; i < mapper.getColumnCount(); i++) {
69: LOGGER.finest(mapper.getColumnName(i));
70: sql.append(mapper.getColumnName(i));
71: if (attributes.length > 0
72: || i < (mapper.getColumnCount() - 1)) {
73: sql.append(", ");
74: }
75: }
76:
77: for (int i = 0; i < attributes.length; i++) {
78: String colName = attributes[i].getLocalName();
79:
80: LOGGER.finest(colName + " isGeom: "
81: + (attributes[i] instanceof GeometryAttributeType));
82:
83: if (attributes[i] instanceof GeometryAttributeType) {
84: sql.append("AsText(" + colName + ") AS " + colName);
85: } else {
86: sql.append(colName);
87: }
88:
89: if (i < (attributes.length - 1)) {
90: sql.append(", ");
91: }
92: }
93: }
94:
95: }
|