Revision 36210 trunk/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/fmap/drivers/jdbc/oracle/OracleSpatialDriver.java

View differences:

OracleSpatialDriver.java
154 154
    public static final String DEFAULT_GEO_FIELD = "GEOMETRY";
155 155
    // public static final String DEFAULT_GEO_FIELD = "MERGEDGEOMETRY";
156 156

  
157
    
157 158
    public static final String ORACLE_ID_FIELD = "ROWID";
158 159
    public static final String DEFAULT_ID_FIELD_CASE_SENSITIVE = "GID";
159 160
    public static final String ORACLE_GEO_SCHEMA = "MDSYS";
......
191 192

  
192 193
    // switch variable
193 194
    private boolean use_geotools = false;
194
    private boolean tableHasSrid = true;
195
    private boolean table_HasSrid = true;
195 196

  
196 197
    // ------------------------------------------------
197 198
    private boolean isNotAvailableYet = true;
......
209 210
    private String idFieldNames;
210 211
    private int oneBasedGeoColInd = 0;
211 212
    private int shapeType = -1;
212
    private boolean needsCollectionLayer = true;
213 213

  
214 214
    // ----------------------------------------------
215 215
    // one feature is cached to avoid querying for each attribute request:
......
223 223
    private String fullTableName = "";
224 224
    private String geoColName = "";
225 225
    private String oracleSRID;
226
    private String epsgSRID;
226
    private String epsg_SRID;
227 227
    private String destProj = "";
228 228
    private Rectangle2D full_Extent = null;
229 229
    private boolean emptyWhereClause = true;
......
344 344
        
