kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 49e1ebe6c2254369543d9a50965e3c2b2b37571584a360cba1c782f7319a14fd |
|---|---|
| Author | Olivier Michallat <olim7t@users.noreply.github.com> · 2016-04-20 18:07 +02:00 |
| Committer | Olivier Michallat <olim7t@users.noreply.github.com> · 2016-04-20 18:07 +02:00 |
| Parents | 6e44dad32a41, b401801f3d44 |
10 files changed
modified changelog/README.md +1 −0
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | - [bug] JAVA-1074: Fix documentation around default timestamp generator. |
| 10 | 10 | - [improvement] JAVA-1109: Document SSLOptions changes in upgrade guide. |
| 11 | 11 | - [improvement] JAVA-1065: Add method to create token from partition key values. |
| 12 | +- [improvement] JAVA-1136: Enable JDK signature check in module driver-extras. | |
| 12 | 13 | |
| 13 | 14 | Merged from 2.1 branch: |
| 14 | 15 |
modified driver-extras/pom.xml +33 −12
| @@ -142,18 +142,39 @@ | ||
| 142 | 142 | <plugin> |
| 143 | 143 | <groupId>org.codehaus.mojo</groupId> |
| 144 | 144 | <artifactId>animal-sniffer-maven-plugin</artifactId> |
| 145 | - <configuration> | |
| 146 | - <!-- | |
| 147 | - There is no support for JDK 8 yet, see | |
| 148 | - https://github.com/mojohaus/animal-sniffer/issues/1 | |
| 149 | - --> | |
| 150 | - <skip>true</skip> | |
| 151 | - <signature> | |
| 152 | - <groupId>org.codehaus.mojo.signature</groupId> | |
| 153 | - <artifactId>java18</artifactId> | |
| 154 | - <version>1.0</version> | |
| 155 | - </signature> | |
| 156 | - </configuration> | |
| 145 | + <executions> | |
| 146 | + <execution> | |
| 147 | + <id>check</id> | |
| 148 | + <phase>process-classes</phase> | |
| 149 | + <goals> | |
| 150 | + <goal>check</goal> | |
| 151 | + </goals> | |
| 152 | + <configuration> | |
| 153 | + <signature> | |
| 154 | + <groupId>org.codehaus.mojo.signature</groupId> | |
| 155 | + <artifactId>java16</artifactId> | |
| 156 | + <version>1.0</version> | |
| 157 | + </signature> | |
| 158 | + <annotations> | |
| 159 | + <annotation>com.datastax.driver.extras.codecs.jdk8.IgnoreJDK6Requirement</annotation> | |
| 160 | + </annotations> | |
| 161 | + </configuration> | |
| 162 | + </execution> | |
| 163 | + <execution> | |
| 164 | + <id>check-jdk8</id> | |
| 165 | + <phase>process-classes</phase> | |
| 166 | + <goals> | |
| 167 | + <goal>check</goal> | |
| 168 | + </goals> | |
| 169 | + <configuration> | |
| 170 | + <signature> | |
| 171 | + <groupId>org.codehaus.mojo.signature</groupId> | |
| 172 | + <artifactId>java18</artifactId> | |
| 173 | + <version>1.0</version> | |
| 174 | + </signature> | |
| 175 | + </configuration> | |
| 176 | + </execution> | |
| 177 | + </executions> | |
| 157 | 178 | </plugin> |
| 158 | 179 | |
| 159 | 180 | <plugin> |
added driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/IgnoreJDK6Requirement.java +25 −0
| @@ -0,0 +1,25 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + */ | |
| 16 | +package com.datastax.driver.extras.codecs.jdk8; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * Annotation used to mark classes in this package as | |
| 20 | + * excluded from JDK signature check performed | |
| 21 | + * by <a href="http://www.mojohaus.org/animal-sniffer/animal-sniffer-maven-plugin/check-mojo.html">animal-sniffer</a> | |
| 22 | + * Maven plugin as they require JDK 8 and not the usual JDK 6. | |
| 23 | + */ | |
| 24 | +@interface IgnoreJDK6Requirement { | |
| 25 | +} |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/InstantCodec.java +25 −30
| @@ -21,90 +21,85 @@ | ||
| 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 | * |
| 47 | 40 | * @see ZonedDateTimeCodec |
| 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 | -public class InstantCodec extends TypeCodec<Instant> { | |
| 43 | +@IgnoreJDK6Requirement | |
| 44 | +@SuppressWarnings("Since15") | |
| 45 | +public class InstantCodec extends TypeCodec<java.time.Instant> { | |
| 51 | 46 | |
| 52 | 47 | public static final InstantCodec instance = new InstantCodec(); |
| 53 | 48 | |
| 54 | 49 | /** |
| 55 | - * A {@link DateTimeFormatter} that parses (most) of | |
| 50 | + * A {@link java.time.format.DateTimeFormatter} that parses (most) of | |
| 56 | 51 | * the ISO formats accepted in CQL. |
| 57 | 52 | */ |
| 58 | - private static final DateTimeFormatter PARSER = new DateTimeFormatterBuilder() | |
| 53 | + private static final java.time.format.DateTimeFormatter PARSER = new java.time.format.DateTimeFormatterBuilder() | |
| 59 | 54 | .parseCaseSensitive() |
| 60 | 55 | .parseStrict() |
| 61 | - .append(DateTimeFormatter.ISO_LOCAL_DATE) | |
| 56 | + .append(java.time.format.DateTimeFormatter.ISO_LOCAL_DATE) | |
| 62 | 57 | .optionalStart() |
| 63 | 58 | .appendLiteral('T') |
| 64 | - .appendValue(HOUR_OF_DAY, 2) | |
| 59 | + .appendValue(java.time.temporal.ChronoField.HOUR_OF_DAY, 2) | |
| 65 | 60 | .appendLiteral(':') |
| 66 | - .appendValue(MINUTE_OF_HOUR, 2) | |
| 61 | + .appendValue(java.time.temporal.ChronoField.MINUTE_OF_HOUR, 2) | |
| 67 | 62 | .optionalEnd() |
| 68 | 63 | .optionalStart() |
| 69 | 64 | .appendLiteral(':') |
| 70 | - .appendValue(SECOND_OF_MINUTE, 2) | |
| 65 | + .appendValue(java.time.temporal.ChronoField.SECOND_OF_MINUTE, 2) | |
| 71 | 66 | .optionalEnd() |
| 72 | 67 | .optionalStart() |
| 73 | - .appendFraction(NANO_OF_SECOND, 0, 9, true) | |
| 68 | + .appendFraction(java.time.temporal.ChronoField.NANO_OF_SECOND, 0, 9, true) | |
| 74 | 69 | .optionalEnd() |
| 75 | 70 | .optionalStart() |
| 76 | 71 | .appendZoneId() |
| 77 | 72 | .optionalEnd() |
| 78 | 73 | .toFormatter() |
| 79 | - .withZone(UTC); | |
| 74 | + .withZone(java.time.ZoneOffset.UTC); | |
| 80 | 75 | |
| 81 | - private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSxxx") | |
| 82 | - .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); | |
| 83 | 78 | |
| 84 | 79 | |
| 85 | 80 | private InstantCodec() { |
| 86 | - super(DataType.timestamp(), Instant.class); | |
| 81 | + super(DataType.timestamp(), java.time.Instant.class); | |
| 87 | 82 | } |
| 88 | 83 | |
| 89 | 84 | @Override |
| 90 | - public ByteBuffer serialize(Instant value, ProtocolVersion protocolVersion) { | |
| 85 | + public ByteBuffer serialize(java.time.Instant value, ProtocolVersion protocolVersion) { | |
| 91 | 86 | return value == null ? null : bigint().serializeNoBoxing(value.toEpochMilli(), protocolVersion); |
| 92 | 87 | } |
| 93 | 88 | |
| 94 | 89 | @Override |
| 95 | - public Instant deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) { | |
| 96 | - 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)); | |
| 97 | 92 | } |
| 98 | 93 | |
| 99 | 94 | @Override |
| 100 | - public String format(Instant value) { | |
| 95 | + public String format(java.time.Instant value) { | |
| 101 | 96 | if (value == null) |
| 102 | 97 | return "NULL"; |
| 103 | 98 | return quote(FORMATTER.format(value)); |
| 104 | 99 | } |
| 105 | 100 | |
| 106 | 101 | @Override |
| 107 | - public Instant parse(String value) { | |
| 102 | + public java.time.Instant parse(String value) { | |
| 108 | 103 | if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) |
| 109 | 104 | return null; |
| 110 | 105 | // strip enclosing single quotes, if any |
| @@ -112,14 +107,14 @@ | ||
| 112 | 107 | value = unquote(value); |
| 113 | 108 | if (isLongLiteral(value)) { |
| 114 | 109 | try { |
| 115 | - return ofEpochMilli(parseLong(value)); | |
| 110 | + return java.time.Instant.ofEpochMilli(parseLong(value)); | |
| 116 | 111 | } catch (NumberFormatException e) { |
| 117 | 112 | throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", value)); |
| 118 | 113 | } |
| 119 | 114 | } |
| 120 | 115 | try { |
| 121 | - return Instant.from(PARSER.parse(value)); | |
| 122 | - } catch (DateTimeParseException e) { | |
| 116 | + return java.time.Instant.from(PARSER.parse(value)); | |
| 117 | + } catch (java.time.format.DateTimeParseException e) { | |
| 123 | 118 | throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", value)); |
| 124 | 119 | } |
| 125 | 120 | } |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/LocalDateCodec.java +12 −13
| @@ -21,39 +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 | -public class LocalDateCodec extends TypeCodec<LocalDate> { | |
| 33 | +@IgnoreJDK6Requirement | |
| 34 | +@SuppressWarnings("Since15") | |
| 35 | +public class LocalDateCodec extends TypeCodec<java.time.LocalDate> { | |
| 37 | 36 | |
| 38 | 37 | public static final LocalDateCodec instance = new LocalDateCodec(); |
| 39 | 38 | |
| 40 | - 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); | |
| 41 | 40 | |
| 42 | 41 | private LocalDateCodec() { |
| 43 | - super(DataType.date(), LocalDate.class); | |
| 42 | + super(DataType.date(), java.time.LocalDate.class); | |
| 44 | 43 | } |
| 45 | 44 | |
| 46 | 45 | @Override |
| 47 | - public ByteBuffer serialize(LocalDate value, ProtocolVersion protocolVersion) { | |
| 46 | + public ByteBuffer serialize(java.time.LocalDate value, ProtocolVersion protocolVersion) { | |
| 48 | 47 | if (value == null) |
| 49 | 48 | return null; |
| 50 | - long days = ChronoUnit.DAYS.between(EPOCH, value); | |
| 49 | + long days = java.time.temporal.ChronoUnit.DAYS.between(EPOCH, value); | |
| 51 | 50 | int unsigned = fromSignedToUnsignedInt((int) days); |
| 52 | 51 | return cint().serializeNoBoxing(unsigned, protocolVersion); |
| 53 | 52 | } |
| 54 | 53 | |
| 55 | 54 | @Override |
| 56 | - public LocalDate deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) { | |
| 55 | + public java.time.LocalDate deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) { | |
| 57 | 56 | if (bytes == null || bytes.remaining() == 0) |
| 58 | 57 | return null; |
| 59 | 58 | int unsigned = cint().deserializeNoBoxing(bytes, protocolVersion); |
| @@ -62,14 +61,14 @@ | ||
| 62 | 61 | } |
| 63 | 62 | |
| 64 | 63 | @Override |
| 65 | - public String format(LocalDate value) { | |
| 64 | + public String format(java.time.LocalDate value) { | |
| 66 | 65 | if (value == null) |
| 67 | 66 | return "NULL"; |
| 68 | - return quote(ISO_LOCAL_DATE.format(value)); | |
| 67 | + return quote(java.time.format.DateTimeFormatter.ISO_LOCAL_DATE.format(value)); | |
| 69 | 68 | } |
| 70 | 69 | |
| 71 | 70 | @Override |
| 72 | - public LocalDate parse(String value) { | |
| 71 | + public java.time.LocalDate parse(String value) { | |
| 73 | 72 | if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) |
| 74 | 73 | return null; |
| 75 | 74 | |
| @@ -95,7 +94,7 @@ | ||
| 95 | 94 | } |
| 96 | 95 | |
| 97 | 96 | try { |
| 98 | - return LocalDate.parse(value, ISO_LOCAL_DATE); | |
| 97 | + return java.time.LocalDate.parse(value, java.time.format.DateTimeFormatter.ISO_LOCAL_DATE); | |
| 99 | 98 | } catch (RuntimeException e) { |
| 100 | 99 | throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value)); |
| 101 | 100 | } |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/LocalTimeCodec.java +13 −13
| @@ -22,48 +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 | -public class LocalTimeCodec extends TypeCodec<LocalTime> { | |
| 31 | +@IgnoreJDK6Requirement | |
| 32 | +@SuppressWarnings("Since15") | |
| 33 | +public class LocalTimeCodec extends TypeCodec<java.time.LocalTime> { | |
| 34 | 34 | |
| 35 | 35 | public static final LocalTimeCodec instance = new LocalTimeCodec(); |
| 36 | 36 | |
| 37 | - 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"); | |
| 38 | 38 | |
| 39 | 39 | private LocalTimeCodec() { |
| 40 | - super(DataType.time(), LocalTime.class); | |
| 40 | + super(DataType.time(), java.time.LocalTime.class); | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | @Override |
| 44 | - public ByteBuffer serialize(LocalTime value, ProtocolVersion protocolVersion) throws InvalidTypeException { | |
| 44 | + public ByteBuffer serialize(java.time.LocalTime value, ProtocolVersion protocolVersion) throws InvalidTypeException { | |
| 45 | 45 | if (value == null) |
| 46 | 46 | return null; |
| 47 | 47 | return bigint().serializeNoBoxing(value.toNanoOfDay(), protocolVersion); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | @Override |
| 51 | - public LocalTime deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) throws InvalidTypeException { | |
| 51 | + public java.time.LocalTime deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) throws InvalidTypeException { | |
| 52 | 52 | if (bytes == null || bytes.remaining() == 0) |
| 53 | 53 | return null; |
| 54 | 54 | long nanosOfDay = bigint().deserializeNoBoxing(bytes, protocolVersion); |
| 55 | - return LocalTime.ofNanoOfDay(nanosOfDay); | |
| 55 | + return java.time.LocalTime.ofNanoOfDay(nanosOfDay); | |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | @Override |
| 59 | - public String format(LocalTime value) { | |
| 59 | + public String format(java.time.LocalTime value) { | |
| 60 | 60 | if (value == null) |
| 61 | 61 | return "NULL"; |
| 62 | 62 | return quote(FORMATTER.format(value)); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | @Override |
| 66 | - public LocalTime parse(String value) { | |
| 66 | + public java.time.LocalTime parse(String value) { | |
| 67 | 67 | if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) |
| 68 | 68 | return null; |
| 69 | 69 | |
| @@ -79,11 +79,11 @@ | ||
| 79 | 79 | } catch (NumberFormatException e) { |
| 80 | 80 | throw new InvalidTypeException(String.format("Cannot parse time value from \"%s\"", value), e); |
| 81 | 81 | } |
| 82 | - return LocalTime.ofNanoOfDay(nanosOfDay); | |
| 82 | + return java.time.LocalTime.ofNanoOfDay(nanosOfDay); | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | try { |
| 86 | - return LocalTime.parse(value); | |
| 86 | + return java.time.LocalTime.parse(value); | |
| 87 | 87 | } catch (RuntimeException e) { |
| 88 | 88 | throw new InvalidTypeException(String.format("Cannot parse time value from \"%s\"", value), e); |
| 89 | 89 | } |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/OptionalCodec.java +11 −11
| @@ -22,20 +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 | -public class OptionalCodec<T> extends MappingCodec<Optional<T>, T> { | |
| 31 | +@IgnoreJDK6Requirement | |
| 32 | +@SuppressWarnings({"Since15", "OptionalUsedAsFieldOrParameterType"}) | |
| 33 | +public class OptionalCodec<T> extends MappingCodec<java.util.Optional<T>, T> { | |
| 34 | 34 | |
| 35 | - private final Predicate<T> isAbsent; | |
| 35 | + private final java.util.function.Predicate<T> isAbsent; | |
| 36 | 36 | |
| 37 | 37 | public OptionalCodec(TypeCodec<T> codec) { |
| 38 | - this(codec, new Predicate<T>() { | |
| 38 | + this(codec, new java.util.function.Predicate<T>() { | |
| 39 | 39 | @Override |
| 40 | 40 | public boolean test(T input) { |
| 41 | 41 | return input == null |
| @@ -46,20 +46,20 @@ | ||
| 46 | 46 | }); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - public OptionalCodec(TypeCodec<T> codec, Predicate<T> isAbsent) { | |
| 49 | + public OptionalCodec(TypeCodec<T> codec, java.util.function.Predicate<T> isAbsent) { | |
| 50 | 50 | // @formatter:off |
| 51 | - 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())); | |
| 52 | 52 | // @formatter:on |
| 53 | 53 | this.isAbsent = isAbsent; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | @Override |
| 57 | - protected Optional<T> deserialize(T value) { | |
| 58 | - 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); | |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | @Override |
| 62 | - protected T serialize(Optional<T> value) { | |
| 62 | + protected T serialize(java.util.Optional<T> value) { | |
| 63 | 63 | return value.isPresent() ? value.get() : absentValue(); |
| 64 | 64 | } |
| 65 | 65 |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/ZonedDateTimeCodec.java +25 −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/> |
| @@ -53,39 +45,41 @@ | ||
| 53 | 45 | * |
| 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 | -public class ZonedDateTimeCodec extends TypeCodec.AbstractTupleCodec<ZonedDateTime> { | |
| 48 | +@IgnoreJDK6Requirement | |
| 49 | +@SuppressWarnings("Since15") | |
| 50 | +public class ZonedDateTimeCodec extends TypeCodec.AbstractTupleCodec<java.time.ZonedDateTime> { | |
| 57 | 51 | |
| 58 | 52 | /** |
| 59 | - * A {@link DateTimeFormatter} that parses (most) of | |
| 53 | + * A {@link java.time.format.DateTimeFormatter} that parses (most) of | |
| 60 | 54 | * the ISO formats accepted in CQL. |
| 61 | 55 | */ |
| 62 | - private static final DateTimeFormatter FORMATTER = new DateTimeFormatterBuilder() | |
| 56 | + private static final java.time.format.DateTimeFormatter FORMATTER = new java.time.format.DateTimeFormatterBuilder() | |
| 63 | 57 | .parseCaseSensitive() |
| 64 | 58 | .parseStrict() |
| 65 | - .append(DateTimeFormatter.ISO_LOCAL_DATE) | |
| 59 | + .append(java.time.format.DateTimeFormatter.ISO_LOCAL_DATE) | |
| 66 | 60 | .optionalStart() |
| 67 | 61 | .appendLiteral('T') |
| 68 | - .appendValue(HOUR_OF_DAY, 2) | |
| 62 | + .appendValue(java.time.temporal.ChronoField.HOUR_OF_DAY, 2) | |
| 69 | 63 | .appendLiteral(':') |
| 70 | - .appendValue(MINUTE_OF_HOUR, 2) | |
| 64 | + .appendValue(java.time.temporal.ChronoField.MINUTE_OF_HOUR, 2) | |
| 71 | 65 | .optionalEnd() |
| 72 | 66 | .optionalStart() |
| 73 | 67 | .appendLiteral(':') |
| 74 | - .appendValue(SECOND_OF_MINUTE, 2) | |
| 68 | + .appendValue(java.time.temporal.ChronoField.SECOND_OF_MINUTE, 2) | |
| 75 | 69 | .optionalEnd() |
| 76 | 70 | .optionalStart() |
| 77 | - .appendFraction(NANO_OF_SECOND, 0, 9, true) | |
| 71 | + .appendFraction(java.time.temporal.ChronoField.NANO_OF_SECOND, 0, 9, true) | |
| 78 | 72 | .optionalEnd() |
| 79 | 73 | .optionalStart() |
| 80 | 74 | .appendZoneOrOffsetId() |
| 81 | 75 | .optionalEnd() |
| 82 | 76 | .toFormatter() |
| 83 | - .withZone(ZoneOffset.UTC); | |
| 77 | + .withZone(java.time.ZoneOffset.UTC); | |
| 84 | 78 | |
| 85 | - 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"); | |
| 86 | 80 | |
| 87 | 81 | public ZonedDateTimeCodec(TupleType tupleType) { |
| 88 | - super(tupleType, ZonedDateTime.class); | |
| 82 | + super(tupleType, java.time.ZonedDateTime.class); | |
| 89 | 83 | List<DataType> types = tupleType.getComponentTypes(); |
| 90 | 84 | checkArgument( |
| 91 | 85 | types.size() == 2 && types.get(0).equals(DataType.timestamp()) && types.get(1).equals(DataType.varchar()), |
| @@ -94,12 +88,12 @@ | ||
| 94 | 88 | } |
| 95 | 89 | |
| 96 | 90 | @Override |
| 97 | - protected ZonedDateTime newInstance() { | |
| 91 | + protected java.time.ZonedDateTime newInstance() { | |
| 98 | 92 | return null; |
| 99 | 93 | } |
| 100 | 94 | |
| 101 | 95 | @Override |
| 102 | - protected ByteBuffer serializeField(ZonedDateTime source, int index, ProtocolVersion protocolVersion) { | |
| 96 | + protected ByteBuffer serializeField(java.time.ZonedDateTime source, int index, ProtocolVersion protocolVersion) { | |
| 103 | 97 | if (index == 0) { |
| 104 | 98 | long millis = source.toInstant().toEpochMilli(); |
| 105 | 99 | return bigint().serializeNoBoxing(millis, protocolVersion); |
| @@ -111,20 +105,20 @@ | ||
| 111 | 105 | } |
| 112 | 106 | |
| 113 | 107 | @Override |
| 114 | - 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) { | |
| 115 | 109 | if (index == 0) { |
| 116 | 110 | long millis = bigint().deserializeNoBoxing(input, protocolVersion); |
| 117 | - return Instant.ofEpochMilli(millis).atZone(ZoneOffset.UTC); | |
| 111 | + return java.time.Instant.ofEpochMilli(millis).atZone(java.time.ZoneOffset.UTC); | |
| 118 | 112 | } |
| 119 | 113 | if (index == 1) { |
| 120 | 114 | String zoneId = varchar().deserialize(input, protocolVersion); |
| 121 | - return target.withZoneSameInstant(ZoneId.of(zoneId)); | |
| 115 | + return target.withZoneSameInstant(java.time.ZoneId.of(zoneId)); | |
| 122 | 116 | } |
| 123 | 117 | throw new IndexOutOfBoundsException("Tuple index out of bounds. " + index); |
| 124 | 118 | } |
| 125 | 119 | |
| 126 | 120 | @Override |
| 127 | - protected String formatField(ZonedDateTime value, int index) { | |
| 121 | + protected String formatField(java.time.ZonedDateTime value, int index) { | |
| 128 | 122 | if (index == 0) { |
| 129 | 123 | return quote(FORMATTER.format(value)); |
| 130 | 124 | } |
| @@ -135,7 +129,7 @@ | ||
| 135 | 129 | } |
| 136 | 130 | |
| 137 | 131 | @Override |
| 138 | - protected ZonedDateTime parseAndSetField(String input, ZonedDateTime target, int index) { | |
| 132 | + protected java.time.ZonedDateTime parseAndSetField(String input, java.time.ZonedDateTime target, int index) { | |
| 139 | 133 | if (index == 0) { |
| 140 | 134 | // strip enclosing single quotes, if any |
| 141 | 135 | if (ParseUtils.isQuoted(input)) |
| @@ -143,20 +137,20 @@ | ||
| 143 | 137 | if (isLongLiteral(input)) { |
| 144 | 138 | try { |
| 145 | 139 | long millis = Long.parseLong(input); |
| 146 | - return ZonedDateTime.ofInstant(Instant.ofEpochMilli(millis), ZoneOffset.UTC); | |
| 140 | + return java.time.ZonedDateTime.ofInstant(java.time.Instant.ofEpochMilli(millis), java.time.ZoneOffset.UTC); | |
| 147 | 141 | } catch (NumberFormatException e) { |
| 148 | 142 | throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", input)); |
| 149 | 143 | } |
| 150 | 144 | } |
| 151 | 145 | try { |
| 152 | - return ZonedDateTime.from(FORMATTER.parse(input)); | |
| 153 | - } catch (DateTimeParseException e) { | |
| 146 | + return java.time.ZonedDateTime.from(FORMATTER.parse(input)); | |
| 147 | + } catch (java.time.format.DateTimeParseException e) { | |
| 154 | 148 | throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", target)); |
| 155 | 149 | } |
| 156 | 150 | } |
| 157 | 151 | if (index == 1) { |
| 158 | 152 | String zoneId = varchar().parse(input); |
| 159 | - return target.withZoneSameInstant(ZoneId.of(zoneId)); | |
| 153 | + return target.withZoneSameInstant(java.time.ZoneId.of(zoneId)); | |
| 160 | 154 | } |
| 161 | 155 | throw new IndexOutOfBoundsException("Tuple index out of bounds. " + index); |
| 162 | 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, |
modified pom.xml +1 −1
| @@ -357,7 +357,7 @@ | ||
| 357 | 357 | <plugin> |
| 358 | 358 | <groupId>org.codehaus.mojo</groupId> |
| 359 | 359 | <artifactId>animal-sniffer-maven-plugin</artifactId> |
| 360 | - <version>1.14</version> | |
| 360 | + <version>1.15</version> | |
| 361 | 361 | <configuration> |
| 362 | 362 | <signature> |
| 363 | 363 | <groupId>org.codehaus.mojo.signature</groupId> |