kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | b401801f3d44b4b60bb97ef427b5a74ef56e0527f48ad37d97a4990186c11129 |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2016-03-24 17:09 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-04-20 18:02 +02:00 |
| Parents | bd350391f78d |
6 files changed
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/InstantCodec.java +23 −29
| @@ -21,26 +21,19 @@ | ||
| 21 | 21 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 22 | 22 | |
| 23 | 23 | import java.nio.ByteBuffer; |
| 24 | -import java.time.Instant; | |
| 25 | -import java.time.format.DateTimeFormatter; | |
| 26 | -import java.time.format.DateTimeFormatterBuilder; | |
| 27 | -import java.time.format.DateTimeParseException; | |
| 28 | 24 | |
| 29 | 25 | import static com.datastax.driver.core.ParseUtils.*; |
| 30 | 26 | import static java.lang.Long.parseLong; |
| 31 | -import static java.time.Instant.ofEpochMilli; | |
| 32 | -import static java.time.ZoneOffset.UTC; | |
| 33 | -import static java.time.temporal.ChronoField.*; | |
| 34 | 27 | |
| 35 | 28 | /** |
| 36 | - * {@link TypeCodec} that maps {@link Instant} to CQL {@code timestamp} | |
| 29 | + * {@link TypeCodec} that maps {@link java.time.Instant} to CQL {@code timestamp} | |
| 37 | 30 | * allowing the setting and retrieval of {@code timestamp} |
| 38 | - * columns as {@link Instant} instances. | |
| 31 | + * columns as {@link java.time.Instant} instances. | |
| 39 | 32 | * <p/> |
| 40 | 33 | * Since C* <code>timestamp</code> columns do not preserve timezones |
| 41 | 34 | * any attached timezone information will be lost. |
| 42 | 35 | * <p/> |
| 43 | - * <strong>IMPORTANT</strong>: this codec's {@link #format(Instant) format} method formats | |
| 36 | + * <strong>IMPORTANT</strong>: this codec's {@link #format(java.time.Instant) format} method formats | |
| 44 | 37 | * timestamps using an ISO-8601 format that includes milliseconds. |
| 45 | 38 | * <strong>This format is incompatible with Cassandra versions < 2.0.9.</strong> |
| 46 | 39 | * |
| @@ -48,64 +41,65 @@ | ||
| 48 | 41 | * @see <a href="https://cassandra.apache.org/doc/cql3/CQL-2.2.html#usingtimestamps">'Working with timestamps' section of CQL specification</a> |
| 49 | 42 | */ |
| 50 | 43 | @IgnoreJDK6Requirement |
| 44 | +@SuppressWarnings("Since15") | |
| 51 | 45 | public class InstantCodec extends TypeCodec<java.time.Instant> { |
| 52 | 46 | |
| 53 | 47 | public static final InstantCodec instance = new InstantCodec(); |
| 54 | 48 | |
| 55 | 49 | /** |
| 56 | - * A {@link DateTimeFormatter} that parses (most) of | |
| 50 | + * A {@link java.time.format.DateTimeFormatter} that parses (most) of | |
| 57 | 51 | * the ISO formats accepted in CQL. |
| 58 | 52 | */ |
| 59 | - private static final DateTimeFormatter PARSER = new DateTimeFormatterBuilder() | |
| 53 | + private static final java.time.format.DateTimeFormatter PARSER = new java.time.format.DateTimeFormatterBuilder() | |
| 60 | 54 | .parseCaseSensitive() |
| 61 | 55 | .parseStrict() |
| 62 | - .append(DateTimeFormatter.ISO_LOCAL_DATE) | |
| 56 | + .append(java.time.format.DateTimeFormatter.ISO_LOCAL_DATE) | |
| 63 | 57 | .optionalStart() |
| 64 | 58 | .appendLiteral('T') |
| 65 | - .appendValue(HOUR_OF_DAY, 2) | |
| 59 | + .appendValue(java.time.temporal.ChronoField.HOUR_OF_DAY, 2) | |
| 66 | 60 | .appendLiteral(':') |
| 67 | - .appendValue(MINUTE_OF_HOUR, 2) | |
| 61 | + .appendValue(java.time.temporal.ChronoField.MINUTE_OF_HOUR, 2) | |
| 68 | 62 | .optionalEnd() |
| 69 | 63 | .optionalStart() |
| 70 | 64 | .appendLiteral(':') |
| 71 | - .appendValue(SECOND_OF_MINUTE, 2) | |
| 65 | + .appendValue(java.time.temporal.ChronoField.SECOND_OF_MINUTE, 2) | |
| 72 | 66 | .optionalEnd() |
| 73 | 67 | .optionalStart() |
| 74 | - .appendFraction(NANO_OF_SECOND, 0, 9, true) | |
| 68 | + .appendFraction(java.time.temporal.ChronoField.NANO_OF_SECOND, 0, 9, true) | |
| 75 | 69 | .optionalEnd() |
| 76 | 70 | .optionalStart() |
| 77 | 71 | .appendZoneId() |
| 78 | 72 | .optionalEnd() |
| 79 | 73 | .toFormatter() |
| 80 | - .withZone(UTC); | |
| 74 | + .withZone(java.time.ZoneOffset.UTC); | |
| 81 | 75 | |
| 82 | - private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSxxx") | |
| 83 | - .withZone(UTC); | |
| 76 | + private static final java.time.format.DateTimeFormatter FORMATTER = java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSxxx") | |
| 77 | + .withZone(java.time.ZoneOffset.UTC); | |
| 84 | 78 | |
| 85 | 79 | |
| 86 | 80 | private InstantCodec() { |
| 87 | - super(DataType.timestamp(), Instant.class); | |
| 81 | + super(DataType.timestamp(), java.time.Instant.class); | |
| 88 | 82 | } |
| 89 | 83 | |
| 90 | 84 | @Override |
| 91 | - public ByteBuffer serialize(Instant value, ProtocolVersion protocolVersion) { | |
| 85 | + public ByteBuffer serialize(java.time.Instant value, ProtocolVersion protocolVersion) { | |
| 92 | 86 | return value == null ? null : bigint().serializeNoBoxing(value.toEpochMilli(), protocolVersion); |
| 93 | 87 | } |
| 94 | 88 | |
| 95 | 89 | @Override |
| 96 | - public Instant deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) { | |
| 97 | - return bytes == null || bytes.remaining() == 0 ? null : ofEpochMilli(bigint().deserializeNoBoxing(bytes, protocolVersion)); | |
| 90 | + public java.time.Instant deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) { | |
| 91 | + return bytes == null || bytes.remaining() == 0 ? null : java.time.Instant.ofEpochMilli(bigint().deserializeNoBoxing(bytes, protocolVersion)); | |
| 98 | 92 | } |
| 99 | 93 | |
| 100 | 94 | @Override |
| 101 | - public String format(Instant value) { | |
| 95 | + public String format(java.time.Instant value) { | |
| 102 | 96 | if (value == null) |
| 103 | 97 | return "NULL"; |
| 104 | 98 | return quote(FORMATTER.format(value)); |
| 105 | 99 | } |
| 106 | 100 | |
| 107 | 101 | @Override |
| 108 | - public Instant parse(String value) { | |
| 102 | + public java.time.Instant parse(String value) { | |
| 109 | 103 | if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) |
| 110 | 104 | return null; |
| 111 | 105 | // strip enclosing single quotes, if any |
| @@ -113,14 +107,14 @@ | ||
| 113 | 107 | value = unquote(value); |
| 114 | 108 | if (isLongLiteral(value)) { |
| 115 | 109 | try { |
| 116 | - return ofEpochMilli(parseLong(value)); | |
| 110 | + return java.time.Instant.ofEpochMilli(parseLong(value)); | |
| 117 | 111 | } catch (NumberFormatException e) { |
| 118 | 112 | throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", value)); |
| 119 | 113 | } |
| 120 | 114 | } |
| 121 | 115 | try { |
| 122 | - return Instant.from(PARSER.parse(value)); | |
| 123 | - } catch (DateTimeParseException e) { | |
| 116 | + return java.time.Instant.from(PARSER.parse(value)); | |
| 117 | + } catch (java.time.format.DateTimeParseException e) { | |
| 124 | 118 | throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", value)); |
| 125 | 119 | } |
| 126 | 120 | } |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/LocalDateCodec.java +11 −13
| @@ -21,40 +21,38 @@ | ||
| 21 | 21 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 22 | 22 | |
| 23 | 23 | import java.nio.ByteBuffer; |
| 24 | -import java.time.LocalDate; | |
| 25 | -import java.time.temporal.ChronoUnit; | |
| 26 | 24 | |
| 27 | 25 | import static com.datastax.driver.core.CodecUtils.*; |
| 28 | 26 | import static com.datastax.driver.core.ParseUtils.*; |
| 29 | 27 | import static java.lang.Long.parseLong; |
| 30 | -import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE; | |
| 31 | 28 | |
| 32 | 29 | /** |
| 33 | 30 | * {@link TypeCodec} that maps |
| 34 | 31 | * {@link java.time.LocalDate} to CQL {@code date}. |
| 35 | 32 | */ |
| 36 | 33 | @IgnoreJDK6Requirement |
| 37 | -public class LocalDateCodec extends TypeCodec<LocalDate> { | |
| 34 | +@SuppressWarnings("Since15") | |
| 35 | +public class LocalDateCodec extends TypeCodec<java.time.LocalDate> { | |
| 38 | 36 | |
| 39 | 37 | public static final LocalDateCodec instance = new LocalDateCodec(); |
| 40 | 38 | |
| 41 | - private static final LocalDate EPOCH = LocalDate.of(1970, 1, 1); | |
| 39 | + private static final java.time.LocalDate EPOCH = java.time.LocalDate.of(1970, 1, 1); | |
| 42 | 40 | |
| 43 | 41 | private LocalDateCodec() { |
| 44 | - super(DataType.date(), LocalDate.class); | |
| 42 | + super(DataType.date(), java.time.LocalDate.class); | |
| 45 | 43 | } |
| 46 | 44 | |
| 47 | 45 | @Override |
| 48 | - public ByteBuffer serialize(LocalDate value, ProtocolVersion protocolVersion) { | |
| 46 | + public ByteBuffer serialize(java.time.LocalDate value, ProtocolVersion protocolVersion) { | |
| 49 | 47 | if (value == null) |
| 50 | 48 | return null; |
| 51 | - long days = ChronoUnit.DAYS.between(EPOCH, value); | |
| 49 | + long days = java.time.temporal.ChronoUnit.DAYS.between(EPOCH, value); | |
| 52 | 50 | int unsigned = fromSignedToUnsignedInt((int) days); |
| 53 | 51 | return cint().serializeNoBoxing(unsigned, protocolVersion); |
| 54 | 52 | } |
| 55 | 53 | |
| 56 | 54 | @Override |
| 57 | - public LocalDate deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) { | |
| 55 | + public java.time.LocalDate deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) { | |
| 58 | 56 | if (bytes == null || bytes.remaining() == 0) |
| 59 | 57 | return null; |
| 60 | 58 | int unsigned = cint().deserializeNoBoxing(bytes, protocolVersion); |
| @@ -63,14 +61,14 @@ | ||
| 63 | 61 | } |
| 64 | 62 | |
| 65 | 63 | @Override |
| 66 | - public String format(LocalDate value) { | |
| 64 | + public String format(java.time.LocalDate value) { | |
| 67 | 65 | if (value == null) |
| 68 | 66 | return "NULL"; |
| 69 | - return quote(ISO_LOCAL_DATE.format(value)); | |
| 67 | + return quote(java.time.format.DateTimeFormatter.ISO_LOCAL_DATE.format(value)); | |
| 70 | 68 | } |
| 71 | 69 | |
| 72 | 70 | @Override |
| 73 | - public LocalDate parse(String value) { | |
| 71 | + public java.time.LocalDate parse(String value) { | |
| 74 | 72 | if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) |
| 75 | 73 | return null; |
| 76 | 74 | |
| @@ -96,7 +94,7 @@ | ||
| 96 | 94 | } |
| 97 | 95 | |
| 98 | 96 | try { |
| 99 | - return LocalDate.parse(value, ISO_LOCAL_DATE); | |
| 97 | + return java.time.LocalDate.parse(value, java.time.format.DateTimeFormatter.ISO_LOCAL_DATE); | |
| 100 | 98 | } catch (RuntimeException e) { |
| 101 | 99 | throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value)); |
| 102 | 100 | } |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/LocalTimeCodec.java +12 −13
| @@ -22,49 +22,48 @@ | ||
| 22 | 22 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 23 | 23 | |
| 24 | 24 | import java.nio.ByteBuffer; |
| 25 | -import java.time.LocalTime; | |
| 26 | -import java.time.format.DateTimeFormatter; | |
| 27 | 25 | |
| 28 | 26 | import static com.datastax.driver.core.ParseUtils.quote; |
| 29 | 27 | |
| 30 | 28 | /** |
| 31 | - * {@link TypeCodec} that maps {@link LocalTime} to CQL {@code time} (long representing nanoseconds since midnight). | |
| 29 | + * {@link TypeCodec} that maps {@link java.time.LocalTime} to CQL {@code time} (long representing nanoseconds since midnight). | |
| 32 | 30 | */ |
| 33 | 31 | @IgnoreJDK6Requirement |
| 34 | -public class LocalTimeCodec extends TypeCodec<LocalTime> { | |
| 32 | +@SuppressWarnings("Since15") | |
| 33 | +public class LocalTimeCodec extends TypeCodec<java.time.LocalTime> { | |
| 35 | 34 | |
| 36 | 35 | public static final LocalTimeCodec instance = new LocalTimeCodec(); |
| 37 | 36 | |
| 38 | - private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss.SSS"); | |
| 37 | + private static final java.time.format.DateTimeFormatter FORMATTER = java.time.format.DateTimeFormatter.ofPattern("HH:mm:ss.SSS"); | |
| 39 | 38 | |
| 40 | 39 | private LocalTimeCodec() { |
| 41 | - super(DataType.time(), LocalTime.class); | |
| 40 | + super(DataType.time(), java.time.LocalTime.class); | |
| 42 | 41 | } |
| 43 | 42 | |
| 44 | 43 | @Override |
| 45 | - public ByteBuffer serialize(LocalTime value, ProtocolVersion protocolVersion) throws InvalidTypeException { | |
| 44 | + public ByteBuffer serialize(java.time.LocalTime value, ProtocolVersion protocolVersion) throws InvalidTypeException { | |
| 46 | 45 | if (value == null) |
| 47 | 46 | return null; |
| 48 | 47 | return bigint().serializeNoBoxing(value.toNanoOfDay(), protocolVersion); |
| 49 | 48 | } |
| 50 | 49 | |
| 51 | 50 | @Override |
| 52 | - public LocalTime deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) throws InvalidTypeException { | |
| 51 | + public java.time.LocalTime deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) throws InvalidTypeException { | |
| 53 | 52 | if (bytes == null || bytes.remaining() == 0) |
| 54 | 53 | return null; |
| 55 | 54 | long nanosOfDay = bigint().deserializeNoBoxing(bytes, protocolVersion); |
| 56 | - return LocalTime.ofNanoOfDay(nanosOfDay); | |
| 55 | + return java.time.LocalTime.ofNanoOfDay(nanosOfDay); | |
| 57 | 56 | } |
| 58 | 57 | |
| 59 | 58 | @Override |
| 60 | - public String format(LocalTime value) { | |
| 59 | + public String format(java.time.LocalTime value) { | |
| 61 | 60 | if (value == null) |
| 62 | 61 | return "NULL"; |
| 63 | 62 | return quote(FORMATTER.format(value)); |
| 64 | 63 | } |
| 65 | 64 | |
| 66 | 65 | @Override |
| 67 | - public LocalTime parse(String value) { | |
| 66 | + public java.time.LocalTime parse(String value) { | |
| 68 | 67 | if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) |
| 69 | 68 | return null; |
| 70 | 69 | |
| @@ -80,11 +79,11 @@ | ||
| 80 | 79 | } catch (NumberFormatException e) { |
| 81 | 80 | throw new InvalidTypeException(String.format("Cannot parse time value from \"%s\"", value), e); |
| 82 | 81 | } |
| 83 | - return LocalTime.ofNanoOfDay(nanosOfDay); | |
| 82 | + return java.time.LocalTime.ofNanoOfDay(nanosOfDay); | |
| 84 | 83 | } |
| 85 | 84 | |
| 86 | 85 | try { |
| 87 | - return LocalTime.parse(value); | |
| 86 | + return java.time.LocalTime.parse(value); | |
| 88 | 87 | } catch (RuntimeException e) { |
| 89 | 88 | throw new InvalidTypeException(String.format("Cannot parse time value from \"%s\"", value), e); |
| 90 | 89 | } |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/OptionalCodec.java +10 −11
| @@ -22,21 +22,20 @@ | ||
| 22 | 22 | |
| 23 | 23 | import java.util.Collection; |
| 24 | 24 | import java.util.Map; |
| 25 | -import java.util.Optional; | |
| 26 | -import java.util.function.Predicate; | |
| 27 | 25 | |
| 28 | 26 | /** |
| 29 | - * A codec that wraps other codecs around JDK 8's {@link Optional} API. | |
| 27 | + * A codec that wraps other codecs around JDK 8's {@link java.util.Optional} API. | |
| 30 | 28 | * |
| 31 | 29 | * @param <T> The wrapped Java type |
| 32 | 30 | */ |
| 33 | 31 | @IgnoreJDK6Requirement |
| 34 | -public class OptionalCodec<T> extends MappingCodec<Optional<T>, T> { | |
| 32 | +@SuppressWarnings({"Since15", "OptionalUsedAsFieldOrParameterType"}) | |
| 33 | +public class OptionalCodec<T> extends MappingCodec<java.util.Optional<T>, T> { | |
| 35 | 34 | |
| 36 | - private final Predicate<T> isAbsent; | |
| 35 | + private final java.util.function.Predicate<T> isAbsent; | |
| 37 | 36 | |
| 38 | 37 | public OptionalCodec(TypeCodec<T> codec) { |
| 39 | - this(codec, new Predicate<T>() { | |
| 38 | + this(codec, new java.util.function.Predicate<T>() { | |
| 40 | 39 | @Override |
| 41 | 40 | public boolean test(T input) { |
| 42 | 41 | return input == null |
| @@ -47,20 +46,20 @@ | ||
| 47 | 46 | }); |
| 48 | 47 | } |
| 49 | 48 | |
| 50 | - public OptionalCodec(TypeCodec<T> codec, Predicate<T> isAbsent) { | |
| 49 | + public OptionalCodec(TypeCodec<T> codec, java.util.function.Predicate<T> isAbsent) { | |
| 51 | 50 | // @formatter:off |
| 52 | - super(codec, new TypeToken<Optional<T>>() {}.where(new TypeParameter<T>() {}, codec.getJavaType())); | |
| 51 | + super(codec, new TypeToken<java.util.Optional<T>>() {}.where(new TypeParameter<T>() {}, codec.getJavaType())); | |
| 53 | 52 | // @formatter:on |
| 54 | 53 | this.isAbsent = isAbsent; |
| 55 | 54 | } |
| 56 | 55 | |
| 57 | 56 | @Override |
| 58 | - protected Optional<T> deserialize(T value) { | |
| 59 | - return isAbsent(value) ? Optional.<T>empty() : Optional.of(value); | |
| 57 | + protected java.util.Optional<T> deserialize(T value) { | |
| 58 | + return isAbsent(value) ? java.util.Optional.<T>empty() : java.util.Optional.of(value); | |
| 60 | 59 | } |
| 61 | 60 | |
| 62 | 61 | @Override |
| 63 | - protected T serialize(Optional<T> value) { | |
| 62 | + protected T serialize(java.util.Optional<T> value) { | |
| 64 | 63 | return value.isPresent() ? value.get() : absentValue(); |
| 65 | 64 | } |
| 66 | 65 |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/ZonedDateTimeCodec.java +24 −31
| @@ -19,23 +19,15 @@ | ||
| 19 | 19 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 20 | 20 | |
| 21 | 21 | import java.nio.ByteBuffer; |
| 22 | -import java.time.Instant; | |
| 23 | -import java.time.ZoneId; | |
| 24 | -import java.time.ZoneOffset; | |
| 25 | -import java.time.ZonedDateTime; | |
| 26 | -import java.time.format.DateTimeFormatter; | |
| 27 | -import java.time.format.DateTimeFormatterBuilder; | |
| 28 | -import java.time.format.DateTimeParseException; | |
| 29 | 22 | import java.util.List; |
| 30 | 23 | |
| 31 | 24 | import static com.datastax.driver.core.ParseUtils.isLongLiteral; |
| 32 | 25 | import static com.datastax.driver.core.ParseUtils.quote; |
| 33 | 26 | import static com.google.common.base.Preconditions.checkArgument; |
| 34 | -import static java.time.temporal.ChronoField.*; | |
| 35 | 27 | |
| 36 | 28 | /** |
| 37 | 29 | * {@link TypeCodec} that maps |
| 38 | - * {@link ZonedDateTime} to CQL {@code tuple<timestamp,varchar>}, | |
| 30 | + * {@link java.time.ZonedDateTime} to CQL {@code tuple<timestamp,varchar>}, | |
| 39 | 31 | * providing a pattern for maintaining timezone information in |
| 40 | 32 | * Cassandra. |
| 41 | 33 | * <p/> |
| @@ -54,39 +46,40 @@ | ||
| 54 | 46 | * @see <a href="https://cassandra.apache.org/doc/cql3/CQL-2.2.html#usingtimestamps">'Working with timestamps' section of CQL specification</a> |
| 55 | 47 | */ |
| 56 | 48 | @IgnoreJDK6Requirement |
| 57 | -public class ZonedDateTimeCodec extends TypeCodec.AbstractTupleCodec<ZonedDateTime> { | |
| 49 | +@SuppressWarnings("Since15") | |
| 50 | +public class ZonedDateTimeCodec extends TypeCodec.AbstractTupleCodec<java.time.ZonedDateTime> { | |
| 58 | 51 | |
| 59 | 52 | /** |
| 60 | - * A {@link DateTimeFormatter} that parses (most) of | |
| 53 | + * A {@link java.time.format.DateTimeFormatter} that parses (most) of | |
| 61 | 54 | * the ISO formats accepted in CQL. |
| 62 | 55 | */ |
| 63 | - private static final DateTimeFormatter FORMATTER = new DateTimeFormatterBuilder() | |
| 56 | + private static final java.time.format.DateTimeFormatter FORMATTER = new java.time.format.DateTimeFormatterBuilder() | |
| 64 | 57 | .parseCaseSensitive() |
| 65 | 58 | .parseStrict() |
| 66 | - .append(DateTimeFormatter.ISO_LOCAL_DATE) | |
| 59 | + .append(java.time.format.DateTimeFormatter.ISO_LOCAL_DATE) | |
| 67 | 60 | .optionalStart() |
| 68 | 61 | .appendLiteral('T') |
| 69 | - .appendValue(HOUR_OF_DAY, 2) | |
| 62 | + .appendValue(java.time.temporal.ChronoField.HOUR_OF_DAY, 2) | |
| 70 | 63 | .appendLiteral(':') |
| 71 | - .appendValue(MINUTE_OF_HOUR, 2) | |
| 64 | + .appendValue(java.time.temporal.ChronoField.MINUTE_OF_HOUR, 2) | |
| 72 | 65 | .optionalEnd() |
| 73 | 66 | .optionalStart() |
| 74 | 67 | .appendLiteral(':') |
| 75 | - .appendValue(SECOND_OF_MINUTE, 2) | |
| 68 | + .appendValue(java.time.temporal.ChronoField.SECOND_OF_MINUTE, 2) | |
| 76 | 69 | .optionalEnd() |
| 77 | 70 | .optionalStart() |
| 78 | - .appendFraction(NANO_OF_SECOND, 0, 9, true) | |
| 71 | + .appendFraction(java.time.temporal.ChronoField.NANO_OF_SECOND, 0, 9, true) | |
| 79 | 72 | .optionalEnd() |
| 80 | 73 | .optionalStart() |
| 81 | 74 | .appendZoneOrOffsetId() |
| 82 | 75 | .optionalEnd() |
| 83 | 76 | .toFormatter() |
| 84 | - .withZone(ZoneOffset.UTC); | |
| 77 | + .withZone(java.time.ZoneOffset.UTC); | |
| 85 | 78 | |
| 86 | - private static final DateTimeFormatter ZONE_FORMATTER = DateTimeFormatter.ofPattern("xxx"); | |
| 79 | + private static final java.time.format.DateTimeFormatter ZONE_FORMATTER = java.time.format.DateTimeFormatter.ofPattern("xxx"); | |
| 87 | 80 | |
| 88 | 81 | public ZonedDateTimeCodec(TupleType tupleType) { |
| 89 | - super(tupleType, ZonedDateTime.class); | |
| 82 | + super(tupleType, java.time.ZonedDateTime.class); | |
| 90 | 83 | List<DataType> types = tupleType.getComponentTypes(); |
| 91 | 84 | checkArgument( |
| 92 | 85 | types.size() == 2 && types.get(0).equals(DataType.timestamp()) && types.get(1).equals(DataType.varchar()), |
| @@ -95,12 +88,12 @@ | ||
| 95 | 88 | } |
| 96 | 89 | |
| 97 | 90 | @Override |
| 98 | - protected ZonedDateTime newInstance() { | |
| 91 | + protected java.time.ZonedDateTime newInstance() { | |
| 99 | 92 | return null; |
| 100 | 93 | } |
| 101 | 94 | |
| 102 | 95 | @Override |
| 103 | - protected ByteBuffer serializeField(ZonedDateTime source, int index, ProtocolVersion protocolVersion) { | |
| 96 | + protected ByteBuffer serializeField(java.time.ZonedDateTime source, int index, ProtocolVersion protocolVersion) { | |
| 104 | 97 | if (index == 0) { |
| 105 | 98 | long millis = source.toInstant().toEpochMilli(); |
| 106 | 99 | return bigint().serializeNoBoxing(millis, protocolVersion); |
| @@ -112,20 +105,20 @@ | ||
| 112 | 105 | } |
| 113 | 106 | |
| 114 | 107 | @Override |
| 115 | - protected ZonedDateTime deserializeAndSetField(ByteBuffer input, ZonedDateTime target, int index, ProtocolVersion protocolVersion) { | |
| 108 | + protected java.time.ZonedDateTime deserializeAndSetField(ByteBuffer input, java.time.ZonedDateTime target, int index, ProtocolVersion protocolVersion) { | |
| 116 | 109 | if (index == 0) { |
| 117 | 110 | long millis = bigint().deserializeNoBoxing(input, protocolVersion); |
| 118 | - return Instant.ofEpochMilli(millis).atZone(ZoneOffset.UTC); | |
| 111 | + return java.time.Instant.ofEpochMilli(millis).atZone(java.time.ZoneOffset.UTC); | |
| 119 | 112 | } |
| 120 | 113 | if (index == 1) { |
| 121 | 114 | String zoneId = varchar().deserialize(input, protocolVersion); |
| 122 | - return target.withZoneSameInstant(ZoneId.of(zoneId)); | |
| 115 | + return target.withZoneSameInstant(java.time.ZoneId.of(zoneId)); | |
| 123 | 116 | } |
| 124 | 117 | throw new IndexOutOfBoundsException("Tuple index out of bounds. " + index); |
| 125 | 118 | } |
| 126 | 119 | |
| 127 | 120 | @Override |
| 128 | - protected String formatField(ZonedDateTime value, int index) { | |
| 121 | + protected String formatField(java.time.ZonedDateTime value, int index) { | |
| 129 | 122 | if (index == 0) { |
| 130 | 123 | return quote(FORMATTER.format(value)); |
| 131 | 124 | } |
| @@ -136,7 +129,7 @@ | ||
| 136 | 129 | } |
| 137 | 130 | |
| 138 | 131 | @Override |
| 139 | - protected ZonedDateTime parseAndSetField(String input, ZonedDateTime target, int index) { | |
| 132 | + protected java.time.ZonedDateTime parseAndSetField(String input, java.time.ZonedDateTime target, int index) { | |
| 140 | 133 | if (index == 0) { |
| 141 | 134 | // strip enclosing single quotes, if any |
| 142 | 135 | if (ParseUtils.isQuoted(input)) |
| @@ -144,20 +137,20 @@ | ||
| 144 | 137 | if (isLongLiteral(input)) { |
| 145 | 138 | try { |
| 146 | 139 | long millis = Long.parseLong(input); |
| 147 | - return ZonedDateTime.ofInstant(Instant.ofEpochMilli(millis), ZoneOffset.UTC); | |
| 140 | + return java.time.ZonedDateTime.ofInstant(java.time.Instant.ofEpochMilli(millis), java.time.ZoneOffset.UTC); | |
| 148 | 141 | } catch (NumberFormatException e) { |
| 149 | 142 | throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", input)); |
| 150 | 143 | } |
| 151 | 144 | } |
| 152 | 145 | try { |
| 153 | - return ZonedDateTime.from(FORMATTER.parse(input)); | |
| 154 | - } catch (DateTimeParseException e) { | |
| 146 | + return java.time.ZonedDateTime.from(FORMATTER.parse(input)); | |
| 147 | + } catch (java.time.format.DateTimeParseException e) { | |
| 155 | 148 | throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", target)); |
| 156 | 149 | } |
| 157 | 150 | } |
| 158 | 151 | if (index == 1) { |
| 159 | 152 | String zoneId = varchar().parse(input); |
| 160 | - return target.withZoneSameInstant(ZoneId.of(zoneId)); | |
| 153 | + return target.withZoneSameInstant(java.time.ZoneId.of(zoneId)); | |
| 161 | 154 | } |
| 162 | 155 | throw new IndexOutOfBoundsException("Tuple index out of bounds. " + index); |
| 163 | 156 | } |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/package-info.java +1 −1
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | * This package contains a collection of convenience |
| 19 | 19 | * {@link com.datastax.driver.core.TypeCodec TypeCodec} instances useful for |
| 20 | 20 | * serializing between CQL types and Java 8 types, such as the ones from the |
| 21 | - * {@link java.time} API and {@link java.util.Optional}. | |
| 21 | + * {@code java.time} API and {@code java.util.Optional}. | |
| 22 | 22 | * <p/> |
| 23 | 23 | * <p/> |
| 24 | 24 | * Note that, while the driver remains globally compatible with older JDKs, |