Revision 14545 trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGisDriver.java
PostGisDriver.java | ||
---|---|---|
48 | 48 |
import java.nio.ByteBuffer; |
49 | 49 |
import java.sql.Date; |
50 | 50 |
import java.sql.ResultSet; |
51 |
import java.sql.ResultSetMetaData; |
|
51 | 52 |
import java.sql.SQLException; |
52 | 53 |
import java.sql.Statement; |
53 | 54 |
import java.sql.Timestamp; |
... | ... | |
422 | 423 |
try { |
423 | 424 |
setAbsolutePosition(index); |
424 | 425 |
int fieldId = idField + 2; |
425 |
byte[] byteBuf = rs.getBytes(fieldId); |
|
426 |
if (byteBuf == null) |
|
427 |
return ValueFactory.createNullValue(); |
|
428 |
else { |
|
429 |
ByteBuffer buf = ByteBuffer.wrap(byteBuf); |
|
430 |
if (metaData.getColumnType(fieldId) == Types.VARCHAR) |
|
431 |
return ValueFactory.createValue(rs.getString(fieldId)); |
|
432 |
if (metaData.getColumnType(fieldId) == Types.FLOAT) |
|
433 |
return ValueFactory.createValue(buf.getFloat()); |
|
434 |
if (metaData.getColumnType(fieldId) == Types.DOUBLE) |
|
435 |
return ValueFactory.createValue(buf.getDouble()); |
|
436 |
if (metaData.getColumnType(fieldId) == Types.REAL) |
|
437 |
return ValueFactory.createValue(buf.getFloat()); |
|
438 |
if (metaData.getColumnType(fieldId) == Types.INTEGER) |
|
439 |
return ValueFactory.createValue(buf.getInt()); |
|
440 |
if (metaData.getColumnType(fieldId) == Types.BIGINT) |
|
441 |
return ValueFactory.createValue(buf.getLong()); |
|
442 |
if (metaData.getColumnType(fieldId) == Types.BIT) |
|
443 |
// TODO |
|
444 |
return ValueFactory.createValue(rs.getBoolean(fieldId)); |
|
445 |
if (metaData.getColumnType(fieldId) == Types.DATE) |
|
446 |
{ |
|
447 |
long daysAfter2000 = buf.getInt() + 1; |
|
448 |
long msecs = daysAfter2000*24*60*60*1000; |
|
449 |
long real_msecs_date1 = (long) (XTypes.NUM_msSecs2000 + msecs); |
|
450 |
Date realDate1 = new Date(real_msecs_date1); |
|
451 |
return ValueFactory.createValue(realDate1); |
|
452 |
} |
|
453 |
if (metaData.getColumnType(fieldId) == Types.TIME) |
|
454 |
{ |
|
455 |
// TODO: |
|
426 |
return getFieldValue(rs, fieldId); |
|
427 |
|
|
428 |
} catch (SQLException e) { |
|
429 |
throw new ReadDriverException("PostGIS Driver",e); |
|
430 |
} |
|
431 |
} |
|
432 |
|
|
433 |
static Value getFieldValue(ResultSet aRs, int fieldId) |
|
434 |
throws SQLException { |
|
435 |
ResultSetMetaData metaData = aRs.getMetaData(); |
|
436 |
byte[] byteBuf = aRs.getBytes(fieldId); |
|
437 |
if (byteBuf == null) |
|
438 |
return ValueFactory.createNullValue(); |
|
439 |
else { |
|
440 |
ByteBuffer buf = ByteBuffer.wrap(byteBuf); |
|
441 |
if (metaData.getColumnType(fieldId) == Types.VARCHAR) |
|
442 |
return ValueFactory.createValue(aRs.getString(fieldId)); |
|
443 |
if (metaData.getColumnType(fieldId) == Types.FLOAT) |
|
444 |
return ValueFactory.createValue(buf.getFloat()); |
|
445 |
if (metaData.getColumnType(fieldId) == Types.DOUBLE) |
|
446 |
return ValueFactory.createValue(buf.getDouble()); |
|
447 |
if (metaData.getColumnType(fieldId) == Types.REAL) |
|
448 |
return ValueFactory.createValue(buf.getFloat()); |
|
449 |
if (metaData.getColumnType(fieldId) == Types.INTEGER) |
|
450 |
return ValueFactory.createValue(buf.getInt()); |
|
451 |
if (metaData.getColumnType(fieldId) == Types.BIGINT) |
|
452 |
return ValueFactory.createValue(buf.getLong()); |
|
453 |
if (metaData.getColumnType(fieldId) == Types.BIT) |
|
454 |
return ValueFactory.createValue((byteBuf[0] == 1)); |
|
455 |
if (metaData.getColumnType(fieldId) == Types.BOOLEAN) |
|
456 |
return ValueFactory.createValue(aRs.getBoolean(fieldId)); |
|
457 |
if (metaData.getColumnType(fieldId) == Types.DATE) |
|
458 |
{ |
|
459 |
long daysAfter2000 = buf.getInt() + 1; |
|
460 |
long msecs = daysAfter2000*24*60*60*1000; |
|
461 |
long real_msecs_date1 = (long) (XTypes.NUM_msSecs2000 + msecs); |
|
462 |
Date realDate1 = new Date(real_msecs_date1); |
|
463 |
return ValueFactory.createValue(realDate1); |
|
464 |
} |
|
465 |
if (metaData.getColumnType(fieldId) == Types.TIME) |
|
466 |
{ |
|
467 |
// TODO: |
|
456 | 468 |
// throw new RuntimeException("TIME type not implemented yet"); |
457 | 469 |
return ValueFactory.createValue("NOT IMPLEMENTED YET"); |
458 | 470 |
} |
... | ... | |
494 | 506 |
} |
495 | 507 |
|
496 | 508 |
} |
497 |
} catch (SQLException e) { |
|
498 |
throw new ReadDriverException("PostGIS Driver",e); |
|
499 |
} |
|
509 |
|
|
500 | 510 |
return ValueFactory.createNullValue(); |
501 | 511 |
|
502 | 512 |
} |
Also available in: Unified diff