root / trunk / libraries / libFMap_dataDB / src / org / gvsig / data / datastores / vectorial / db / sde / SDEFeaturesWriter.java @ 20802
History | View | Annotate | Download (25.4 KB)
1 |
|
---|---|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program 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
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* Generalitat Valenciana
|
23 |
* Conselleria d'Infraestructures i Transport
|
24 |
* Av. Blasco Ib??ez, 50
|
25 |
* 46010 VALENCIA
|
26 |
* SPAIN
|
27 |
*
|
28 |
* +34 963862235
|
29 |
* gvsig@gva.es
|
30 |
* www.gvsig.gva.es
|
31 |
*
|
32 |
* or
|
33 |
*
|
34 |
* IVER T.I. S.A
|
35 |
* Salamanca 50
|
36 |
* 46005 Valencia
|
37 |
* Spain
|
38 |
*
|
39 |
* +34 963163400
|
40 |
* dac@iver.es
|
41 |
*/
|
42 |
|
43 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
44 |
*
|
45 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
46 |
*
|
47 |
* This program is free software; you can redistribute it and/or
|
48 |
* modify it under the terms of the GNU General Public License
|
49 |
* as published by the Free Software Foundation; either version 2
|
50 |
* of the License, or (at your option) any later version.
|
51 |
*
|
52 |
* This program is distributed in the hope that it will be useful,
|
53 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
54 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
55 |
* GNU General Public License for more details.
|
56 |
*
|
57 |
* You should have received a copy of the GNU General Public License
|
58 |
* along with this program; if not, write to the Free Software
|
59 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
60 |
*
|
61 |
* For more information, contact:
|
62 |
*
|
63 |
* Generalitat Valenciana
|
64 |
* Conselleria d'Infraestructures i Transport
|
65 |
* Av. Blasco Ib??ez, 50
|
66 |
* 46010 VALENCIA
|
67 |
* SPAIN
|
68 |
*
|
69 |
* +34 963862235
|
70 |
* gvsig@gva.es
|
71 |
* www.gvsig.gva.es
|
72 |
*
|
73 |
* or
|
74 |
*
|
75 |
* IVER T.I. S.A
|
76 |
* Salamanca 50
|
77 |
* 46005 Valencia
|
78 |
* Spain
|
79 |
*
|
80 |
* +34 963163400
|
81 |
* dac@iver.es
|
82 |
*/
|
83 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
84 |
*
|
85 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
86 |
*
|
87 |
* This program is free software; you can redistribute it and/or
|
88 |
* modify it under the terms of the GNU General Public License
|
89 |
* as published by the Free Software Foundation; either version 2
|
90 |
* of the License, or (at your option) any later version.
|
91 |
*
|
92 |
* This program is distributed in the hope that it will be useful,
|
93 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
94 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
95 |
* GNU General Public License for more details.
|
96 |
*
|
97 |
* You should have received a copy of the GNU General Public License
|
98 |
* along with this program; if not, write to the Free Software
|
99 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
100 |
*
|
101 |
* For more information, contact:
|
102 |
*
|
103 |
* Generalitat Valenciana
|
104 |
* Conselleria d'Infraestructures i Transport
|
105 |
* Av. Blasco Ib??ez, 50
|
106 |
* 46010 VALENCIA
|
107 |
* SPAIN
|
108 |
*
|
109 |
* +34 963862235
|
110 |
* gvsig@gva.es
|
111 |
* www.gvsig.gva.es
|
112 |
*
|
113 |
* or
|
114 |
*
|
115 |
* IVER T.I. S.A
|
116 |
* Salamanca 50
|
117 |
* 46005 Valencia
|
118 |
* Spain
|
119 |
*
|
120 |
* +34 963163400
|
121 |
* dac@iver.es
|
122 |
*/
|
123 |
package org.gvsig.data.datastores.vectorial.db.sde; |
124 |
|
125 |
import java.awt.geom.PathIterator; |
126 |
import java.awt.geom.Point2D; |
127 |
import java.util.ArrayList; |
128 |
import java.util.Date; |
129 |
import java.util.Iterator; |
130 |
|
131 |
import org.gvsig.data.IDataStoreParameters; |
132 |
import org.gvsig.data.datastores.vectorial.ISelectiveWriter; |
133 |
import org.gvsig.data.datastores.vectorial.db.DBAttributeDescriptor; |
134 |
import org.gvsig.data.datastores.vectorial.db.DBFeatureType; |
135 |
import org.gvsig.data.exception.CloseException; |
136 |
import org.gvsig.data.exception.DataException; |
137 |
import org.gvsig.data.exception.InitializeException; |
138 |
import org.gvsig.data.exception.InitializeWriterException; |
139 |
import org.gvsig.data.exception.OpenException; |
140 |
import org.gvsig.data.exception.ReadException; |
141 |
import org.gvsig.data.exception.WriteException; |
142 |
import org.gvsig.data.vectorial.IFeature; |
143 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
144 |
import org.gvsig.data.vectorial.IFeatureStore; |
145 |
import org.gvsig.data.vectorial.IFeatureType; |
146 |
import org.gvsig.data.vectorial.INewFeatureStoreParameters; |
147 |
|
148 |
import com.esri.sde.sdk.client.SDEPoint; |
149 |
import com.esri.sde.sdk.client.SeColumnDefinition; |
150 |
import com.esri.sde.sdk.client.SeConnection; |
151 |
import com.esri.sde.sdk.client.SeCoordinateReference; |
152 |
import com.esri.sde.sdk.client.SeDelete; |
153 |
import com.esri.sde.sdk.client.SeException; |
154 |
import com.esri.sde.sdk.client.SeInsert; |
155 |
import com.esri.sde.sdk.client.SeLayer; |
156 |
import com.esri.sde.sdk.client.SeRegisteredColumn; |
157 |
import com.esri.sde.sdk.client.SeRow; |
158 |
import com.esri.sde.sdk.client.SeShape; |
159 |
import com.esri.sde.sdk.client.SeTable; |
160 |
import com.esri.sde.sdk.client.SeUpdate; |
161 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
162 |
import com.iver.cit.gvsig.fmap.core.FShape; |
163 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
164 |
|
165 |
|
166 |
/**
|
167 |
* DOCUMENT ME!
|
168 |
*
|
169 |
* @author Vicente Caballero Navarro
|
170 |
*/
|
171 |
class SDEFeaturesWriter implements ISelectiveWriter { |
172 |
DBFeatureType featureType; |
173 |
boolean bCreateTable = false; |
174 |
SDEStoreParameters parameters; |
175 |
|
176 |
protected SeConnection conex;
|
177 |
protected SDEStore store;
|
178 |
protected boolean previousAutocommit; |
179 |
|
180 |
|
181 |
public void postProcess() throws OpenException, WriteException { |
182 |
try {
|
183 |
conex.commitTransaction(); |
184 |
} catch (SeException e) {
|
185 |
throw new WriteException(this.store.getName(),e); |
186 |
} |
187 |
} |
188 |
|
189 |
public void cancelProcess() throws WriteException { |
190 |
try {
|
191 |
conex.rollbackTransaction(); |
192 |
} catch (SeException e) {
|
193 |
throw new WriteException(this.store.getName(),e); |
194 |
} |
195 |
} |
196 |
|
197 |
|
198 |
|
199 |
SDEFeaturesWriter() { |
200 |
} |
201 |
|
202 |
/* (non-Javadoc)
|
203 |
* @see org.gvsig.data.datastores.vectorial.IFeaturesWriter#init(org.gvsig.data.vectorial.IFeatureStore)
|
204 |
*/
|
205 |
public void init(IFeatureStore store) throws InitializeWriterException { |
206 |
this.store = (SDEStore)store;
|
207 |
try {
|
208 |
this.conex = this.store.getWriterConnection(); |
209 |
} catch (ReadException e) {
|
210 |
throw new InitializeWriterException(this.getClass().getName(),e); |
211 |
} |
212 |
|
213 |
SDEStore sdeStore = (SDEStore) store; |
214 |
this.parameters = sdeStore.getParametersSDE();
|
215 |
this.featureType = (DBFeatureType) this.store.getDefaultFeatureType(); |
216 |
} |
217 |
|
218 |
/* (non-Javadoc)
|
219 |
* @see org.gvsig.data.datastores.vectorial.IFeaturesWriter#preProcess()
|
220 |
*/
|
221 |
public void preProcess() throws WriteException, ReadException { |
222 |
try {
|
223 |
conex.startTransaction(); |
224 |
} catch (SeException e) {
|
225 |
throw new WriteException(this.store.getName(),e); |
226 |
} |
227 |
|
228 |
if (bCreateTable) {
|
229 |
SDEExplorer explorer = (SDEExplorer) this.store.getExplorer();
|
230 |
|
231 |
IDataStoreParameters params = this.store.getParameters();
|
232 |
explorer.remove(params, conex); |
233 |
|
234 |
INewFeatureStoreParameters newParam = (INewFeatureStoreParameters) explorer.createNewDataStoreParameter(); |
235 |
|
236 |
newParam.setFeatureType(this.featureType);
|
237 |
explorer.add(newParam, conex); |
238 |
} |
239 |
} |
240 |
|
241 |
/* (non-Javadoc)
|
242 |
* @see org.gvsig.data.datastores.vectorial.ISelectiveWriter#deleteFeature(org.gvsig.data.vectorial.IFeature)
|
243 |
*/
|
244 |
public void deleteFeature(IFeature feature) throws WriteException { |
245 |
try {
|
246 |
SeDelete delete = new SeDelete(conex);
|
247 |
String id = getFliterForIDForPStatement(featureType);
|
248 |
String where = id + " = '" + feature.get(id) + "'"; |
249 |
delete.fromTable(featureType.getTableID(),where); |
250 |
delete.close(); |
251 |
} catch (SeException e) {
|
252 |
throw new WriteException(this.store.getName(), e); |
253 |
} |
254 |
} |
255 |
|
256 |
/* (non-Javadoc)
|
257 |
* @see org.gvsig.data.datastores.vectorial.IFeaturesWriter#insertFeature(org.gvsig.data.vectorial.IFeature)
|
258 |
*/
|
259 |
public void insertFeature(IFeature feature) throws WriteException { |
260 |
try {
|
261 |
SeLayer lay = null;
|
262 |
|
263 |
for (int i = 0; i < conex.getLayers().size(); i++) { |
264 |
SeLayer selay = (SeLayer) conex.getLayers().elementAt(i); |
265 |
|
266 |
if (featureType.getTableID().toLowerCase().endsWith(selay.getName().toLowerCase())) {
|
267 |
lay = (SeLayer) conex.getLayers().elementAt(i); |
268 |
break;
|
269 |
} |
270 |
} |
271 |
SeInsert insert = new SeInsert(conex);
|
272 |
String[] names=featureType.getFields(); |
273 |
String[] newNames=new String[names.length-1]; |
274 |
int j=0; |
275 |
for (int i=0;i<names.length;i++){ |
276 |
if (!names[i].equals(featureType.getFieldsId()[0])){ |
277 |
newNames[j]=names[i]; |
278 |
j++; |
279 |
} |
280 |
} |
281 |
insert.intoTable(lay.getName(),newNames); |
282 |
insert.setWriteMode(true);
|
283 |
SeRow row = insert.getRowToSet(); |
284 |
Iterator iterator = featureType.iterator();
|
285 |
int jObjectID=0; |
286 |
while (iterator.hasNext()) {
|
287 |
IFeatureAttributeDescriptor fad = (IFeatureAttributeDescriptor) iterator.next(); |
288 |
if (fad.getName().equals(featureType.getFieldsId()[0])){ |
289 |
jObjectID++; |
290 |
continue;
|
291 |
} |
292 |
Object value=feature.get(fad.ordinal());
|
293 |
|
294 |
if (fad.getDataType() == IFeatureAttributeDescriptor.TYPE_GEOMETRY) {
|
295 |
IGeometry geom = (IGeometry) feature.get(fad.ordinal()); |
296 |
writeGeometry(geom, row, lay, fad.ordinal()-jObjectID); |
297 |
} else if (fad.getDataType() == IFeatureAttributeDescriptor.TYPE_STRING) { |
298 |
if (value==null){ |
299 |
value="";
|
300 |
} |
301 |
row.setString(fad.ordinal()-jObjectID, |
302 |
(String)value);
|
303 |
} else if (fad.getDataType() == IFeatureAttributeDescriptor.TYPE_INT) { |
304 |
if (value==null){ |
305 |
value=new Integer(0); |
306 |
} |
307 |
row.setInteger(fad.ordinal()-jObjectID, |
308 |
(Integer)value);
|
309 |
} else if (fad.getDataType() == IFeatureAttributeDescriptor.TYPE_LONG) { |
310 |
if (value==null){ |
311 |
value=new Long(0); |
312 |
} |
313 |
row.setLong(fad.ordinal()-jObjectID, (Long) value);
|
314 |
} else if (fad.getDataType() == IFeatureAttributeDescriptor.TYPE_FLOAT) { |
315 |
if (value==null){ |
316 |
value=new Float(0); |
317 |
} |
318 |
row.setFloat(fad.ordinal()-jObjectID, |
319 |
(Float) value);
|
320 |
} else if (fad.getDataType() == IFeatureAttributeDescriptor.TYPE_DOUBLE) { |
321 |
if (value==null){ |
322 |
value=new Double(0); |
323 |
} |
324 |
row.setDouble(fad.ordinal()-jObjectID, |
325 |
(Double) value);
|
326 |
} else if (fad.getDataType() == IFeatureAttributeDescriptor.TYPE_DATE) { |
327 |
if (value==null){ |
328 |
value=new Date(); |
329 |
} |
330 |
row.setDate(fad.ordinal()-jObjectID, (Date) value);
|
331 |
} else if (fad.getDataType() == IFeatureAttributeDescriptor.TYPE_BOOLEAN) { |
332 |
boolean b = false; |
333 |
if (value==null){ |
334 |
b=false;
|
335 |
}else{
|
336 |
b = feature.getBoolean(fad.ordinal()); |
337 |
} |
338 |
if (b) {
|
339 |
row.setInteger(fad.ordinal()-jObjectID, new Integer(1)); |
340 |
} else {
|
341 |
row.setInteger(fad.ordinal()-jObjectID, new Integer(0)); |
342 |
} |
343 |
} |
344 |
} |
345 |
|
346 |
insert.execute(); |
347 |
insert.close(); |
348 |
} catch (SeException e) {
|
349 |
throw new WriteException(this.getClass().getName(), e); |
350 |
} |
351 |
} |
352 |
|
353 |
/**
|
354 |
* DOCUMENT ME!
|
355 |
*
|
356 |
* @param geom DOCUMENT ME!
|
357 |
* @param row DOCUMENT ME!
|
358 |
* @param lay DOCUMENT ME!
|
359 |
* @param ordinal DOCUMENT ME!
|
360 |
*
|
361 |
* @throws SeException DOCUMENT ME!
|
362 |
*/
|
363 |
private void writeGeometry(IGeometry geom, SeRow row, SeLayer lay, |
364 |
int ordinal) throws SeException { |
365 |
SeCoordinateReference scr = lay.getCoordRef(); |
366 |
if (geom==null || geom.getGeometryType()==0){ |
367 |
SeShape exp = new SeShape(scr);
|
368 |
exp.makeNil(); |
369 |
row.setShape(ordinal,exp); |
370 |
}else if (geom.getGeometryType() == FShape.POINT) { |
371 |
SeShape exp = new SeShape(scr);
|
372 |
SDEPoint[] vec = new SDEPoint[1]; |
373 |
FPoint2D point = (FPoint2D) geom.getInternalShape(); |
374 |
SDEPoint sdv = new SDEPoint(point.getX(), point.getY());
|
375 |
vec[0] = sdv;
|
376 |
exp.generatePoint(1, vec);
|
377 |
row.setShape(ordinal, exp); |
378 |
} else if ((geom.getGeometryType() == FShape.LINE) || |
379 |
(geom.getGeometryType() == FShape.POLYGON)) { |
380 |
ArrayList points = null; |
381 |
ArrayList partsOffset = null; |
382 |
PathIterator theIterator = geom.getPathIterator(null); |
383 |
int theType;
|
384 |
int numParts = 0; |
385 |
|
386 |
// Use this array to store segment coordinate data
|
387 |
double[] theData = new double[6]; |
388 |
while (!theIterator.isDone()) {
|
389 |
//while not done
|
390 |
theType = theIterator.currentSegment(theData); |
391 |
|
392 |
//Populate a segment of the new
|
393 |
// GeneralPathX object.
|
394 |
//Process the current segment to populate a new
|
395 |
// segment of the new GeneralPathX object.
|
396 |
switch (theType) {
|
397 |
case PathIterator.SEG_MOVETO: |
398 |
if (points == null) { |
399 |
points = new ArrayList(); |
400 |
} |
401 |
partsOffset.add(new Integer(points.size())); |
402 |
numParts++; |
403 |
points.add(new Point2D.Double(theData[0], theData[1])); |
404 |
|
405 |
break;
|
406 |
|
407 |
case PathIterator.SEG_LINETO: |
408 |
points.add(new Point2D.Double(theData[0], theData[1])); |
409 |
|
410 |
break;
|
411 |
|
412 |
case PathIterator.SEG_QUADTO: |
413 |
System.out.println("Not supported here"); |
414 |
|
415 |
break;
|
416 |
|
417 |
case PathIterator.SEG_CUBICTO: |
418 |
System.out.println("Not supported here"); |
419 |
|
420 |
break;
|
421 |
|
422 |
case PathIterator.SEG_CLOSE: |
423 |
|
424 |
// A?adimos el primer punto para cerrar.
|
425 |
Point2D firstPoint = (Point2D) points.get(0); |
426 |
points.add(new Point2D.Double(firstPoint.getX(), |
427 |
firstPoint.getY())); |
428 |
|
429 |
break;
|
430 |
} //end switch
|
431 |
|
432 |
theIterator.next(); |
433 |
} //end while loop
|
434 |
|
435 |
SDEPoint[] vec = new SDEPoint[points.size()]; |
436 |
|
437 |
for (int i = 0; i < vec.length; i++) { |
438 |
Point2D p = (Point2D) points.get(i); |
439 |
vec[i] = new SDEPoint(p.getX(), p.getY());
|
440 |
} |
441 |
|
442 |
int[] offsetParts = new int[partsOffset.size()]; |
443 |
|
444 |
for (int i = 0; i < offsetParts.length; i++) { |
445 |
offsetParts[i] = ((Integer) partsOffset.get(i)).intValue();
|
446 |
} |
447 |
|
448 |
SeShape exp = new SeShape(scr);
|
449 |
|
450 |
if (geom.getGeometryType() == FShape.LINE) {
|
451 |
exp.generateLine(vec.length, offsetParts.length, offsetParts, |
452 |
vec); |
453 |
} else if (geom.getGeometryType() == FShape.POLYGON) { |
454 |
exp.generatePolygon(vec.length, offsetParts.length, |
455 |
offsetParts, vec); |
456 |
} |
457 |
|
458 |
row.setShape(ordinal, exp); |
459 |
} |
460 |
} |
461 |
|
462 |
/* (non-Javadoc)
|
463 |
* @see org.gvsig.data.datastores.vectorial.IFeaturesWriter#updateFeatureType(org.gvsig.data.vectorial.IFeatureType)
|
464 |
*/
|
465 |
public void updateFeatureType(IFeatureType featureType) { |
466 |
this.featureType = (DBFeatureType) featureType;
|
467 |
} |
468 |
|
469 |
/**
|
470 |
* DOCUMENT ME!
|
471 |
*
|
472 |
* @param createTable The bCreateTable to set.
|
473 |
*/
|
474 |
public void setCreateTable(boolean createTable) { |
475 |
bCreateTable = createTable; |
476 |
} |
477 |
|
478 |
/* (non-Javadoc)
|
479 |
* @see org.gvsig.data.datastores.vectorial.ISelectiveWriter#updateFeature(org.gvsig.data.vectorial.IFeature, org.gvsig.data.vectorial.IFeature)
|
480 |
*/
|
481 |
public void updateFeature(IFeature oldFeature, IFeature feature) |
482 |
throws WriteException, ReadException {
|
483 |
try {
|
484 |
SeLayer lay = null;
|
485 |
|
486 |
for (int i = 0; i < conex.getLayers().size(); i++) { |
487 |
SeLayer selay = (SeLayer) conex.getLayers().elementAt(i); |
488 |
|
489 |
if (featureType.getTableID().toLowerCase().endsWith(selay.getName().toLowerCase())) {
|
490 |
lay = (SeLayer) conex.getLayers().elementAt(i); |
491 |
} |
492 |
} |
493 |
String[] names=featureType.getFields(); |
494 |
String[] newNames=new String[names.length-1]; |
495 |
int j=0; |
496 |
for (int i=0;i<names.length;i++){ |
497 |
if (!names[i].equals(featureType.getFieldsId()[0])){ |
498 |
newNames[j]=names[i]; |
499 |
j++; |
500 |
} |
501 |
} |
502 |
SeUpdate update = new SeUpdate(conex);
|
503 |
|
504 |
String id = getFliterForIDForPStatement(featureType);
|
505 |
String where = id + " = '" + feature.get(id) + "'"; |
506 |
update.toTable(featureType.getTableID(), |
507 |
newNames, where); |
508 |
update.setWriteMode(true);
|
509 |
|
510 |
SeRow row = update.getRowToSet(); |
511 |
Iterator iterator = featureType.iterator();
|
512 |
int jObjectID=0; |
513 |
while (iterator.hasNext()) {
|
514 |
IFeatureAttributeDescriptor fad = (IFeatureAttributeDescriptor) iterator.next(); |
515 |
if (fad.getName().equals(featureType.getFieldsId()[0])){ |
516 |
jObjectID++; |
517 |
continue;
|
518 |
} |
519 |
Object value=feature.get(fad.ordinal());
|
520 |
if (fad.getDataType() == IFeatureAttributeDescriptor.TYPE_GEOMETRY) {
|
521 |
IGeometry geom = (IGeometry) feature.get(fad.ordinal()); |
522 |
writeGeometry(geom, row, lay, fad.ordinal()-jObjectID); |
523 |
} else if (fad.getDataType() == IFeatureAttributeDescriptor.TYPE_STRING) { |
524 |
row.setString(fad.ordinal()-jObjectID, |
525 |
feature.getString(fad.ordinal())); |
526 |
} else if (fad.getDataType() == IFeatureAttributeDescriptor.TYPE_INT) { |
527 |
row.setInteger(fad.ordinal()-jObjectID, |
528 |
(Integer) feature.get(fad.ordinal()));
|
529 |
} else if (fad.getDataType() == IFeatureAttributeDescriptor.TYPE_LONG) { |
530 |
row.setLong(fad.ordinal()-jObjectID, (Long) feature.get(fad.ordinal()));
|
531 |
} else if (fad.getDataType() == IFeatureAttributeDescriptor.TYPE_FLOAT) { |
532 |
row.setFloat(fad.ordinal()-jObjectID, |
533 |
(Float) feature.get(fad.ordinal()));
|
534 |
} else if (fad.getDataType() == IFeatureAttributeDescriptor.TYPE_DOUBLE) { |
535 |
row.setDouble(fad.ordinal()-jObjectID, |
536 |
(Double) feature.get(fad.ordinal()));
|
537 |
} else if (fad.getDataType() == IFeatureAttributeDescriptor.TYPE_DATE) { |
538 |
row.setDate(fad.ordinal()-jObjectID, (Date) feature.get(fad.ordinal()));
|
539 |
} else if (fad.getDataType() == IFeatureAttributeDescriptor.TYPE_BOOLEAN) { |
540 |
boolean b = false; |
541 |
if (value==null){ |
542 |
b=false;
|
543 |
}else{
|
544 |
b = feature.getBoolean(fad.ordinal()); |
545 |
} |
546 |
if (b) {
|
547 |
row.setInteger(fad.ordinal()-jObjectID, new Integer(1)); |
548 |
} else {
|
549 |
row.setInteger(fad.ordinal()-jObjectID, new Integer(0)); |
550 |
} |
551 |
} |
552 |
} |
553 |
|
554 |
update.execute(); |
555 |
update.close(); |
556 |
} catch (SeException e) {
|
557 |
throw new WriteException(this.getClass().getName(),e); |
558 |
} |
559 |
} |
560 |
|
561 |
/* (non-Javadoc)
|
562 |
* @see org.gvsig.data.datastores.vectorial.ISelectiveWriter#deleteAttribute(org.gvsig.data.vectorial.IFeatureAttributeDescriptor)
|
563 |
*/
|
564 |
public void deleteAttribute(IFeatureAttributeDescriptor attribute) |
565 |
throws WriteException {
|
566 |
try {
|
567 |
SeTable table = new SeTable(conex,featureType.getTableID());
|
568 |
table.dropColumn(attribute.getName()); |
569 |
} catch (SeException e) {
|
570 |
throw new WriteException(this.store.getName(),e); |
571 |
} |
572 |
} |
573 |
|
574 |
/* (non-Javadoc)
|
575 |
* @see org.gvsig.data.datastores.vectorial.ISelectiveWriter#updateAttribute(org.gvsig.data.vectorial.IFeatureAttributeDescriptor, org.gvsig.data.vectorial.IFeatureAttributeDescriptor)
|
576 |
*/
|
577 |
public void updateAttribute(IFeatureAttributeDescriptor oldAttribute, |
578 |
IFeatureAttributeDescriptor attribute) |
579 |
throws WriteException, ReadException {
|
580 |
try {
|
581 |
SeTable table = new SeTable(conex,featureType.getTableID());
|
582 |
SeRegisteredColumn column=null;//new SeRegisteredColumn(conex); |
583 |
|
584 |
SeRegisteredColumn[] columns=table.getColumnList();
|
585 |
for (int i = 0; i < columns.length; i++) { |
586 |
if(columns[i].getName().equals(oldAttribute.getName())){
|
587 |
column=columns[i]; |
588 |
} |
589 |
} |
590 |
DBAttributeDescriptor dbAttribute=(DBAttributeDescriptor)attribute; |
591 |
column.setAllowsNulls(dbAttribute.isAllowNull()); |
592 |
column.setDecimalDigits(dbAttribute.getPrecision()); |
593 |
column.setSize(dbAttribute.getSize()); |
594 |
column.setType(SDETypes.fieldTypeToInt(dbAttribute.getDataType())); |
595 |
table.alterColumn(column); |
596 |
} catch (SeException e) {
|
597 |
throw new WriteException(this.store.getName(),e); |
598 |
} |
599 |
} |
600 |
|
601 |
/* (non-Javadoc)
|
602 |
* @see org.gvsig.data.datastores.vectorial.ISelectiveWriter#insertAttribute(org.gvsig.data.vectorial.IFeatureAttributeDescriptor)
|
603 |
*/
|
604 |
public void insertAttribute(IFeatureAttributeDescriptor attribute) |
605 |
throws WriteException {
|
606 |
try {
|
607 |
SeTable table = new SeTable(conex,featureType.getTableID());
|
608 |
DBAttributeDescriptor dbAttribute=(DBAttributeDescriptor)attribute; |
609 |
SeColumnDefinition column=new SeColumnDefinition(dbAttribute.getName(),
|
610 |
SDETypes.fieldTypeToInt(dbAttribute.getDataType()), |
611 |
dbAttribute.getSize(), |
612 |
dbAttribute.getPrecision(), |
613 |
dbAttribute.isAllowNull()); |
614 |
|
615 |
table.addColumn(column); |
616 |
} catch (SeException e) {
|
617 |
throw new WriteException(this.store.getName(),e); |
618 |
} |
619 |
} |
620 |
|
621 |
/**
|
622 |
* DOCUMENT ME!
|
623 |
*
|
624 |
* @param gvSIGgeometryType DOCUMENT ME!
|
625 |
*
|
626 |
* @return DOCUMENT ME!
|
627 |
*/
|
628 |
public boolean canWriteGeometry(int gvSIGgeometryType) { |
629 |
switch (gvSIGgeometryType) {
|
630 |
case FShape.POINT:
|
631 |
return true; |
632 |
|
633 |
case FShape.LINE:
|
634 |
return true; |
635 |
|
636 |
case FShape.POLYGON:
|
637 |
return true; |
638 |
|
639 |
case FShape.ARC:
|
640 |
return false; |
641 |
|
642 |
case FShape.ELLIPSE:
|
643 |
return false; |
644 |
|
645 |
case FShape.MULTIPOINT:
|
646 |
return true; |
647 |
|
648 |
case FShape.TEXT:
|
649 |
return false; |
650 |
} |
651 |
|
652 |
return false; |
653 |
} |
654 |
|
655 |
/**
|
656 |
* DOCUMENT ME!
|
657 |
*
|
658 |
* @param parameters DOCUMENT ME!
|
659 |
* @param featureType DOCUMENT ME!
|
660 |
*
|
661 |
* @throws InitializeWriterException DOCUMENT ME!
|
662 |
* @throws InitializeException DOCUMENT ME!
|
663 |
*/
|
664 |
// public static void create(SDEStoreParameters parameters,
|
665 |
// IFeatureType featureType)
|
666 |
// throws InitializeWriterException, InitializeException {
|
667 |
// SeConnection con = SDEUtils.getConnection(parameters.getHost(),parameters.getPort(),parameters.getDb(),
|
668 |
// parameters.getUser(), parameters.getPassw());
|
669 |
// }
|
670 |
|
671 |
protected static String getFliterForIDForPStatement(DBFeatureType fType) { |
672 |
if (fType.getFieldsId().length != 1) { |
673 |
throw new UnsupportedOperationException("ID fields > 1"); |
674 |
} |
675 |
|
676 |
String id = fType.getFieldsId()[0]; |
677 |
|
678 |
return id;
|
679 |
} |
680 |
/*
|
681 |
* (non-Javadoc)
|
682 |
* @see org.gvsig.data.datastores.vectorial.IFeaturesWriter#dispose()
|
683 |
*/
|
684 |
public void dispose() throws DataException { |
685 |
try {
|
686 |
this.conex.close();
|
687 |
} catch (SeException e) {
|
688 |
throw new CloseException(this.store.getName(),e); |
689 |
} |
690 |
this.conex = null; |
691 |
} |
692 |
} |