/** * Get or create a date value for the given date. * * @param dateValue the date value, a bit field with bits for the year, * month, and day * @param timeNanos the nanoseconds since midnight * @return the value */ public static ValueTimestamp fromDateValueAndNanos(long dateValue, long timeNanos) { return (ValueTimestamp) Value.cache(new ValueTimestamp(dateValue, timeNanos)); }
/** * 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)); }
/** * Get or create a short value for the given short. * * @param i the short * @return the value */ public static ValueShort get(short i) { return (ValueShort) Value.cache(new ValueShort(i)); }
/** * Get or create a long value for the given long. * * @param i the long * @return the value */ public static ValueLong get(long i) { if (i >= 0 && i < STATIC_SIZE) { return STATIC_CACHE[(int) i]; } return (ValueLong) Value.cache(new ValueLong(i)); }
/** * Get or create a date value for the given date. * * @param dateValue the date value * @return the value */ public static ValueDate fromDateValue(long dateValue) { return (ValueDate) Value.cache(new ValueDate(dateValue)); }
/** * Get or create a geometry value for the given geometry. * * @param bytes the WKB representation of the geometry * @return the value */ public static ValueGeometry get(byte[] bytes) { return (ValueGeometry) Value.cache(new ValueGeometry(bytes, null)); }
/** * Get or create byte value for the given byte. * * @param i the byte * @return the value */ public static ValueByte get(byte i) { return (ValueByte) Value.cache(new ValueByte(i)); }
/** * Get or create a date value for the given date. * * @param dateValue the date value, a bit field with bits for the year, * month, and day * @param timeNanos the nanoseconds since midnight * @param timeZoneOffsetMins the timezone offset in minutes * @return the value */ public static ValueTimestampTimeZone fromDateValueAndNanos(long dateValue, long timeNanos, short timeZoneOffsetMins) { return (ValueTimestampTimeZone) Value.cache(new ValueTimestampTimeZone( dateValue, timeNanos, timeZoneOffsetMins)); }
/** * Get or create big decimal value for the given big decimal. * * @param dec the bit decimal * @return the value */ public static ValueDecimal get(BigDecimal dec) { if (BigDecimal.ZERO.equals(dec)) { return (ValueDecimal) ZERO; } else if (BigDecimal.ONE.equals(dec)) { return (ValueDecimal) ONE; } return (ValueDecimal) Value.cache(new ValueDecimal(dec)); }
/** * Get or create float value for the given float. * * @param d the float * @return the value */ public static ValueFloat get(float d) { if (d == 1.0F) { return ONE; } else if (d == 0.0F) { // -0.0 == 0.0, and we want to return 0.0 for both return ZERO; } return (ValueFloat) Value.cache(new ValueFloat(d)); }
/** * Get or create double value for the given double. * * @param d the double * @return the value */ public static ValueDouble get(double d) { if (d == 1.0) { return ONE; } else if (d == 0.0) { // -0.0 == 0.0, and we want to return 0.0 for both return ZERO; } else if (Double.isNaN(d)) { return NAN; } return (ValueDouble) Value.cache(new ValueDouble(d)); }
/** * Get or create a bytes value for the given byte array. * Do not clone the date. * * @param b the byte array * @return the value */ public static ValueBytes getNoCopy(byte[] b) { if (b.length == 0) { return EMPTY; } ValueBytes obj = new ValueBytes(b); if (b.length > SysProperties.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE) { return obj; } return (ValueBytes) Value.cache(obj); }
/** * Get or create a string value for the given string. * * @param s the string * @param treatEmptyStringsAsNull whether or not to treat empty strings as * NULL * @return the value */ public static Value get(String s, boolean treatEmptyStringsAsNull) { if (s.isEmpty()) { return treatEmptyStringsAsNull ? ValueNull.INSTANCE : EMPTY; } ValueString obj = new ValueString(StringUtils.cache(s)); if (s.length() > SysProperties.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE) { return obj; } return Value.cache(obj); // this saves memory, but is really slow // return new ValueString(s.intern()); }
private static ValueGeometry get(Geometry g) { byte[] bytes = convertToWKB(g); return (ValueGeometry) Value.cache(new ValueGeometry(bytes, g)); }
/** * Get or create a case insensitive string value for the given string. * The value will have the same case as the passed string. * * @param s the string * @return the value */ public static ValueStringIgnoreCase get(String s) { if (s.length() == 0) { return EMPTY; } ValueStringIgnoreCase obj = new ValueStringIgnoreCase(StringUtils.cache(s)); if (s.length() > SysProperties.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE) { return obj; } ValueStringIgnoreCase cache = (ValueStringIgnoreCase) Value.cache(obj); // the cached object could have the wrong case // (it would still be 'equal', but we don't like to store it) if (cache.value.equals(s)) { return cache; } return obj; }
/** * Get or create a time value. * * @param nanos the nanoseconds since midnight * @return the value */ public static ValueTime fromNanos(long nanos) { if (!SysProperties.UNLIMITED_TIME_RANGE) { if (nanos < 0L || nanos >= DateTimeUtils.NANOS_PER_DAY) { StringBuilder builder = new StringBuilder(); DateTimeUtils.appendTime(builder, nanos); throw DbException.get(ErrorCode.INVALID_DATETIME_CONSTANT_2, "TIME", builder.toString()); } } return (ValueTime) Value.cache(new ValueTime(nanos)); }
/** * 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)); }
/** * Get or create a java object value for the given byte array. * Do not clone the data. * * @param javaObject the object * @param b the byte array * @param dataHandler provides the object serializer * @return the value */ public static ValueJavaObject getNoCopy(Object javaObject, byte[] b, DataHandler dataHandler) { if (b != null && b.length == 0) { return EMPTY; } ValueJavaObject obj; if (SysProperties.serializeJavaObject) { if (b == null) { b = JdbcUtils.serialize(javaObject, dataHandler); } obj = new ValueJavaObject(b, dataHandler); } else { obj = new NotSerialized(javaObject, b, dataHandler); } if (b == null || b.length > SysProperties.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE) { return obj; } return (ValueJavaObject) Value.cache(obj); }
return obj; return (ValueStringFixed) Value.cache(obj);
/** * 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 = Bits.readLong(binary, 0); long low = Bits.readLong(binary, 8); return (ValueUuid) Value.cache(new ValueUuid(high, low)); }