Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_1_RELEASE / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / DefaultDBDriver.java @ 9531

History | View | Annotate | Download (22.6 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.drivers;
42

    
43
import java.awt.geom.Rectangle2D;
44
import java.io.IOException;
45
import java.sql.Connection;
46
import java.sql.DatabaseMetaData;
47
import java.sql.Driver;
48
import java.sql.DriverManager;
49
import java.sql.ResultSet;
50
import java.sql.ResultSetMetaData;
51
import java.sql.SQLException;
52
import java.sql.Statement;
53
import java.sql.Types;
54
import java.util.Hashtable;
55

    
56
import org.apache.log4j.Logger;
57

    
58
import com.hardcode.gdbms.engine.data.DataSourceFactory;
59
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
60
import com.hardcode.gdbms.engine.values.Value;
61
import com.hardcode.gdbms.engine.values.ValueFactory;
62
import com.iver.cit.gvsig.fmap.DriverException;
63
import com.iver.cit.gvsig.fmap.DriverJdbcNotFoundExceptionType;
64
import com.iver.cit.gvsig.fmap.Messages;
65
import com.iver.cit.gvsig.fmap.SqlDriveExceptionType;
66
import com.iver.cit.gvsig.fmap.core.IFeature;
67
import com.iver.cit.gvsig.fmap.core.IGeometry;
68
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
69
import com.iver.cit.gvsig.fmap.layers.XMLException;
70
import com.iver.utiles.XMLEntity;
71
import com.iver.utiles.swing.JPasswordDlg;
72

    
73

    
74

    
75
/**
76
 * Clase abstracta qu
77
 */
78
public abstract class DefaultDBDriver implements VectorialJDBCDriver, ObjectDriver {
79
    private static Logger logger = Logger.getLogger(SelectableDataSource.class.getName());
80
    private static Hashtable poolPassw = new Hashtable();
81

    
82
    protected Connection conn;
83
    // protected String tableName;
84
    // protected String whereClause;
85
    // protected String fields;
86
    // protected String sqlOrig;
87
    private DBLayerDefinition lyrDef = null;
88
    protected ResultSet rs;
89
    protected boolean bCursorActivo = false;
90
    protected Statement st;
91
    protected int numReg=-1;
92

    
93
    private Rectangle2D fullExtent = null;
94

    
95
    // protected String strFID_FieldName;
96
    // protected String idFID_FieldName;
97

    
98
    protected Hashtable hashRelate;
99

    
100

    
101
    protected ResultSetMetaData metaData = null;
102
    protected Rectangle2D workingArea;
103
        private String driverClass;
104
        private String userName;
105
        private String dbUrl;
106
        private String className;
107
        private String catalogName;
108
        private String tableName;
109
        private String[] fields;
110
        private String FIDfield;
111
        private String geometryField;
112
        private String whereClause;
113
        private String strSRID;
114
        //private double flatness;
115

    
116
    abstract public void setData(Connection conn, DBLayerDefinition lyrDef);
117

    
118
        /**
119
         * @return devuelve la Conexi?n a la base de datos, para que
120
         * el usuario pueda hacer la consulta que quiera, si lo desea.
121
         * Por ejemplo, esto puede ser ?til para abrir un cuadro de dialogo
122
         * avanazado y lanzar peticiones del tipo "Devuelveme un buffer
123
         * a las autopistas", y con el resultset que te venga, escribir
124
         * un shape, o cosas as?.
125
         */
126
        public Connection getConnection()
127
        {
128
            return conn;
129
        }
130
        public String[] getFields()
131
        {
132
        /* StringTokenizer tokenizer = new StringTokenizer(fields, ",");
133
        String[] arrayFields = new String[tokenizer.countTokens()];
134
        int i=0;
135
        while (tokenizer.hasMoreTokens())
136
        {
137
            arrayFields[i] = tokenizer.nextToken();
138
            i++;
139
        }
140
            return arrayFields; */
141
        return lyrDef.getFieldNames();
142

    
143
        }
144
    /**
145
     * First, the geometry field. After, the rest of fields
146
     * @return
147
     */
148
    public String getTotalFields()
149
    {
150
        String strAux = getGeometryField(getLyrDef().getFieldGeometry());
151
        String[] fieldNames = getLyrDef().getFieldNames();
152
        for (int i=0; i< fieldNames.length; i++)
153
        {
154
            strAux = strAux + ", " + fieldNames[i];
155
        }
156
        return strAux;
157
    }
158

    
159
        /* (non-Javadoc)
160
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#getWhereClause()
161
         */
162
        public String getWhereClause()
163
        {
164
            return lyrDef.getWhereClause().toUpperCase();
165
        }
166
        public String getTableName()
167
        {
168
            return lyrDef.getTableName();
169
        }
170

    
171

    
172
        /**
173
         * @throws DriverIOException
174
         * @throws DriverException
175
         * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeCount()
176
         */
177
        public int getShapeCount() throws IOException {
178
                    if (numReg == -1)
179
                    {
180
                        try
181
                    {
182
                            Statement s = conn.createStatement();
183
                            ResultSet r = s.executeQuery("SELECT COUNT(*) AS NUMREG FROM " + lyrDef.getTableName() + " " + getCompleteWhere());
184
                            r.next();
185
                            numReg = r.getInt(1);
186
                            System.err.println("numReg = " + numReg);
187
                    }
188
                        catch (SQLException e)
189
                        {
190
                            throw new IOException(e.getMessage());
191
                        }
192
                    }
193

    
194
            return numReg;
195
        }
196

    
197
    /**
198
     * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFullExtent()
199
     */
200
    public Rectangle2D getFullExtent(){
201
        // Por defecto recorremos todas las geometrias.
202
        // Las bases de datos como PostGIS pueden y deben
203
        // sobreescribir este m?todo.
204
        if (fullExtent == null)
205
        {
206
            try
207
            {
208
                IFeatureIterator itGeom = getFeatureIterator("SELECT " +
209
                        getGeometryField(getLyrDef().getFieldGeometry()) + ", " + getLyrDef().getFieldID() + " FROM " +
210
                        getLyrDef().getTableName() +  " " + getCompleteWhere());
211
                IGeometry geom;
212
                int cont = 0;
213
                while (itGeom.hasNext())
214
                {
215
                    geom = itGeom.next().getGeometry();
216
                    if (cont==0)
217
                        fullExtent = geom.getBounds2D();
218
                    else
219
                        fullExtent.add(geom.getBounds2D());
220
                    cont++;
221
                }
222
            }
223
            catch (DriverException e) {
224
                // TODO Auto-generated catch block
225
                e.printStackTrace();
226
            }
227

    
228
        }
229
        return fullExtent;
230
    }
231

    
232

    
233
        /**
234
         * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeType()
235
         */
236
        public int getShapeType() {
237
        /* IGeometry geom;
238
        if (shapeType == -1)
239
        {
240
                shapeType = FShape.MULTI;
241
                try {
242
                        geom = getShape(0);
243
                        if (geom != null)
244
                                shapeType = geom.getGeometryType();
245
                } catch (IOException e) {
246
                        // e.printStackTrace();
247
                }
248
        }
249
        return shapeType; */
250
                return lyrDef.getShapeType();
251
        }
252

    
253
        public int getFieldType(int idField) throws com.hardcode.gdbms.engine.data.driver.DriverException
254
        {
255
            String str = "";
256
            try {
257
                int i = idField + 2; // idField viene basado en 1, y
258
                                        // adem?s nos saltamos el campo de geometry
259
                str = metaData.getColumnClassName(i);
260
            if (metaData.getColumnType(i) == Types.VARCHAR)
261
                return Types.VARCHAR;
262
                    if (metaData.getColumnType(i) == Types.FLOAT)
263
                        return Types.FLOAT;
264
                    if (metaData.getColumnType(i) == Types.DOUBLE)
265
                        return Types.DOUBLE;
266
                    if (metaData.getColumnType(i) == Types.INTEGER)
267
                        return Types.INTEGER;
268
                    if (metaData.getColumnType(i) == Types.SMALLINT)
269
                        return Types.SMALLINT;
270
                    if (metaData.getColumnType(i) == Types.TINYINT)
271
                        return Types.TINYINT;                    
272
                    if (metaData.getColumnType(i) == Types.BIGINT)
273
                        return Types.BIGINT;
274
                    if (metaData.getColumnType(i) == Types.BIT)
275
                        return Types.BIT;
276
                    if (metaData.getColumnType(i) == Types.DATE)
277
                        return Types.DATE;
278
            if (metaData.getColumnType(i) == Types.DECIMAL)
279
                return Types.DOUBLE;
280
            if (metaData.getColumnType(i) == Types.NUMERIC)
281
                return Types.DOUBLE;
282
            if (metaData.getColumnType(i) == Types.DATE)
283
                return Types.DATE;
284
            if (metaData.getColumnType(i) == Types.TIME)
285
                return Types.TIME;
286
            if (metaData.getColumnType(i) == Types.TIMESTAMP)
287
                return Types.TIMESTAMP;
288

    
289
            } catch (SQLException e) {
290
                    throw new com.hardcode.gdbms.engine.data.driver.DriverException(e);
291
            }
292
        throw new com.hardcode.gdbms.engine.data.driver.DriverException("Tipo no soportado: " + str);
293
        }
294
    /**
295
     * Obtiene el valor que se encuentra en la fila y columna indicada
296
     * Esta es la implementaci?n por defecto. Si lo del absolute
297
     * no va bien, como es el caso del PostGis, el driver lo
298
     * tiene que reimplementar
299
     *
300
     * @param rowIndex fila
301
     * @param fieldId columna
302
     *
303
     * @return subclase de Value con el valor del origen de datos
304
     *
305
     * @throws DriverException Si se produce un error accediendo al DataSource
306
     */
307
    public Value getFieldValue(long rowIndex, int idField)
308
        throws com.hardcode.gdbms.engine.data.driver.DriverException
309
        {
310
                int i = (int) (rowIndex + 1);
311
                int fieldId = idField+2;
312
                try {
313
                    rs.absolute(i);
314
                if (metaData.getColumnType(fieldId) == Types.VARCHAR)
315
                {
316
                    String strAux = rs.getString(fieldId);
317
                    if (strAux == null) strAux = "";
318
                    return ValueFactory.createValue(strAux);
319
                }
320
                        if (metaData.getColumnType(fieldId) == Types.FLOAT)
321
                            return ValueFactory.createValue(rs.getFloat(fieldId));
322
                        if (metaData.getColumnType(fieldId) == Types.DOUBLE)
323
                            return ValueFactory.createValue(rs.getDouble(fieldId));
324
                        if (metaData.getColumnType(fieldId) == Types.INTEGER)
325
                            return ValueFactory.createValue(rs.getInt(fieldId));
326
                        if (metaData.getColumnType(fieldId) == Types.BIGINT)
327
                            return ValueFactory.createValue(rs.getLong(fieldId));
328
                        if (metaData.getColumnType(fieldId) == Types.BIT)
329
                            return ValueFactory.createValue(rs.getBoolean(fieldId));
330
                        if (metaData.getColumnType(fieldId) == Types.DATE)
331
                            return ValueFactory.createValue(rs.getDate(fieldId));
332
                } catch (SQLException e) {
333
                throw new com.hardcode.gdbms.engine.data.driver.DriverException("Tipo no soportado: columna " + fieldId );
334
                }
335
                return null;
336

    
337

    
338
        }
339

    
340
    /**
341
     * Obtiene el n?mero de campos del DataSource
342
     *
343
     * @return
344
     *
345
     * @throws DriverException Si se produce alg?n error accediendo al
346
     *         DataSource
347
     */
348
    public int getFieldCount() throws com.hardcode.gdbms.engine.data.driver.DriverException
349
    {
350
        try {
351
            // Suponemos que el primer campo es el de las geometries, y no lo
352
            // contamos
353
            return rs.getMetaData().getColumnCount()-1;
354
        } catch (SQLException e) {
355
            throw new com.hardcode.gdbms.engine.data.driver.DriverException(e);
356
        }
357

    
358
    }
359

    
360
    /**
361
     * Devuelve el nombre del campo fieldId-?simo
362
     *
363
     * @param fieldId ?ndice del campo cuyo nombre se quiere obtener
364
     *
365
     * @return
366
     * @throws com.hardcode.gdbms.engine.data.driver.DriverException
367
     *
368
     * @throws DriverException Si se produce alg?n error accediendo al
369
     *         DataSource
370
     */
371
    public String getFieldName(int fieldId) throws com.hardcode.gdbms.engine.data.driver.DriverException
372
    {
373
        try {
374
            return rs.getMetaData().getColumnName(fieldId+2);
375
        } catch (SQLException e) {
376
            throw new com.hardcode.gdbms.engine.data.driver.DriverException(e);
377
        }
378
    }
379

    
380
    /**
381
     * Obtiene el n?mero de registros del DataSource
382
     *
383
     * @return
384
     *
385
     * @throws DriverException Si se produce alg?n error accediendo al
386
     *         DataSource
387
     */
388
    public long getRowCount()
389
    {
390
        try {
391
            return getShapeCount();
392
        } catch (IOException e) {
393
            // TODO Auto-generated catch block
394
            e.printStackTrace();
395
        }
396
        return -1;
397
    }
398

    
399
    public void close()
400
    {
401
    }
402

    
403
    /**
404
     * Recorre el recordset creando una tabla Hash que usaremos para
405
     * relacionar el n?mero de un registro con su identificador ?nico.
406
     * Debe ser llamado en el setData justo despu?s de crear el recorset
407
     * principal
408
     * @throws SQLException
409
     */
410
    protected void doRelateID_FID() throws SQLException
411
    {
412
        hashRelate = new Hashtable();
413

    
414

    
415
        String strSQL = "SELECT " + getLyrDef().getFieldID() + " FROM " + getLyrDef().getTableName()
416
        + " " + getCompleteWhere() + " ORDER BY " + getLyrDef().getFieldID();
417
        Statement s = getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
418
        ResultSet r = s.executeQuery(strSQL);
419
        int id=0;
420
        int gid;
421
        int index = 0;
422
        while (r.next())
423
        {
424
            String aux = r.getString(1);
425
            Value val = ValueFactory.createValue(aux);
426
            hashRelate.put(val, new Integer(index));
427
            System.out.println("ASOCIANDO CLAVE " + aux + " CON VALOR " + index);
428
            index++;
429
        }
430
        numReg = index;
431
        r.close();
432
        // rs.beforeFirst();
433

    
434
    }
435

    
436
    /* (non-Javadoc)
437
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#getRowIndexByFID(java.lang.Object)
438
     */
439
    public int getRowIndexByFID(IFeature FID)
440
    {
441
        int resul;
442
        // Object obj = FID.getAttribute(lyrDef.getIdFieldID());
443
        String theId = FID.getID();
444
        Value aux = ValueFactory.createValue(theId);
445
        // System.err.println("Mirando si existe " + aux.toString());
446
        if (hashRelate.containsKey(aux))
447
        {
448
                Integer rowIndex = (Integer) hashRelate.get(aux);
449
                resul = rowIndex.intValue();
450
                // System.err.println("Row asociada a " + aux.toString() + ":" + resul);
451
                return resul;
452
        }
453
        else
454
                return -1;
455
    }
456

    
457
    /* (non-Javadoc)
458
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#setXMLEntity(com.iver.utiles.XMLEntity)
459
     */
460
    public void setXMLEntity(XMLEntity xml) throws XMLException
461
    {
462

    
463
        className = xml.getStringProperty("className");
464
        dbUrl = xml.getStringProperty("dbURL");
465
        catalogName = xml.getStringProperty("catalog");
466
        userName =xml.getStringProperty("username");
467
        driverClass =xml.getStringProperty("driverclass");
468
        tableName = xml.getStringProperty("tablename");
469
        fields = xml.getStringArrayProperty("fields");
470
        FIDfield = xml.getStringProperty("FID");
471
        geometryField = xml.getStringProperty("THE_GEOM");
472
        whereClause = xml.getStringProperty("whereclause");
473
        strSRID = xml.getStringProperty("SRID");
474
        if (xml.contains("minXworkArea"))
475
        {
476
            double x = xml.getDoubleProperty("minXworkArea");
477
            double y = xml.getDoubleProperty("minYworkArea");
478
            double H = xml.getDoubleProperty("HworkArea");
479
            double W = xml.getDoubleProperty("WworkArea");
480
            workingArea = new Rectangle2D.Double(x,y,W,H);
481
        }
482

    
483
        DBLayerDefinition lyrDef = new DBLayerDefinition();
484
        lyrDef.setCatalogName(catalogName);
485
        lyrDef.setTableName(tableName);
486
        lyrDef.setFieldNames(fields);
487
        lyrDef.setFieldID(FIDfield);
488
        lyrDef.setFieldGeometry(geometryField);
489
        lyrDef.setWhereClause(whereClause);
490
        // lyrDef.setClassToInstantiate(driverClass);
491
        if (workingArea != null)
492
            lyrDef.setWorkingArea(workingArea);
493

    
494
        lyrDef.setSRID_EPSG(strSRID);
495

    
496
        setLyrDef(lyrDef);
497

    
498
    }
499

    
500
    public void load() throws DriverException{
501
            try {
502
            Class.forName(driverClass);
503

    
504
            String keyPool = dbUrl + "_" + userName;
505
            Connection newConn = null;
506
            String clave = null;
507
            if (!poolPassw.containsKey(keyPool))
508
            {
509
                JPasswordDlg dlg = new JPasswordDlg();
510
                String strMessage = Messages.getString("conectar_jdbc");
511
                String strPassword = Messages.getString("password");
512
                dlg.setMessage(strMessage + " " + dbUrl + ". " + strPassword + "?");
513
                dlg.show();
514
                clave = dlg.getPassword();
515
                if (clave == null)
516
                    return;
517
                poolPassw.put(keyPool, clave);
518
            }
519
            else
520
            {
521
                clave = (String) poolPassw.get(keyPool);
522
            }
523
            newConn = DriverManager.getConnection(dbUrl, userName, clave);
524
            newConn.setAutoCommit(false);
525

    
526
            DBLayerDefinition lyrDef = new DBLayerDefinition();
527
            if (getLyrDef() == null) {
528
                    lyrDef.setCatalogName(catalogName);
529
                    lyrDef.setTableName(tableName);
530
                    lyrDef.setFieldNames(fields);
531
                    lyrDef.setFieldID(FIDfield);
532
                    lyrDef.setFieldGeometry(geometryField);
533
                    lyrDef.setWhereClause(whereClause);
534
                    // lyrDef.setClassToInstantiate(driverClass);
535
                    if (workingArea != null)
536
                        lyrDef.setWorkingArea(workingArea);
537

    
538
                    lyrDef.setSRID_EPSG(strSRID);
539
            } else {
540
                    lyrDef = getLyrDef();
541
            }
542

    
543

    
544

    
545
            setData(newConn, lyrDef);
546
        } catch (ClassNotFoundException e) {
547
            logger.debug(e);
548
            DriverJdbcNotFoundExceptionType type =
549
                    new DriverJdbcNotFoundExceptionType();
550
            type.setDriverJdbcClassName(driverClass);
551
            type.setLayerName(this.getTableName());
552
            throw new DriverException("Driver JDBC no encontrado", e,  type);
553
        } catch (SQLException e) {
554
            logger.debug(e);
555
            SqlDriveExceptionType type =
556
                    new SqlDriveExceptionType();
557
            type.setSql("No disponible");
558
            throw new DriverException(e, type);
559
        }
560
    }
561
    /* (non-Javadoc)
562
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#getXMLEntity()
563
     */
564
    public XMLEntity getXMLEntity()
565
    {
566
        XMLEntity xml = new XMLEntity();
567
        xml.putProperty("className",this.getClass().getName());
568
        try {
569
            DatabaseMetaData metadata = getConnection().getMetaData();
570
            xml.putProperty("dbURL", metadata.getURL());
571
            xml.putProperty("catalog", getLyrDef().getCatalogName());
572
            // TODO: NO DEBEMOS GUARDAR EL NOMBRE DE USUARIO Y CONTRASE?A
573
            // AQUI. Hay que utilizar un pool de conexiones
574
            // y pedir al usuario que conecte a la base de datos
575
            // en la primera capa. En el resto, usar la conexi?n
576
            // creada con anterioridad.
577
            String userName = metadata.getUserName();
578
            int aux = userName.indexOf("@");
579
            if (aux != -1)
580
                userName = userName.substring(0,aux);
581
            xml.putProperty("username", userName);
582

    
583
            Driver drv = DriverManager.getDriver(metadata.getURL());
584
            // System.out.println(drv.getClass().getName());
585
            xml.putProperty("driverclass", drv.getClass().getName());
586

    
587
            xml.putProperty("tablename", getTableName());
588
            xml.putProperty("fields", lyrDef.getFieldNames());
589
            xml.putProperty("FID", lyrDef.getFieldID());
590
            xml.putProperty("THE_GEOM", lyrDef.getFieldGeometry());
591
            xml.putProperty("whereclause", getWhereClause());
592
            xml.putProperty("SRID", lyrDef.getSRID_EPSG());
593
            if (getWorkingArea() != null)
594
            {
595
                xml.putProperty("minXworkArea", getWorkingArea().getMinX());
596
                xml.putProperty("minYworkArea", getWorkingArea().getMinY());
597
                xml.putProperty("HworkArea", getWorkingArea().getHeight());
598
                xml.putProperty("WworkArea", getWorkingArea().getWidth());
599
            }
600

    
601
        } catch (SQLException e) {
602
            // TODO Auto-generated catch block
603
            e.printStackTrace();
604
        }
605

    
606

    
607
        return xml;
608

    
609
    }
610

    
611
    /**
612
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver#setWorkingArea(java.awt.geom.Rectangle2D)
613
     */
614
    public void setWorkingArea(Rectangle2D rect) {
615
        this.workingArea = rect;
616
    }
617

    
618
    /**
619
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver#getWorkingArea()
620
     */
621
    public Rectangle2D getWorkingArea() {
622
        return workingArea;
623
    }
624

    
625
    /* (non-Javadoc)
626
     * @see com.hardcode.gdbms.engine.data.driver.GDBMSDriver#setDataSourceFactory(com.hardcode.gdbms.engine.data.DataSourceFactory)
627
     */
628
    public void setDataSourceFactory(DataSourceFactory arg0) {
629
        // TODO Auto-generated method stub
630

    
631
    }
632

    
633
    /**
634
     * @return Returns the lyrDef.
635
     */
636
    public DBLayerDefinition getLyrDef() {
637
        return lyrDef;
638
    }
639

    
640
    /**
641
     * @param lyrDef The lyrDef to set.
642
     */
643
    public void setLyrDef(DBLayerDefinition lyrDef) {
644
        this.lyrDef = lyrDef;
645
    }
646

    
647
    abstract public String getSqlTotal();
648

    
649
    /**
650
     * @return Returns the completeWhere. WITHOUT order by clause!!
651
     */
652
    abstract public String getCompleteWhere();
653

    
654
    /* (non-Javadoc)
655
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#reLoad()
656
     */
657
    public void reload() throws IOException
658
    {
659
                try {
660
                    if (conn == null) this.load();
661

    
662
                        conn.commit();
663

    
664
                    setData(conn, lyrDef);
665
                } catch (SQLException e) {
666
                        throw new IOException(e.getMessage());
667
                } catch (DriverException e) {
668
                        throw new IOException(e.getMessage());
669
                }
670

    
671
    }
672

    
673
    public int getFieldWidth(int fieldId)
674
    {
675
            int i = -1;
676
            try {
677
                    int aux = fieldId + 2; // idField viene basado en 1, y
678
                        i = rs.getMetaData().getColumnDisplaySize(aux);
679
                } catch (SQLException e) {
680
                        e.printStackTrace();
681
                }
682
                // SUN define que getColumnDisplaySize devuelve numeros negativos cuando el campo es de tipo Text o Vartext
683
                // sin ancho. Nosotros vamos a devolver 255 para que fucione, por lo menos al exportar a DBF.
684
                // Nota: Si se truncan cadenas, este es el sitio que lo provoca.
685
                if (i <0) i=255;
686
                return i;
687
    }
688

    
689
//        public void setFlatness(double flatness) {
690
//                this.flatness = flatness;
691
//        }
692

    
693
}