@Override public Value readValue(ByteBuffer buff) { return ValueUuid.get(buff.getLong(), buff.getLong()); }
@Override public String getSQL() { return StringUtils.quoteStringSQL(getString()); }
ValueUuid uuid = ValueUuid.getNewRandom(); String s = uuid.getString(); s = s.replace('-', '_').toUpperCase(); sequenceName = "SYSTEM_SEQUENCE_" + s;
/** * Get or create a UUID for the given 16 bytes. * * @param binary the byte array (must be at least 16 bytes long) * @return the UUID */ public static ValueUuid get(byte[] binary) { if (binary.length < 16) { return get(StringUtils.convertBytesToHex(binary)); } long high = Utils.readLong(binary, 0); long low = Utils.readLong(binary, 8); return (ValueUuid) Value.cache(new ValueUuid(high, low)); }
break; case RANDOM_UUID: result = ValueUuid.getNewRandom(); break;
/** * Get or create a UUID for the given high and low order values. * * @param high the most significant bits * @param low the least significant bits * @return the UUID */ public static ValueUuid get(long high, long low) { return (ValueUuid) Value.cache(new ValueUuid(high, low)); }
@Override public boolean equals(Object other) { return other instanceof ValueUuid && compareSecure((Value) other, null) == 0; }
@Override public void set(PreparedStatement prep, int parameterIndex) throws SQLException { prep.setBytes(parameterIndex, getBytes()); }
@Override public String getString() { StringBuilder buff = new StringBuilder(36); appendHex(buff, high >> 32, 4); buff.append('-'); appendHex(buff, high >> 16, 2); buff.append('-'); appendHex(buff, high, 2); buff.append('-'); appendHex(buff, low >> 48, 2); buff.append('-'); appendHex(buff, low, 6); return buff.toString(); }
/** * Create a new UUID using the pseudo random number generator. * * @return the new UUID */ public static ValueUuid getNewRandom() { long high = MathUtils.secureRandomLong(); long low = MathUtils.secureRandomLong(); // version 4 (random) high = (high & (~0xf000L)) | 0x4000L; // variant (Leach-Salz) low = (low & 0x3fffffffffffffffL) | 0x8000000000000000L; return new ValueUuid(high, low); }
v = buff == null ? (Value) ValueNull.INSTANCE : ValueUuid.get(buff); break;
/** * Get or create a UUID for the given text representation. * * @param s the text representation of the UUID * @return the UUID */ public static ValueUuid get(String s) { long low = 0, high = 0; for (int i = 0, j = 0, length = s.length(); i < length; i++) { char c = s.charAt(i); if (c >= '0' && c <= '9') { low = (low << 4) | (c - '0'); } else if (c >= 'a' && c <= 'f') { low = (low << 4) | (c - 'a' + 0xa); } else if (c == '-') { continue; } else if (c >= 'A' && c <= 'F') { low = (low << 4) | (c - 'A' + 0xa); } else if (c <= ' ') { continue; } else { throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, s); } if (j++ == 15) { high = low; low = 0; } } return (ValueUuid) Value.cache(new ValueUuid(high, low)); }
} else if (x instanceof UUID) { UUID u = (UUID) x; return ValueUuid.get(u.getMostSignificantBits(), u.getLeastSignificantBits()); } else if (x instanceof Object[]) {
return ValueJavaObject.getNoCopy(null, readBytes()); case Value.UUID: return ValueUuid.get(readLong(), readLong()); case Value.BOOLEAN: return ValueBoolean.get(readBoolean());