kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | da387b9045149d97a7438af110e8cce5489bed72c4cf32753fe5ded5bea413ed |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2016-01-25 12:41 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-01-25 12:41 +01:00 |
| Parents | bca2e40699da |
2 files changed
modified driver-core/src/main/java/com/datastax/driver/core/TypeCodec.java +21 −1
| @@ -486,11 +486,16 @@ | ||
| 486 | 486 | /** |
| 487 | 487 | * Parse the given CQL literal into an instance of the Java type |
| 488 | 488 | * handled by this codec. |
| 489 | + * <p/> | |
| 489 | 490 | * Implementors should take care of unquoting and unescaping the given CQL string |
| 490 | 491 | * where applicable. |
| 491 | - * Null values and empty Strings should be accepted, as weel as the string {@code "NULL"}; | |
| 492 | + * Null values and empty Strings should be accepted, as well as the string {@code "NULL"}; | |
| 492 | 493 | * in most cases, implementations should interpret these inputs has equivalent to a {@code null} |
| 493 | 494 | * reference. |
| 495 | + * <p/> | |
| 496 | + * Implementing this method is not strictly mandatory: internally, the driver only uses it to | |
| 497 | + * parse the INITCOND when building the metadata of an aggregate function (and in most cases it | |
| 498 | + * will use a built-in codec, unless the INITCOND has a custom type). | |
| 494 | 499 | * |
| 495 | 500 | * @param value The CQL string to parse, may be {@code null} or empty. |
| 496 | 501 | * @return An instance of T; may be {@code null} on a {@code null input}. |
| @@ -501,10 +506,25 @@ | ||
| 501 | 506 | /** |
| 502 | 507 | * Format the given value as a valid CQL literal according |
| 503 | 508 | * to the CQL type handled by this codec. |
| 509 | + * <p/> | |
| 504 | 510 | * Implementors should take care of quoting and escaping the resulting CQL literal |
| 505 | 511 | * where applicable. |
| 506 | 512 | * Null values should be accepted; in most cases, implementations should |
| 507 | 513 | * return the CQL keyword {@code "NULL"} for {@code null} inputs. |
| 514 | + * <p/> | |
| 515 | + * Implementing this method is not strictly mandatory. It is used: | |
| 516 | + * <ol> | |
| 517 | + * <li>in the query builder, when values are inlined in the query string (see | |
| 518 | + * {@link com.datastax.driver.core.querybuilder.BuiltStatement} for a detailed | |
| 519 | + * explanation of when this happens);</li> | |
| 520 | + * <li>in the {@link QueryLogger}, if parameter logging is enabled;</li> | |
| 521 | + * <li>to format the INITCOND in {@link AggregateMetadata#asCQLQuery(boolean)};</li> | |
| 522 | + * <li>in the {@code toString()} implementation of some objects ({@link UDTValue}, | |
| 523 | + * {@link TupleValue}, and the internal representation of a {@code ROWS} response), | |
| 524 | + * which may appear in driver logs.</li> | |
| 525 | + * </ol> | |
| 526 | + * If choose not to implement this method, you can return a constant string (for example | |
| 527 | + * "XxxCodec.format not implemented"). | |
| 508 | 528 | * |
| 509 | 529 | * @param value An instance of T; may be {@code null}. |
| 510 | 530 | * @return CQL string |
modified manual/custom_codecs/README.md +1 −1
| @@ -140,7 +140,7 @@ | ||
| 140 | 140 | |
| 141 | 141 | ```java |
| 142 | 142 | ObjectMapper objectMapper = ... |
| 143 | -JsonCodec<MyPojo> myJsonCodec = new JsonCodec<MyPojo>(MyPojo.class, objectMapper); | |
| 143 | +JsonCodec<MyPojo> myJsonCodec = new JsonCodec<MyPojo>(MyPojo.class); | |
| 144 | 144 | CodecRegistry myCodecRegistry = cluster.getConfiguration().getCodecRegistry(); |
| 145 | 145 | myCodecRegistry.register(myJsonCodec); |
| 146 | 146 | ``` |