@Override public String toString() { return Str.toWebSafeBase64(toBytes()); }
@Override public void serialize(TUUID tuuid, JsonGenerator generator, SerializerProvider serializerProvider) throws IOException { generator.writeString(tuuid.toString()); }
public static TUUID fromBytes(byte[] bytes) { U.must(bytes.length == 24, "Expected 24 bytes, got: %s", bytes.length); ByteBuffer buf = ByteBuffer.wrap(bytes); return new TUUID(buf.getLong(), buf.getLong(), buf.getLong()); }
public static TUUID fromString(String tuuid) { U.notNull(tuuid, "TUUID"); return fromBytes(Str.fromWebSafeBase64(tuuid)); } }
@Override public TUUID deserialize(JsonParser parser, DeserializationContext context) throws IOException { return TUUID.fromString(parser.getText()); }
private static Object convertResultValue(String type, Object value) { byte[] bytes; switch (type) { case "TUUID": U.must(value instanceof byte[], "Expecting byte[] value to convert to TUUID!"); bytes = (byte[]) value; return TUUID.fromBytes(bytes); case "UUID": U.must(value instanceof byte[], "Expecting byte[] value to convert to UUID!"); bytes = (byte[]) value; return Msc.bytesToUUID(bytes); default: throw U.rte("Unknown type: '%s'", type); } }
return (T) TUUID.fromString(value);
return (T) TUUID.fromBytes(((byte[]) value)); } else { throw U.rte("Cannot convert the value '%s' to TUUID!", value);
public static void bind(PreparedStatement stmt, Object[] args) throws SQLException { for (int i = 0; i < args.length; i++) { Object arg = args[i]; if (arg instanceof WebData) { // unwrap the arg to a real value represented by the web data arg = ((WebData) arg).unwrap(); } if (arg instanceof byte[]) { byte[] bytes = (byte[]) arg; stmt.setBytes(i + 1, bytes); } else if (arg instanceof UUID) { UUID uuid = (UUID) arg; byte[] bytes = Msc.uuidToBytes(uuid); stmt.setBytes(i + 1, bytes); } else if (arg instanceof TUUID) { TUUID tuuid = (TUUID) arg; stmt.setBytes(i + 1, tuuid.toBytes()); } else { stmt.setObject(i + 1, arg); } } }
return tuuid.toString();
@Override public TUUID tuuid(ByteBuffer buf) { return new TUUID(longValue(buf), longValue(buf), longValue(buf)); }
private static Object convertResultValue(String type, Object value) { byte[] bytes; switch (type) { case "TUUID": U.must(value instanceof byte[], "Expecting byte[] value to convert to TUUID!"); bytes = (byte[]) value; return TUUID.fromBytes(bytes); case "UUID": U.must(value instanceof byte[], "Expecting byte[] value to convert to UUID!"); bytes = (byte[]) value; return Msc.bytesToUUID(bytes); default: throw U.rte("Unknown type: '%s'", type); } }
public static void bind(PreparedStatement stmt, Object[] args) throws SQLException { for (int i = 0; i < args.length; i++) { Object arg = args[i]; if (arg instanceof WebData) { // unwrap the arg to a real value represented by the web data arg = ((WebData) arg).unwrap(); } if (arg instanceof byte[]) { byte[] bytes = (byte[]) arg; stmt.setBytes(i + 1, bytes); } else if (arg instanceof UUID) { UUID uuid = (UUID) arg; byte[] bytes = Msc.uuidToBytes(uuid); stmt.setBytes(i + 1, bytes); } else if (arg instanceof TUUID) { TUUID tuuid = (TUUID) arg; stmt.setBytes(i + 1, tuuid.toBytes()); } else { stmt.setObject(i + 1, arg); } } }