001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package org.geotools.data.geometryless;
018:
019: import java.util.logging.Logger;
020:
021: //import org.geotools.data.jdbc.DefaultSQLBuilder;
022: import org.geotools.data.jdbc.GeoAPISQLBuilder;
023: import org.geotools.data.jdbc.fidmapper.FIDMapper;
024:
025: import org.geotools.feature.AttributeType;
026: import org.geotools.feature.GeometryAttributeType; // import org.geotools.filter.SQLEncoder;
027: import org.geotools.data.geometryless.filter.SQLEncoderBBOX;
028: import org.opengis.feature.type.Name;
029:
030: /**
031: * A an extension of DefaultSQLBuilder, which supports point geometries that
032: * are specified with x,y columns
033: *
034: * @author Chris Holmes, TOPP
035: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/geometryless/src/main/java/org/geotools/data/geometryless/BBOXSQLBuilder.java $
036: * @version $Id: BBOXSQLBuilder.java 27862 2007-11-12 19:51:19Z desruisseaux $
037: */
038: public class BBOXSQLBuilder extends GeoAPISQLBuilder {
039: /** The logger for the mysql module. */
040: private static final Logger LOGGER = org.geotools.util.logging.Logging
041: .getLogger("org.geotools.data.geometryless");
042: private String XMinColumnName = null;
043: private String YMinColumnName = null;
044: private String XMaxColumnName = null;
045: private String YMaxColumnName = null;
046:
047: public BBOXSQLBuilder(SQLEncoderBBOX encoder, String minx,
048: String miny, String maxx, String maxy) {
049: super (encoder, null, null);
050: this .XMinColumnName = minx;
051: this .YMinColumnName = miny;
052: this .XMaxColumnName = maxx;
053: this .YMaxColumnName = maxy;
054: }
055:
056: /**
057: * Produces the select information required.
058: *
059: * <p>
060: * The featureType, if known, is always requested.
061: * </p>
062: *
063: * <p>
064: * sql: <code>featureID (,attributeColumn)</code>
065: * </p>
066: *
067: * <p>
068: * We may need to provide AttributeReaders with a hook so they can request
069: * a wrapper function.
070: * </p>
071: *
072: * @param sql
073: * @param mapper
074: * @param attributes
075: */
076: public void sqlColumns(StringBuffer sql, FIDMapper mapper,
077: AttributeType[] attributes) {
078: for (int i = 0; i < mapper.getColumnCount(); i++) {
079: LOGGER.finest(mapper.getColumnName(i));
080: sql.append(mapper.getColumnName(i));
081:
082: if ((attributes.length > 0)
083: || (i < (mapper.getColumnCount() - 1))) {
084: sql.append(", ");
085: }
086: }
087:
088: for (int i = 0; i < attributes.length; i++) {
089: String colName = attributes[i].getName();
090:
091: LOGGER.finest(attributes[i].getName() + " isGeom: "
092: + (attributes[i] instanceof GeometryAttributeType));
093:
094: //Here we want the x and y columns to be requested.
095: if (attributes[i] instanceof GeometryAttributeType) {
096: sql.append(XMinColumnName + "," + YMinColumnName + ", "
097: + XMaxColumnName + ", " + YMaxColumnName);
098:
099: //"AsText(" + attributes[i].getName() + ") AS " + attributes[i].getName());
100: } else {
101: sql.append(colName);
102: }
103:
104: if (i < (attributes.length - 1)) {
105: sql.append(", ");
106: }
107: }
108: }
109: }
|