Revision 13444 trunk/extensions/extSDE/src/com/iver/cit/gvsig/fmap/drivers/sde/ArcSdeDriver.java

View differences:

ArcSdeDriver.java
65 65
import com.esri.sde.sdk.client.SeShapeFilter;
66 66
import com.esri.sde.sdk.client.SeSqlConstruct;
67 67
import com.esri.sde.sdk.client.SeTable;
68
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException;
69
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
70
import com.hardcode.gdbms.driver.exceptions.ReloadDriverException;
68 71
import com.hardcode.gdbms.engine.data.DataSourceFactory;
69 72
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
70 73
import com.hardcode.gdbms.engine.data.edition.DataWare;
......
72 75
import com.hardcode.gdbms.engine.values.ValueFactory;
73 76
import com.iver.andami.messages.Messages;
74 77
import com.iver.andami.messages.NotificationManager;
75
import com.iver.cit.gvsig.fmap.DriverException;
76 78
import com.iver.cit.gvsig.fmap.DriverJdbcNotFoundExceptionType;
77 79
import com.iver.cit.gvsig.fmap.core.FShape;
78 80
import com.iver.cit.gvsig.fmap.core.ICanReproject;
......
86 88
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
87 89
import com.iver.cit.gvsig.fmap.drivers.db.utils.ConnectionWithParams;
88 90
import com.iver.cit.gvsig.fmap.drivers.db.utils.SingleVectorialDBConnectionManager;
89
import com.iver.cit.gvsig.fmap.edition.EditionException;
90 91
import com.iver.cit.gvsig.fmap.edition.IWriteable;
91 92
import com.iver.cit.gvsig.fmap.edition.IWriter;
92 93
import com.iver.cit.gvsig.fmap.layers.XMLException;
94
import com.iver.cit.gvsig.project.documents.gui.FOpenDialog;
93 95
import com.iver.utiles.XMLEntity;
94 96
import com.iver.utiles.swing.JPasswordDlg;
95 97

  
......
115 117
    private long lastRowServed = -1;
116 118
//    private SeConnection alphanumericConnection = null;
117 119
    private IConnection spatialConnection=null;
118
    private String strEPSG;
119
    private String originalEPSG = null;
120
    private String strEPSG = "-1";
121
    private String originalEPSG = "-1";
120 122
    private String sqlTotal;
121 123
    private long posActual = -1;
122 124
    private SeRow cachedRow = null;
