001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) Copyright IBM Corporation, 2005-2006. All rights reserved.
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.db2;
018:
019: import com.vividsolutions.jts.geom.Geometry;
020:
021: import org.geotools.data.FeatureReader;
022: import org.geotools.data.jdbc.FeatureTypeInfo;
023: import org.geotools.data.jdbc.JDBCTextFeatureWriter;
024: import org.geotools.data.jdbc.QueryData;
025: import org.geotools.feature.AttributeType;
026: import org.geotools.feature.Feature;
027: import org.geotools.feature.FeatureType;
028:
029: import java.io.IOException;
030:
031: import java.util.logging.Logger;
032:
033: /**
034: * DOCUMENT ME!
035: *
036: * @author David Adler - IBM Corporation
037: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/db2/src/main/java/org/geotools/data/db2/DB2FeatureWriter.java $
038: */
039: public class DB2FeatureWriter extends JDBCTextFeatureWriter {
040: private DB2SQLBuilder sqlBuilder;
041:
042: private static final Logger LOGGER = org.geotools.util.logging.Logging
043: .getLogger("org.geotools.data.db2");
044:
045: /**
046: * DOCUMENT ME!
047: *
048: * @param reader
049: * @param queryData
050: * @param sqlBuilder
051: * DOCUMENT ME!
052: *
053: * @throws IOException
054: */
055: public DB2FeatureWriter(FeatureReader reader, QueryData queryData,
056: DB2SQLBuilder sqlBuilder) throws IOException {
057: super (reader, queryData);
058: this .sqlBuilder = sqlBuilder;
059: }
060:
061: /**
062: * Generates the SQL delete statement
063: *
064: * @param feature
065: *
066: * @return DB2 DELETE statement
067: *
068: * @throws IOException
069: * @throws UnsupportedOperationException
070: */
071: protected String makeDeleteSql(Feature feature) throws IOException {
072: String deleteSQL = this .sqlBuilder.makeDeleteSql(feature);
073: return (deleteSQL);
074: }
075:
076: /**
077: * Generates the SQL UPDATE statement.
078: *
079: * @param feature the feature to insert.
080: *
081: * @return DB2 INSERT statement
082: *
083: * @throws IOException
084: */
085: protected String makeInsertSql(Feature feature) throws IOException {
086: FeatureTypeInfo ftInfo = queryData.getFeatureTypeInfo();
087: FeatureType featureType = ftInfo.getSchema();
088: AttributeType[] attributes = featureType.getAttributeTypes();
089: String insertSQL = this .sqlBuilder.makeInsertSql(attributes,
090: feature);
091: return (insertSQL);
092: }
093:
094: /**
095: * Generates the SQL UPDATE statement
096: *
097: * @param feature
098: *
099: * @return DB2 UPDATE statement
100: *
101: * @throws IOException
102: * @throws UnsupportedOperationException
103: */
104: protected String makeUpdateSql(Feature live, Feature current)
105: throws IOException {
106: FeatureTypeInfo ftInfo = queryData.getFeatureTypeInfo();
107: FeatureType featureType = ftInfo.getSchema();
108: AttributeType[] attributes = featureType.getAttributeTypes();
109:
110: String updateSQL = this .sqlBuilder.makeUpdateSql(attributes,
111: live, current);
112:
113: return (updateSQL);
114: }
115:
116: /* (non-Javadoc)
117: * This isn't actually used but must be provided because it is defined as abstract in the
118: * parent hierarchy.
119: * @see org.geotools.data.jdbc.JDBCTextFeatureWriter#getGeometryInsertText(com.vividsolutions.jts.geom.Geometry, int)
120: */
121: protected String getGeometryInsertText(Geometry geom, int srid)
122: throws IOException {
123:
124: return null;
125: }
126:
127: }
|