kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 977ad7941eff5c5d10c75dfae91e7d63ece6c577fc695a139c5599b67363493c |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2016-09-07 14:17 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-10-03 09:02 -07:00 |
| Parents | 86638feb1f1b |
1 file changed
modified manual/custom_codecs/extras/README.md +8 −13
| @@ -82,9 +82,9 @@ | ||
| 82 | 82 | |
| 83 | 83 | Like for JDK8, there is a codec for each time type: |
| 84 | 84 | |
| 85 | -* [InstantCodec][InstantCodec_joda]: [Instant][Instant_joda] to `timestamp`; | |
| 86 | -* [LocalDateCodec][LocalDateCodec_joda]: [LocalDate][LocalDate_joda] to `date`; | |
| 87 | -* [LocalTime][LocalTime_joda]: [LocalTime][LocalTime_joda] to `time`. | |
| 85 | +* [InstantCodec][InstantCodec_joda]: maps [Instant][Instant_joda] to `timestamp`; | |
| 86 | +* [LocalDateCodec][LocalDateCodec_joda]: maps [LocalDate][LocalDate_joda] to `date`; | |
| 87 | +* [LocalTimeCodec][LocalTimeCodec_joda]: maps [LocalTime][LocalTime_joda] to `time`. | |
| 88 | 88 | |
| 89 | 89 | ```java |
| 90 | 90 | import com.datastax.driver.extras.codecs.joda.InstantCodec; |
| @@ -127,7 +127,7 @@ | ||
| 127 | 127 | |
| 128 | 128 | * [SimpleTimestampCodec] maps `timestamp` to a primitive Java `long` representing the number of milliseconds since the |
| 129 | 129 | Epoch; |
| 130 | -* [SimpleDateCodec] maps `date` to a primitive Java `int` representing the number of milliseconds since the Epoch. | |
| 130 | +* [SimpleDateCodec] maps `date` to a primitive Java `int` representing the number of days since the Epoch. | |
| 131 | 131 | |
| 132 | 132 | There is no extra codec for `time`, because by default the driver already maps that type to a `long` representing the |
| 133 | 133 | number of milliseconds since midnight. |
| @@ -166,14 +166,10 @@ | ||
| 166 | 166 | // state saved as 0 |
| 167 | 167 | ``` |
| 168 | 168 | |
| 169 | -Note that if you registered both codecs at the same time, there would be a problem: because `session.execute` uses a | |
| 170 | -[simple statement](../../statements/simple/), the target CQL type is not known in advance, so the driver picks the first | |
| 171 | -codec that accepts a `State`. So one of the statements would serialize its value to the wrong type, and the request | |
| 172 | -would fail on the server side. | |
| 169 | +Note that if you registered an `EnumNameCodec` and an `EnumOrdinalCodec` _for the same enum_ at the same time, there could be a problem when executing [simple statements](../../statements/simple/), because in a simple statement, the target CQL type of a given query parameter is not known in advance, so the driver, on a best-effort attempt, will pick one or the other, whichever was registered first. If the chosen codec proves to be the wrong one, the request would fail on the server side. | |
| 173 | 170 | |
| 174 | 171 | In practice, this is unlikely to happen, because you'll probably stick to a single CQL type for a given enum type; |
| 175 | -however, if you ever run into that issue, the workaround is to use [prepared statements](../../statements/prepared/), | |
| 176 | -for which the driver knows the CQL type and can pick the exact codec. | |
| 172 | +however, if you ever run into that issue, the workaround is to use [prepared statements](../../statements/prepared/), for which the driver knows the CQL type and can pick the exact codec. | |
| 177 | 173 | |
| 178 | 174 | [EnumNameCodec]: http://docs.datastax.com/en/drivers/java/3.0/com/datastax/driver/extras/codecs/enums/EnumNameCodec.html |
| 179 | 175 | [EnumOrdinalCodec]: http://docs.datastax.com/en/drivers/java/3.0/com/datastax/driver/extras/codecs/enums/EnumOrdinalCodec.html |
| @@ -231,7 +227,7 @@ | ||
| 231 | 227 | |
| 232 | 228 | It requires an explicit dependency on the JSR-353 API and an implementation: |
| 233 | 229 | |
| 234 | -```java | |
| 230 | +```xml | |
| 235 | 231 | <dependency> |
| 236 | 232 | <groupId>javax.json</groupId> |
| 237 | 233 | <artifactId>javax.json-api</artifactId> |
| @@ -337,8 +333,7 @@ | ||
| 337 | 333 | cluster.getConfiguration().getCodecRegistry() |
| 338 | 334 | .register(optionalIntCodec); |
| 339 | 335 | |
| 340 | -TypeToken<Optional<Integer>> optionalIntToken = new TypeToken<Optional<Integer>>() { | |
| 341 | -}; | |
| 336 | +TypeToken<Optional<Integer>> optionalIntToken = new TypeToken<Optional<Integer>>() {}; | |
| 342 | 337 | |
| 343 | 338 | // schema: create table example (id int primary key, v int); |
| 344 | 339 | PreparedStatement pst = session.prepare("insert into example (id, v) values (?, ?)"); |