diff -urN pgjdbc.bin_geom/org/postgresql/jdbc2/AbstractJdbc2Connection.java pgjdbc.bin_uuid/org/postgresql/jdbc2/AbstractJdbc2Connection.java --- pgjdbc.bin_geom/org/postgresql/jdbc2/AbstractJdbc2Connection.java 2011-09-25 00:48:19.801259402 +0300 +++ pgjdbc.bin_uuid/org/postgresql/jdbc2/AbstractJdbc2Connection.java 2011-09-25 00:56:22.916554156 +0300 @@ -164,6 +164,7 @@ binaryOids.set(Oid.TEXT_ARRAY); binaryOids.set(Oid.POINT); binaryOids.set(Oid.BOX); + binaryOids.set(Oid.UUID); } // the pre 8.0 servers do not disclose their internal encoding for // time fields so do not try to use them. diff -urN pgjdbc.bin_geom/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java pgjdbc.bin_uuid/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java --- pgjdbc.bin_geom/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java 2011-09-25 00:48:19.802259397 +0300 +++ pgjdbc.bin_uuid/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java 2011-09-25 00:53:57.253373855 +0300 @@ -166,8 +166,12 @@ if (type.equals("unknown")) return getString(columnIndex); - if (type.equals("uuid")) + if (type.equals("uuid")) { + if (isBinary(columnIndex)) { + return getUUID(this_row[columnIndex - 1]); + } return getUUID(getString(columnIndex)); + } // Specialized support for ref cursors is neater. if (type.equals("refcursor")) @@ -3163,6 +3167,15 @@ { return data; } + + /** + * Newer JVMs will return a java.util.UUID object, but it isn't + * available in older versions. + */ + protected Object getUUID(byte[] data) throws SQLException + { + return data; + } private class PrimaryKey { diff -urN pgjdbc.bin_geom/org/postgresql/jdbc3g/AbstractJdbc3gResultSet.java pgjdbc.bin_uuid/org/postgresql/jdbc3g/AbstractJdbc3gResultSet.java --- pgjdbc.bin_geom/org/postgresql/jdbc3g/AbstractJdbc3gResultSet.java 2011-09-21 19:53:08.246972795 +0300 +++ pgjdbc.bin_uuid/org/postgresql/jdbc3g/AbstractJdbc3gResultSet.java 2011-09-25 01:00:40.115100120 +0300 @@ -15,6 +15,7 @@ import java.util.Vector; import org.postgresql.core.*; +import org.postgresql.util.ByteConverter; import org.postgresql.util.GT; import org.postgresql.util.PSQLState; import org.postgresql.util.PSQLException; @@ -40,5 +41,10 @@ return uuid; } + + protected Object getUUID(byte[] data) throws SQLException + { + return new UUID(ByteConverter.int8(data, 0), ByteConverter.int8(data, 8)); + } } diff -urN pgjdbc.bin_geom/org/postgresql/jdbc3g/AbstractJdbc3gStatement.java pgjdbc.bin_uuid/org/postgresql/jdbc3g/AbstractJdbc3gStatement.java --- pgjdbc.bin_geom/org/postgresql/jdbc3g/AbstractJdbc3gStatement.java 2011-09-21 19:53:08.247972788 +0300 +++ pgjdbc.bin_uuid/org/postgresql/jdbc3g/AbstractJdbc3gStatement.java 2011-09-25 00:58:35.156807525 +0300 @@ -15,6 +15,7 @@ import org.postgresql.core.Oid; import org.postgresql.jdbc3.AbstractJdbc3Connection; +import org.postgresql.util.ByteConverter; public abstract class AbstractJdbc3gStatement extends org.postgresql.jdbc3.AbstractJdbc3Statement { @@ -32,7 +33,7 @@ { if (x instanceof UUID && connection.haveMinimumServerVersion("8.3")) { - setString(parameterIndex, x.toString(), Oid.UUID); + setUuid(parameterIndex, (UUID)x); } else { super.setObject(parameterIndex, x); } @@ -42,10 +43,20 @@ { if (targetSqlType == Types.OTHER && x instanceof UUID && connection.haveMinimumServerVersion("8.3")) { - setString(parameterIndex, x.toString(), Oid.UUID); + setUuid(parameterIndex, (UUID) x); } else { super.setObject(parameterIndex, x, targetSqlType, scale); } } -} + private void setUuid(int parameterIndex, UUID uuid) throws SQLException { + if (connection.binaryTransferSend(Oid.UUID)) { + byte[] val = new byte[16]; + ByteConverter.int8(val, 0, uuid.getMostSignificantBits()); + ByteConverter.int8(val, 8, uuid.getLeastSignificantBits()); + bindBytes(parameterIndex, val, Oid.UUID); + } else { + bindLiteral(parameterIndex, uuid.toString(), Oid.UUID); + } + } +} \ No newline at end of file