Is your feature request related to a problem? If so, please give a short summary of the problem and how the feature would resolve it
I am trying to execute SQL queries with UUID objects in Java mapping to uniqueidentifier values in the database. This works, but when passing a UUID value as an input to a query using PreparedStatement#setObject() the value ends up being transferred as a string over the wire. This is inefficient both computationally (UUID#toString()) and also transfers more data over the network (36 bytes vs. 16 bytes).
Describe the preferred solution
When reading uniqueidentifier values from a ResultSet I can call ResultSet#getObject(int, Class) with the second parameter as UUID.class. This will give back the correct UUID value as expected without first converting the byte array to a String. Essentially I would want to have the same possibility when calling PreparedStatement#setObject() with a UUID object as input.
Describe alternatives you've considered
The alternative (workaround) I now use to do this is to manually convert the UUID value to a byte[] value (essentially using the same logic as in Util#asGuidByteArray(UUID)) and then give that byte[] object to PreparedStatement#setObject().
Additional context
Looking at the code I found this relevant block:
|
if (JDBCType.GUID == jdbcType) { |
|
if (null != cryptoMeta) { |
|
if (value instanceof String) { |
|
value = UUID.fromString((String) value); |
|
} |
|
byte[] bArray = Util.asGuidByteArray((UUID) value); |
|
op.execute(this, bArray); |
|
} else { |
|
op.execute(this, String.valueOf(value)); |
|
} |
Apparently it looks like what I want is possible, but only when cryptoMeta is set. I don't understand how encryption is related to this.
Reference Documentations/Specifications
Reference Implementation
Is your feature request related to a problem? If so, please give a short summary of the problem and how the feature would resolve it
I am trying to execute SQL queries with
UUIDobjects in Java mapping touniqueidentifiervalues in the database. This works, but when passing aUUIDvalue as an input to a query usingPreparedStatement#setObject()the value ends up being transferred as a string over the wire. This is inefficient both computationally (UUID#toString()) and also transfers more data over the network (36 bytes vs. 16 bytes).Describe the preferred solution
When reading
uniqueidentifiervalues from aResultSetI can callResultSet#getObject(int, Class)with the second parameter asUUID.class. This will give back the correct UUID value as expected without first converting the byte array to a String. Essentially I would want to have the same possibility when callingPreparedStatement#setObject()with aUUIDobject as input.Describe alternatives you've considered
The alternative (workaround) I now use to do this is to manually convert the
UUIDvalue to abyte[]value (essentially using the same logic as inUtil#asGuidByteArray(UUID)) and then give thatbyte[]object toPreparedStatement#setObject().Additional context
Looking at the code I found this relevant block:
mssql-jdbc/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java
Lines 1597 to 1606 in 1f550f1
Apparently it looks like what I want is possible, but only when
cryptoMetais set. I don't understand how encryption is related to this.Reference Documentations/Specifications
Reference Implementation