345 345
        if (tn.indexOf(".") == -1) {
346 346
        	
347
        	if (lyrDef.getSchema() == null) {
347
        	if (lyrDef.getSchema() == null || lyrDef.getSchema().length() == 0) {
348 348
        		fullTableName = _cwp.getUser().toUpperCase() + "." + tn;
349 349
        	} else {
350 350
        		fullTableName = lyrDef.getSchema() + "." + tn;
......
362 362
        // getMetaDataInThisThread();
363 363
        cleanWhereClause();
364 364
        loadSdoMetadata();
365
        oneRowMetadata();
365
        oneRowMetadata(); 
366 366

  
367 367
        setDestProjection(lyrDef.getSRID_EPSG());
368 368
        workingAreaInViewsCS = lyrDef.getWorkingArea();
369 369
        
370
        if ((workingAreaInViewsCS != null) && (epsgSRID != null)) {
370
        if ((workingAreaInViewsCS != null) && isTableHasSrid() && (getEpsgSRID() != null)) {
371 371
            IProjection viewProj = CRSFactory.getCRS(destProj);
372
            IProjection tableProj = CRSFactory.getCRS("EPSG:" + epsgSRID);
372
            IProjection tableProj = CRSFactory.getCRS("EPSG:" + getEpsgSRID());
373 373
            ICoordTrans reprojecter = viewProj.getCT(tableProj);
374 374
        	workingAreaInTablesCS = reprojecter.convert(workingAreaInViewsCS);
375 375
            workingAreaInTablesCSStruct = shapeToStruct(workingAreaInTablesCS,
376
                    FShape.NULL, tableHasSrid, false, true);
376
                    FShape.NULL, isTableHasSrid(), false, true);
377
        } else {
378
            if (workingAreaInViewsCS != null) {
379
            	workingAreaInTablesCS = (Rectangle2D) workingAreaInViewsCS.clone();
380
                workingAreaInTablesCSStruct = shapeToStruct(workingAreaInTablesCS,
381
                        FShape.NULL, isTableHasSrid(), false, true);
382
            }
377 383
        }
378 384

  
379 385
        cancelIDLoad = false;
......
421 427

  
422 428
        if (obj == null) {
423 429
            logger.warn("No SRID found for this table.");
424
            tableHasSrid = false;
430
            setTableHasSrid(false);
425 431

  
426 432
            return null;
427 433
        }
......
492 498

  
493 499
            }
494 500

  
495
            ResultSet _rs = _st.executeQuery(qry);
501
            ResultSet _rs = _st.executeQuery(qry); 
496 502

  
497 503
            if (_rs.next()) {
498 504
                oracleSRID = getOracleSridFromCurrentRecord(_rs);
499 505

  
500
                isGeogCS = OracleSpatialUtils.getIsGCS(oracleSRID, tableHasSrid);
506
                isGeogCS = OracleSpatialUtils.getIsGCS(oracleSRID, isTableHasSrid());
501 507

  
502
                try {
503
					epsgSRID = oracleSridToEpsgSrid(oracleSRID);
504
				} catch (Exception e) {
505
					logger.error("Unknown oracle SRID: " + oracleSRID);
506
					tableHasSrid = false;
507
				}
508
                if (oracleSRID == null) {
509
					setTableHasSrid(false);
510
                } else {
511
                    try {
512
    					setEpsgSRID( oracleSridToEpsgSrid(oracleSRID) );
513
    				} catch (Exception e) {
514
    					// logger.error("Unknown oracle SRID: " + oracleSRID);
515
    					setTableHasSrid(true);
516
    					setEpsgSRID( oracleSRID );
517
    				}
518
                }
519
                
508 520
                full_Extent = getFullExtentFromCurrentRecord(_rs);
509 521

  
510 522
                hasRealiableExtent = realiableExtent(full_Extent, isGeogCS);
......
789 801
        	logger.warn("Assumed MULTI");
790 802
        }
791 803
        
792
        return resp;
804
        return resp; 
793 805
	}
794 806

  
795 807
	private int getShapeTypeFromArray(ArrayList arrlist) {
796 808
		
809
		int sz = arrlist.size();
810
		
811
		if (sz == 0) {
812
			return FShape.MULTI;
813
		}
814
		
797 815
		int resp = ((Integer) arrlist.get(0)).intValue();
816
		boolean needs3d = (resp > FShape.Z) ? true : false;
798 817
		
799
		int sz = arrlist.size();
800 818
		int aux = 0;
801 819
		for (int i=1; i<sz; i++) {
802 820
			aux = ((Integer) arrlist.get(i)).intValue();
803
			if (aux != resp) return FShape.MULTI;
821
			if (aux != resp) {
822
				resp = FShape.MULTI;
823
			}
824
			if (aux > FShape.Z) {
825
				needs3d = true;
826
			}
804 827
		}
805
		return resp;
828
		return needs3d ? ((resp % FShape.Z) + FShape.Z) : (resp % FShape.Z);
806 829
	}
807 830

  
808 831
	private String getIdFieldNames() {
......
852 875

  
853 876
        singleCachedFeatureRowNum = -1;
854 877

  
855
        Object[] rs_st = getViewResultSet(null, sql, tableHasSrid);
878
        Object[] rs_st = getViewResultSet(null, sql, isTableHasSrid());
856 879

  
857 880
        ResultSet localrs = (ResultSet) rs_st[0];
858 881
        Statement _st = (Statement) rs_st[1];
......
893 916

  
894 917
        singleCachedFeatureRowNum = -1;
895 918
        
896
        STRUCT local_st = shapeToStruct(r, FShape.NULL, tableHasSrid, false, true);
897
        Object[] rs_st = getViewResultSet(local_st, null, tableHasSrid);
919
        STRUCT local_st = shapeToStruct(r, FShape.NULL, isTableHasSrid(), false, true);
920
        Object[] rs_st = getViewResultSet(local_st, null, isTableHasSrid());
898 921
        ResultSet localrs = (ResultSet) rs_st[0];
899 922
        Statement _st = (Statement) rs_st[1];
900 923

  
......
924 947
            return getFeatureIterator(r, strEPSG);
925 948
        } else {
926 949

  
927
            STRUCT local_st = shapeToStruct(r, FShape.NULL, tableHasSrid, false, true);
928
            Object[] rs_st = getViewResultSet(local_st, null, tableHasSrid);
950
            STRUCT local_st = shapeToStruct(r, FShape.NULL, isTableHasSrid(), false, true);
951
            Object[] rs_st = getViewResultSet(local_st, null, isTableHasSrid());
929 952
            ResultSet localrs = (ResultSet) rs_st[0];
930 953
            Statement _st = (Statement) rs_st[1];
931 954

  
......
1096 1119
            st.close();
1097 1120
            numReg = row;
1098 1121

  
1099
            needsCollectionLayer = OracleSpatialUtils.hasSeveralGeometryTypes(types, false);
1122
            /*
1123
            boolean needsCollectionLayer = OracleSpatialUtils.hasSeveralGeometryTypes(types, false);
1100 1124

  
1101 1125
            if (needsCollectionLayer) {
1102 1126
                shapeType = FShape.MULTI;
1103 1127
            }
1128
            */
1104 1129
        }
1105 1130
        catch (SQLException e) {
1106 1131
        	logger.error("While setting id-row hashmap: " + e.getMessage());
......
1366 1391
                gtype = new NUMBER((dim * 1000) +
1367 1392
                        (item_info_array[1].intValue() % 1000));
1368 1393

  
1369
                if (tableHasSrid) {
1394
                if (isTableHasSrid()) {
1370 1395
                	_srid = new NUMBER(Integer.parseInt(oracleSRID));
1371 1396
                }
1372 1397
            }
......
1379 1404

  
1380 1405
            STRUCT itemst = null;
1381 1406

  
1382
            if (tableHasSrid) {
1407
            if (isTableHasSrid()) {
1383 1408

  
1384 1409
                itemst = OracleSpatialUtils.createStruct(gtype, _srid,
1385 1410
                        item_info_array, item_ords, ((ConnectionJDBC)conn).getConnection());
......
1655 1680
			}
1656 1681
		} else {
1657 1682
			String waqry = getValidViewConstructor(workingAreaInTablesCSStruct,
1658
					oracleSRID, tableHasSrid, isGeogCS);
1683
					oracleSRID, isTableHasSrid(), isGeogCS);
1659 1684

  
1660 1685
			if (emptyWhereClause) {
1661 1686
				resp = resp + _where + "(sdo_relate(" + geoColName + ", " + waqry
......
2220 2245
            }
2221 2246

  
2222 2247
            if (ds.getRowCount() > 1) {
2223
                logger.error("===============");
2224
                logger.error(
2225
                    "DBF file is wrong: More than one preferred Oracle Spatial code found for EPSG code: " +
2248
                // logger.error("===============");
2249
                logger.warn(
2250
                    "DBF file is wrong?: More than one preferred Oracle Spatial code found for EPSG code: " +
2226 2251
                    epsg);
2227 2252

  
2228 2253
                for (int i = 0; i < ds.getRowCount(); i++) {
......
2231 2256
                    if (i == 0) {
2232 2257
                        resp = "" + aux;
2233 2258
                    }
2234

  
2235
                    logger.error("" + aux);
2259
                    // logger.error("" + aux);
2236 2260
                }
2237

  
2238
                logger.error("===============");
2239

  
2261
                // logger.error("===============");
2240 2262
                return resp;
2241 2263
            }
2242 2264

  
2243 2265
            resp = "" +
2244 2266
                Math.round(((DoubleValue) ds.getRow(0)[0]).doubleValue());
2267
        } catch (Exception pe) {
2268
        	throw pe;
2269
            // logger.error("Error with SQL statement. " + pe.getMessage());
2245 2270
        }
2246
        catch (Exception pe) {
2247
            logger.error("Error with SQL statement. " + pe.getMessage());
2248
        }
2249 2271

  
2250 2272
        return resp;
2251 2273
    }
......
2274 2296
                    DataSourceFactory.AUTOMATIC_OPENING);
