Revision 10727

View differences:

branches/v10/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGIS.java
2 2
 * Created on 26-oct-2005
3 3
 *
4 4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 * 
5
 *
6 6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 * 
7
 *
8 8
 * This program is free software; you can redistribute it and/or
9 9
 * modify it under the terms of the GNU General Public License
10 10
 * as published by the Free Software Foundation; either version 2
11 11
 * of the License, or (at your option) any later version.
12
 *  
12
 *
13 13
 * This program is distributed in the hope that it will be useful,
14 14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 16
 * GNU General Public License for more details.
17
 * 
17
 *
18 18
 * You should have received a copy of the GNU General Public License
19 19
 * along with this program; if not, write to the Free Software
20 20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
 *  
21
 *
22 22
 * For more information, contact:
23 23
 *
24 24
 *  Generalitat Valenciana
......
30 30
 *      +34 963862235
31 31
 *   gvsig@gva.es
32 32
 *      www.gvsig.gva.es
33
 * 
33
 *
34 34
 *    or
35
 * 
35
 *
36 36
 *   IVER T.I. S.A
37 37
 *   Salamanca 50
38 38
 *   46005 Valencia
39 39
 *   Spain
40
 * 
40
 *
41 41
 *   +34 963163400
42 42
 *   dac@iver.es
43 43
 */
......
66 66
public class PostGIS {
67 67

  
68 68
	private String toEncode;
69
	
69

  
70 70
	/**
71 71
	 * Mover esto a IverUtiles
72
	 * 
72
	 *
73 73
	 * @param val
74 74
	 * @return
75 75
	 */
......
93 93
	/**
94 94
	 * @param dbLayerDef
95 95
	 * @param fieldsDescr
96
	 * @param bCreateGID @DEPRECATED 
96
	 * @param bCreateGID @DEPRECATED
97 97
	 * @return
98 98
	 */
99 99
	public String getSqlCreateSpatialTable(DBLayerDefinition dbLayerDef,
......
123 123
			 */
124 124
			if (fieldsDescr[i].getFieldName().equalsIgnoreCase("gid"))
125 125
				continue;
126
			
126

  
127 127
			resul = resul + ", " + dbLayerDef.getFieldNames()[i] + " "	+ strType;
128 128
			j++;
129 129
		}
......
165 165
	 * should be a string or a number. To perform an insert strings need quotes
166 166
	 * around them, and numbers work fine with quotes, so this method can be
167 167
	 * called on unknown objects.
168
	 * 
168
	 *
169 169
	 * @param value
170 170
	 *            The object to add quotes to.
171
	 * 
171
	 *
172 172
	 * @return a string representation of the object with quotes.
173 173
	 */
174 174
	protected String addQuotes(Object value) {
......
179 179
				retString = "null";
180 180
			else
181 181
				retString = "'" + doubleQuote(value) + "'";
182
			
182

  
183 183
		} else {
184 184
			retString = "null";
185 185
		}
......
209 209
	 * Based in code from JUMP (VividSolutions) and Geotools Things to be aware:
210 210
	 * We always will use Spatial Tables with Unique ID. IFeature has the same
211 211
	 * field order than dbLayerDef.getFieldNames()
212
	 * 
212
	 *
213 213
	 * @param dbLayerDef
214 214
	 * @param feat
215 215
	 * @return
......
245 245
			else
246 246
				sqlBuf.append(addQuotes(feat.getAttribute(j)) + ", ");
247 247
		}
248
				
248

  
249 249
		sqlBuf.append(" GeometryFromText( '"
250 250
				+ feat.getGeometry().toJTSGeometry().toText() + "', "
251 251
				+ dbLayerDef.getSRID_EPSG() + ")");
......
267 267
	}
268 268

  
269 269
	public String getSqlModifyFeature(DBLayerDefinition dbLayerDef, IFeature feat) {
270
		/* 
270
		/*
271 271
		 	UPDATE weather
272 272
		 	SET temp_hi = temp_hi - 2,  temp_lo = temp_lo - 2
273 273
		 	WHERE date > '1994-11-28';
......
296 296
		sqlBuf.deleteCharAt(sqlBuf.lastIndexOf(","));
297 297
		if (feat.getGeometry() != null)
298 298
		{
299
			sqlBuf.append(", " + dbLayerDef.getFieldGeometry());		
299
			sqlBuf.append(", " + dbLayerDef.getFieldGeometry());
300 300
			sqlBuf.append(" = ");
301 301
			sqlBuf.append(" GeometryFromText( '"
302 302
				+ feat.getGeometry().toJTSGeometry().toText() + "', "
......
311 311

  
312 312
	/**
313 313
	 * TODO: NECESITAMOS OTRO M?TODO PARA BORRAR CORRECTAMENTE.
314
	 *	 Esto provocar? errores, ya que getID que viene en un row no 
314
	 *	 Esto provocar? errores, ya que getID que viene en un row no
315 315
	 *	 nos sirve dentro de un writer para modificar y/o borrar entidades
316 316
	 *	 Por ahora, cojo el ID del campo que me indica el dbLayerDef
317 317
	 * @param dbLayerDef
......
321 321
	public String getSqlDeleteFeature(DBLayerDefinition dbLayerDef, IRow row) {
322 322
		// DELETE FROM weather WHERE city = 'Hayward';
323 323
		// TODO: NECESITAMOS OTRO M?TODO PARA BORRAR CORRECTAMENTE.
324
		// Esto provocar? errores, ya que getID que viene en un row no 
324
		// Esto provocar? errores, ya que getID que viene en un row no
325 325
		// nos sirve dentro de un writer para modificar y/o borrar entidades
326 326
		// Por ahora, cojo el ID del campo que me indica el dbLayerDev
327 327
		StringBuffer sqlBuf = new StringBuffer("DELETE FROM "
......
337 337
	public String getEncoding() {
338 338
		return toEncode;
339 339
	}
340
	public void setEncoding(String toEncode)
341
	{
342
		this.toEncode = toEncode;
340
	public void setEncoding(String toEncode){
341
		if (toEncode.compareToIgnoreCase("SQL_ASCII") == 0){
342
		   this.toEncode = "ASCII";
343
		  } else {
344
			  this.toEncode = toEncode;
345
		  }
343 346
	}
344 347

  
345 348
}

Also available in: Unified diff