Revision 3109 trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGisDriver.java

View differences:

PostGisDriver.java
44 44
package com.iver.cit.gvsig.fmap.drivers.jdbc.postgis;
45 45

  
46 46
import java.awt.geom.Rectangle2D;
47
import java.io.IOException;
47 48
import java.nio.ByteBuffer;
48 49
import java.sql.Connection;
49 50
import java.sql.ResultSet;
50 51
import java.sql.SQLException;
51 52
import java.sql.Statement;
52 53
import java.sql.Types;
54
import java.util.Hashtable;
53 55

  
54 56
import org.apache.log4j.Logger;
55 57
import org.postgis.PGbox2d;
......
75 77
 */
76 78
public class PostGisDriver extends DefaultDBDriver implements ICanReproject {
77 79
    private static Logger logger = Logger.getLogger(PostGisDriver.class.getName());
80
    
81
    private static int FETCH_SIZE = 5000;
78 82
    private WKBParser parser = new WKBParser();
79 83
    private int fetch_min=-1;
80 84
    private int fetch_max=-1;
......
161 165
            }
162 166
            logger.info("Cadena SQL:" + sqlAux);
163 167
	        st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
164
	        st.setFetchSize(5000);
168
	        // st.setFetchSize(FETCH_SIZE);
165 169
	        st.execute("declare wkb_cursor binary cursor for " + sqlOrig);
166
	        rs = st.executeQuery("fetch forward all in wkb_cursor");
170
	        rs = st.executeQuery("fetch forward " + FETCH_SIZE + " in wkb_cursor");
167 171
	        // st.execute("begin"); 
168 172
	        // bCursorActivo = true; 
169 173
	        // rs = st.executeQuery(sqlOrig);
170 174
            fetch_min = 0;
171
            fetch_max = rs.getFetchSize();
175
            fetch_max = FETCH_SIZE-1;
172 176
            metaData = rs.getMetaData();
173 177
            doRelateID_FID();
174 178
            
......
232 236
            }
233 237

  
234 238
	        st.execute("declare wkb_cursor_prov binary cursor for " + sql);
235
	        ResultSet rs = st.executeQuery("fetch forward all in wkb_cursor_prov");
239
	        ResultSet rs = st.executeQuery("fetch forward " + FETCH_SIZE + " in wkb_cursor_prov");
236 240
            // st.execute("BEGIN");
237 241
            bCursorActivo = true;
238 242
            // ResultSet rs = st.executeQuery(sql);
239
            geomIterator = new PostGisFeatureIterator(rs);
243
            geomIterator = new PostGisFeatureIterator(rs, st);
240 244
        } catch (SQLException e) {
241 245
            e.printStackTrace();
242 246
            throw new com.iver.cit.gvsig.fmap.DriverException(e);
......
364 368
        // EL ABSOLUTE NO HACE QUE SE VUELVAN A LEER LAS
365 369
        // FILAS, ASI QUE MONTAMOS ESTA HISTORIA PARA QUE
366 370
        // LO HAGA
367
        // System.out.println("getShape " + index);
368
        /* if (index < fetch_min)
371
        // System.out.println("getShape " + index + " fetchMin=" + fetch_min + " fetchMax=" + fetch_max);
372
        if (index < fetch_min)
369 373
        {
370 374
            // rs.close();
371 375
            st.execute("CLOSE wkb_cursor");
372 376
            st.execute("declare wkb_cursor binary cursor for " + sqlOrig);
373
            rs = st.executeQuery("fetch forward all in wkb_cursor");
377
            rs = st.executeQuery("fetch forward " + FETCH_SIZE + " in wkb_cursor");
374 378
            
375 379
            // rs.beforeFirst();           
376 380
            
377 381
            // rs = st.executeQuery(sqlOrig);
378 382
            fetch_min = 0;
379
            fetch_max = rs.getFetchSize();
383
            fetch_max = FETCH_SIZE-1;
380 384
        }
381
        while (index >= fetch_max)
385
        while (index > fetch_max)
382 386
        {
383
            rs.afterLast();
387
            rs = st.executeQuery("fetch forward " + FETCH_SIZE + " in wkb_cursor");
388
            // rs.next();
389
            /* rs.afterLast();
384 390
            // forzamos una carga
385
            rs.next();
386
            fetch_min = fetch_max;
387
            fetch_max = fetch_max + rs.getFetchSize();
391
            rs.next(); */
392
            fetch_min = fetch_max+1;
393
            fetch_max = fetch_min + FETCH_SIZE -1;
388 394
            // System.out.println("fetchSize = " + rs.getFetchSize() + " " + fetch_min + "-" + fetch_max);
389 395
        } 
390
        rs.absolute(index+1 - fetch_min);
391
        */
392
        rs.absolute(index+1);
396
        rs.absolute(index - fetch_min + 1);
393 397
        
398
        // rs.absolute(index+1);
399
        
394 400
    }
395 401
	/**
396 402
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#getGeometryField(java.lang.String)
......
464 470
        // TODO POR AHORA, REPROYECTA SIEMPRE gvSIG.
465 471
        return false;
466 472
    }
473
    /* (non-Javadoc)
474
     * @see com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver#doRelateID_FID()
475
     */
476
    protected void doRelateID_FID()
477
    {
478
        hashRelate = new Hashtable();
479
        try {
480
            for (int index = 0; index < getShapeCount(); index++)
481
            {
482
                Value aux = getFieldValue(index, idFID_FieldName-2);
483
                hashRelate.put(aux, new Integer(index));             
484
                // System.out.println("Row " + index + " clave=" + aux);
485
            }
486
/*             int index = 0;
487
            
488
            while (rs.next())
489
            {
490
                Value aux = getFieldValue(index, idFID_FieldName-2);
491
                hashRelate.put(aux, new Integer(index));
492
                index++;
493
                System.out.println("Row " + index + " clave=" + aux);                 
494
            }
495
            numReg = index; */
496
            // rs.beforeFirst();
497
        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
498
            // TODO Auto-generated catch block
499
            e.printStackTrace();
500
        } catch (IOException e) {
501
            // TODO Auto-generated catch block
502
            e.printStackTrace();
503
        }          
504
    }
467 505
    
468 506
    
469 507
}

Also available in: Unified diff