2275 2297

  
2276 2298
            if (ds.getRowCount() == 0) {
2277
                logger.error("Oracle Spatial code not found in table: " + ora);
2299
                logger.warn("Oracle Spatial code not found in table: " + ora);
2278 2300
                throw new Exception("Unknown Oracle code: " + ora);
2279 2301
            }
2280 2302

  
2281 2303
            if (ds.getRowCount() > 1) {
2282
                logger.error("===============");
2283
                logger.error(
2284
                    "DBF file is wrong: More than one EPSG code found for Oracle Spatial code: " +
2304
                // logger.error("===============");
2305
                logger.warn(
2306
                    "DBF file is wrong?: More than one EPSG code found for Oracle Spatial code: " +
2285 2307
                    ora);
2286 2308

  
2287 2309
                for (int i = 0; i < ds.getRowCount(); i++) {
......
2292 2314
                        resp = aux;
2293 2315
                    }
2294 2316

  
2295
                    logger.error("" + aux);
2317
                 // logger.error("" + aux);
2296 2318
                }
2297 2319

  
2298
                logger.error("===============");
2320
             // logger.error("===============");
2299 2321

  
2300 2322
                return resp;
2301 2323
            }
2302 2324

  
2303 2325
            resp = "" +
2304 2326
                Math.round(((DoubleValue) ds.getRow(0)[0]).doubleValue());
2327
        } catch (Exception pe) {
2328
        	throw pe;
2329
            // logger.warn("Error with SQL statement. " + pe.getMessage());
2305 2330
        }
2306
        catch (Exception pe) {
2307
            logger.error("Error with SQL statement. " + pe.getMessage());
2308
        }
2309 2331

  
2310 2332
        return resp;
2311 2333
    }
......
2867 2889

  
2868 2890
        try {
2869 2891
            STRUCT the_struct = OracleSpatialUtils.fShapeToSTRUCT(shp, _conn,
2870
                    _srid, agu_bien, hasSrid, _isGeoCS);
2892
                    _srid, agu_bien, hasSrid, _isGeoCS, forced_type);
2871 2893

  
2872 2894
            return the_struct;
2873 2895
        }
......
3271 3293
                logger.error("While initializing OS Writer: " + e.getMessage(), e);
3272 3294
            }
3273 3295

  
3274
            writer.setStoreWithSrid(tableHasSrid);
3296
            writer.setStoreWithSrid(isTableHasSrid());
3275 3297
        }
3276 3298

  
3277 3299
        return writer;
......
3865 3887
	public void setAdaptedFetchSize(int v) {
3866 3888
		adaptedFetchSize = v;
3867 3889
	}
3868
        
3869
    
3870 3890

  
3891
	private boolean isTableHasSrid() {
3892
		return table_HasSrid;
3893
	}
3894

  
3895
	private void setTableHasSrid(boolean b) {
3896
		this.table_HasSrid = b;
3897
	}
3898

  
3899
	private String getEpsgSRID() {
3900
		return epsg_SRID; 
3901
	}
3902

  
3903
	private void setEpsgSRID(String e) {
3904
		this.epsg_SRID = e;
3905
	}
3906

  
3871 3907
}
3872 3908

  
3873 3909
// [eiel-gestion-conexiones]

Also available in: Unified diff