Revision 11012 branches/v10/extensions/extSDE/src/com/iver/cit/gvsig/fmap/drivers/sde/ArcSdeDriver.java
ArcSdeDriver.java | ||
---|---|---|
46 | 46 |
import java.awt.geom.Rectangle2D; |
47 | 47 |
import java.io.IOException; |
48 | 48 |
import java.sql.Connection; |
49 |
import java.sql.SQLException; |
|
50 | 49 |
import java.sql.Types; |
51 | 50 |
import java.util.Hashtable; |
52 |
import java.util.TreeMap; |
|
53 | 51 |
import java.util.Vector; |
54 | 52 |
|
55 | 53 |
import com.esri.sde.sdk.client.SeColumnDefinition; |
... | ... | |
61 | 59 |
import com.esri.sde.sdk.client.SeObjectId; |
62 | 60 |
import com.esri.sde.sdk.client.SeQuery; |
63 | 61 |
import com.esri.sde.sdk.client.SeQueryInfo; |
64 |
import com.esri.sde.sdk.client.SeRegisteredColumn; |
|
65 | 62 |
import com.esri.sde.sdk.client.SeRow; |
66 | 63 |
import com.esri.sde.sdk.client.SeShape; |
67 | 64 |
import com.esri.sde.sdk.client.SeShapeFilter; |
68 | 65 |
import com.esri.sde.sdk.client.SeSqlConstruct; |
69 | 66 |
import com.esri.sde.sdk.client.SeTable; |
70 | 67 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
68 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
|
71 | 69 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
72 | 70 |
import com.hardcode.gdbms.engine.values.Value; |
73 | 71 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
... | ... | |
81 | 79 |
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition; |
82 | 80 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
83 | 81 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
84 |
import com.iver.cit.gvsig.fmap.drivers.VectorialSDEDriver; |
|
82 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
|
83 |
import com.iver.cit.gvsig.fmap.drivers.sde.utils.SDELayerDefinition; |
|
84 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
|
85 | 85 |
import com.iver.cit.gvsig.fmap.edition.IWriteable; |
86 | 86 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
87 | 87 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
... | ... | |
95 | 95 |
* @uml.dependency supplier="com.iver.cit.gvsig.fmap.drivers.sde.ArcSdeFeatureIterator" |
96 | 96 |
* @uml.dependency supplier="com.iver.cit.gvsig.fmap.drivers.sde.SDELayerDefinition" |
97 | 97 |
*/ |
98 |
public class ArcSdeDriver implements ICanReproject, IWriteable, |
|
99 |
VectorialSDEDriver { |
|
98 |
public class ArcSdeDriver implements ICanReproject, IWriteable, VectorialSDEDriver, ObjectDriver{ |
|
100 | 99 |
protected static Hashtable poolPassw = new Hashtable(); |
101 | 100 |
private SeLayer layer; |
102 | 101 |
private SeQuery query; |
... | ... | |
137 | 136 |
protected String driverClass; |
138 | 137 |
protected String className; |
139 | 138 |
protected String catalogName; |
139 |
private ArcSdeWriter writer; |
|
140 | 140 |
|
141 | 141 |
/** |
142 | 142 |
* Recorre el recordset creando una tabla Hash que usaremos para relacionar |
... | ... | |
154 | 154 |
} |
155 | 155 |
|
156 | 156 |
int index = 0; |
157 |
|
|
158 |
while (row != null) { |
|
159 |
SeShape shpVal = row.getShape(idSpatialColumn); |
|
160 |
SeObjectId objID = shpVal.getFeatureId(); |
|
161 |
String theKey = "" + objID.longValue(); |
|
157 |
Value value=getFieldValue(index,getLyrDef().getIdFieldID()); |
|
158 |
int fid=getLyrDef().getIdFieldID(); |
|
159 |
while (value != null) { |
|
160 |
//SeShape shpVal = row.getShape(idSpatialColumn); |
|
161 |
//SeObjectId objID = shpVal.getFeatureId(); |
|
162 |
String theKey = value.toString(); |
|
162 | 163 |
hashRelate.put(theKey, new Integer(index)); |
163 |
row = query.fetch();
|
|
164 |
index++;
|
|
164 |
value = getFieldValue(index,fid);
|
|
165 |
index++;
|
|
165 | 166 |
} |
166 | 167 |
|
167 | 168 |
numReg = index; |
168 |
} catch (SeException e) {
|
|
169 |
e.printStackTrace();
|
|
170 |
}
|
|
169 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
|
170 |
e.printStackTrace();
|
|
171 |
}
|
|
171 | 172 |
} |
172 | 173 |
/** |
173 | 174 |
* @return |
... | ... | |
276 | 277 |
} |
277 | 278 |
|
278 | 279 |
public String getName() { |
279 |
return "ArcSDE driver";
|
|
280 |
return "gvSIG SDE driver";
|
|
280 | 281 |
} |
281 | 282 |
|
282 | 283 |
/** |
... | ... | |
336 | 337 |
Value val = null; |
337 | 338 |
|
338 | 339 |
try { |
339 |
int idFieldArcSDE = fieldId + 1; // SIEMPRE CONTANDO CON
|
|
340 |
int idFieldArcSDE = fieldId; // SIEMPRE CONTANDO CON |
|
340 | 341 |
// QUE NOS HAN PASADO EL PRIMER CAMPO EL DE SHAPE |
341 | 342 |
row = obtainRow(rowIndex); |
342 |
|
|
343 |
if (row==null) |
|
344 |
return null; |
|
343 | 345 |
int dataType = colDefs[idFieldArcSDE].getType(); |
344 | 346 |
|
345 | 347 |
switch (dataType) { |
... | ... | |
533 | 535 |
//TODO aqu? se puede saber la proyecci?n |
534 | 536 |
//layer.getCoordRef().getSrid(); |
535 | 537 |
|
536 |
if ((cols != null) && (cols.length != 0)) { |
|
537 |
if (!cols[0].equals(lyrDef.getFieldGeometry())) { |
|
538 |
this.fields = new String[cols.length + 1]; |
|
539 |
this.fields[0] = lyrDef.getFieldGeometry(); |
|
540 |
|
|
541 |
for (int i = 1; i < fields.length; i++) { |
|
542 |
fields[i] = cols[i - 1]; |
|
543 |
} |
|
544 |
} else { |
|
545 |
fields = cols; |
|
546 |
} |
|
547 |
} else { |
|
548 |
SeSqlConstruct sqlConstruct = new SeSqlConstruct(tableName); |
|
549 |
sqlTotal = sqlConstruct.getWhere(); |
|
550 |
|
|
551 |
SeTable table1 = new SeTable(conn, tableName); |
|
552 |
|
|
553 |
/* |
|
554 |
* Get the table's column definition. |
|
555 |
*/ |
|
556 |
SeColumnDefinition[] tableDef = table1.describe(); |
|
557 |
this.fields = new String[tableDef.length]; |
|
558 |
|
|
559 |
/* |
|
560 |
* Store the names of all the table's columns in the |
|
561 |
* String array cols. This array specifies the columns |
|
562 |
* to be retrieved from the database. |
|
563 |
*/ |
|
564 |
int idField = 1; |
|
565 |
|
|
566 |
for (int i = 0; i < tableDef.length; i++) { |
|
567 |
if (tableDef[i].getType() == SeColumnDefinition.TYPE_SHAPE) { |
|
568 |
this.fields[0] = tableDef[i].getName(); |
|
569 |
} else { |
|
570 |
this.fields[idField] = tableDef[i].getName(); |
|
571 |
idField++; |
|
572 |
} |
|
573 |
} |
|
574 |
|
|
575 |
lyrDef.setFieldNames(fields); |
|
576 |
} |
|
577 |
|
|
538 |
// if ((cols != null) && (cols.length != 0)) {
|
|
539 |
// if (!cols[0].equals(lyrDef.getFieldGeometry())) {
|
|
540 |
// this.fields = new String[cols.length + 1];
|
|
541 |
// this.fields[0] = lyrDef.getFieldGeometry();
|
|
542 |
// |
|
543 |
// for (int i = 1; i < fields.length; i++) {
|
|
544 |
// fields[i] = cols[i - 1];
|
|
545 |
// }
|
|
546 |
// } else {
|
|
547 |
// fields = cols;
|
|
548 |
// }
|
|
549 |
// } else {
|
|
550 |
// SeSqlConstruct sqlConstruct = new SeSqlConstruct(tableName);
|
|
551 |
// sqlTotal = sqlConstruct.getWhere();
|
|
552 |
// |
|
553 |
// SeTable table1 = new SeTable(conn, tableName);
|
|
554 |
// |
|
555 |
// /*
|
|
556 |
// * Get the table's column definition.
|
|
557 |
// */
|
|
558 |
// SeColumnDefinition[] tableDef = table1.describe();
|
|
559 |
// this.fields = new String[tableDef.length];
|
|
560 |
// |
|
561 |
// /*
|
|
562 |
// * Store the names of all the table's columns in the
|
|
563 |
// * String array cols. This array specifies the columns
|
|
564 |
// * to be retrieved from the database.
|
|
565 |
// */
|
|
566 |
// int idField = 1;
|
|
567 |
// |
|
568 |
// for (int i = 0; i < tableDef.length; i++) {
|
|
569 |
// if (tableDef[i].getType() == SeColumnDefinition.TYPE_SHAPE) {
|
|
570 |
// this.fields[0] = tableDef[i].getName();
|
|
571 |
// } else {
|
|
572 |
// this.fields[idField] = tableDef[i].getName();
|
|
573 |
// idField++;
|
|
574 |
// }
|
|
575 |
// }
|
|
576 |
// |
|
577 |
// lyrDef.setFieldNames(fields);
|
|
578 |
// }
|
|
579 |
fields=cols; |
|
578 | 580 |
sqlConstruct = new SeSqlConstruct(layerName); |
579 | 581 |
|
580 | 582 |
// Create a query stream between the client and server |
... | ... | |
640 | 642 |
break; |
641 | 643 |
} |
642 | 644 |
} |
643 |
|
|
645 |
fields=cols; |
|
644 | 646 |
SeQuery extentQuery = new SeQuery(conn, fields, sqlConstruct); |
645 | 647 |
SeQueryInfo queryInfo = new SeQueryInfo(); |
646 | 648 |
queryInfo.setConstruct(sqlConstruct); |
... | ... | |
718 | 720 |
} |
719 | 721 |
|
720 | 722 |
public IWriter getWriter() { |
721 |
return null; |
|
723 |
if (writer == null) { |
|
724 |
writer = new ArcSdeWriter(); |
|
725 |
writer.setDriver(this); |
|
726 |
writer.setSeLayer(layer); |
|
727 |
try { |
|
728 |
writer.initialize(getLyrDef()); |
|
729 |
} |
|
730 |
catch (EditionException e) { |
|
731 |
|
|
732 |
} |
|
733 |
} |
|
734 |
|
|
735 |
return writer; |
|
722 | 736 |
} |
723 | 737 |
|
724 | 738 |
/** |
... | ... | |
878 | 892 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#reLoad() |
879 | 893 |
*/ |
880 | 894 |
public void reload() throws IOException { |
881 |
setData(null, lyrDef); |
|
895 |
try { |
|
896 |
load(); |
|
897 |
} catch (DriverException e) { |
|
898 |
e.printStackTrace(); |
|
899 |
} |
|
900 |
//setData(null, lyrDef); |
|
882 | 901 |
} |
883 | 902 |
|
884 | 903 |
public void setDataSourceFactory(DataSourceFactory dsf) { |
... | ... | |
948 | 967 |
public Object getConnection() { |
949 | 968 |
return conn; |
950 | 969 |
} |
951 |
public String[] getTableNames(Object conex, String dbName) throws SQLException { |
|
952 |
Vector theLayers=null; |
|
953 |
try { |
|
954 |
theLayers = ((SeConnection)conex).getLayers(); |
|
955 |
} catch (SeException e) { |
|
956 |
throw new SQLException(e.getMessage()); |
|
957 |
} |
|
958 |
TreeMap ret = new TreeMap(); |
|
959 |
for (int i = 0; i < theLayers.size(); i++) { |
|
960 |
SeLayer layer = (SeLayer) theLayers.elementAt(i); |
|
961 |
ret.put(layer.getTableName(), layer.getTableName()); |
|
962 |
} |
|
963 |
return (String[]) ret.keySet().toArray(new String[0]); |
|
964 |
} |
|
965 |
public String[] getAllFields(Object conex, String tableName) { |
|
966 |
try { |
|
967 |
SeTable table = new SeTable(((SeConnection)conex),tableName); |
|
968 |
SeRegisteredColumn[] columns=table.getColumnList(); |
|
969 |
String[] fieldNames=new String[columns.length]; |
|
970 |
for (int i=0; i < columns.length; i++){ |
|
971 |
fieldNames[i]=columns[i].getName(); |
|
972 |
} |
|
973 |
return fieldNames; |
|
974 |
} catch (SeException e) { |
|
975 |
e.printStackTrace(); |
|
976 |
} |
|
977 |
return null; |
|
978 |
} |
|
979 |
public String[] getAllFieldTypeNames(Object conex, String tableName) { |
|
980 |
try { |
|
981 |
SeTable table = new SeTable(((SeConnection)conex),tableName); |
|
982 |
SeRegisteredColumn[] columns=table.getColumnList(); |
|
983 |
String[] fieldNames=new String[columns.length]; |
|
984 |
for (int i=0; i < columns.length; i++){ |
|
985 |
fieldNames[i]=String.valueOf(columns[i].getType()); |
|
986 |
} |
|
987 |
return fieldNames; |
|
988 |
} catch (SeException e) { |
|
989 |
e.printStackTrace(); |
|
990 |
} |
|
991 |
return null; |
|
992 |
} |
|
993 |
public String[] getIdFieldsCandidates(Object conn2, String tableName) { |
|
994 |
return getAllFields(conn2,tableName);
|
|
995 |
} |
|
996 |
public String[] getGeometryFieldsCandidates(Object conn2, String tableName) { |
|
997 |
return getAllFields(conn2,tableName);
|
|
998 |
} |
|
970 |
// public String[] getTableNames(Object conex, String dbName) throws SQLException {
|
|
971 |
// Vector theLayers=null;
|
|
972 |
// try {
|
|
973 |
// theLayers = ((SeConnection)conex).getLayers();
|
|
974 |
// } catch (SeException e) {
|
|
975 |
// throw new SQLException(e.getMessage());
|
|
976 |
// }
|
|
977 |
// TreeMap ret = new TreeMap();
|
|
978 |
// for (int i = 0; i < theLayers.size(); i++) {
|
|
979 |
// SeLayer layer = (SeLayer) theLayers.elementAt(i);
|
|
980 |
// ret.put(layer.getTableName(), layer.getTableName());
|
|
981 |
// }
|
|
982 |
// return (String[]) ret.keySet().toArray(new String[0]);
|
|
983 |
// }
|
|
984 |
// public String[] getAllFields(Object conex, String tableName) {
|
|
985 |
// try {
|
|
986 |
// SeTable table = new SeTable(((SeConnection)conex),tableName);
|
|
987 |
// SeRegisteredColumn[] columns=table.getColumnList();
|
|
988 |
// String[] fieldNames=new String[columns.length];
|
|
989 |
// for (int i=0; i < columns.length; i++){
|
|
990 |
// fieldNames[i]=columns[i].getName();
|
|
991 |
// }
|
|
992 |
// return fieldNames;
|
|
993 |
// } catch (SeException e) {
|
|
994 |
// e.printStackTrace();
|
|
995 |
// }
|
|
996 |
// return null;
|
|
997 |
// }
|
|
998 |
// public String[] getAllFieldTypeNames(Object conex, String tableName) {
|
|
999 |
// try {
|
|
1000 |
// SeTable table = new SeTable(((SeConnection)conex),tableName);
|
|
1001 |
// SeRegisteredColumn[] columns=table.getColumnList();
|
|
1002 |
// String[] fieldNames=new String[columns.length];
|
|
1003 |
// for (int i=0; i < columns.length; i++){
|
|
1004 |
// fieldNames[i]=String.valueOf(columns[i].getType());
|
|
1005 |
// }
|
|
1006 |
// return fieldNames;
|
|
1007 |
// } catch (SeException e) {
|
|
1008 |
// e.printStackTrace();
|
|
1009 |
// }
|
|
1010 |
// return null;
|
|
1011 |
// }
|
|
1012 |
// public String[] getIdFieldsCandidates(Object conn2, String tableName) {
|
|
1013 |
// return new String[]{"OBJECTID"};//getAllFields(conn2,tableName);
|
|
1014 |
// }
|
|
1015 |
// public String[] getGeometryFieldsCandidates(Object conn2, String tableName) {
|
|
1016 |
// return new String[]{"SHAPE"};//getAllFields(conn2,tableName);
|
|
1017 |
// }
|
|
999 | 1018 |
public String getConnectionString( |
1000 | 1019 |
String host, |
1001 | 1020 |
String port, |
Also available in: Unified diff