......
147 149
    protected void doRelateID_FID() {
148 150
        hashRelate = new Hashtable();
149 151

  
150
        try {
151
            if (row == null) {
152
        	if (row == null) {
152 153
                System.out.println(" No rows fetched");
153 154

  
154 155
                return;
......
156 157

  
157 158
            int index = 0;
158 159
            int fid=getLyrDef().getIdFieldID();
159
            Value value=getFieldValue(index,fid-1);
160
            Value value=getFieldValue(index,fid);
160 161

  
161 162
            while (value != null) {
162 163
                //SeShape shpVal = row.getShape(idSpatialColumn);
......
164 165
            	String theKey = value.toString();
165 166
                hashRelate.put(theKey, new Integer(index));
166 167
                index++;
167
                value = getFieldValue(index,fid-1);
168
                value = getFieldValue(index,fid);
168 169

  
169 170

  
170 171
            }
171 172

  
172 173
            numReg = index;
173
        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
174
        	NotificationManager.addError(e);
175
		}
176 174
    }
177 175
    /**
178 176
	 * @return
......
196 194
        return null;
197 195
    }
198 196

  
199
    public IFeatureIterator getFeatureIterator(String sql)
200
        throws DriverException {
197
    public IFeatureIterator getFeatureIterator(String sql){
201 198
        return null;
202 199
    }
203 200

  
204
    public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG)
205
        throws DriverException {
201
    public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG) {
206 202
        /*
207 203
         *   Generate a rectangular shape that will be used as a filter
208 204
         */
......
250 246
    public void close() {
251 247
    }
252 248

  
253
    public void open() throws DriverException {
249
    public void open() {
254 250
    }
255 251

  
256 252
    public int getRowIndexByFID(IFeature FID) {
......
270 266
        return layer.getSpatialColumn();
271 267
    }
272 268

  
273
    public int getShapeCount() throws IOException {
269
    public int getShapeCount() {
274 270
        return numReg;
275 271
    }
276 272

  
......
330 326
        return cachedRow;
331 327
    }
332 328

  
333
    public Value getFieldValue(long rowIndex, int fieldId)
334
        throws com.hardcode.gdbms.engine.data.driver.DriverException {
329
    public Value getFieldValue(long rowIndex, int fieldId) {
335 330
        SeRow row;
336 331
        Value val = null;
337 332

  
......
376 371
                break;
377 372

  
378 373
            case SeColumnDefinition.TYPE_STRING:
374
            case SeColumnDefinition.TYPE_NSTRING:
379 375

  
380 376
                String strAux = row.getString(idFieldArcSDE);
381 377

  
......
396 392
        return ValueFactory.createNullValue();
397 393
    }
398 394

  
399
    public int getFieldCount()
400
        throws com.hardcode.gdbms.engine.data.driver.DriverException {
395
    public int getFieldCount(){
401 396
        return fields.length - 1;
402 397
    }
403 398

  
404
    public String getFieldName(int fieldId)
405
        throws com.hardcode.gdbms.engine.data.driver.DriverException {
399
    public String getFieldName(int fieldId) {
406 400
        return fields[fieldId + 1];
407 401
    }
408 402

  
......
410 404
        return numReg;
411 405
    }
412 406

  
413
    public int getFieldType(int i)
414
        throws com.hardcode.gdbms.engine.data.driver.DriverException {
415
        return fieldTypes[i];
407
    public int getFieldType(int i) {
408
        return fieldTypes[i+1];
416 409
    }
417 410

  
418 411
    /**
419 412
     * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
420 413
     */
421
    public int[] getPrimaryKeys()
422
        throws com.hardcode.gdbms.engine.data.driver.DriverException {
414
    public int[] getPrimaryKeys() {
423 415
        throw new UnsupportedOperationException();
424 416
    }
425 417

  
426 418
    /**
427 419
     * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
428 420
     */
429
    public void write(DataWare arg0)
430
        throws com.hardcode.gdbms.engine.data.driver.DriverException {
421
    public void write(DataWare arg0) {
431 422
    }
432 423

  
433 424
    public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG,
434
        String[] alphaNumericFieldsNeeded) throws DriverException {
425
        String[] alphaNumericFieldsNeeded) {
435 426
        /*
436 427
        *   Generate a rectangular shape that will be used as a filter
437 428
        */
......
480 471
    public boolean isWritable() {
481 472
        return false;
482 473
    }
483
    public void setData(IConnection connection, DBLayerDefinition lyrDef) {
474
    public void setData(IConnection connection, DBLayerDefinition lyrDef) throws DBException {
484 475
    	 String[] fieldsAux=null;
485 476
         FieldDescription[] fds=lyrDef.getFieldsDesc();
486 477
    	 if ((fds != null) && (fds.length != 0)) {
......
494 485
             }
495 486
         }
496 487
        lyrDef.setFieldNames(fieldsAux);
497
    	setLyrDef(lyrDef);
488
        lyrDef.setIdFieldID(lyrDef.getIdField(lyrDef.getFieldID())-1);
489
        setLyrDef(lyrDef);
498 490
        // Conexi?n:
499 491
        String server = lyrDef.getHost();
500 492
        int instance = lyrDef.getPort();
......
502 494
        String user = lyrDef.getUser();
503 495
        String password = lyrDef.getPassword();
504 496
        String[] cols = lyrDef.getFieldNames();
505
        String tableName = lyrDef.getTableName();
497
        String tableName = lyrDef.getComposedTableName();
506 498

  
507 499
        try {
508 500
            alphanumericConnection =new SeConnection(server, instance, database, user, password);
......
525 517
                SeLayer layer = (SeLayer) theLayers.elementAt(i);
526 518

  
527 519
                if (layer.getName().compareToIgnoreCase(layerName) == 0) {
528
                    ;
520
                	layerID = layer.getID();
521
                    strSpatialColumn = layer.getSpatialColumn();
529 522
                }
530 523

  
531
                layerID = layer.getID();
532
                strSpatialColumn = layer.getSpatialColumn();
524

  
533 525
            }
534 526

  
535 527
            if (layerID == null) {
......
664 656

  
665 657
            doRelateID_FID();
666 658
        } catch (SeException e) {
667
        	NotificationManager.addError(e);
659
        	throw new DBException(e);
668 660
        }
669 661
    }
670 662

  
......
710 702
        return 5151;
711 703
    }
712 704

  
713
    public String getSourceProjection() {
705
    public String getSourceProjection(IConnection conn,DBLayerDefinition dbld) {
714 706
        return originalEPSG;
715 707
    }
716 708

  
......
733 725
             writer.setDriver(this);
734 726
             writer.setSeLayer(layer);
735 727
             try {
736
                 writer.initialize(getLyrDef());
737
             }
738
             catch (EditionException e) {
739

  
740
             }
728
				writer.initialize(getLyrDef());
729
			} catch (InitializeWriterException e) {
730
				NotificationManager.addError(e);
731
			}
741 732
         }
742 733

  
743 734
         return writer;
......
777 768
        xml.putProperty("tablename", getTableName());
778 769
        xml.putProperty("fields", fields);
779 770
        xml.putProperty("ID", lyrDef.getFieldID());
771
        xml.putProperty("idfield",lyrDef.getIdFieldID());
780 772
        xml.putProperty("THE_GEOM", lyrDef.getFieldGeometry());
781 773
        xml.putProperty("whereclause", getWhereClause());
782 774
        xml.putProperty("SRID", lyrDef.getSRID_EPSG());
......
812 804
        fields = xml.getStringArrayProperty("fields");
813 805
        lyrDef.setFieldNames(fields);
814 806
        lyrDef.setFieldID(xml.getStringProperty("ID"));
807
        if (xml.contains("idfield"))
808
        	lyrDef.setIdFieldID(xml.getIntProperty("idfield"));
815 809
        lyrDef.setFieldGeometry(xml.getStringProperty("THE_GEOM"));
816 810
        lyrDef.setWhereClause(xml.getStringProperty("whereclause"));
817 811
        lyrDef.setSRID_EPSG(xml.getStringProperty("SRID"));
......
832 826
        }
833 827

  
834 828
        lyrDef.setCatalogName(catalogName);
835
        lyrDef.setFieldNames(fields);
836 829

  
837 830
        if (workingArea != null) {
838 831
            lyrDef.setWorkingArea(workingArea);
......
842 835
    }
843 836

  
844 837
    public int getFieldWidth(int fieldId) {
845
        return colDefs[fieldId].getSize();
838
        return colDefs[fieldId+1].getSize();
846 839
    }
847 840

  
848 841
    public void setLyrDef(DBLayerDefinition lyrDef) {
......
904 897
    /* (non-Javadoc)
905 898
    * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#reLoad()
906 899
    */
907
    public void reload() throws IOException {
900
    public void reload() throws ReloadDriverException{
908 901
    	try {
909 902
			load();
910
		} catch (DriverException e) {
911
			NotificationManager.addError(e);
903
		} catch (ReadDriverException e) {
904
			throw new ReloadDriverException(this.className,e);
912 905
		}
913
       	//setData(null, lyrDef);
914
    }
906
	}
915 907

  
916 908
    public void setDataSourceFactory(DataSourceFactory dsf) {
917 909
        // TODO Auto-generated method stub
918 910
    }
919 911

  
920
    public void load() throws DriverException {
912
    public void load() throws ReadDriverException{
921 913
    	try {
922 914
            if (driverClass != null)
923 915
            	Class.forName(driverClass);
......
995 987

  
996 988
            setData(newConn, lyrDef);
997 989
        } catch (ClassNotFoundException e) {
998
            DriverJdbcNotFoundExceptionType type =
999
            	new DriverJdbcNotFoundExceptionType();
1000
            type.setDriverJdbcClassName(driverClass);
1001
            type.setLayerName(this.getTableName());
1002
            throw new DriverException("Driver JDBC no encontrado", e,  type);
990
        	throw new ReadDriverException(this.className,e);
1003 991
        } catch (DBException e) {
992
        	throw new ReadDriverException(this.className,e);
1004 993

  
1005
        	throw new DriverException(e.getMessage());
1006

  
1007 994
		}
1008 995
    }
1009 996

  
......
1054 1041
			throw new DBException(e);
1055 1042
		}
1056 1043
	}
1057
	public String[] getIdFieldsCandidates(IConnection conn2, String tableName) {
1058
		return new String[]{"OBJECTID"};//getAllFields(conn2,tableName);
1044
	public String[] getIdFieldsCandidates(IConnection conn2, String tableName) throws DBException {
1045
		return getAllFields(conn2,tableName);
1059 1046
	}
1060 1047
	public String[] getGeometryFieldsCandidates(IConnection conn2, String tableName) {
1061 1048
		return new String[]{"SHAPE"};//getAllFields(conn2,tableName);

Also available in: Unified diff