@Override public Date parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // strip enclosing single quotes, if any if (ParseUtils.isQuoted(value)) value = ParseUtils.unquote(value); if (ParseUtils.isLongLiteral(value)) { try { return new Date(Long.parseLong(value)); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse timestamp value from \"%s\"", value)); } } try { return ParseUtils.parseDate(value); } catch (ParseException e) { throw new InvalidTypeException( String.format("Cannot parse timestamp value from \"%s\"", value)); } }
@Override public Long parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // enclosing single quotes required, even for long literals if (!ParseUtils.isQuoted(value)) throw new InvalidTypeException("time values must be enclosed by single quotes"); value = value.substring(1, value.length() - 1); if (ParseUtils.isLongLiteral(value)) { try { return Long.parseLong(value); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse time value from \"%s\"", value), e); } } try { return ParseUtils.parseTime(value); } catch (ParseException e) { throw new InvalidTypeException( String.format("Cannot parse time value from \"%s\"", value), e); } }
@Override public LocalDate parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // single quotes are optional for long literals, mandatory for date patterns // strip enclosing single quotes, if any if (ParseUtils.isQuoted(value)) value = ParseUtils.unquote(value); if (ParseUtils.isLongLiteral(value)) { long unsigned; try { unsigned = Long.parseLong(value); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse date value from \"%s\"", value), e); } try { int days = CodecUtils.fromCqlDateToDaysSinceEpoch(unsigned); return LocalDate.fromDaysSinceEpoch(days); } catch (IllegalArgumentException e) { throw new InvalidTypeException( String.format("Cannot parse date value from \"%s\"", value), e); } } try { Date date = ParseUtils.parseDate(value, pattern); return LocalDate.fromMillisSinceEpoch(date.getTime()); } catch (ParseException e) { throw new InvalidTypeException( String.format("Cannot parse date value from \"%s\"", value), e); } }
@Override public Long parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // enclosing single quotes required, even for long literals if (!ParseUtils.isQuoted(value)) throw new InvalidTypeException("time values must be enclosed by single quotes"); value = value.substring(1, value.length() - 1); if (ParseUtils.isLongLiteral(value)) { try { return Long.parseLong(value); } catch (NumberFormatException e) { throw new InvalidTypeException(String.format("Cannot parse time value from \"%s\"", value), e); } } try { return ParseUtils.parseTime(value); } catch (ParseException e) { throw new InvalidTypeException(String.format("Cannot parse time value from \"%s\"", value), e); } }
@Override public Long parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // enclosing single quotes required, even for long literals if (!ParseUtils.isQuoted(value)) throw new InvalidTypeException("time values must be enclosed by single quotes"); value = value.substring(1, value.length() - 1); if (ParseUtils.isLongLiteral(value)) { try { return Long.parseLong(value); } catch (NumberFormatException e) { throw new InvalidTypeException(String.format("Cannot parse time value from \"%s\"", value), e); } } try { return ParseUtils.parseTime(value); } catch (ParseException e) { throw new InvalidTypeException(String.format("Cannot parse time value from \"%s\"", value), e); } }
@Override public Timestamp parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // strip enclosing single quotes, if any if (isQuoted(value)) value = unquote(value); if (isLongLiteral(value)) { try { return new Timestamp(parseLong(value)); } catch (NumberFormatException e) { throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", value)); } } try { return new Timestamp(PARSER.parseMillis(value)); } catch (RuntimeException e) { throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", value)); } } }
@Override public Date parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // strip enclosing single quotes, if any if (ParseUtils.isQuoted(value)) value = ParseUtils.unquote(value); if (ParseUtils.isLongLiteral(value)) { try { return new Date(Long.parseLong(value)); } catch (NumberFormatException e) { throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", value)); } } try { return ParseUtils.parseDate(value); } catch (ParseException e) { throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", value)); } }
@Override public java.time.Instant parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // strip enclosing single quotes, if any if (isQuoted(value)) value = unquote(value); if (isLongLiteral(value)) { try { return java.time.Instant.ofEpochMilli(parseLong(value)); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse timestamp value from \"%s\"", value)); } } try { return java.time.Instant.from(PARSER.parse(value)); } catch (java.time.format.DateTimeParseException e) { throw new InvalidTypeException( String.format("Cannot parse timestamp value from \"%s\"", value)); } } }
@Override public Long parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // enclosing single quotes required, even for long literals if (!ParseUtils.isQuoted(value)) throw new InvalidTypeException("time values must be enclosed by single quotes"); value = value.substring(1, value.length() - 1); if (ParseUtils.isLongLiteral(value)) { try { return Long.parseLong(value); } catch (NumberFormatException e) { throw new InvalidTypeException(String.format("Cannot parse time value from \"%s\"", value), e); } } try { return ParseUtils.parseTime(value); } catch (ParseException e) { throw new InvalidTypeException(String.format("Cannot parse time value from \"%s\"", value), e); } }
@Override public Date parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // strip enclosing single quotes, if any if (ParseUtils.isQuoted(value)) value = ParseUtils.unquote(value); if (ParseUtils.isLongLiteral(value)) { try { return new Date(Long.parseLong(value)); } catch (NumberFormatException e) { throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", value)); } } try { return ParseUtils.parseDate(value); } catch (ParseException e) { throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", value)); } }
@Override public Date parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // strip enclosing single quotes, if any if (ParseUtils.isQuoted(value)) value = ParseUtils.unquote(value); if (ParseUtils.isLongLiteral(value)) { try { return new Date(Long.parseLong(value)); } catch (NumberFormatException e) { throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", value)); } } try { return ParseUtils.parseDate(value); } catch (ParseException e) { throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", value)); } }
@Override public java.time.LocalTime parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // enclosing single quotes required, even for long literals if (!ParseUtils.isQuoted(value)) throw new InvalidTypeException("time values must be enclosed by single quotes"); value = value.substring(1, value.length() - 1); if (ParseUtils.isLongLiteral(value)) { long nanosOfDay; try { nanosOfDay = Long.parseLong(value); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse time value from \"%s\"", value), e); } return java.time.LocalTime.ofNanoOfDay(nanosOfDay); } try { return java.time.LocalTime.parse(value); } catch (RuntimeException e) { throw new InvalidTypeException( String.format("Cannot parse time value from \"%s\"", value), e); } } }
@Override public Long parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // single quotes are optional for long literals, mandatory for date patterns // strip enclosing single quotes, if any if (isQuoted(value)) value = unquote(value); if (isLongLiteral(value)) { try { return parseLong(value); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse timestamp value from \"%s\"", value), e); } } try { return parseDate(value).getTime(); } catch (ParseException e) { throw new InvalidTypeException( String.format("Cannot parse timestamp value from \"%s\"", value), e); } }
@Override public java.time.LocalDateTime parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) { return null; } // strip enclosing single quotes, if any if (ParseUtils.isQuoted(value)) { value = ParseUtils.unquote(value); } if (isLongLiteral(value)) { try { long millis = Long.parseLong(value); return java.time.LocalDateTime.ofInstant( java.time.Instant.ofEpochMilli(millis), java.time.ZoneOffset.UTC); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse timestamp value from \"%s\"", value)); } } try { return java.time.LocalDateTime.from(FORMATTER.parse(value)); } catch (java.time.format.DateTimeParseException e) { throw new InvalidTypeException( String.format("Cannot parse timestamp value from \"%s\"", value)); } } }
@Override public LocalTime parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // enclosing single quotes required, even for long literals if (!ParseUtils.isQuoted(value)) throw new InvalidTypeException("time values must be enclosed by single quotes"); value = value.substring(1, value.length() - 1); if (ParseUtils.isLongLiteral(value)) { long nanosOfDay; try { nanosOfDay = Long.parseLong(value); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse time value from \"%s\"", value), e); } return LocalTime.fromMillisOfDay(NANOSECONDS.toMillis(nanosOfDay)); } try { return LocalTime.parse(value); } catch (RuntimeException e) { throw new InvalidTypeException( String.format("Cannot parse time value from \"%s\"", value), e); } } }
@Override public Time parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // enclosing single quotes required, even for long literals if (!ParseUtils.isQuoted(value)) throw new InvalidTypeException("time values must be enclosed by single quotes"); value = value.substring(1, value.length() - 1); if (ParseUtils.isLongLiteral(value)) { long nanosOfDay; try { nanosOfDay = Long.parseLong(value); } catch (NumberFormatException e) { throw new InvalidTypeException(String.format("Cannot parse time value from \"%s\"", value), e); } return new Time(LocalTime.fromMillisOfDay(nanosOfDay / 1000000L).getMillisOfSecond()); } try { return new Time(LocalTime.parse(value).toDateTimeToday().getMillis()); } catch (RuntimeException e) { throw new InvalidTypeException(String.format("Cannot parse time value from \"%s\"", value), e); } }
@Override public Integer parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // single quotes are optional for long literals, mandatory for date patterns // strip enclosing single quotes, if any if (isQuoted(value)) value = unquote(value); if (isLongLiteral(value)) { long unsigned; try { unsigned = Long.parseLong(value); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse date value from \"%s\"", value), e); } try { return fromCqlDateToDaysSinceEpoch(unsigned); } catch (IllegalArgumentException e) { throw new InvalidTypeException( String.format("Cannot parse date value from \"%s\"", value), e); } } try { Date date = parseDate(value, pattern); return (int) MILLISECONDS.toDays(date.getTime()); } catch (ParseException e) { throw new InvalidTypeException( String.format("Cannot parse date value from \"%s\"", value), e); } }
@Override public Instant parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // strip enclosing single quotes, if any if (isQuoted(value)) value = unquote(value); if (isLongLiteral(value)) { try { return new Instant(parseLong(value)); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse timestamp value from \"%s\"", value)); } } try { return new Instant(PARSER.parseMillis(value)); } catch (RuntimeException e) { throw new InvalidTypeException( String.format("Cannot parse timestamp value from \"%s\"", value)); } } }
@Override public LocalDate parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // single quotes are optional for long literals, mandatory for date patterns // strip enclosing single quotes, if any if (ParseUtils.isQuoted(value)) value = ParseUtils.unquote(value); if (ParseUtils.isLongLiteral(value)) { long unsigned; try { unsigned = Long.parseLong(value); } catch (NumberFormatException e) { throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e); } try { int days = CodecUtils.fromCqlDateToDaysSinceEpoch(unsigned); return LocalDate.fromDaysSinceEpoch(days); } catch (IllegalArgumentException e) { throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e); } } try { Date date = ParseUtils.parseDate(value, pattern); return LocalDate.fromMillisSinceEpoch(date.getTime()); } catch (ParseException e) { throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e); } }
@Override public LocalDate parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // single quotes are optional for long literals, mandatory for date patterns // strip enclosing single quotes, if any if (ParseUtils.isQuoted(value)) value = ParseUtils.unquote(value); if (ParseUtils.isLongLiteral(value)) { long unsigned; try { unsigned = Long.parseLong(value); } catch (NumberFormatException e) { throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e); } try { int days = CodecUtils.fromCqlDateToDaysSinceEpoch(unsigned); return LocalDate.fromDaysSinceEpoch(days); } catch (IllegalArgumentException e) { throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e); } } try { Date date = ParseUtils.parseDate(value, pattern); return LocalDate.fromMillisSinceEpoch(date.getTime()); } catch (ParseException e) { throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e); } }