Elffuss BraidHub

kikocis/java-driver public

Improve custom codecs docs.
Changesetda387b9045149d97a7438af110e8cce5489bed72c4cf32753fe5ded5bea413ed
Authorolim7t <omichallat+github@gmail.com> · 2016-01-25 12:41 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2016-01-25 12:41 +01:00
Parentsbca2e40699da

Browse the files at this changeset

2 files changed

modified driver-core/src/main/java/com/datastax/driver/core/TypeCodec.java +21 −1
@@ -486,11 +486,16 @@
486486 /**
487487 * Parse the given CQL literal into an instance of the Java type
488488 * handled by this codec.
489+ * <p/>
489490 * Implementors should take care of unquoting and unescaping the given CQL string
490491 * 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"};
492493 * in most cases, implementations should interpret these inputs has equivalent to a {@code null}
493494 * 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).
494499 *
495500 * @param value The CQL string to parse, may be {@code null} or empty.
496501 * @return An instance of T; may be {@code null} on a {@code null input}.
@@ -501,10 +506,25 @@
501506 /**
502507 * Format the given value as a valid CQL literal according
503508 * to the CQL type handled by this codec.
509+ * <p/>
504510 * Implementors should take care of quoting and escaping the resulting CQL literal
505511 * where applicable.
506512 * Null values should be accepted; in most cases, implementations should
507513 * 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").
508528 *
509529 * @param value An instance of T; may be {@code null}.
510530 * @return CQL string
modified manual/custom_codecs/README.md +1 −1
@@ -140,7 +140,7 @@
140140
141141 ```java
142142 ObjectMapper objectMapper = ...
143-JsonCodec<MyPojo> myJsonCodec = new JsonCodec<MyPojo>(MyPojo.class, objectMapper);
143+JsonCodec<MyPojo> myJsonCodec = new JsonCodec<MyPojo>(MyPojo.class);
144144 CodecRegistry myCodecRegistry = cluster.getConfiguration().getCodecRegistry();
145145 myCodecRegistry.register(myJsonCodec);
146146 ```