88 |
88 |
|
89 |
89 |
/**
|
90 |
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"
|
|
91 |
* @author Vicente Caballero Navarro
|
94 |
92 |
*/
|
95 |
93 |
public class ArcSdeDriver implements ICanReproject, IWriteable, VectorialSDEDriver, ObjectDriver{
|
96 |
94 |
protected static Hashtable poolPassw = new Hashtable();
|
97 |
95 |
private SeLayer layer;
|
98 |
|
private SeQuery query;
|
99 |
|
private SeQuery queryAux;
|
|
96 |
private SeQuery query=null;
|
|
97 |
private SeQuery queryAux=null;
|
100 |
98 |
private SeSqlConstruct sqlConstruct;
|
101 |
99 |
private SeColumnDefinition[] colDefs;
|
102 |
100 |
private SeRow row = null;
|
103 |
101 |
private int numReg = -1;
|
104 |
|
/**
|
105 |
|
* @uml.property name="fullExtent"
|
106 |
|
*/
|
107 |
102 |
private Rectangle2D fullExtent = null;
|
108 |
103 |
private Hashtable hashRelate = null;
|
109 |
104 |
private int idSpatialColumn = -1;
|
110 |
|
/**
|
111 |
|
* @uml.property name="fields"
|
112 |
|
*/
|
113 |
105 |
private String[] fields;
|
114 |
106 |
private int[] fieldTypes;
|
115 |
107 |
private long lastRowServed = -1;
|
116 |
|
private SeConnection conn = null;
|
|
108 |
private SeConnection alphanumericConnection = null;
|
|
109 |
private SeConnection spatialConnection=null;
|
117 |
110 |
private String strEPSG;
|
118 |
111 |
private String originalEPSG = null;
|
119 |
|
/**
|
120 |
|
* @uml.property name="sqlTotal"
|
121 |
|
*/
|
122 |
112 |
private String sqlTotal;
|
123 |
113 |
private long posActual = -1;
|
124 |
114 |
private SeRow cachedRow = null;
|
125 |
|
/**
|
126 |
|
* @uml.property name="lyrDef"
|
127 |
|
*/
|
128 |
115 |
protected VectorialSDELayerDefinition lyrDef = null;
|
129 |
|
/**
|
130 |
|
* @uml.property name="workingArea"
|
131 |
|
*/
|
132 |
116 |
protected Rectangle2D workingArea;
|
133 |
117 |
protected String driverClass;
|
134 |
118 |
protected String className;
|
... | ... | |
151 |
135 |
}
|
152 |
136 |
|
153 |
137 |
int index = 0;
|
154 |
|
Value value=getFieldValue(index,getLyrDef().getIdFieldID());
|
|
138 |
Value value=getFieldValue(index,getLyrDef().getIdFieldID()-1);
|
155 |
139 |
int fid=getLyrDef().getIdFieldID();
|
156 |
140 |
while (value != null) {
|
157 |
141 |
//SeShape shpVal = row.getShape(idSpatialColumn);
|
158 |
142 |
//SeObjectId objID = shpVal.getFeatureId();
|
159 |
143 |
String theKey = value.toString();
|
160 |
144 |
hashRelate.put(theKey, new Integer(index));
|
|
145 |
index++;
|
161 |
146 |
value = getFieldValue(index,fid-1);
|
162 |
|
index++;
|
|
147 |
|
|
148 |
|
163 |
149 |
}
|
164 |
150 |
|
165 |
151 |
numReg = index;
|
... | ... | |
169 |
155 |
}
|
170 |
156 |
/**
|
171 |
157 |
* @return
|
172 |
|
* @uml.property name="fullExtent"
|
173 |
158 |
*/
|
174 |
159 |
public Rectangle2D getFullExtent() {
|
175 |
160 |
return fullExtent;
|
... | ... | |
179 |
164 |
|
180 |
165 |
try {
|
181 |
166 |
row = obtainRow(index);
|
182 |
|
|
|
167 |
if (row==null)
|
|
168 |
return null;
|
183 |
169 |
SeShape spVal = row.getShape(idSpatialColumn);
|
184 |
170 |
IGeometry geom = ArcSdeFeatureIterator.getGeometry(spVal);
|
185 |
171 |
return geom;
|
... | ... | |
201 |
187 |
*/
|
202 |
188 |
try {
|
203 |
189 |
SeShape shape = new SeShape(layer.getCoordRef());
|
204 |
|
|
205 |
|
SeExtent extent = new SeExtent(r.getMinX(), r.getMinY(),
|
206 |
|
r.getMaxX(), r.getMaxY());
|
|
190 |
SeExtent extent=layer.getExtent();
|
207 |
191 |
shape.generateRectangle(extent);
|
208 |
192 |
|
209 |
193 |
SeShape[] shapes = new SeShape[1];
|
... | ... | |
223 |
207 |
SeQuery spatialQuery = null;
|
224 |
208 |
SeSqlConstruct sqlCons = new SeSqlConstruct(layer.getName());
|
225 |
209 |
|
226 |
|
spatialQuery = new SeQuery(conn, fields, sqlCons);
|
|
210 |
spatialQuery = new SeQuery(spatialConnection, fields, sqlCons);
|
227 |
211 |
|
228 |
212 |
/*
|
229 |
213 |
* Set spatial constraints
|
230 |
214 |
*/
|
231 |
|
spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false,
|
|
215 |
spatialQuery.setSpatialConstraints(SeQuery.SE_SPATIAL_FIRST, false,
|
232 |
216 |
filters);
|
233 |
217 |
|
234 |
218 |
spatialQuery.prepareQuery();
|
... | ... | |
292 |
276 |
return layer.getName();
|
293 |
277 |
}
|
294 |
278 |
|
295 |
|
private SeRow obtainRow(long rowIndex) throws SeException {
|
296 |
|
if (rowIndex != posActual) {
|
|
279 |
private synchronized SeRow obtainRow(long rowIndex) throws SeException {
|
|
280 |
if (rowIndex != posActual) {
|
297 |
281 |
if (rowIndex == 0) {
|
298 |
282 |
if (query != null) {
|
299 |
283 |
if (query.inProgress()) {
|
300 |
284 |
query.close();
|
301 |
285 |
}
|
|
286 |
query = new SeQuery(spatialConnection, fields, sqlConstruct);
|
|
287 |
query.prepareQuery();
|
|
288 |
query.execute();
|
302 |
289 |
}
|
303 |
|
query = new SeQuery(conn, fields, sqlConstruct);
|
304 |
|
query.prepareQuery();
|
305 |
|
query.execute();
|
306 |
|
|
307 |
290 |
lastRowServed = -1;
|
308 |
291 |
}
|
309 |
292 |
|
... | ... | |
311 |
294 |
row = query.fetch();
|
312 |
295 |
lastRowServed++;
|
313 |
296 |
} else {
|
314 |
|
if (queryAux != null) {
|
315 |
|
queryAux.close();
|
|
297 |
if (queryAux != null && queryAux.inProgress()) {
|
|
298 |
queryAux.close();
|
316 |
299 |
}
|
317 |
300 |
|
318 |
|
queryAux = new SeQuery(conn, fields, sqlConstruct);
|
319 |
|
|
|
301 |
queryAux = new SeQuery(spatialConnection, fields, sqlConstruct);
|
320 |
302 |
SeObjectId rowID = new SeObjectId(rowIndex + 1);
|
321 |
303 |
row = queryAux.fetchRow(layer.getName(), rowID, fields);
|
322 |
304 |
}
|
323 |
|
|
324 |
305 |
posActual = rowIndex;
|
325 |
306 |
cachedRow = row;
|
326 |
307 |
}
|
... | ... | |
435 |
416 |
*/
|
436 |
417 |
try {
|
437 |
418 |
SeShape shape = new SeShape(layer.getCoordRef());
|
438 |
|
|
439 |
|
SeExtent extent = new SeExtent(r.getMinX(), r.getMinY(),
|
440 |
|
r.getMaxX(), r.getMaxY());
|
|
419 |
SeExtent extent=layer.getExtent();
|
441 |
420 |
shape.generateRectangle(extent);
|
442 |
421 |
|
443 |
422 |
SeShape[] shapes = new SeShape[1];
|
... | ... | |
457 |
436 |
SeQuery spatialQuery = null;
|
458 |
437 |
SeSqlConstruct sqlCons = new SeSqlConstruct(layer.getName());
|
459 |
438 |
|
460 |
|
spatialQuery = new SeQuery(conn, fields, sqlCons);
|
|
439 |
spatialQuery = new SeQuery(alphanumericConnection, fields, sqlCons);
|
461 |
440 |
|
462 |
441 |
/*
|
463 |
442 |
* Set spatial constraints
|
... | ... | |
480 |
459 |
public boolean isWritable() {
|
481 |
460 |
return false;
|
482 |
461 |
}
|
483 |
|
|
484 |
462 |
public void setData(Connection connection, DBLayerDefinition lyrDef) {
|
485 |
463 |
setLyrDef(lyrDef);
|
486 |
464 |
// Conexi?n:
|
... | ... | |
492 |
470 |
String password = sdeDef.getPassword();
|
493 |
471 |
String[] cols = sdeDef.getFieldNames();
|
494 |
472 |
String tableName = sdeDef.getTableName();
|
495 |
|
|
496 |
473 |
try {
|
497 |
|
conn = new SeConnection(server, instance, database, user, password);
|
|
474 |
alphanumericConnection = new SeConnection(server, instance, database, user, password);
|
|
475 |
spatialConnection = new SeConnection(server, instance, database, user, password);
|
498 |
476 |
} catch (SeException e) {
|
499 |
477 |
e.printStackTrace();
|
500 |
478 |
|
501 |
479 |
return;
|
502 |
480 |
}
|
503 |
|
|
504 |
481 |
// Fetching data
|
505 |
482 |
String layerName = tableName;
|
506 |
483 |
SeObjectId layerID = null;
|
507 |
484 |
String strSpatialColumn = "";
|
508 |
485 |
|
509 |
486 |
try {
|
510 |
|
Vector theLayers = conn.getLayers();
|
|
487 |
Vector theLayers = spatialConnection.getLayers();
|
511 |
488 |
|
512 |
489 |
for (int i = 0; i < theLayers.size(); i++) {
|
513 |
490 |
SeLayer layer = (SeLayer) theLayers.elementAt(i);
|
... | ... | |
527 |
504 |
}
|
528 |
505 |
|
529 |
506 |
// layerName = layer.getName();
|
530 |
|
layer = new SeLayer(conn, layerName, strSpatialColumn);
|
|
507 |
layer = new SeLayer(spatialConnection, layerName, strSpatialColumn);
|
531 |
508 |
|
532 |
509 |
//TODO aqu? se puede saber la proyecci?n
|
533 |
510 |
//layer.getCoordRef().getSrid();
|
... | ... | |
577 |
554 |
sqlConstruct = new SeSqlConstruct(layerName);
|
578 |
555 |
|
579 |
556 |
// Create a query stream between the client and server
|
580 |
|
query = new SeQuery(conn, fields, sqlConstruct);
|
|
557 |
query = new SeQuery(spatialConnection, fields, sqlConstruct);
|
581 |
558 |
query.prepareQuery();
|
582 |
559 |
query.execute();
|
583 |
560 |
row = query.fetch();
|
... | ... | |
640 |
617 |
}
|
641 |
618 |
}
|
642 |
619 |
fields=cols;
|
643 |
|
SeQuery extentQuery = new SeQuery(conn, fields, sqlConstruct);
|
|
620 |
SeQuery extentQuery = new SeQuery(spatialConnection, fields, sqlConstruct);
|
644 |
621 |
SeQueryInfo queryInfo = new SeQueryInfo();
|
645 |
622 |
queryInfo.setConstruct(sqlConstruct);
|
646 |
623 |
|
... | ... | |
775 |
752 |
xml.putProperty("dbName", sdeDef.getSchema());
|
776 |
753 |
xml.putProperty("connName", sdeDef.getConnectionName());
|
777 |
754 |
|
|
755 |
xml.putProperty("typeShape",sdeDef.getShapeType());
|
|
756 |
|
778 |
757 |
if (getWorkingArea() != null) {
|
779 |
758 |
xml.putProperty("minXworkArea", getWorkingArea().getMinX());
|
780 |
759 |
xml.putProperty("minYworkArea", getWorkingArea().getMinY());
|
... | ... | |
809 |
788 |
lyrDef.setSchema(xml.getStringProperty("dbName"));
|
810 |
789 |
lyrDef.setConnectionName(xml.getStringProperty("connName"));
|
811 |
790 |
}
|
812 |
|
|
|
791 |
lyrDef.setShapeType(xml.getIntProperty("typeShape"));
|
813 |
792 |
if (xml.contains("minXworkArea")) {
|
814 |
793 |
double x = xml.getDoubleProperty("minXworkArea");
|
815 |
794 |
double y = xml.getDoubleProperty("minYworkArea");
|
... | ... | |
872 |
851 |
|
873 |
852 |
/**
|
874 |
853 |
* @return
|
875 |
|
* @uml.property name="lyrDef"
|
876 |
854 |
*/
|
877 |
855 |
public DBLayerDefinition getLyrDef() {
|
878 |
|
return lyrDef;
|
879 |
|
}
|
|
856 |
// Esto hace saltar un error.
|
|
857 |
// if (this.spatialConnection != null){
|
|
858 |
// lyrDef.setSeConnection();
|
|
859 |
// }
|
|
860 |
return lyrDef;
|
|
861 |
}
|
880 |
862 |
|
881 |
863 |
/**
|
882 |
864 |
* Empty method called when the layer is going to be removed from the view.
|
... | ... | |
962 |
944 |
}
|
963 |
945 |
|
964 |
946 |
public Object getConnection() {
|
965 |
|
return conn;
|
|
947 |
return spatialConnection;
|
966 |
948 |
}
|
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 |
949 |
public String getConnectionString(
|
1016 |
950 |
String host,
|
1017 |
951 |
String port,
|
... | ... | |
1030 |
964 |
resp += "/" + dbname.toLowerCase();
|
1031 |
965 |
return resp;
|
1032 |
966 |
}
|
|
967 |
|
1033 |
968 |
}
|