Revision 11193 trunk/extensions/extSDE/src/com/iver/cit/gvsig/fmap/drivers/sde/ArcSdeDriver.java
ArcSdeDriver.java | ||
---|---|---|
2 | 2 |
* Created on 13-may-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 |
*/ |
... | ... | |
45 | 45 |
|
46 | 46 |
import java.awt.geom.Rectangle2D; |
47 | 47 |
import java.io.IOException; |
48 |
import java.sql.Connection; |
|
48 | 49 |
import java.sql.Types; |
49 | 50 |
import java.util.Hashtable; |
50 | 51 |
import java.util.Vector; |
... | ... | |
62 | 63 |
import com.esri.sde.sdk.client.SeShape; |
63 | 64 |
import com.esri.sde.sdk.client.SeShapeFilter; |
64 | 65 |
import com.esri.sde.sdk.client.SeSqlConstruct; |
65 |
import com.esri.sde.sdk.client.SeTable;
|
|
66 |
import com.hardcode.gdbms.engine.data.DataSourceFactory;
|
|
66 | 67 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
67 | 68 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
68 | 69 |
import com.hardcode.gdbms.engine.values.Value; |
69 | 70 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
70 | 71 |
import com.iver.cit.gvsig.fmap.DriverException; |
72 |
import com.iver.cit.gvsig.fmap.DriverJdbcNotFoundExceptionType; |
|
73 |
import com.iver.cit.gvsig.fmap.Messages; |
|
71 | 74 |
import com.iver.cit.gvsig.fmap.core.FShape; |
75 |
import com.iver.cit.gvsig.fmap.core.ICanReproject; |
|
72 | 76 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
73 | 77 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
78 |
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition; |
|
74 | 79 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
75 | 80 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
76 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
|
81 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
|
82 |
import com.iver.cit.gvsig.fmap.edition.IWriteable; |
|
83 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
|
84 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
|
85 |
import com.iver.utiles.XMLEntity; |
|
86 |
import com.iver.utiles.swing.JPasswordDlg; |
|
77 | 87 |
|
78 |
public class ArcSdeDriver implements VectorialDatabaseDriver, ObjectDriver { |
|
79 | 88 |
|
89 |
/** |
|
90 |
* Driver of ArcSDE. |
|
91 |
* @author Vicente Caballero Navarro |
|
92 |
* @uml.dependency supplier="com.iver.cit.gvsig.fmap.drivers.sde.ArcSdeFeatureIterator" |
|
93 |
* @uml.dependency supplier="com.iver.cit.gvsig.fmap.drivers.sde.SDELayerDefinition" |
|
94 |
*/ |
|
95 |
public class ArcSdeDriver implements ICanReproject, IWriteable, VectorialSDEDriver, ObjectDriver{ |
|
96 |
protected static Hashtable poolPassw = new Hashtable(); |
|
80 | 97 |
private SeLayer layer; |
81 | 98 |
private SeQuery query; |
82 | 99 |
private SeQuery queryAux; |
... | ... | |
84 | 101 |
private SeColumnDefinition[] colDefs; |
85 | 102 |
private SeRow row = null; |
86 | 103 |
private int numReg = -1; |
104 |
/** |
|
105 |
* @uml.property name="fullExtent" |
|
106 |
*/ |
|
87 | 107 |
private Rectangle2D fullExtent = null; |
88 | 108 |
private Hashtable hashRelate = null; |
89 | 109 |
private int idSpatialColumn = -1; |
110 |
/** |
|
111 |
* @uml.property name="fields" |
|
112 |
*/ |
|
90 | 113 |
private String[] fields; |
91 | 114 |
private int[] fieldTypes; |
92 | 115 |
private long lastRowServed = -1; |
93 | 116 |
private SeConnection conn = null; |
117 |
private String strEPSG; |
|
118 |
private String originalEPSG = null; |
|
94 | 119 |
/** |
95 |
* Recorre el recordset creando una tabla Hash que usaremos para |
|
96 |
* relacionar el n?mero de un registro con su identificador ?nico. |
|
97 |
* Debe ser llamado en el setData justo despu?s de crear el recorset |
|
98 |
* principal |
|
120 |
* @uml.property name="sqlTotal" |
|
121 |
*/ |
|
122 |
private String sqlTotal; |
|
123 |
private long posActual = -1; |
|
124 |
private SeRow cachedRow = null; |
|
125 |
/** |
|
126 |
* @uml.property name="lyrDef" |
|
127 |
*/ |
|
128 |
protected VectorialSDELayerDefinition lyrDef = null; |
|
129 |
/** |
|
130 |
* @uml.property name="workingArea" |
|
131 |
*/ |
|
132 |
protected Rectangle2D workingArea; |
|
133 |
protected String driverClass; |
|
134 |
protected String className; |
|
135 |
protected String catalogName; |
|
136 |
private ArcSdeWriter writer; |
|
137 |
|
|
138 |
/** |
|
139 |
* Recorre el recordset creando una tabla Hash que usaremos para relacionar |
|
140 |
* el n?mero de un registro con su identificador ?nico. Debe ser llamado |
|
141 |
* en el setData justo despu?s de crear el recorset principal |
|
99 | 142 |
*/ |
100 |
private void doRelateID_FID() |
|
101 |
{ |
|
143 |
protected void doRelateID_FID() { |
|
102 | 144 |
hashRelate = new Hashtable(); |
145 |
|
|
103 | 146 |
try { |
104 |
// query.execute(); |
|
105 |
// row = query.fetch(); |
|
106 |
if( row == null ) { |
|
107 |
|
|
147 |
if (row == null) { |
|
108 | 148 |
System.out.println(" No rows fetched"); |
149 |
|
|
109 | 150 |
return; |
110 | 151 |
} |
152 |
|
|
111 | 153 |
int index = 0; |
112 |
while( row != null )
|
|
113 |
{
|
|
114 |
SeShape shpVal = row.getShape(idSpatialColumn);
|
|
115 |
SeObjectId objID = shpVal.getFeatureId();
|
|
116 |
String theKey = "" + objID.longValue();
|
|
117 |
// System.out.println("Antes de meter en el hash " + theKey);
|
|
154 |
Value value=getFieldValue(index,getLyrDef().getIdFieldID());
|
|
155 |
int fid=getLyrDef().getIdFieldID();
|
|
156 |
while (value != null) {
|
|
157 |
//SeShape shpVal = row.getShape(idSpatialColumn);
|
|
158 |
//SeObjectId objID = shpVal.getFeatureId();
|
|
159 |
String theKey = value.toString();
|
|
118 | 160 |
hashRelate.put(theKey, new Integer(index)); |
119 |
row = query.fetch(); |
|
120 |
index++; |
|
121 |
} |
|
122 |
numReg = index; |
|
123 |
// Close the query. |
|
124 |
// query.close(); |
|
125 |
} catch (SeException e) |
|
126 |
{ |
|
127 |
e.printStackTrace(); |
|
128 |
} |
|
129 |
|
|
130 |
} |
|
131 |
|
|
132 |
public void setData(String host, int port, String db, String userDB, String pwdDB, |
|
133 |
String tableName, String[] cols, |
|
134 |
String whereClause) |
|
135 |
{ |
|
136 |
// Conexi?n: |
|
137 |
|
|
138 |
String server = host; |
|
139 |
int instance = port; |
|
140 |
String database = db; |
|
141 |
String user = userDB; |
|
142 |
String password = pwdDB; |
|
143 |
try { |
|
144 |
conn = new SeConnection(server, instance, database, user, password); |
|
145 |
}catch (SeException e) { |
|
146 |
e.printStackTrace(); |
|
147 |
return; |
|
148 |
} |
|
149 |
|
|
150 |
// Fetching data |
|
151 |
|
|
152 |
String layerName = tableName; |
|
153 |
SeObjectId layerID = null; |
|
154 |
String strSpatialColumn = ""; |
|
155 |
try { |
|
156 |
Vector theLayers = conn.getLayers(); |
|
157 |
for (int i=0; i < theLayers.size(); i++) |
|
158 |
{ |
|
159 |
SeLayer layer = (SeLayer)theLayers.elementAt(i); |
|
160 |
if (layer.getName().compareToIgnoreCase(layerName) == 0 ); |
|
161 |
{ |
|
162 |
layerID = layer.getID(); |
|
163 |
strSpatialColumn = layer.getSpatialColumn(); |
|
164 |
} |
|
165 |
} |
|
166 |
if (layerID == null) |
|
167 |
{ |
|
168 |
System.err.println("Capa no encontrada"); |
|
169 |
return; |
|
161 |
value = getFieldValue(index,fid-1); |
|
162 |
index++; |
|
170 | 163 |
} |
171 |
// layerName = layer.getName(); |
|
172 |
layer = new SeLayer( conn, layerName, strSpatialColumn ); |
|
173 |
|
|
174 |
if (cols != null) |
|
175 |
this.fields = cols; |
|
176 |
else |
|
177 |
{ |
|
178 |
SeSqlConstruct sqlConstruct = new SeSqlConstruct( tableName ); |
|
179 |
SeTable table1 = new SeTable(conn, tableName ); |
|
180 |
/* |
|
181 |
* Get the table's column definition. |
|
182 |
*/ |
|
183 |
SeColumnDefinition[] tableDef = table1.describe(); |
|
184 |
this.fields = new String[tableDef.length]; |
|
185 |
|
|
186 |
/* |
|
187 |
* Store the names of all the table's columns in the |
|
188 |
* String array cols. This array specifies the columns |
|
189 |
* to be retrieved from the database. |
|
190 |
*/ |
|
191 |
int idField=1; |
|
192 |
for( int i = 0 ; i < tableDef.length ; i++ ) { |
|
193 |
if (tableDef[i].getType() == SeColumnDefinition.TYPE_SHAPE) |
|
194 |
{ |
|
195 |
this.fields[0] = tableDef[i].getName(); |
|
196 |
} |
|
197 |
else |
|
198 |
{ |
|
199 |
this.fields[idField] = tableDef[i].getName(); |
|
200 |
idField++; |
|
201 |
} |
|
202 |
} |
|
203 |
} |
|
204 |
|
|
205 |
|
|
206 |
sqlConstruct = new SeSqlConstruct( layerName); |
|
207 |
// Create a query stream between the client and server |
|
208 |
|
|
209 |
query = new SeQuery( conn, fields, sqlConstruct ); |
|
210 |
query.prepareQuery(); |
|
211 |
query.execute(); |
|
212 |
row = query.fetch(); |
|
213 |
if (row == null) |
|
214 |
{ |
|
215 |
System.out.println("La tabla " + getName() + " no tiene registros"); |
|
216 |
return; |
|
217 |
} |
|
218 |
|
|
219 |
colDefs = row.getColumns(); |
|
220 |
fieldTypes = new int[colDefs.length-1]; |
|
221 |
for (int colNum = 0; colNum < colDefs.length; colNum++) |
|
222 |
{ |
|
223 |
SeColumnDefinition colDef = colDefs[colNum]; |
|
224 |
int dataType = colDef.getType(); |
|
225 |
if (dataType == SeColumnDefinition.TYPE_SHAPE) |
|
226 |
{ |
|
227 |
if (colNum != 0) |
|
228 |
{ |
|
229 |
System.err.println("Por favor, el campo de shapes deber ser el primero"); |
|
230 |
return; |
|
231 |
} |
|
232 |
idSpatialColumn = colNum; |
|
233 |
} |
|
234 |
if (dataType == SeColumnDefinition.TYPE_STRING) |
|
235 |
fieldTypes[colNum-1] = Types.VARCHAR; |
|
236 |
if (dataType == SeColumnDefinition.TYPE_FLOAT) |
|
237 |
fieldTypes[colNum-1] = Types.FLOAT; |
|
238 |
if (dataType == SeColumnDefinition.TYPE_DOUBLE) |
|
239 |
fieldTypes[colNum-1] = Types.DOUBLE; |
|
240 |
if (dataType == SeColumnDefinition.TYPE_INTEGER) |
|
241 |
fieldTypes[colNum-1] = Types.INTEGER; |
|
242 |
if (dataType == SeColumnDefinition.TYPE_SMALLINT) |
|
243 |
fieldTypes[colNum-1] = Types.INTEGER; |
|
244 |
if (dataType == SeColumnDefinition.TYPE_DATE) |
|
245 |
fieldTypes[colNum-1] = Types.DATE; |
|
246 |
|
|
247 |
} |
|
248 |
// query.close(); |
|
249 |
SeQuery extentQuery = new SeQuery( conn, fields, sqlConstruct ); |
|
250 |
SeQueryInfo queryInfo = new SeQueryInfo(); |
|
251 |
queryInfo.setConstruct(sqlConstruct); |
|
252 |
// queryInfo.setQueryType(SeQueryInfo.SE_QUERYTYPE_JFA); |
|
253 |
// extentQuery.prepareQueryInfo(queryInfo); |
|
254 |
|
|
255 |
SeExtent seExtent = extentQuery.calculateLayerExtent(queryInfo); |
|
256 |
fullExtent = new Rectangle2D.Double( |
|
257 |
seExtent.getMinX(), seExtent.getMinY(), |
|
258 |
seExtent.getMaxX()- seExtent.getMinX(), |
|
259 |
seExtent.getMaxY()- seExtent.getMinY()); |
|
260 |
extentQuery.close(); |
|
261 |
|
|
262 |
doRelateID_FID(); |
|
263 |
|
|
264 |
} |
|
265 |
catch (SeException e) |
|
266 |
{ |
|
267 |
e.printStackTrace(); |
|
268 |
} |
|
269 | 164 |
|
270 |
|
|
165 |
numReg = index; |
|
166 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) { |
|
167 |
e.printStackTrace(); |
|
168 |
} |
|
271 | 169 |
} |
272 |
|
|
170 |
/** |
|
171 |
* @return |
|
172 |
* @uml.property name="fullExtent" |
|
173 |
*/ |
|
273 | 174 |
public Rectangle2D getFullExtent() { |
274 |
return fullExtent; |
|
275 |
} |
|
276 |
|
|
277 |
public int getShapeType() { |
|
278 |
// TODO Auto-generated method stub |
|
279 |
int shapeType = -1; |
|
280 |
switch (layer.getShapeTypes()) |
|
281 |
{ |
|
282 |
case SeLayer.TYPE_POINT: |
|
283 |
shapeType = FShape.POINT; |
|
284 |
break; |
|
285 |
case SeLayer.TYPE_LINE: |
|
286 |
case SeLayer.TYPE_MULTI_LINE: |
|
287 |
case SeLayer.TYPE_MULTI_SIMPLE_LINE: |
|
288 |
shapeType = FShape.LINE; |
|
289 |
break; |
|
290 |
case SeLayer.TYPE_POLYGON: |
|
291 |
case SeLayer.TYPE_MULTI_POLYGON: |
|
292 |
shapeType = FShape.POLYGON; |
|
293 |
break; |
|
294 |
|
|
295 |
} |
|
296 |
return FShape.MULTI; |
|
297 |
} |
|
298 |
|
|
175 |
return fullExtent; |
|
176 |
} |
|
299 | 177 |
public IGeometry getShape(int index) { |
300 | 178 |
SeRow row; |
179 |
|
|
301 | 180 |
try { |
302 | 181 |
row = obtainRow(index); |
182 |
|
|
303 | 183 |
SeShape spVal = row.getShape(idSpatialColumn); |
304 | 184 |
IGeometry geom = ArcSdeFeatureIterator.getGeometry(spVal); |
305 |
// queryAux.close(); |
|
306 | 185 |
return geom; |
307 | 186 |
} catch (SeException e) { |
308 |
// TODO Auto-generated catch block |
|
309 | 187 |
e.printStackTrace(); |
310 | 188 |
} |
311 |
return null;
|
|
189 |
return null; |
|
312 | 190 |
} |
313 | 191 |
|
314 | 192 |
public IFeatureIterator getFeatureIterator(String sql) |
315 |
throws DriverException { |
|
316 |
// TODO Auto-generated method stub |
|
193 |
throws DriverException { |
|
317 | 194 |
return null; |
318 | 195 |
} |
319 | 196 |
|
320 | 197 |
public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG) |
321 |
throws DriverException {
|
|
198 |
throws DriverException { |
|
322 | 199 |
/* |
323 | 200 |
* Generate a rectangular shape that will be used as a filter |
324 | 201 |
*/ |
325 | 202 |
try { |
326 | 203 |
SeShape shape = new SeShape(layer.getCoordRef()); |
327 |
|
|
328 |
SeExtent extent = new SeExtent( r.getMinX(),
|
|
329 |
r.getMinY(),r.getMaxX(),r.getMaxY());
|
|
204 |
|
|
205 |
SeExtent extent = new SeExtent(r.getMinX(), r.getMinY(),
|
|
206 |
r.getMaxX(), r.getMaxY());
|
|
330 | 207 |
shape.generateRectangle(extent); |
331 |
|
|
208 |
|
|
332 | 209 |
SeShape[] shapes = new SeShape[1]; |
333 | 210 |
shapes[0] = shape; |
334 |
|
|
211 |
|
|
335 | 212 |
/* |
336 | 213 |
* Retrieve all the shapes that are contained within the |
337 | 214 |
* rectangles envelope. |
338 | 215 |
*/ |
339 |
SeShapeFilter filters[] = new SeShapeFilter[1];
|
|
216 |
SeShapeFilter[] filters = new SeShapeFilter[1];
|
|
340 | 217 |
SeShapeFilter filter = null; |
341 |
|
|
342 |
filter = new SeShapeFilter( layer.getName(), layer.getSpatialColumn(), shape, SeFilter.METHOD_ENVP); |
|
218 |
|
|
219 |
filter = new SeShapeFilter(layer.getName(), |
|
220 |
layer.getSpatialColumn(), shape, SeFilter.METHOD_ENVP); |
|
343 | 221 |
filters[0] = filter; |
344 |
|
|
222 |
|
|
345 | 223 |
SeQuery spatialQuery = null; |
346 |
SeSqlConstruct sqlCons = new SeSqlConstruct( layer.getName() );
|
|
347 |
|
|
224 |
SeSqlConstruct sqlCons = new SeSqlConstruct(layer.getName());
|
|
225 |
|
|
348 | 226 |
spatialQuery = new SeQuery(conn, fields, sqlCons); |
227 |
|
|
349 | 228 |
/* |
350 | 229 |
* Set spatial constraints |
351 | 230 |
*/ |
352 |
spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false, filters); |
|
231 |
spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false, |
|
232 |
filters); |
|
353 | 233 |
|
354 | 234 |
spatialQuery.prepareQuery(); |
355 |
|
|
235 |
|
|
356 | 236 |
spatialQuery.execute(); |
357 |
|
|
237 |
|
|
358 | 238 |
return new ArcSdeFeatureIterator(spatialQuery); |
359 | 239 |
} catch (SeException e) { |
360 |
// TODO Auto-generated catch block |
|
361 | 240 |
e.printStackTrace(); |
362 | 241 |
return null; |
363 | 242 |
} |
364 |
|
|
365 | 243 |
} |
366 | 244 |
|
367 |
|
|
368 | 245 |
public void close() { |
369 |
// TODO Auto-generated method stub |
|
370 |
|
|
371 | 246 |
} |
372 | 247 |
|
373 | 248 |
public void open() throws DriverException { |
374 |
// TODO Auto-generated method stub |
|
375 |
|
|
376 | 249 |
} |
377 | 250 |
|
378 | 251 |
public int getRowIndexByFID(IFeature FID) { |
379 | 252 |
int resul; |
380 | 253 |
String strID = FID.getID(); |
381 |
// System.out.println("Recuperando " + strID + " del hash"); |
|
382 | 254 |
Integer rowIndex = (Integer) hashRelate.get(strID); |
383 |
if (rowIndex == null) |
|
384 |
{ |
|
385 |
System.err.println("Error: No se ha encontrado " + strID + " dentro del Hash"); |
|
255 |
|
|
256 |
if (rowIndex == null) { |
|
257 |
System.err.println("Error: No se ha encontrado " + strID + |
|
258 |
" dentro del Hash"); |
|
386 | 259 |
} |
387 | 260 |
resul = rowIndex.intValue(); |
388 | 261 |
return resul; |
... | ... | |
397 | 270 |
} |
398 | 271 |
|
399 | 272 |
public DriverAttributes getDriverAttributes() { |
400 |
// TODO Auto-generated method stub |
|
401 | 273 |
return null; |
402 | 274 |
} |
403 | 275 |
|
404 | 276 |
public String getName() { |
405 |
return "ArcSDE driver";
|
|
277 |
return "gvSIG SDE driver";
|
|
406 | 278 |
} |
407 | 279 |
|
280 |
/** |
|
281 |
* @return |
|
282 |
* @uml.property name="fields" |
|
283 |
*/ |
|
408 | 284 |
public String[] getFields() { |
409 |
String[] attributes = new String[fields.length-1];
|
|
410 |
for (int i=1; i < fields.length; i++)
|
|
411 |
attributes[i-1] = fields[i];
|
|
412 |
return attributes;
|
|
413 |
}
|
|
285 |
String[] attributes = new String[fields.length - 1];
|
|
286 |
for (int i = 1; i < fields.length; i++)
|
|
287 |
attributes[i - 1] = fields[i];
|
|
288 |
return attributes;
|
|
289 |
}
|
|
414 | 290 |
|
415 |
public String getWhereClause() { |
|
416 |
// TODO Auto-generated method stub |
|
417 |
return ""; |
|
418 |
} |
|
419 |
|
|
420 | 291 |
public String getTableName() { |
421 | 292 |
return layer.getName(); |
422 | 293 |
} |
423 | 294 |
|
424 |
private SeRow obtainRow(long rowIndex) throws SeException |
|
425 |
{ |
|
426 |
if (rowIndex == 0) |
|
427 |
{ |
|
428 |
if (query != null) |
|
429 |
{ |
|
430 |
if (query.inProgress()) |
|
431 |
query.close(); |
|
295 |
private SeRow obtainRow(long rowIndex) throws SeException { |
|
296 |
if (rowIndex != posActual) { |
|
297 |
if (rowIndex == 0) { |
|
298 |
if (query != null) { |
|
299 |
if (query.inProgress()) { |
|
300 |
query.close(); |
|
301 |
} |
|
302 |
} |
|
303 |
query = new SeQuery(conn, fields, sqlConstruct); |
|
304 |
query.prepareQuery(); |
|
305 |
query.execute(); |
|
306 |
|
|
307 |
lastRowServed = -1; |
|
432 | 308 |
} |
433 |
query = new SeQuery( conn, fields, sqlConstruct ); |
|
434 |
query.prepareQuery(); |
|
435 |
query.execute(); |
|
436 |
|
|
437 |
lastRowServed = -1; |
|
309 |
|
|
310 |
if (lastRowServed == (rowIndex - 1)) { |
|
311 |
row = query.fetch(); |
|
312 |
lastRowServed++; |
|
313 |
} else { |
|
314 |
if (queryAux != null) { |
|
315 |
queryAux.close(); |
|
316 |
} |
|
317 |
|
|
318 |
queryAux = new SeQuery(conn, fields, sqlConstruct); |
|
319 |
|
|
320 |
SeObjectId rowID = new SeObjectId(rowIndex + 1); |
|
321 |
row = queryAux.fetchRow(layer.getName(), rowID, fields); |
|
322 |
} |
|
323 |
|
|
324 |
posActual = rowIndex; |
|
325 |
cachedRow = row; |
|
438 | 326 |
} |
439 |
if (lastRowServed == rowIndex-1) |
|
440 |
{ |
|
441 |
row = query.fetch(); |
|
442 |
lastRowServed++; |
|
443 |
} |
|
444 |
else |
|
445 |
{ |
|
446 |
if (queryAux != null) queryAux.close(); |
|
447 |
queryAux = new SeQuery( conn, fields, sqlConstruct ); |
|
448 |
SeObjectId rowID = new SeObjectId(rowIndex+1); |
|
449 |
row = queryAux.fetchRow(layer.getName(), rowID, fields); |
|
450 |
} |
|
451 |
// queryAux.close(); |
|
452 |
return row; |
|
453 |
|
|
454 |
|
|
327 |
|
|
328 |
return cachedRow; |
|
455 | 329 |
} |
456 |
public Value getFieldValue(long rowIndex, int fieldId) throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
330 |
|
|
331 |
public Value getFieldValue(long rowIndex, int fieldId) |
|
332 |
throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
457 | 333 |
SeRow row; |
458 | 334 |
Value val = null; |
335 |
|
|
459 | 336 |
try { |
460 |
int idFieldArcSDE = fieldId + 1; // SIEMPRE CONTANDO CON
|
|
461 |
// QUE NOS HAN PASADO EL PRIMER CAMPO EL DE SHAPE
|
|
337 |
int idFieldArcSDE = fieldId+1; // SIEMPRE CONTANDO CON
|
|
338 |
// QUE NOS HAN PASADO EL PRIMER CAMPO EL DE SHAPE |
|
462 | 339 |
row = obtainRow(rowIndex); |
340 |
if (row==null) |
|
341 |
return null; |
|
463 | 342 |
int dataType = colDefs[idFieldArcSDE].getType(); |
464 |
if ( dataType == SeColumnDefinition.TYPE_STRING) |
|
465 |
{ |
|
343 |
|
|
344 |
switch (dataType) { |
|
345 |
case SeColumnDefinition.TYPE_INT16: |
|
346 |
val = ValueFactory.createValue(row.getShort(idFieldArcSDE) |
|
347 |
.intValue()); |
|
348 |
|
|
349 |
break; |
|
350 |
|
|
351 |
case SeColumnDefinition.TYPE_INT32: |
|
352 |
case SeColumnDefinition.TYPE_INT64: |
|
353 |
val = ValueFactory.createValue(row.getInteger(idFieldArcSDE) |
|
354 |
.intValue()); |
|
355 |
|
|
356 |
break; |
|
357 |
|
|
358 |
case SeColumnDefinition.TYPE_FLOAT32: |
|
359 |
val = ValueFactory.createValue(row.getFloat(idFieldArcSDE) |
|
360 |
.floatValue()); |
|
361 |
|
|
362 |
break; |
|
363 |
|
|
364 |
case SeColumnDefinition.TYPE_FLOAT64: |
|
365 |
val = ValueFactory.createValue(row.getDouble(idFieldArcSDE) |
|
366 |
.doubleValue()); |
|
367 |
|
|
368 |
break; |
|
369 |
|
|
370 |
case SeColumnDefinition.TYPE_DATE: |
|
371 |
val = ValueFactory.createValue(row.getTime(idFieldArcSDE) |
|
372 |
.getTime()); |
|
373 |
|
|
374 |
break; |
|
375 |
|
|
376 |
case SeColumnDefinition.TYPE_STRING: |
|
377 |
|
|
466 | 378 |
String strAux = row.getString(idFieldArcSDE); |
467 |
if (strAux == null) strAux = ""; |
|
468 |
val = ValueFactory.createValue(strAux); |
|
379 |
|
|
380 |
if (strAux == null) { |
|
381 |
strAux = ""; |
|
382 |
} |
|
383 |
|
|
384 |
val = ValueFactory.createValue(strAux); |
|
385 |
|
|
386 |
break; |
|
469 | 387 |
} |
470 |
if (dataType == SeColumnDefinition.TYPE_FLOAT) |
|
471 |
{ |
|
472 |
val = ValueFactory.createValue(row.getFloat(idFieldArcSDE).floatValue()); |
|
473 |
} |
|
474 |
if (dataType == SeColumnDefinition.TYPE_DOUBLE) |
|
475 |
{ |
|
476 |
val = ValueFactory.createValue(row.getDouble(idFieldArcSDE).doubleValue()); |
|
477 |
} |
|
478 |
if (dataType == SeColumnDefinition.TYPE_INTEGER) |
|
479 |
{ |
|
480 |
val = ValueFactory.createValue(row.getInteger(idFieldArcSDE).intValue()); |
|
481 |
} |
|
482 |
if (dataType == SeColumnDefinition.TYPE_SMALLINT) |
|
483 |
{ |
|
484 |
val = ValueFactory.createValue(row.getShort(idFieldArcSDE).intValue()); |
|
485 |
} |
|
486 |
|
|
487 |
if (dataType == SeColumnDefinition.TYPE_DATE) |
|
488 |
{ |
|
489 |
val = ValueFactory.createValue(row.getDate(idFieldArcSDE)); |
|
490 |
} |
|
491 |
// queryAux.close(); |
|
388 |
|
|
492 | 389 |
return val; |
493 |
|
|
494 | 390 |
} catch (SeException e) { |
495 |
// TODO Auto-generated catch block |
|
496 | 391 |
e.printStackTrace(); |
497 |
|
|
498 | 392 |
} |
499 |
|
|
393 |
|
|
500 | 394 |
return ValueFactory.createNullValue(); |
501 | 395 |
} |
502 | 396 |
|
503 |
public int getFieldCount() throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
504 |
return fields.length-1; |
|
397 |
public int getFieldCount() |
|
398 |
throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
399 |
return fields.length - 1; |
|
505 | 400 |
} |
506 | 401 |
|
507 |
public String getFieldName(int fieldId) throws com.hardcode.gdbms.engine.data.driver.DriverException {
|
|
508 |
// System.out.println("En ArcSdeDriver: getFieldName(" + fieldId + ")=" + fields[fieldId+1]);
|
|
509 |
return fields[fieldId+1];
|
|
402 |
public String getFieldName(int fieldId) |
|
403 |
throws com.hardcode.gdbms.engine.data.driver.DriverException {
|
|
404 |
return fields[fieldId + 1];
|
|
510 | 405 |
} |
511 | 406 |
|
512 |
public long getRowCount() throws com.hardcode.gdbms.engine.data.driver.DriverException {
|
|
407 |
public long getRowCount() { |
|
513 | 408 |
return numReg; |
514 | 409 |
} |
515 | 410 |
|
516 |
public int getFieldType(int i) throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
411 |
public int getFieldType(int i) |
|
412 |
throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
517 | 413 |
return fieldTypes[i]; |
518 | 414 |
} |
519 | 415 |
|
520 | 416 |
/** |
521 | 417 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys() |
522 | 418 |
*/ |
523 |
public int[] getPrimaryKeys() throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
419 |
public int[] getPrimaryKeys() |
|
420 |
throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
524 | 421 |
throw new UnsupportedOperationException(); |
525 | 422 |
} |
526 | 423 |
|
527 | 424 |
/** |
528 | 425 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare) |
529 | 426 |
*/ |
530 |
public void write(DataWare arg0) throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
427 |
public void write(DataWare arg0) |
|
428 |
throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
429 |
} |
|
430 |
|
|
431 |
public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG, |
|
432 |
String[] alphaNumericFieldsNeeded) throws DriverException { |
|
433 |
/* |
|
434 |
* Generate a rectangular shape that will be used as a filter |
|
435 |
*/ |
|
436 |
try { |
|
437 |
SeShape shape = new SeShape(layer.getCoordRef()); |
|
438 |
|
|
439 |
SeExtent extent = new SeExtent(r.getMinX(), r.getMinY(), |
|
440 |
r.getMaxX(), r.getMaxY()); |
|
441 |
shape.generateRectangle(extent); |
|
442 |
|
|
443 |
SeShape[] shapes = new SeShape[1]; |
|
444 |
shapes[0] = shape; |
|
445 |
|
|
446 |
/* |
|
447 |
* Retrieve all the shapes that are contained within the |
|
448 |
* rectangles envelope. |
|
449 |
*/ |
|
450 |
SeShapeFilter[] filters = new SeShapeFilter[1]; |
|
451 |
SeShapeFilter filter = null; |
|
452 |
|
|
453 |
filter = new SeShapeFilter(layer.getName(), |
|
454 |
layer.getSpatialColumn(), shape, SeFilter.METHOD_ENVP); |
|
455 |
filters[0] = filter; |
|
456 |
|
|
457 |
SeQuery spatialQuery = null; |
|
458 |
SeSqlConstruct sqlCons = new SeSqlConstruct(layer.getName()); |
|
459 |
|
|
460 |
spatialQuery = new SeQuery(conn, fields, sqlCons); |
|
461 |
|
|
462 |
/* |
|
463 |
* Set spatial constraints |
|
464 |
*/ |
|
465 |
spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false, |
|
466 |
filters); |
|
467 |
|
|
468 |
spatialQuery.prepareQuery(); |
|
469 |
|
|
470 |
spatialQuery.execute(); |
|
471 |
|
|
472 |
return new ArcSdeFeatureIterator(spatialQuery); |
|
473 |
} catch (SeException e) { |
|
474 |
e.printStackTrace(); |
|
475 |
|
|
476 |
return null; |
|
477 |
} |
|
478 |
} |
|
479 |
|
|
480 |
public boolean isWritable() { |
|
481 |
return false; |
|
482 |
} |
|
483 |
|
|
484 |
public void setData(Connection connection, DBLayerDefinition lyrDef) { |
|
485 |
setLyrDef(lyrDef); |
|
486 |
// Conexi?n: |
|
487 |
VectorialSDELayerDefinition sdeDef = (VectorialSDELayerDefinition) lyrDef; |
|
488 |
String server = sdeDef.getHost(); |
|
489 |
int instance = Integer.parseInt(sdeDef.getPort()); |
|
490 |
String database = sdeDef.getSchema(); |
|
491 |
String user = sdeDef.getUser(); |
|
492 |
String password = sdeDef.getPassword(); |
|
493 |
String[] cols = sdeDef.getFieldNames(); |
|
494 |
String tableName = sdeDef.getTableName(); |
|
495 |
|
|
496 |
try { |
|
497 |
conn = new SeConnection(server, instance, database, user, password); |
|
498 |
} catch (SeException e) { |
|
499 |
e.printStackTrace(); |
|
500 |
|
|
501 |
return; |
|
502 |
} |
|
503 |
|
|
504 |
// Fetching data |
|
505 |
String layerName = tableName; |
|
506 |
SeObjectId layerID = null; |
|
507 |
String strSpatialColumn = ""; |
|
508 |
|
|
509 |
try { |
|
510 |
Vector theLayers = conn.getLayers(); |
|
511 |
|
|
512 |
for (int i = 0; i < theLayers.size(); i++) { |
|
513 |
SeLayer layer = (SeLayer) theLayers.elementAt(i); |
|
514 |
|
|
515 |
if (layer.getName().compareToIgnoreCase(layerName) == 0) { |
|
516 |
; |
|
517 |
} |
|
518 |
|
|
519 |
layerID = layer.getID(); |
|
520 |
strSpatialColumn = layer.getSpatialColumn(); |
|
521 |
} |
|
522 |
|
|
523 |
if (layerID == null) { |
|
524 |
System.err.println("Capa no encontrada"); |
|
525 |
|
|
526 |
return; |
|
527 |
} |
|
528 |
|
|
529 |
// layerName = layer.getName(); |
|
530 |
layer = new SeLayer(conn, layerName, strSpatialColumn); |
|
531 |
|
|
532 |
//TODO aqu? se puede saber la proyecci?n |
|
533 |
//layer.getCoordRef().getSrid(); |
|
534 |
|
|
535 |
// if ((cols != null) && (cols.length != 0)) { |
|
536 |
// if (!cols[0].equals(lyrDef.getFieldGeometry())) { |
|
537 |
// this.fields = new String[cols.length + 1]; |
|
538 |
// this.fields[0] = lyrDef.getFieldGeometry(); |
|
539 |
// |
|
540 |
// for (int i = 1; i < fields.length; i++) { |
|
541 |
// fields[i] = cols[i - 1]; |
|
542 |
// } |
|
543 |
// } else { |
|
544 |
// fields = cols; |
|
545 |
// } |
|
546 |
// } else { |
|
547 |
// SeSqlConstruct sqlConstruct = new SeSqlConstruct(tableName); |
|
548 |
// sqlTotal = sqlConstruct.getWhere(); |
|
549 |
// |
|
550 |
// SeTable table1 = new SeTable(conn, tableName); |
|
551 |
// |
|
552 |
// /* |
|
553 |
// * Get the table's column definition. |
|
554 |
// */ |
|
555 |
// SeColumnDefinition[] tableDef = table1.describe(); |
|
556 |
// this.fields = new String[tableDef.length]; |
|
557 |
// |
|
558 |
// /* |
|
559 |
// * Store the names of all the table's columns in the |
|
560 |
// * String array cols. This array specifies the columns |
|
561 |
// * to be retrieved from the database. |
|
562 |
// */ |
|
563 |
// int idField = 1; |
|
564 |
// |
|
565 |
// for (int i = 0; i < tableDef.length; i++) { |
|
566 |
// if (tableDef[i].getType() == SeColumnDefinition.TYPE_SHAPE) { |
|
567 |
// this.fields[0] = tableDef[i].getName(); |
|
568 |
// } else { |
|
569 |
// this.fields[idField] = tableDef[i].getName(); |
|
570 |
// idField++; |
|
571 |
// } |
|
572 |
// } |
|
573 |
// |
|
574 |
// lyrDef.setFieldNames(fields); |
|
575 |
// } |
|
576 |
fields=cols; |
|
577 |
sqlConstruct = new SeSqlConstruct(layerName); |
|
578 |
|
|
579 |
// Create a query stream between the client and server |
|
580 |
query = new SeQuery(conn, fields, sqlConstruct); |
|
581 |
query.prepareQuery(); |
|
582 |
query.execute(); |
|
583 |
row = query.fetch(); |
|
584 |
|
|
585 |
if (row == null) { |
|
586 |
System.out.println("La tabla " + getName() + |
|
587 |
" no tiene registros"); |
|
588 |
|
|
589 |
return; |
|
590 |
} |
|
591 |
|
|
592 |
colDefs = row.getColumns(); |
|
593 |
lyrDef.setShapeType(obtainShapeType(row.getShape(0).getType())); |
|
594 |
fieldTypes = new int[colDefs.length - 1]; |
|
595 |
|
|
596 |
for (int colNum = 0; colNum < colDefs.length; colNum++) { |
|
597 |
SeColumnDefinition colDef = colDefs[colNum]; |
|
598 |
int dataType = colDef.getType(); |
|
599 |
|
|
600 |
switch (dataType) { |
|
601 |
case SeColumnDefinition.TYPE_SHAPE: |
|
602 |
|
|
603 |
if (colNum != 0) { |
|
604 |
System.err.println( |
|
605 |
"Por favor, el campo de shapes deber ser el primero"); |
|
606 |
|
|
607 |
return; |
|
608 |
} |
|
609 |
|
|
610 |
idSpatialColumn = colNum; |
|
611 |
|
|
612 |
break; |
|
613 |
|
|
614 |
case SeColumnDefinition.TYPE_INT16: |
|
615 |
case SeColumnDefinition.TYPE_INT32: |
|
616 |
case SeColumnDefinition.TYPE_INT64: |
|
617 |
fieldTypes[colNum - 1] = Types.INTEGER; |
|
618 |
|
|
619 |
break; |
|
620 |
|
|
621 |
case SeColumnDefinition.TYPE_FLOAT32: |
|
622 |
fieldTypes[colNum - 1] = Types.FLOAT; |
|
623 |
|
|
624 |
break; |
|
625 |
|
|
626 |
case SeColumnDefinition.TYPE_FLOAT64: |
|
627 |
fieldTypes[colNum - 1] = Types.DOUBLE; |
|
628 |
|
|
629 |
break; |
|
630 |
|
|
631 |
case SeColumnDefinition.TYPE_DATE: |
|
632 |
fieldTypes[colNum - 1] = Types.DATE; |
|
633 |
|
|
634 |
break; |
|
635 |
|
|
636 |
default: |
|
637 |
fieldTypes[colNum - 1] = Types.VARCHAR; |
|
638 |
|
|
639 |
break; |
|
640 |
} |
|
641 |
} |
|
642 |
fields=cols; |
|
643 |
SeQuery extentQuery = new SeQuery(conn, fields, sqlConstruct); |
|
644 |
SeQueryInfo queryInfo = new SeQueryInfo(); |
|
645 |
queryInfo.setConstruct(sqlConstruct); |
|
646 |
|
|
647 |
SeExtent seExtent = extentQuery.calculateLayerExtent(queryInfo); |
|
648 |
fullExtent = new Rectangle2D.Double(seExtent.getMinX(), |
|
649 |
seExtent.getMinY(), |
|
650 |
seExtent.getMaxX() - seExtent.getMinX(), |
|
651 |
seExtent.getMaxY() - seExtent.getMinY()); |
|
652 |
extentQuery.close(); |
|
653 |
|
|
654 |
doRelateID_FID(); |
|
655 |
} catch (SeException e) { |
|
656 |
e.printStackTrace(); |
|
657 |
} |
|
658 |
} |
|
659 |
|
|
660 |
private int obtainShapeType(int type) { |
|
661 |
int shapeType = -1; |
|
662 |
|
|
663 |
switch (type) { |
|
664 |
case SeLayer.TYPE_POINT: |
|
665 |
shapeType = FShape.POINT; |
|
666 |
|
|
667 |
break; |
|
668 |
|
|
669 |
case SeLayer.TYPE_LINE: |
|
670 |
case SeLayer.TYPE_SIMPLE_LINE: |
|
671 |
case SeLayer.TYPE_MULTI_LINE: |
|
672 |
case SeLayer.TYPE_MULTI_SIMPLE_LINE: |
|
673 |
shapeType = FShape.LINE; |
|
674 |
|
|
675 |
break; |
|
676 |
|
|
677 |
case SeLayer.TYPE_POLYGON: |
|
678 |
case SeLayer.TYPE_MULTI_POLYGON: |
|
679 |
shapeType = FShape.POLYGON; |
|
680 |
|
|
681 |
break; |
|
682 |
|
|
683 |
default: |
|
684 |
shapeType = FShape.MULTI; |
|
685 |
} |
|
686 |
|
|
687 |
return shapeType; |
|
688 |
} |
|
689 |
|
|
690 |
public String getCompleteWhere() { |
|
691 |
return null; |
|
692 |
} |
|
693 |
|
|
694 |
public String getConnectionStringBeginning() { |
|
695 |
return ""; |
|
696 |
} |
|
697 |
|
|
698 |
public int getDefaultPort() { |
|
699 |
return 5151; |
|
700 |
} |
|
701 |
|
|
702 |
public String getSourceProjection() { |
|
703 |
return originalEPSG; |
|
704 |
} |
|
705 |
|
|
706 |
public String getDestProjection() { |
|
707 |
return strEPSG; |
|
708 |
} |
|
709 |
|
|
710 |
public void setDestProjection(String toEPSG) { |
|
711 |
this.strEPSG = toEPSG; |
|
712 |
} |
|
713 |
|
|
714 |
public boolean canReproject(String toEPSGdestinyProjection) { |
|
715 |
// TODO POR AHORA, REPROYECTA SIEMPRE gvSIG. |
|
716 |
return false; |
|
717 |
} |
|
718 |
|
|
719 |
public IWriter getWriter() { |
|
720 |
if (writer == null) { |
|
721 |
writer = new ArcSdeWriter(); |
|
722 |
writer.setDriver(this); |
|
723 |
writer.setSeLayer(layer); |
|
724 |
try { |
|
725 |
writer.initialize(getLyrDef()); |
|
726 |
} |
|
727 |
catch (EditionException e) { |
|
728 |
|
|
729 |
} |
|
730 |
} |
|
731 |
|
|
732 |
return writer; |
|
733 |
} |
|
734 |
|
|
735 |
/** |
|
736 |
* @return |
|
737 |
* @uml.property name="sqlTotal" |
|
738 |
*/ |
|
739 |
public String getSqlTotal() { |
|
740 |
return sqlTotal; |
|
741 |
} |
|
742 |
|
|
743 |
public XMLEntity getXMLEntity() { |
|
744 |
VectorialSDELayerDefinition sdeDef = (VectorialSDELayerDefinition) getLyrDef(); |
|
745 |
XMLEntity xml = new XMLEntity(); |
|
746 |
xml.putProperty("className", this.getClass().getName()); |
|
747 |
xml.putProperty("driverclass", this.getClass().getName()); |
|
748 |
xml.putProperty("catalog", sdeDef.getCatalogName()); |
|
749 |
|
|
750 |
// TODO: NO DEBEMOS GUARDAR EL NOMBRE DE USUARIO Y CONTRASE?A |
|
751 |
// AQUI. Hay que utilizar un pool de conexiones |
|
752 |
// y pedir al usuario que conecte a la base de datos |
|
753 |
// en la primera capa. En el resto, usar la conexi?n |
|
754 |
// creada con anterioridad. |
|
755 |
String userName = sdeDef.getUser(); |
|
756 |
if (userName != null) { |
|
757 |
int aux = userName.indexOf("@"); |
|
758 |
|
|
759 |
if (aux != -1) { |
|
760 |
userName = userName.substring(0, aux); |
|
761 |
} |
|
762 |
} |
|
763 |
|
|
764 |
xml.putProperty("username", userName); |
|
765 |
|
|
766 |
xml.putProperty("tablename", getTableName()); |
|
767 |
xml.putProperty("fields", fields); |
|
768 |
xml.putProperty("ID", sdeDef.getFieldID()); |
|
769 |
xml.putProperty("THE_GEOM", sdeDef.getFieldGeometry()); |
|
770 |
xml.putProperty("whereclause", getWhereClause()); |
|
771 |
xml.putProperty("SRID", sdeDef.getSRID_EPSG()); |
|
772 |
|
|
773 |
xml.putProperty("host", sdeDef.getHost()); |
|
774 |
xml.putProperty("port", sdeDef.getPort()); |
|
775 |
xml.putProperty("dbName", sdeDef.getSchema()); |
|
776 |
xml.putProperty("connName", sdeDef.getConnectionName()); |
|
777 |
|
|
778 |
if (getWorkingArea() != null) { |
|
779 |
xml.putProperty("minXworkArea", getWorkingArea().getMinX()); |
|
780 |
xml.putProperty("minYworkArea", getWorkingArea().getMinY()); |
|
781 |
xml.putProperty("HworkArea", getWorkingArea().getHeight()); |
|
782 |
xml.putProperty("WworkArea", getWorkingArea().getWidth()); |
|
783 |
} |
|
784 |
|
|
785 |
return xml; |
|
786 |
} |
|
787 |
|
|
788 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
|
789 |
className = xml.getStringProperty("className"); |
|
790 |
catalogName = xml.getStringProperty("catalog"); |
|
791 |
lyrDef = new ArcSDELayerDefinition(); |
|
792 |
|
|
793 |
if (xml.contains("username")) { |
|
794 |
lyrDef.setUser(xml.getStringProperty("username")); |
|
795 |
} |
|
796 |
|
|
797 |
driverClass = xml.getStringProperty("driverclass"); |
|
798 |
lyrDef.setTableName(xml.getStringProperty("tablename")); |
|
799 |
fields = xml.getStringArrayProperty("fields"); |
|
800 |
lyrDef.setFieldNames(fields); |
|
801 |
lyrDef.setFieldID(xml.getStringProperty("ID")); |
|
802 |
lyrDef.setFieldGeometry(xml.getStringProperty("THE_GEOM")); |
|
803 |
lyrDef.setWhereClause(xml.getStringProperty("whereclause")); |
|
804 |
lyrDef.setSRID_EPSG(xml.getStringProperty("SRID")); |
|
805 |
|
|
806 |
if (xml.contains("host")) { |
|
807 |
lyrDef.setHost(xml.getStringProperty("host")); |
|
808 |
lyrDef.setPort(xml.getStringProperty("port")); |
|
809 |
lyrDef.setSchema(xml.getStringProperty("dbName")); |
|
810 |
lyrDef.setConnectionName(xml.getStringProperty("connName")); |
|
811 |
} |
|
812 |
|
|
813 |
if (xml.contains("minXworkArea")) { |
|
814 |
double x = xml.getDoubleProperty("minXworkArea"); |
|
815 |
double y = xml.getDoubleProperty("minYworkArea"); |
|
816 |
double H = xml.getDoubleProperty("HworkArea"); |
|
817 |
double W = xml.getDoubleProperty("WworkArea"); |
|
818 |
workingArea = new Rectangle2D.Double(x, y, W, H); |
|
819 |
} |
|
820 |
|
|
821 |
lyrDef.setCatalogName(catalogName); |
|
822 |
lyrDef.setFieldNames(fields); |
|
823 |
|
|
824 |
if (workingArea != null) { |
|
825 |
lyrDef.setWorkingArea(workingArea); |
|
826 |
} |
|
827 |
|
|
828 |
setLyrDef(lyrDef); |
|
829 |
} |
|
830 |
|
|
831 |
public int getFieldWidth(int fieldId) { |
|
832 |
return colDefs[fieldId].getSize(); |
|
833 |
} |
|
834 |
|
|
835 |
public void setLyrDef(DBLayerDefinition lyrDef) { |
|
836 |
this.lyrDef = (VectorialSDELayerDefinition) lyrDef; |
|
837 |
} |
|
838 |
|
|
839 |
/** |
|
840 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver#setWorkingArea(java.awt.geom.Rectangle2D) |
|
841 |
* @uml.property name="workingArea" |
|
842 |
*/ |
|
843 |
public void setWorkingArea(Rectangle2D rect) { |
|
844 |
this.workingArea = rect; |
|
845 |
} |
|
846 |
|
|
847 |
/** |
|
848 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver#getWorkingArea() |
|
849 |
* @uml.property name="workingArea" |
|
850 |
*/ |
|
851 |
public Rectangle2D getWorkingArea() { |
|
852 |
return workingArea; |
|
853 |
} |
|
854 |
|
|
855 |
/** |
|
856 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeType() |
|
857 |
*/ |
|
858 |
public int getShapeType() { |
|
859 |
return lyrDef.getShapeType(); |
|
860 |
} |
|
861 |
|
|
862 |
/* (non-Javadoc) |
|
863 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#getWhereClause() |
|
864 |
*/ |
|
865 |
public String getWhereClause() { |
|
866 |
if (lyrDef.getWhereClause() == null) { |
|
867 |
return ""; |
|
868 |
} |
|
869 |
|
|
870 |
return lyrDef.getWhereClause().toUpperCase(); |
|
871 |
} |
|
872 |
|
|
873 |
/** |
|
874 |
* @return |
|
875 |
* @uml.property name="lyrDef" |
|
876 |
*/ |
|
877 |
public DBLayerDefinition getLyrDef() { |
|
878 |
return lyrDef; |
|
879 |
} |
|
880 |
|
|
881 |
/** |
|
882 |
* Empty method called when the layer is going to be removed from the view. |
|
883 |
* Subclasses can overwrite it if needed. |
|
884 |
*/ |
|
885 |
public void remove() { |
|
886 |
} |
|
887 |
|
|
888 |
/* (non-Javadoc) |
|
889 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#reLoad() |
|
890 |
*/ |
|
891 |
public void reload() throws IOException { |
|
892 |
try { |
|
893 |
load(); |
|
894 |
} catch (DriverException e) { |
|
895 |
e.printStackTrace(); |
|
896 |
} |
|
897 |
//setData(null, lyrDef); |
|
898 |
} |
|
899 |
|
|
900 |
public void setDataSourceFactory(DataSourceFactory dsf) { |
|
531 | 901 |
// TODO Auto-generated method stub |
532 |
|
|
533 | 902 |
} |
534 | 903 |
|
904 |
public void load() throws DriverException { |
|
905 |
try { |
|
906 |
if (driverClass != null) { |
|
907 |
Class.forName(driverClass); |
|
908 |
} |
|
909 |
|
|
910 |
String _drvName = getName(); |
|
911 |
|
|
912 |
String keyPool = _drvName.toLowerCase() + "_" + |
|
913 |
lyrDef.getHost().toLowerCase() + "_" + lyrDef.getPort() + "_" + |
|
914 |
lyrDef.getSchema().toLowerCase() + "_" + |
|
915 |
lyrDef.getUser().toLowerCase(); |
|
916 |
|
|
917 |
String clave = null; |
|
918 |
|
|
919 |
if (poolPassw.containsKey(keyPool)) { |
|
920 |
clave = (String) poolPassw.get(keyPool); |
|
921 |
|
|
922 |
lyrDef.setPassword(clave); |
|
923 |
} else { |
|
924 |
JPasswordDlg dlg = new JPasswordDlg(); |
|
925 |
String strMessage = Messages.getString("conectar_sde"); |
|
926 |
String strPassword = Messages.getString("password"); |
|
927 |
dlg.setMessage(strMessage + " [" + _drvName + ", " + |
|
928 |
lyrDef.getHost() + ", " + lyrDef.getPort() + ", " + |
|
929 |
lyrDef.getSchema() + ", " + lyrDef.getUser() + "]. " + |
|
930 |
strPassword + "?"); |
|
931 |
dlg.show(); |
|
932 |
clave = dlg.getPassword(); |
|
933 |
|
|
934 |
if (clave == null) { |
|
935 |
return; |
|
936 |
} |
|
937 |
|
|
938 |
poolPassw.put(keyPool, clave); |
|
939 |
lyrDef.setPassword(clave); |
|
940 |
|
|
941 |
} |
|
942 |
|
|
943 |
DBLayerDefinition lyrDef = new DBLayerDefinition(); |
|
944 |
|
|
945 |
if (getLyrDef() == null) { |
|
946 |
lyrDef.setCatalogName(catalogName); |
|
947 |
lyrDef.setFieldNames(fields); |
|
948 |
if (workingArea != null) { |
|
949 |
lyrDef.setWorkingArea(workingArea); |
|
950 |
} |
|
951 |
} else { |
|
952 |
lyrDef = getLyrDef(); |
|
953 |
} |
|
954 |
|
|
955 |
setData(null, lyrDef); |
|
956 |
} catch (ClassNotFoundException e) { |
|
957 |
DriverJdbcNotFoundExceptionType type = new DriverJdbcNotFoundExceptionType(); |
|
958 |
type.setDriverJdbcClassName(driverClass); |
|
959 |
type.setLayerName(this.getLyrDef().getTableName()); |
|
960 |
throw new DriverException("Driver SDE no encontrado", e, type); |
|
961 |
} |
|
962 |
} |
|
963 |
|
|
964 |
public Object getConnection() { |
|
965 |
return conn; |
|
966 |
} |
|
967 |
// public String[] getTableNames(Object conex, String dbName) throws SQLException { |
|
968 |
// Vector theLayers=null; |
|
969 |
// try { |
|
970 |
// theLayers = ((SeConnection)conex).getLayers(); |
|
971 |
// } catch (SeException e) { |
|
972 |
// throw new SQLException(e.getMessage()); |
|
973 |
// } |
|
974 |
// TreeMap ret = new TreeMap(); |
|
975 |
// for (int i = 0; i < theLayers.size(); i++) { |
|
976 |
// SeLayer layer = (SeLayer) theLayers.elementAt(i); |
|
977 |
// ret.put(layer.getTableName(), layer.getTableName()); |
|
978 |
// } |
|
979 |
// return (String[]) ret.keySet().toArray(new String[0]); |
|
980 |
// } |
|
981 |
// public String[] getAllFields(Object conex, String tableName) { |
|
982 |
// try { |
|
983 |
// SeTable table = new SeTable(((SeConnection)conex),tableName); |
|
984 |
// SeRegisteredColumn[] columns=table.getColumnList(); |
|
985 |
// String[] fieldNames=new String[columns.length]; |
|
986 |
// for (int i=0; i < columns.length; i++){ |
|
987 |
// fieldNames[i]=columns[i].getName(); |
|
988 |
// } |
|
989 |
// return fieldNames; |
|
990 |
// } catch (SeException e) { |
|
991 |
// e.printStackTrace(); |
|
992 |
// } |
|
993 |
// return null; |
|
994 |
// } |
|
995 |
// public String[] getAllFieldTypeNames(Object conex, String tableName) { |
|
996 |
// try { |
|
997 |
// SeTable table = new SeTable(((SeConnection)conex),tableName); |
|
998 |
// SeRegisteredColumn[] columns=table.getColumnList(); |
|
999 |
// String[] fieldNames=new String[columns.length]; |
|
1000 |
// for (int i=0; i < columns.length; i++){ |
|
1001 |
// fieldNames[i]=String.valueOf(columns[i].getType()); |
|
1002 |
// } |
|
1003 |
// return fieldNames; |
|
1004 |
// } catch (SeException e) { |
|
1005 |
// e.printStackTrace(); |
|
1006 |
// } |
|
1007 |
// return null; |
|
1008 |
// } |
|
1009 |
// public String[] getIdFieldsCandidates(Object conn2, String tableName) { |
|
1010 |
// return new String[]{"OBJECTID"};//getAllFields(conn2,tableName); |
|
1011 |
// } |
|
1012 |
// public String[] getGeometryFieldsCandidates(Object conn2, String tableName) { |
|
1013 |
// return new String[]{"SHAPE"};//getAllFields(conn2,tableName); |
|
1014 |
// } |
|
1015 |
public String getConnectionString( |
|
1016 |
String host, |
|
1017 |
String port, |
|
1018 |
String dbname, |
|
1019 |
String user, |
|
1020 |
String pw) { |
|
1021 |
|
|
1022 |
String resp = getConnectionStringBeginning() + "//" + host.toLowerCase(); |
|
1023 |
|
|
1024 |
if (dbname.trim().length() > 0) { |
|
1025 |
resp += ":" + port; |
|
1026 |
} else { |
|
1027 |
resp += ":" + getDefaultPort(); |
|
1028 |
} |
|
1029 |
|
|
1030 |
resp += "/" + dbname.toLowerCase(); |
|
1031 |
return resp; |
|
1032 |
} |
|
535 | 1033 |
} |
Also available in: Unified diff