提交 f03ec003 authored 作者: Roy-Breeze's avatar Roy-Breeze

Add suport for converting JAVA_OBJECT to UUID for better Postgres compatibility

上级 61b93a60
......@@ -910,6 +910,14 @@ public abstract class Value {
case BYTES:
return ValueUuid.get(getBytesNoCopy());
case JAVA_OBJECT:
Object object = JdbcUtils.deserialize(getBytesNoCopy(), getDataHandler());
if (object instanceof java.util.UUID) {
java.util.UUID uuid = (java.util.UUID) object;
return ValueUuid.get(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
}
else {
throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, getString());
}
case TIMESTAMP_TZ:
throw DbException.get(
ErrorCode.DATA_CONVERSION_ERROR_1, getString());
......
......@@ -285,8 +285,12 @@ public class TestValue extends TestBase {
ValueUuid min = ValueUuid.get(minHigh, minLow);
assertEquals("00000000-0000-4000-8000-000000000000", min.getString());
ValueJavaObject vo = ValueJavaObject.getNoCopy(UUID.randomUUID(), null, null);
assertThrows(DbException.class, vo).convertTo(Value.UUID);
// Test conversion from ValueJavaObject to ValueUuid
ValueJavaObject vo_uuid = ValueJavaObject.getNoCopy(UUID.randomUUID(), null, null);
assertTrue(vo_uuid.convertTo(Value.UUID) instanceof ValueUuid);
ValueJavaObject vo_string = ValueJavaObject.getNoCopy(new String("This is not a ValueUuid object"), null, null);
assertThrows(DbException.class, vo_string).convertTo(Value.UUID);
}
private void testModulusDouble() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论