kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 2ce86b39619b9ca8fca9ac661b1b5efde8be1646379748075e32887e128e46c5 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-10-15 20:09 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-10-18 20:14 +02:00 |
| Parents | 7c8de89c8f6b |
5 files changed
modified driver-core/src/main/java/com/datastax/driver/core/CodecRegistry.java +119 −126
| @@ -39,110 +39,113 @@ | ||
| 39 | 39 | import static com.datastax.driver.core.DataType.Name.SET; |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | - * A registry for {@link TypeCodec codec}s. When the driver | |
| 43 | - * needs to serialize or deserialize an object, | |
| 44 | - * it will lookup in the registry for | |
| 45 | - * a suitable codec. | |
| 42 | + * A registry for {@link TypeCodec}s. When the driver needs to serialize or deserialize a Java type to/from CQL, | |
| 43 | + * it will lookup in the registry for a suitable codec. The registry is initialized with default codecs that handle | |
| 44 | + * basic conversions (e.g. CQL {@code text} to {@code java.lang.String}), and users can add their own. Complex | |
| 45 | + * codecs can also be generated on-the-fly from simpler ones (more details below). | |
| 46 | 46 | * |
| 47 | - * <h3>Usage</h3> | |
| 47 | + * <h3>Creating a registry</h3> | |
| 48 | 48 | * |
| 49 | 49 | * <p> |
| 50 | - * By default, the driver uses the CodecRegistry's {@link CodecRegistry#DEFAULT_INSTANCE}, | |
| 51 | - * a shareable instance that initially contains all the built-in codecs required by the driver. | |
| 52 | - * | |
| 53 | - * <p> | |
| 54 | - * For most users, the default instance is good enough and | |
| 55 | - * they won't need to manipulate {@link CodecRegistry} instances directly. | |
| 56 | - * Only those willing to {@link #register(TypeCodec) register} user-defined codecs are required to do so: | |
| 50 | + * By default, the driver uses {@link CodecRegistry#DEFAULT_INSTANCE}, a shareable, JVM-wide instance initialized with | |
| 51 | + * built-in codecs for all the base CQL types. | |
| 52 | + * The only reason to create your own instances is if you have multiple {@code Cluster} objects that use different | |
| 53 | + * sets of codecs. In that case, use {@link com.datastax.driver.core.Cluster.Builder#withCodecRegistry(CodecRegistry)} | |
| 54 | + * to associate the registry with the cluster: | |
| 57 | 55 | * |
| 58 | 56 | * <pre> |
| 59 | - * CodecRegistry myCodecRegistry; | |
| 60 | - * // use the default instance | |
| 61 | - * myCodecRegistry = CodecRegistry.DEFAULT_INSTANCE; | |
| 62 | - * // or alternatively, create a new one | |
| 63 | - * myCodecRegistry = new CodecRegistry(); | |
| 64 | - * // then register additional codecs | |
| 57 | + * {@code | |
| 58 | + * CodecRegistry myCodecRegistry = new CodecRegistry(); | |
| 65 | 59 | * myCodecRegistry.register(myCodec1, myCodec2, myCodec3); |
| 66 | - * </pre> | |
| 67 | - * | |
| 68 | - * <p> | |
| 69 | - * To be used by the driver, {@link CodecRegistry} instances must then | |
| 70 | - * be associated with a {@link Cluster} instance: | |
| 71 | - * | |
| 72 | - * <pre> | |
| 73 | - * CodecRegistry myCodecRegistry = ... | |
| 74 | 60 | * Cluster cluster = Cluster.builder().withCodecRegistry(myCodecRegistry).build(); |
| 75 | - * </pre> | |
| 76 | 61 | * |
| 77 | - * To retrieve the {@link CodecRegistry} instance associated with a Cluster, do the | |
| 78 | - * following: | |
| 79 | - * | |
| 80 | - * <pre> | |
| 62 | + * // To retrieve the registry later: | |
| 81 | 63 | * CodecRegistry registry = cluster.getConfiguration().getCodecRegistry(); |
| 82 | - * </pre> | |
| 83 | - * | |
| 84 | - * <h3>Example</h3> | |
| 85 | - * | |
| 86 | - * <p> | |
| 87 | - * Suppose that one wants to have all CQL timestamps seamlessly | |
| 88 | - * converted to {@code java.time.DateTime} instances and vice versa; the following | |
| 89 | - * code contains the necessary steps to achieve this: | |
| 90 | - * | |
| 91 | - * <pre> | |
| 92 | - * // 1. Instantiate the custom codec | |
| 93 | - * TypeCodec<DateTime> timestampCodec = ... | |
| 94 | - * // 2. Register the codec | |
| 95 | - * CodecRegistry.DEFAULT_INSTANCE.register(timestampCodec); | |
| 96 | - * </pre> | |
| 64 | + * }</pre> | |
| 97 | 65 | * |
| 98 | - * <p> | |
| 99 | - * Read the | |
| 100 | - * <a href="http://datastax.github.io/java-driver/features/custom_codecs">online documentation</a> | |
| 101 | - * for more examples. | |
| 102 | - * | |
| 103 | - * <h3>Notes</h3> | |
| 66 | + * {@code CodecRegistry} instances are thread-safe. | |
| 104 | 67 | * |
| 105 | 68 | * <p> |
| 106 | - * <strong>Registration order</strong>: the order in which codecs are registered matters: | |
| 107 | - * when looking for a suitable codec, the registry will consider | |
| 108 | - * all registered codecs <em>in the order they were registered</em>, and | |
| 109 | - * will pick the first matching one. | |
| 69 | + * It is possible to turn on log messages by setting the {@code com.datastax.driver.core.CodecRegistry} logger | |
| 70 | + * level to {@code TRACE}. Beware that the registry can be very verbose at this log level. | |
| 110 | 71 | * |
| 111 | - * <p> | |
| 112 | - * If a codec is registered while another codec already handles the <em>exact same</em> | |
| 113 | - * CQL-to-Java mapping, that codec will never be used (unless | |
| 114 | - * the user forces its usage through e.g. {@link GettableByIndexData#get(int, TypeCodec)}). | |
| 115 | - * In order words, it is not possible to replace an existing codec, | |
| 116 | - * specially the built-in ones; it is only possible to enrich the initial | |
| 117 | - * set of codecs with new ones. | |
| 72 | + * <h3>Registering and using custom codecs</h3> | |
| 118 | 73 | * |
| 119 | - * <p> | |
| 120 | - * <strong>On-the-fly codec instantiation</strong>: When a {@link CodecRegistry} | |
| 121 | - * cannot find a suitable codec among all registered codecs, | |
| 122 | - * it will attempt to create such a codec on-the-fly. If the creation succeeds, that codec is returned; | |
| 123 | - * otherwise, a {@link CodecNotFoundException} is thrown. | |
| 74 | + * To create a custom codec, write a class that extends {@link TypeCodec}, create an instance, and pass it to one of | |
| 75 | + * the {@link #register(TypeCodec) register} methods: | |
| 124 | 76 | * |
| 125 | - * <p> | |
| 126 | - * Note that {@link CodecRegistry} instances can only create codecs in very limited situations: | |
| 77 | + * <pre> | |
| 78 | + * {@code | |
| 79 | + * // A codec that maps timestamps to JDK8's LocalDate | |
| 80 | + * class LocalDateCodec extends TypeCodec<LocalDate> { | |
| 81 | + * ... | |
| 82 | + * } | |
| 83 | + * myCodecRegistry.register(new LocalDateCodec()); | |
| 84 | + * }</pre> | |
| 85 | + * | |
| 86 | + * The conversion will be available to: | |
| 87 | + * <ul> | |
| 88 | + * <li>all driver types that implement {@link GettableByIndexData}, {@link GettableByNameData}, | |
| 89 | + * {@link SettableByIndexData} and/or {@link SettableByNameData}. Namely: {@link Row}, | |
| 90 | + * {@link BoundStatement}, {@link UDTValue} and {@link TupleValue};</li> | |
| 91 | + * <li>{@link Session#newSimpleStatement(String, Object...) simple statements}.</li> | |
| 92 | + * </ul> | |
| 93 | + * | |
| 94 | + * Example: | |
| 95 | + * <pre> | |
| 96 | + * {@code | |
| 97 | + * Row row = session.executeQuery("select date from some_table where pk = 1").one(); | |
| 98 | + * LocalDate date = row.get(0, LocalDate.class); // uses LocalDateCodec registered above | |
| 99 | + * }</pre> | |
| 100 | + * | |
| 101 | + * You can also bypass the codec registry by passing a standalone codec instance to methods such as | |
| 102 | + * {@link GettableByIndexData#get(int, TypeCodec)}. | |
| 103 | + * | |
| 104 | + * <h3>Codec generation</h3> | |
| 105 | + * | |
| 106 | + * When a {@code CodecRegistry} cannot find a suitable codec among existing ones, it will attempt to create it on-the-fly: | |
| 107 | + * It can manage: | |
| 108 | + * | |
| 109 | + * <ul> | |
| 110 | + * <li>collections of known types. For example, if you registered a {@code TypeCodec<LocalDate>}, you get | |
| 111 | + * {@code List<LocalDate>>} handled for free. This works recursively for nested collections;</li> | |
| 112 | + * <li>{@link UserType user types}, mapped to {@link UDTValue} objects. Custom codecs are available recursively | |
| 113 | + * to the UDT's fields, so if one of your fields is a {@code timestamp} you can use your {@code LocaDateCodec} to retrieve | |
| 114 | + * it as a {@code LocalDate};</li> | |
| 115 | + * <li>{@link TupleType tuple types}, mapped to {@link TupleValue} (with the same rules for nested fields);</li> | |
| 116 | + * <li>{@link com.datastax.driver.core.DataType.CustomType custom types}, mapped to {@code ByteBuffer}.</li> | |
| 117 | + * </ul> | |
| 118 | + * | |
| 119 | + * If the codec registry encounters a mapping that it can't handle automatically, a {@link CodecNotFoundException} is thrown; | |
| 120 | + * you'll need to register a custom codec for it. | |
| 121 | + * | |
| 122 | + * <h3>Performance and caching</h3> | |
| 123 | + * | |
| 124 | + * Whenever possible, the registry will cache the result of a codec lookup for a specific type mapping, including any generated | |
| 125 | + * codec. For example, if you registered {@code LocalDateCodec} and ask the registry for a codec to convert a CQL | |
| 126 | + * {@code list<timestamp>} to a Java {@code List<LocalDate>}: | |
| 127 | 127 | * <ol> |
| 128 | - * <li>Codecs for {@link UserType user types} are created on the fly using {@link TypeCodec#userType(UserType)};</li> | |
| 129 | - * <li>Codecs for {@link TupleType tuple types} are created on the fly using {@link TypeCodec#tuple(TupleType)}};</li> | |
| 130 | - * <li>Codecs for collections are created on the fly using {@link TypeCodec#list(TypeCodec)}}, {@link TypeCodec#set(TypeCodec)}} and | |
| 131 | - * {@link TypeCodec#map(TypeCodec, TypeCodec)}}, if their element types can be handled by existing codecs (or codecs that can | |
| 132 | - * themselves be generated).</li> | |
| 133 | - * <li>Codecs for {@link com.datastax.driver.core.DataType.CustomType custom types} are created on the fly using {@link TypeCodec#custom(DataType.CustomType)};</li> | |
| 128 | + * <li>the first lookup will generate a {@code TypeCodec<List<LocalDate>>} from {@code LocalDateCodec}, and put it in | |
| 129 | + * the cache;</li> | |
| 130 | + * <li>the second lookup will hit the cache directly, and reuse the previously generated instance.</li> | |
| 134 | 131 | * </ol> |
| 135 | - * Other combinations of Java and CQL types cannot have their codecs created on the fly; | |
| 136 | - * such codecs must be manually registered. | |
| 137 | - * <p> | |
| 138 | 132 | * |
| 139 | - * <strong>Debugging the codec registry</strong>: it is possible to turn on log messages | |
| 140 | - * by setting the {@code com.datastax.driver.core.CodecRegistry} logger level to {@code TRACE}. | |
| 141 | - * Beware that the registry can be very verbose at this log level. | |
| 133 | + * The javadoc for each {@link #codecFor(DataType) codecFor} variant specifies whether the result can be cached or not. | |
| 142 | 134 | * |
| 143 | - * <p> | |
| 144 | - * <strong>Thread-safety</strong>: {@link CodecRegistry} instances are thread-safe. | |
| 135 | + * <h3>Codec order</h3> | |
| 136 | + * | |
| 137 | + * When the registry looks up a codec, the rules of precedence are: | |
| 145 | 138 | * |
| 139 | + * <ul> | |
| 140 | + * <li>if a result was previously cached for that mapping, it is returned;</li> | |
| 141 | + * <li>otherwise, the registry checks the list of "basic" codecs: the default ones, and the ones that were explicitly | |
| 142 | + * registered (in the order that they were registered). It calls each codec's {@code accepts} methods to determine if | |
| 143 | + * it can handle the mapping, and if so returns it;</li> | |
| 144 | + * <li>otherwise, the registry tries to generate a codec, according to the rules outlined above.</li> | |
| 145 | + * </ul> | |
| 146 | + * | |
| 147 | + * It is currently impossible to override an existing codec. If you try to do so, {@link #register(TypeCodec)} will log a | |
| 148 | + * warning and ignore it. | |
| 146 | 149 | */ |
| 147 | 150 | public final class CodecRegistry { |
| 148 | 151 | |
| @@ -172,10 +175,9 @@ | ||
| 172 | 175 | ); |
| 173 | 176 | |
| 174 | 177 | /** |
| 175 | - * A default instance of CodecRegistry. | |
| 176 | - * For most applications, sharing a single instance of CodecRegistry is fine. | |
| 177 | - * But note that any codec registered with this instance will immediately | |
| 178 | - * be available for all its clients. | |
| 178 | + * The default {@code CodecRegistry} instance. | |
| 179 | + * | |
| 180 | + * It will be shared among all {@link Cluster} instances that were not explicitly built with a different instance. | |
| 179 | 181 | */ |
| 180 | 182 | public static final CodecRegistry DEFAULT_INSTANCE = new CodecRegistry(); |
| 181 | 183 | |
| @@ -298,7 +300,7 @@ | ||
| 298 | 300 | private final LoadingCache<CacheKey, TypeCodec<?>> cache; |
| 299 | 301 | |
| 300 | 302 | /** |
| 301 | - * Creates a default CodecRegistry instance with default cache options. | |
| 303 | + * Creates a new instance initialized with built-in codecs for all the base CQL types. | |
| 302 | 304 | */ |
| 303 | 305 | public CodecRegistry() { |
| 304 | 306 | this.codecs = new CopyOnWriteArrayList<TypeCodec<?>>(PRIMITIVE_CODECS); |
| @@ -323,8 +325,8 @@ | ||
| 323 | 325 | * <p> |
| 324 | 326 | * This method will log a warning and ignore the codec if it collides with a previously registered one. |
| 325 | 327 | * Note that this check is not done in a completely thread-safe manner; codecs should typically be registered |
| 326 | - * at application startup, not in a highly concurrent context (if a race condition occurs, the worst outcome | |
| 327 | - * is that no warning gets logged, and the codec gets registered but will never actually be used). | |
| 328 | + * at application startup, not in a highly concurrent context (if a race condition occurs, the worst possible | |
| 329 | + * outcome is that no warning gets logged, and the codec gets registered but will never actually be used). | |
| 328 | 330 | * |
| 329 | 331 | * @param newCodec The codec to add to the registry. |
| 330 | 332 | * @return this CodecRegistry (for method chaining). |
| @@ -379,22 +381,20 @@ | ||
| 379 | 381 | /** |
| 380 | 382 | * Returns a {@link TypeCodec codec} that accepts the given value. |
| 381 | 383 | * <p> |
| 382 | - * This method takes an actual Java object and tries to locate a suitable codec for it. | |
| 383 | - * For this reason, codecs must perform a {@link TypeCodec#accepts(Object) "manual" inspection} | |
| 384 | - * of the object to determine if they can accept it or not, which, depending on the implementations, | |
| 385 | - * can be an expensive operation; besides, the resulting codec cannot be cached. | |
| 384 | + * This method takes an arbitrary Java object and tries to locate a suitable codec for it. | |
| 385 | + * Codecs must perform a {@link TypeCodec#accepts(Object) runtime inspection} of the object to determine | |
| 386 | + * if they can accept it or not, which, depending on the implementations, can be expensive; besides, the | |
| 387 | + * resulting codec cannot be cached. | |
| 386 | 388 | * Therefore there might be a performance penalty when using this method. |
| 387 | 389 | * <p> |
| 388 | - * Furthermore, this method would return the first matching codec, regardless of its accepted {@link DataType CQL type}. | |
| 389 | - * For this reason, this method might not return the most accurate codec and should be | |
| 390 | - * reserved for situations where the target CQL type is not available or unknown. | |
| 391 | - * In the Java driver, this happens mainly when serializing a value in a {@link SimpleStatement} | |
| 392 | - * or in the {@link com.datastax.driver.core.querybuilder.QueryBuilder}, where no CQL type information | |
| 393 | - * is available. | |
| 394 | - * <p> | |
| 395 | - * Regular application code should avoid using this method. | |
| 390 | + * Furthermore, this method returns the first matching codec, regardless of its accepted CQL type. | |
| 391 | + * It should be reserved for situations where the target CQL type is not available or unknown. | |
| 392 | + * In the Java driver, this happens mainly when serializing a value in a | |
| 393 | + * {@link Session#newSimpleStatement(String, Object...) SimpleStatement} or in the | |
| 394 | + * {@link com.datastax.driver.core.querybuilder.QueryBuilder}, where no CQL type information is available. | |
| 396 | 395 | * <p> |
| 397 | - * Codecs returned by this method are <em>NOT</em> cached. | |
| 396 | + * Codecs returned by this method are <em>NOT</em> cached (see the {@link CodecRegistry top-level documentation} | |
| 397 | + * of this class for more explanations about caching). | |
| 398 | 398 | * |
| 399 | 399 | * @param value The value the codec should accept; must not be {@code null}. |
| 400 | 400 | * @return A suitable codec. |
| @@ -407,13 +407,13 @@ | ||
| 407 | 407 | /** |
| 408 | 408 | * Returns a {@link TypeCodec codec} that accepts the given {@link DataType CQL type}. |
| 409 | 409 | * <p> |
| 410 | - * This method would return the first matching codec, regardless of its accepted Java type. | |
| 411 | - * For this reason, this method might not return the most accurate codec and should be | |
| 412 | - * reserved for situations where the runtime type is not available or unknown. | |
| 410 | + * This method returns the first matching codec, regardless of its accepted Java type. | |
| 411 | + * It should be reserved for situations where the Java type is not available or unknown. | |
| 413 | 412 | * In the Java driver, this happens mainly when deserializing a value using the |
| 414 | - * {@link AbstractGettableData#getObject(int)} method. | |
| 413 | + * {@link GettableByIndexData#getObject(int) getObject} method. | |
| 415 | 414 | * <p> |
| 416 | - * Codecs returned by this method are cached. | |
| 415 | + * Codecs returned by this method are cached (see the {@link CodecRegistry top-level documentation} | |
| 416 | + * of this class for more explanations about caching). | |
| 417 | 417 | * |
| 418 | 418 | * @param cqlType The {@link DataType CQL type} the codec should accept; must not be {@code null}. |
| 419 | 419 | * @return A suitable codec. |
| @@ -430,12 +430,8 @@ | ||
| 430 | 430 | * This method can only handle raw (non-parameterized) Java types. |
| 431 | 431 | * For parameterized types, use {@link #codecFor(DataType, TypeToken)} instead. |
| 432 | 432 | * <p> |
| 433 | - * Note that type inheritance needs special care. | |
| 434 | - * If a codec accepts a Java type that is assignable to the | |
| 435 | - * given Java type, that codec may be returned if it is found first | |
| 436 | - * in the registry, <em>even if another codec is a better match</em>. | |
| 437 | - * <p> | |
| 438 | - * Codecs returned by this method are cached. | |
| 433 | + * Codecs returned by this method are cached (see the {@link CodecRegistry top-level documentation} | |
| 434 | + * of this class for more explanations about caching). | |
| 439 | 435 | * |
| 440 | 436 | * @param cqlType The {@link DataType CQL type} the codec should accept; must not be {@code null}. |
| 441 | 437 | * @param javaType The Java type the codec should accept; can be {@code null}. |
| @@ -452,12 +448,8 @@ | ||
| 452 | 448 | * <p> |
| 453 | 449 | * This method handles parameterized types thanks to Guava's {@link TypeToken} API. |
| 454 | 450 | * <p> |
| 455 | - * Note that type inheritance needs special care. | |
| 456 | - * If a codec accepts a Java type that is assignable to the | |
| 457 | - * given Java type, that codec may be returned if it is found first | |
| 458 | - * in the registry, <em>even if another codec is a better match</em>. | |
| 459 | - * <p> | |
| 460 | - * Codecs returned by this method are cached. | |
| 451 | + * Codecs returned by this method are cached (see the {@link CodecRegistry top-level documentation} | |
| 452 | + * of this class for more explanations about caching). | |
| 461 | 453 | * |
| 462 | 454 | * @param cqlType The {@link DataType CQL type} the codec should accept; must not be {@code null}. |
| 463 | 455 | * @param javaType The {@link TypeToken Java type} the codec should accept; can be {@code null}. |
| @@ -472,13 +464,14 @@ | ||
| 472 | 464 | * Returns a {@link TypeCodec codec} that accepts the given {@link DataType CQL type} |
| 473 | 465 | * and the given value. |
| 474 | 466 | * <p> |
| 475 | - * This method takes an actual Java object and tries to locate a suitable codec for it. | |
| 476 | - * For this reason, codecs must perform a {@link TypeCodec#accepts(Object) "manual" inspection} | |
| 477 | - * of the object to determine if they can accept it or not, which, depending on the implementations, | |
| 478 | - * can be an expensive operation; besides, the resulting codec cannot be cached. | |
| 467 | + * This method takes an arbitrary Java object and tries to locate a suitable codec for it. | |
| 468 | + * Codecs must perform a {@link TypeCodec#accepts(Object) runtime inspection} of the object to determine | |
| 469 | + * if they can accept it or not, which, depending on the implementations, can be expensive; besides, the | |
| 470 | + * resulting codec cannot be cached. | |
| 479 | 471 | * Therefore there might be a performance penalty when using this method. |
| 480 | 472 | * <p> |
| 481 | - * Codecs returned by this method are <em>NOT</em> cached. | |
| 473 | + * Codecs returned by this method are <em>NOT</em> cached (see the {@link CodecRegistry top-level documentation} | |
| 474 | + * of this class for more explanations about caching). | |
| 482 | 475 | * |
| 483 | 476 | * @param cqlType The {@link DataType CQL type} the codec should accept; can be {@code null}. |
| 484 | 477 | * @param value The value the codec should accept; must not be {@code null}. |
modified driver-core/src/main/java/com/datastax/driver/core/GettableByIndexData.java +153 −50
| @@ -23,10 +23,12 @@ | ||
| 23 | 23 | |
| 24 | 24 | import com.google.common.reflect.TypeToken; |
| 25 | 25 | |
| 26 | +import com.datastax.driver.core.exceptions.CodecNotFoundException; | |
| 27 | + | |
| 26 | 28 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 27 | 29 | |
| 28 | 30 | /** |
| 29 | - * Collection of (typed) CQL values that can be retrieved by index (starting a 0). | |
| 31 | + * Collection of (typed) CQL values that can be retrieved by index (starting at 0). | |
| 30 | 32 | */ |
| 31 | 33 | public interface GettableByIndexData { |
| 32 | 34 | |
| @@ -43,121 +45,169 @@ | ||
| 43 | 45 | |
| 44 | 46 | /** |
| 45 | 47 | * Returns the {@code i}th value as a boolean. |
| 48 | + * <p> | |
| 49 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code boolean} | |
| 50 | + * (for CQL type {@code boolean}, this will be the built-in codec). | |
| 46 | 51 | * |
| 47 | 52 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 48 | - * @return the boolean value of the {@code i}th element. If the | |
| 49 | - * value is NULL, {@code false} is returned. | |
| 53 | + * @return the boolean value of the {@code i}th element. If the value is NULL, {@code false} is returned. | |
| 54 | + * If you need to distinguish NULL and false values, check first with {@link #isNull(int)} or use {@code get(i, Boolean.class)}. | |
| 50 | 55 | * |
| 51 | 56 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 57 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 58 | + * type to a boolean. | |
| 52 | 59 | */ |
| 53 | 60 | public boolean getBool(int i); |
| 54 | 61 | |
| 55 | 62 | /** |
| 56 | 63 | * Returns the {@code i}th value as a byte. |
| 64 | + * <p> | |
| 65 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code byte} | |
| 66 | + * (for CQL type {@code tinyint}, this will be the built-in codec). | |
| 57 | 67 | * |
| 58 | 68 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 59 | - * @return the value of the {@code i}th element as a byte. If the | |
| 60 | - * value is NULL, {@code 0} is returned. | |
| 69 | + * @return the value of the {@code i}th element as a byte. If the value is NULL, {@code 0} is returned. | |
| 70 | + * If you need to distinguish NULL and 0, check first with {@link #isNull(int)} or use {@code get(i, Byte.class)}. | |
| 61 | 71 | * |
| 62 | 72 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 73 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 74 | + * type to a byte. | |
| 63 | 75 | */ |
| 64 | 76 | public byte getByte(int i); |
| 65 | 77 | |
| 66 | 78 | /** |
| 67 | 79 | * Returns the {@code i}th value as a short. |
| 80 | + * <p> | |
| 81 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code short} | |
| 82 | + * (for CQL type {@code smallint}, this will be the built-in codec). | |
| 68 | 83 | * |
| 69 | 84 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 70 | - * @return the value of the {@code i}th element as a short. If the | |
| 71 | - * value is NULL, {@code 0} is returned. | |
| 85 | + * @return the value of the {@code i}th element as a short. If the value is NULL, {@code 0} is returned. | |
| 86 | + * If you need to distinguish NULL and 0, check first with {@link #isNull(int)} or use {@code get(i, Short.class)}. | |
| 72 | 87 | * |
| 73 | 88 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 89 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 90 | + * type to a short. | |
| 74 | 91 | */ |
| 75 | 92 | public short getShort(int i); |
| 76 | 93 | |
| 77 | 94 | /** |
| 78 | 95 | * Returns the {@code i}th value as an integer. |
| 96 | + * <p> | |
| 97 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code int} | |
| 98 | + * (for CQL type {@code int}, this will be the built-in codec). | |
| 79 | 99 | * |
| 80 | 100 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 81 | - * @return the value of the {@code i}th element as an integer. If the | |
| 82 | - * value is NULL, {@code 0} is returned. | |
| 101 | + * @return the value of the {@code i}th element as an integer. If the value is NULL, {@code 0} is returned. | |
| 102 | + * If you need to distinguish NULL and 0, check first with {@link #isNull(int)} or use {@code get(i, Integer.class)}. | |
| 83 | 103 | * |
| 84 | 104 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 105 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 106 | + * type to an int. | |
| 85 | 107 | */ |
| 86 | 108 | public int getInt(int i); |
| 87 | 109 | |
| 88 | 110 | /** |
| 89 | 111 | * Returns the {@code i}th value as a long. |
| 112 | + * <p> | |
| 113 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code byte} | |
| 114 | + * (for CQL types {@code bigint} and {@code counter}, this will be the built-in codec). | |
| 90 | 115 | * |
| 91 | 116 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 92 | - * @return the value of the {@code i}th element as a long. If the | |
| 93 | - * value is NULL, {@code 0L} is returned. | |
| 117 | + * @return the value of the {@code i}th element as a long. If the value is NULL, {@code 0L} is returned. | |
| 118 | + * If you need to distinguish NULL and 0L, check first with {@link #isNull(int)} or use {@code get(i, Long.class)}. | |
| 94 | 119 | * |
| 95 | 120 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 121 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 122 | + * type to a long. | |
| 96 | 123 | */ |
| 97 | 124 | public long getLong(int i); |
| 98 | 125 | |
| 99 | 126 | /** |
| 100 | 127 | * Returns the {@code i}th value as a date. |
| 128 | + * <p> | |
| 129 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a {@code Date} | |
| 130 | + * (for CQL type {@code timestamp}, this will be the built-in codec). | |
| 101 | 131 | * |
| 102 | 132 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 103 | 133 | * @return the value of the {@code i}th element as a data. If the |
| 104 | 134 | * value is NULL, {@code null} is returned. |
| 105 | 135 | * |
| 106 | 136 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 137 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 138 | + * type to a {@code Date}. | |
| 107 | 139 | */ |
| 108 | 140 | public Date getTimestamp(int i); |
| 109 | 141 | |
| 110 | 142 | /** |
| 111 | 143 | * Returns the {@code i}th value as a date (without time). |
| 144 | + * <p> | |
| 145 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a {@link LocalDate} | |
| 146 | + * (for CQL type {@code date}, this will be the built-in codec). | |
| 112 | 147 | * |
| 113 | 148 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 114 | 149 | * @return the value of the {@code i}th element as an date. If the |
| 115 | 150 | * value is NULL, {@code null} is returned. |
| 116 | 151 | * |
| 117 | 152 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 153 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 154 | + * type to a {@code LocalDate}. | |
| 118 | 155 | */ |
| 119 | 156 | public LocalDate getDate(int i); |
| 120 | 157 | |
| 121 | 158 | /** |
| 122 | 159 | * Returns the {@code i}th value as a long in nanoseconds since midnight. |
| 160 | + * <p> | |
| 161 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code long} | |
| 162 | + * (for CQL type {@code time}, this will be the built-in codec). | |
| 123 | 163 | * |
| 124 | 164 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 125 | 165 | * @return the value of the {@code i}th element as a long. If the |
| 126 | 166 | * value is NULL, {@code 0L} is returned. |
| 127 | 167 | * |
| 128 | 168 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 169 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 170 | + * type to a long. | |
| 129 | 171 | */ |
| 130 | 172 | public long getTime(int i); |
| 131 | 173 | |
| 132 | 174 | /** |
| 133 | 175 | * Returns the {@code i}th value as a float. |
| 176 | + * <p> | |
| 177 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code float} | |
| 178 | + * (for CQL type {@code float}, this will be the built-in codec). | |
| 134 | 179 | * |
| 135 | 180 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 136 | - * @return the value of the {@code i}th element as a float. If the | |
| 137 | - * value is NULL, {@code 0.0f} is returned. | |
| 181 | + * @return the value of the {@code i}th element as a float. If the value is NULL, {@code 0.0f} is returned. | |
| 182 | + * If you need to distinguish NULL and 0.0f, check first with {@link #isNull(int)} or use {@code get(i, Float.class)}. | |
| 138 | 183 | * |
| 139 | 184 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 185 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 186 | + * type to a float. | |
| 140 | 187 | */ |
| 141 | 188 | public float getFloat(int i); |
| 142 | 189 | |
| 143 | 190 | /** |
| 144 | 191 | * Returns the {@code i}th value as a double. |
| 192 | + * <p> | |
| 193 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code double} | |
| 194 | + * (for CQL type {@code double}, this will be the built-in codec). | |
| 145 | 195 | * |
| 146 | 196 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 147 | - * @return the value of the {@code i}th element as a double. If the | |
| 148 | - * value is NULL, {@code 0.0} is returned. | |
| 197 | + * @return the value of the {@code i}th element as a double. If the value is NULL, {@code 0.0} is returned. | |
| 198 | + * If you need to distinguish NULL and 0.0, check first with {@link #isNull(int)} or use {@code get(i, Double.class)}. | |
| 149 | 199 | * |
| 150 | 200 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 201 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 202 | + * type to a double. | |
| 151 | 203 | */ |
| 152 | 204 | public double getDouble(int i); |
| 153 | 205 | |
| 154 | 206 | /** |
| 155 | - * Returns the {@code i}th value as a ByteBuffer. | |
| 156 | - * | |
| 157 | - * Note: this method always return the bytes composing the value, even if | |
| 158 | - * the column is not of type BLOB. That is, this method never throw an | |
| 159 | - * InvalidTypeException. However, if the type is not BLOB, it is up to the | |
| 160 | - * caller to handle the returned value correctly. | |
| 207 | + * Returns the {@code i}th value as a {@code ByteBuffer}. | |
| 208 | + * <p> | |
| 209 | + * This method does not use any codec; it returns a copy of the binary representation of the value. It is up to the | |
| 210 | + * caller to convert the returned value appropriately. | |
| 161 | 211 | * |
| 162 | 212 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 163 | 213 | * @return the value of the {@code i}th element as a ByteBuffer. If the |
| @@ -170,75 +220,104 @@ | ||
| 170 | 220 | /** |
| 171 | 221 | * Returns the {@code i}th value as a byte array. |
| 172 | 222 | * <p> |
| 173 | - * Note that this method validate that the column is of type BLOB. If you want to retrieve | |
| 174 | - * the bytes for any type, use {@link #getBytesUnsafe(int)} instead. | |
| 223 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code ByteBuffer} | |
| 224 | + * (for CQL type {@code blob}, this will be the built-in codec). | |
| 175 | 225 | * |
| 176 | 226 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 177 | 227 | * @return the value of the {@code i}th element as a byte array. If the |
| 178 | 228 | * value is NULL, {@code null} is returned. |
| 179 | 229 | * |
| 180 | 230 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 231 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 232 | + * type to a {@code ByteBuffer}. | |
| 181 | 233 | */ |
| 182 | 234 | public ByteBuffer getBytes(int i); |
| 183 | 235 | |
| 184 | 236 | /** |
| 185 | 237 | * Returns the {@code i}th value as a string. |
| 238 | + * <p> | |
| 239 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java string | |
| 240 | + * (for CQL types {@code text}, {@code varchar} and {@code ascii}, this will be the built-in codec). | |
| 186 | 241 | * |
| 187 | 242 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 188 | 243 | * @return the value of the {@code i}th element as a string. If the |
| 189 | 244 | * value is NULL, {@code null} is returned. |
| 190 | 245 | * |
| 191 | 246 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 247 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 248 | + * type to a string. | |
| 192 | 249 | */ |
| 193 | 250 | public String getString(int i); |
| 194 | 251 | |
| 195 | 252 | /** |
| 196 | 253 | * Returns the {@code i}th value as a variable length integer. |
| 254 | + * <p> | |
| 255 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a {@code BigInteger} | |
| 256 | + * (for CQL type {@code varint}, this will be the built-in codec). | |
| 197 | 257 | * |
| 198 | 258 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 199 | 259 | * @return the value of the {@code i}th element as a variable |
| 200 | 260 | * length integer. If the value is NULL, {@code null} is returned. |
| 201 | 261 | * |
| 202 | 262 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 263 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 264 | + * type to a {@code BigInteger}. | |
| 203 | 265 | */ |
| 204 | 266 | public BigInteger getVarint(int i); |
| 205 | 267 | |
| 206 | 268 | /** |
| 207 | 269 | * Returns the {@code i}th value as a variable length decimal. |
| 270 | + * <p> | |
| 271 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a {@code BigDecimal} | |
| 272 | + * (for CQL type {@code decimal}, this will be the built-in codec). | |
| 208 | 273 | * |
| 209 | 274 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 210 | 275 | * @return the value of the {@code i}th element as a variable |
| 211 | 276 | * length decimal. If the value is NULL, {@code null} is returned. |
| 212 | 277 | * |
| 213 | 278 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 279 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 280 | + * type to a {@code BigDecimal}. | |
| 214 | 281 | */ |
| 215 | 282 | public BigDecimal getDecimal(int i); |
| 216 | 283 | |
| 217 | 284 | /** |
| 218 | 285 | * Returns the {@code i}th value as a UUID. |
| 286 | + * <p> | |
| 287 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a {@code UUID} | |
| 288 | + * (for CQL types {@code uuid} and {@code timeuuid}, this will be the built-in codec). | |
| 219 | 289 | * |
| 220 | 290 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 221 | 291 | * @return the value of the {@code i}th element as a UUID. |
| 222 | 292 | * If the value is NULL, {@code null} is returned. |
| 223 | 293 | * |
| 224 | 294 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 295 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 296 | + * type to a {@code UUID}. | |
| 225 | 297 | */ |
| 226 | 298 | public UUID getUUID(int i); |
| 227 | 299 | |
| 228 | 300 | /** |
| 229 | 301 | * Returns the {@code i}th value as an InetAddress. |
| 302 | + * <p> | |
| 303 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to an {@code InetAddress} | |
| 304 | + * (for CQL type {@code inet}, this will be the built-in codec). | |
| 230 | 305 | * |
| 231 | 306 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 232 | 307 | * @return the value of the {@code i}th element as an InetAddress. |
| 233 | 308 | * If the value is NULL, {@code null} is returned. |
| 234 | 309 | * |
| 235 | 310 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 311 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 312 | + * type to a {@code InetAddress}. | |
| 236 | 313 | */ |
| 237 | 314 | public InetAddress getInet(int i); |
| 238 | 315 | |
| 239 | 316 | /** |
| 240 | 317 | * Returns the {@code i}th value as a list. |
| 241 | 318 | * <p> |
| 319 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a list of the specified type. | |
| 320 | + * <p> | |
| 242 | 321 | * If the type of the elements is generic, use {@link #getList(int, TypeToken)}. |
| 243 | 322 | * <p> |
| 244 | 323 | * Implementation note: the actual {@link List} implementation will depend |
| @@ -246,7 +325,7 @@ | ||
| 246 | 325 | * make no assumptions concerning its mutability nor its thread-safety. |
| 247 | 326 | * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also |
| 248 | 327 | * codec-dependent. By default, the driver will return mutable instances, and |
| 249 | - * a CQL {@code NULL} will mapped to an empty collection (note that Cassandra | |
| 328 | + * a CQL {@code NULL} will be mapped to an empty collection (note that Cassandra | |
| 250 | 329 | * makes no distinction between {@code NULL} and an empty collection). |
| 251 | 330 | * |
| 252 | 331 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| @@ -255,12 +334,16 @@ | ||
| 255 | 334 | * {@code T} objects. |
| 256 | 335 | * |
| 257 | 336 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 337 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 338 | + * type to a list. | |
| 258 | 339 | */ |
| 259 | 340 | public <T> List<T> getList(int i, Class<T> elementsClass); |
| 260 | 341 | |
| 261 | 342 | /** |
| 262 | 343 | * Returns the {@code i}th value as a list. |
| 263 | 344 | * <p> |
| 345 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a list of the specified type. | |
| 346 | + * <p> | |
| 264 | 347 | * Use this variant with nested collections, which produce a generic element type: |
| 265 | 348 | * <pre> |
| 266 | 349 | * {@code List<List<String>> l = row.getList(1, new TypeToken<List<String>>() {});} |
| @@ -280,12 +363,16 @@ | ||
| 280 | 363 | * {@code T} objects. |
| 281 | 364 | * |
| 282 | 365 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 366 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 367 | + * type to a list. | |
| 283 | 368 | */ |
| 284 | 369 | public <T> List<T> getList(int i, TypeToken<T> elementsType); |
| 285 | 370 | |
| 286 | 371 | /** |
| 287 | 372 | * Returns the {@code i}th value as a set. |
| 288 | 373 | * <p> |
| 374 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a set of the specified type. | |
| 375 | + * <p> | |
| 289 | 376 | * If the type of the elements is generic, use {@link #getSet(int, TypeToken)}. |
| 290 | 377 | * <p> |
| 291 | 378 | * Implementation note: the actual {@link Set} implementation will depend |
| @@ -302,12 +389,16 @@ | ||
| 302 | 389 | * {@code T} objects. |
| 303 | 390 | * |
| 304 | 391 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 392 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 393 | + * type to a set. | |
| 305 | 394 | */ |
| 306 | 395 | public <T> Set<T> getSet(int i, Class<T> elementsClass); |
| 307 | 396 | |
| 308 | 397 | /** |
| 309 | 398 | * Returns the {@code i}th value as a set. |
| 310 | 399 | * <p> |
| 400 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a set of the specified type. | |
| 401 | + * <p> | |
| 311 | 402 | * Use this variant with nested collections, which produce a generic element type: |
| 312 | 403 | * <pre> |
| 313 | 404 | * {@code Set<List<String>> l = row.getSet(1, new TypeToken<List<String>>() {});} |
| @@ -327,12 +418,16 @@ | ||
| 327 | 418 | * {@code T} objects. |
| 328 | 419 | * |
| 329 | 420 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 421 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 422 | + * type to a set. | |
| 330 | 423 | */ |
| 331 | 424 | public <T> Set<T> getSet(int i, TypeToken<T> elementsType); |
| 332 | 425 | |
| 333 | 426 | /** |
| 334 | 427 | * Returns the {@code i}th value as a map. |
| 335 | 428 | * <p> |
| 429 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a map of the specified types. | |
| 430 | + * <p> | |
| 336 | 431 | * If the type of the keys and/or values is generic, use {@link #getMap(int, TypeToken, TypeToken)}. |
| 337 | 432 | * <p> |
| 338 | 433 | * Implementation note: the actual {@link Map} implementation will depend |
| @@ -350,6 +445,8 @@ | ||
| 350 | 445 | * {@code K} to {@code V} objects. |
| 351 | 446 | * |
| 352 | 447 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 448 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 449 | + * type to a map. | |
| 353 | 450 | */ |
| 354 | 451 | public <K, V> Map<K, V> getMap(int i, Class<K> keysClass, Class<V> valuesClass); |
| 355 | 452 | |
| @@ -357,6 +454,8 @@ | ||
| 357 | 454 | /** |
| 358 | 455 | * Returns the {@code i}th value as a map. |
| 359 | 456 | * <p> |
| 457 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a map of the specified types. | |
| 458 | + * <p> | |
| 360 | 459 | * Use this variant with nested collections, which produce a generic element type: |
| 361 | 460 | * <pre> |
| 362 | 461 | * {@code Map<Int, List<String>> l = row.getMap(1, TypeToken.of(Integer.class), new TypeToken<List<String>>() {});} |
| @@ -377,57 +476,68 @@ | ||
| 377 | 476 | * {@code K} to {@code V} objects. |
| 378 | 477 | * |
| 379 | 478 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 479 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 480 | + * type to a map. | |
| 380 | 481 | */ |
| 381 | 482 | public <K, V> Map<K, V> getMap(int i, TypeToken<K> keysType, TypeToken<V> valuesType); |
| 382 | 483 | |
| 383 | 484 | /** |
| 384 | 485 | * Return the {@code i}th value as a UDT value. |
| 486 | + * <p> | |
| 487 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a {@code UDTValue} | |
| 488 | + * (if the CQL type is a UDT, the registry will generate a codec automatically). | |
| 385 | 489 | * |
| 386 | 490 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 387 | 491 | * @return the value of the {@code i}th element as a UDT value. If the value is NULL, |
| 388 | 492 | * then {@code null} will be returned. |
| 389 | 493 | * |
| 390 | 494 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 495 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 496 | + * type to a {@code UDTValue}. | |
| 391 | 497 | */ |
| 392 | 498 | public UDTValue getUDTValue(int i); |
| 393 | 499 | |
| 394 | 500 | /** |
| 395 | 501 | * Return the {@code i}th value as a tuple value. |
| 502 | + * <p> | |
| 503 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a {@code TupleValue} | |
| 504 | + * (if the CQL type is a tuple, the registry will generate a codec automatically). | |
| 396 | 505 | * |
| 397 | 506 | * @param i the index ({@code 0 <= i < size()}) to retrieve. |
| 398 | 507 | * @return the value of the {@code i}th element as a tuple value. If the value is NULL, |
| 399 | 508 | * then {@code null} will be returned. |
| 400 | 509 | * |
| 401 | 510 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 511 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 512 | + * type to a {@code TupleValue}. | |
| 402 | 513 | */ |
| 403 | 514 | public TupleValue getTupleValue(int i); |
| 404 | 515 | |
| 405 | 516 | /** |
| 406 | 517 | * Returns the {@code i}th value as the Java type matching its CQL type. |
| 407 | 518 | * <p> |
| 408 | - * Note: if two or more codecs are available | |
| 409 | - * for the underlying CQL type, <em>the one that will be used will be | |
| 410 | - * the first one to be registered.</em>. | |
| 519 | + * This method uses the {@link CodecRegistry} to find the first codec that handles the underlying CQL type. The Java type | |
| 520 | + * of the returned object will be determined by the codec that was selected. | |
| 411 | 521 | * <p> |
| 412 | - * For these reasons, it is generally preferable to use the more | |
| 413 | - * deterministic methods {@link #get(int, Class)} or {@link #get(int, TypeToken)} instead. | |
| 522 | + * Use this method to dynamically inspect elements when types aren't known in advance, for instance if you're writing a | |
| 523 | + * generic row logger. If you know the target Java type, it is generally preferable to use typed getters, such as the | |
| 524 | + * ones for built-in types ({@link #getBool(int)}, {@link #getInt(int)}, etc.), or {@link #get(int, Class)} and | |
| 525 | + * {@link #get(int, TypeToken)} for custom types. | |
| 414 | 526 | * |
| 415 | 527 | * @param i the index to retrieve. |
| 416 | 528 | * @return the value of the {@code i}th value as the Java type matching its CQL type. |
| 417 | 529 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 530 | + * | |
| 531 | + * @see CodecRegistry#codecFor(DataType) | |
| 418 | 532 | */ |
| 419 | 533 | public Object getObject(int i); |
| 420 | 534 | |
| 421 | 535 | /** |
| 422 | 536 | * Returns the {@code i}th value converted to the given Java type. |
| 423 | 537 | * <p> |
| 424 | - * A suitable {@link TypeCodec} instance for the underlying CQL type and {@code targetClass} must | |
| 425 | - * have been previously registered with the {@link CodecRegistry} currently in use. | |
| 538 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to the given Java type. | |
| 426 | 539 | * <p> |
| 427 | - * This method should be used instead of {@link #getObject(int)} in cases | |
| 428 | - * where more than one codec is registered for the same CQL type; specifying the Java class | |
| 429 | - * allows the {@link CodecRegistry} to narrow down the search and return only an exactly-matching codec (if any), | |
| 430 | - * thus avoiding any risk of ambiguity. | |
| 540 | + * If the target type is generic, use {@link #get(int, TypeToken)}. | |
| 431 | 541 | * <p> |
| 432 | 542 | * Implementation note: the actual object returned by this method will depend |
| 433 | 543 | * on the {@link TypeCodec codec} being used; therefore, callers should |
| @@ -440,22 +550,15 @@ | ||
| 440 | 550 | * @param targetClass The Java type the value should be converted to. |
| 441 | 551 | * @return the value of the {@code i}th value converted to the given Java type. |
| 442 | 552 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 443 | - * @throws com.datastax.driver.core.exceptions.CodecNotFoundException | |
| 444 | - * if no {@link TypeCodec} instance for {@code targetClass} could be found | |
| 445 | - * by the {@link CodecRegistry} currently in use. | |
| 553 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 554 | + * type to {@code targetClass}. | |
| 446 | 555 | */ |
| 447 | 556 | <T> T get(int i, Class<T> targetClass); |
| 448 | 557 | |
| 449 | 558 | /** |
| 450 | 559 | * Returns the {@code i}th value converted to the given Java type. |
| 451 | 560 | * <p> |
| 452 | - * A suitable {@link TypeCodec} instance for the underlying CQL type and {@code targetType} must | |
| 453 | - * have been previously registered with the {@link CodecRegistry} currently in use. | |
| 454 | - * <p> | |
| 455 | - * This method should be used instead of {@link #getObject(int)} in cases | |
| 456 | - * where more than one codec is registered for the same CQL type; specifying the Java class | |
| 457 | - * allows the {@link CodecRegistry} to narrow down the search and return only an exactly-matching codec (if any), | |
| 458 | - * thus avoiding any risk of ambiguity. | |
| 561 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to the given Java type. | |
| 459 | 562 | * <p> |
| 460 | 563 | * Implementation note: the actual object returned by this method will depend |
| 461 | 564 | * on the {@link TypeCodec codec} being used; therefore, callers should |
| @@ -468,17 +571,17 @@ | ||
| 468 | 571 | * @param targetType The Java type the value should be converted to. |
| 469 | 572 | * @return the value of the {@code i}th value converted to the given Java type. |
| 470 | 573 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 471 | - * @throws com.datastax.driver.core.exceptions.CodecNotFoundException | |
| 472 | - * if no {@link TypeCodec} instance for {@code targetType} could be found | |
| 473 | - * by the {@link CodecRegistry} currently in use. | |
| 574 | + * @throws CodecNotFoundException if there is no registered codec to convert the element's CQL | |
| 575 | + * type to {@code targetType}. | |
| 474 | 576 | */ |
| 475 | 577 | <T> T get(int i, TypeToken<T> targetType); |
| 476 | 578 | |
| 477 | 579 | /** |
| 478 | 580 | * Returns the {@code i}th value converted using the given {@link TypeCodec}. |
| 479 | 581 | * <p> |
| 480 | - * Note that this method allows to entirely bypass the {@link CodecRegistry} currently in use | |
| 481 | - * and forces the driver to use the given codec instead. | |
| 582 | + * This method entirely bypasses the {@link CodecRegistry} and forces the driver to use the given codec instead. | |
| 583 | + * This can be useful if the codec would collide with a previously registered one, or if you want to use the | |
| 584 | + * codec just once without registering it. | |
| 482 | 585 | * <p> |
| 483 | 586 | * It is the caller's responsibility to ensure that the given codec {@link TypeCodec#accepts(DataType) accepts} |
| 484 | 587 | * the underlying CQL type; failing to do so may result in {@link InvalidTypeException}s being thrown. |
modified driver-core/src/main/java/com/datastax/driver/core/GettableByNameData.java +149 −39
| @@ -23,6 +23,7 @@ | ||
| 23 | 23 | |
| 24 | 24 | import com.google.common.reflect.TypeToken; |
| 25 | 25 | |
| 26 | +import com.datastax.driver.core.exceptions.CodecNotFoundException; | |
| 26 | 27 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 27 | 28 | |
| 28 | 29 | /** |
| @@ -42,116 +43,172 @@ | ||
| 42 | 43 | |
| 43 | 44 | /** |
| 44 | 45 | * Returns the value for {@code name} as a boolean. |
| 46 | + * <p> | |
| 47 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code boolean} | |
| 48 | + * (for CQL type {@code boolean}, this will be the built-in codec). | |
| 45 | 49 | * |
| 46 | 50 | * @param name the name to retrieve. |
| 47 | - * @return the boolean value for {@code name}. If the value is NULL, | |
| 48 | - * {@code false} is returned. | |
| 51 | + * @return the boolean value for {@code name}. If the value is NULL, {@code false} is returned. | |
| 52 | + * If you need to distinguish NULL and false values, check first with {@link #isNull(String)} or use {@code get(name, Boolean.class)}. | |
| 49 | 53 | * |
| 50 | 54 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 55 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 56 | + * type to a boolean. | |
| 51 | 57 | */ |
| 52 | 58 | public boolean getBool(String name); |
| 53 | 59 | |
| 54 | 60 | /** |
| 55 | 61 | * Returns the value for {@code name} as a byte. |
| 62 | + * <p> | |
| 63 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code byte} | |
| 64 | + * (for CQL type {@code tinyint}, this will be the built-in codec). | |
| 56 | 65 | * |
| 57 | 66 | * @param name the name to retrieve. |
| 58 | - * @return the value for {@code name} as a byte. If the value is NULL, | |
| 67 | + * @return the value for {@code name} as a byte. If the value is NULL, {@code 0} is returned. | |
| 68 | + * If you need to distinguish NULL and 0, check first with {@link #isNull(String)} or use {@code get(name, Byte.class)}. | |
| 59 | 69 | * {@code 0} is returned. |
| 60 | 70 | * |
| 61 | 71 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 72 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 73 | + * type to a byte. | |
| 62 | 74 | */ |
| 63 | 75 | public byte getByte(String name); |
| 64 | 76 | |
| 65 | 77 | /** |
| 66 | 78 | * Returns the value for {@code name} as a short. |
| 79 | + * <p> | |
| 80 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code short} | |
| 81 | + * (for CQL type {@code smallint}, this will be the built-in codec). | |
| 67 | 82 | * |
| 68 | 83 | * @param name the name to retrieve. |
| 69 | - * @return the value for {@code name} as a short. If the value is NULL, | |
| 84 | + * @return the value for {@code name} as a short. If the value is NULL, {@code 0} is returned. | |
| 85 | + * If you need to distinguish NULL and 0, check first with {@link #isNull(String)} or use {@code get(name, Short.class)}. | |
| 70 | 86 | * {@code 0} is returned. |
| 71 | 87 | * |
| 72 | 88 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 89 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 90 | + * type to a short. | |
| 73 | 91 | */ |
| 74 | 92 | public short getShort(String name); |
| 75 | 93 | |
| 76 | 94 | /** |
| 77 | 95 | * Returns the value for {@code name} as an integer. |
| 96 | + * <p> | |
| 97 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code int} | |
| 98 | + * (for CQL type {@code int}, this will be the built-in codec). | |
| 78 | 99 | * |
| 79 | 100 | * @param name the name to retrieve. |
| 80 | - * @return the value for {@code name} as an integer. If the value is NULL, | |
| 101 | + * @return the value for {@code name} as an integer. If the value is NULL, {@code 0} is returned. | |
| 102 | + * If you need to distinguish NULL and 0, check first with {@link #isNull(String)} or use {@code get(name, Integer.class)}. | |
| 81 | 103 | * {@code 0} is returned. |
| 82 | 104 | * |
| 83 | 105 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 106 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 107 | + * type to an int. | |
| 84 | 108 | */ |
| 85 | 109 | public int getInt(String name); |
| 86 | 110 | |
| 87 | 111 | /** |
| 88 | 112 | * Returns the value for {@code name} as a long. |
| 113 | + * <p> | |
| 114 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code byte} | |
| 115 | + * (for CQL types {@code bigint} and {@code counter}, this will be the built-in codec). | |
| 89 | 116 | * |
| 90 | 117 | * @param name the name to retrieve. |
| 91 | - * @return the value for {@code name} as a long. If the value is NULL, | |
| 92 | - * {@code 0L} is returned. | |
| 118 | + * @return the value for {@code name} as a long. If the value is NULL, {@code 0L} is returned. | |
| 119 | + * If you need to distinguish NULL and 0L, check first with {@link #isNull(String)} or use {@code get(name, Long.class)}. | |
| 93 | 120 | * |
| 94 | 121 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 122 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 123 | + * type to a long. | |
| 95 | 124 | */ |
| 96 | 125 | public long getLong(String name); |
| 97 | 126 | |
| 98 | 127 | /** |
| 99 | 128 | * Returns the value for {@code name} as a date. |
| 129 | + * <p> | |
| 130 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a {@code Date} | |
| 131 | + * (for CQL type {@code timestamp}, this will be the built-in codec). | |
| 100 | 132 | * |
| 101 | 133 | * @param name the name to retrieve. |
| 102 | 134 | * @return the value for {@code name} as a date. If the value is NULL, |
| 103 | 135 | * {@code null} is returned. |
| 104 | 136 | * |
| 105 | 137 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 138 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 139 | + * type to a {@code Date}. | |
| 106 | 140 | */ |
| 107 | 141 | public Date getTimestamp(String name); |
| 108 | 142 | |
| 109 | 143 | /** |
| 110 | 144 | * Returns the value for {@code name} as a date (without time). |
| 145 | + * <p> | |
| 146 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a {@link LocalDate} | |
| 147 | + * (for CQL type {@code date}, this will be the built-in codec). | |
| 111 | 148 | * |
| 112 | 149 | * @param name the name to retrieve. |
| 113 | 150 | * @return the value for {@code name} as a date. If the value is NULL, |
| 114 | 151 | * {@code null} is returned. |
| 115 | 152 | * |
| 116 | 153 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 154 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 155 | + * type to a {@code LocalDate}. | |
| 117 | 156 | */ |
| 118 | 157 | public LocalDate getDate(String name); |
| 119 | 158 | |
| 120 | 159 | /** |
| 121 | 160 | * Returns the value for {@code name} as a long in nanoseconds since midnight. |
| 161 | + * <p> | |
| 162 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code long} | |
| 163 | + * (for CQL type {@code time}, this will be the built-in codec). | |
| 122 | 164 | * |
| 123 | 165 | * @param name the name to retrieve. |
| 124 | 166 | * @return the value for {@code name} as a long. If the value is NULL, |
| 125 | 167 | * {@code 0L} is returned. |
| 126 | 168 | * |
| 127 | 169 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 170 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 171 | + * type to a long. | |
| 128 | 172 | */ |
| 129 | 173 | public long getTime(String name); |
| 130 | 174 | |
| 131 | 175 | /** |
| 132 | 176 | * Returns the value for {@code name} as a float. |
| 177 | + * <p> | |
| 178 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code float} | |
| 179 | + * (for CQL type {@code float}, this will be the built-in codec). | |
| 133 | 180 | * |
| 134 | 181 | * @param name the name to retrieve. |
| 135 | - * @return the value for {@code name} as a float. If the value is NULL, | |
| 136 | - * {@code 0.0f} is returned. | |
| 182 | + * @return the value for {@code name} as a float. If the value is NULL, {@code 0.0f} is returned. | |
| 183 | + * If you need to distinguish NULL and 0.0f, check first with {@link #isNull(String)} or use {@code get(name, Float.class)}. | |
| 137 | 184 | * |
| 138 | 185 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 186 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 187 | + * type to a float. | |
| 139 | 188 | */ |
| 140 | 189 | public float getFloat(String name); |
| 141 | 190 | |
| 142 | 191 | /** |
| 143 | 192 | * Returns the value for {@code name} as a double. |
| 193 | + * <p> | |
| 194 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code double} | |
| 195 | + * (for CQL type {@code double}, this will be the built-in codec). | |
| 144 | 196 | * |
| 145 | 197 | * @param name the name to retrieve. |
| 146 | - * @return the value for {@code name} as a double. If the value is NULL, | |
| 147 | - * {@code 0.0} is returned. | |
| 198 | + * @return the value for {@code name} as a double. If the value is NULL, {@code 0.0} is returned. | |
| 199 | + * If you need to distinguish NULL and 0.0, check first with {@link #isNull(String)} or use {@code get(name, Double.class)}. | |
| 148 | 200 | * |
| 149 | 201 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 202 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 203 | + * type to a double. | |
| 150 | 204 | */ |
| 151 | 205 | public double getDouble(String name); |
| 152 | 206 | |
| 153 | 207 | /** |
| 154 | 208 | * Returns the value for {@code name} as a ByteBuffer. |
| 209 | + * <p> | |
| 210 | + * This method does not use any codec; it returns a copy of the binary representation of the value. It is up to the | |
| 211 | + * caller to convert the returned value appropriately. | |
| 155 | 212 | * |
| 156 | 213 | * Note: this method always return the bytes composing the value, even if |
| 157 | 214 | * the column is not of type BLOB. That is, this method never throw an |
| @@ -169,75 +226,104 @@ | ||
| 169 | 226 | /** |
| 170 | 227 | * Returns the value for {@code name} as a byte array. |
| 171 | 228 | * <p> |
| 172 | - * Note that this method validate that the column is of type BLOB. If you want to retrieve | |
| 173 | - * the bytes for any type, use {@link #getBytesUnsafe(String)} instead. | |
| 229 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java {@code ByteBuffer} | |
| 230 | + * (for CQL type {@code blob}, this will be the built-in codec). | |
| 174 | 231 | * |
| 175 | 232 | * @param name the name to retrieve. |
| 176 | 233 | * @return the value for {@code name} as a byte array. If the value is NULL, |
| 177 | 234 | * {@code null} is returned. |
| 178 | 235 | * |
| 179 | 236 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 237 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 238 | + * type to a {@code ByteBuffer}. | |
| 180 | 239 | */ |
| 181 | 240 | public ByteBuffer getBytes(String name); |
| 182 | 241 | |
| 183 | 242 | /** |
| 184 | 243 | * Returns the value for {@code name} as a string. |
| 244 | + * <p> | |
| 245 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a Java string | |
| 246 | + * (for CQL types {@code text}, {@code varchar} and {@code ascii}, this will be the built-in codec). | |
| 185 | 247 | * |
| 186 | 248 | * @param name the name to retrieve. |
| 187 | 249 | * @return the value for {@code name} as a string. If the value is NULL, |
| 188 | 250 | * {@code null} is returned. |
| 189 | 251 | * |
| 190 | 252 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 253 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 254 | + * type to a string. | |
| 191 | 255 | */ |
| 192 | 256 | public String getString(String name); |
| 193 | 257 | |
| 194 | 258 | /** |
| 195 | 259 | * Returns the value for {@code name} as a variable length integer. |
| 260 | + * <p> | |
| 261 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a {@code BigInteger} | |
| 262 | + * (for CQL type {@code varint}, this will be the built-in codec). | |
| 196 | 263 | * |
| 197 | 264 | * @param name the name to retrieve. |
| 198 | 265 | * @return the value for {@code name} as a variable length integer. |
| 199 | 266 | * If the value is NULL, {@code null} is returned. |
| 200 | 267 | * |
| 201 | 268 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 269 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 270 | + * type to a {@code BigInteger}. | |
| 202 | 271 | */ |
| 203 | 272 | public BigInteger getVarint(String name); |
| 204 | 273 | |
| 205 | 274 | /** |
| 206 | 275 | * Returns the value for {@code name} as a variable length decimal. |
| 276 | + * <p> | |
| 277 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a {@code BigDecimal} | |
| 278 | + * (for CQL type {@code decimal}, this will be the built-in codec). | |
| 207 | 279 | * |
| 208 | 280 | * @param name the name to retrieve. |
| 209 | 281 | * @return the value for {@code name} as a variable length decimal. |
| 210 | 282 | * If the value is NULL, {@code null} is returned. |
| 211 | 283 | * |
| 212 | 284 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 285 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 286 | + * type to a {@code BigDecimal}. | |
| 213 | 287 | */ |
| 214 | 288 | public BigDecimal getDecimal(String name); |
| 215 | 289 | |
| 216 | 290 | /** |
| 217 | 291 | * Returns the value for {@code name} as a UUID. |
| 292 | + * <p> | |
| 293 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a {@code UUID} | |
| 294 | + * (for CQL types {@code uuid} and {@code timeuuid}, this will be the built-in codec). | |
| 218 | 295 | * |
| 219 | 296 | * @param name the name to retrieve. |
| 220 | 297 | * @return the value for {@code name} as a UUID. |
| 221 | 298 | * If the value is NULL, {@code null} is returned. |
| 222 | 299 | * |
| 223 | 300 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 301 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 302 | + * type to a {@code UUID}. | |
| 224 | 303 | */ |
| 225 | 304 | public UUID getUUID(String name); |
| 226 | 305 | |
| 227 | 306 | /** |
| 228 | 307 | * Returns the value for {@code name} as an InetAddress. |
| 308 | + * <p> | |
| 309 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to an {@code InetAddress} | |
| 310 | + * (for CQL type {@code inet}, this will be the built-in codec). | |
| 229 | 311 | * |
| 230 | 312 | * @param name the name to retrieve. |
| 231 | 313 | * @return the value for {@code name} as an InetAddress. |
| 232 | 314 | * If the value is NULL, {@code null} is returned. |
| 233 | 315 | * |
| 234 | 316 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 317 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 318 | + * type to a {@code InetAddress}. | |
| 235 | 319 | */ |
| 236 | 320 | public InetAddress getInet(String name); |
| 237 | 321 | |
| 238 | 322 | /** |
| 239 | 323 | * Returns the value for {@code name} as a list. |
| 240 | 324 | * <p> |
| 325 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a list of the specified type. | |
| 326 | + * <p> | |
| 241 | 327 | * If the type of the elements is generic, use {@link #getList(String, TypeToken)}. |
| 242 | 328 | * <p> |
| 243 | 329 | * Implementation note: the actual {@link List} implementation will depend |
| @@ -254,12 +340,16 @@ | ||
| 254 | 340 | * {@code T} objects. |
| 255 | 341 | * |
| 256 | 342 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 343 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 344 | + * type to a list. | |
| 257 | 345 | */ |
| 258 | 346 | public <T> List<T> getList(String name, Class<T> elementsClass); |
| 259 | 347 | |
| 260 | 348 | /** |
| 261 | 349 | * Returns the value for {@code name} as a list. |
| 262 | 350 | * <p> |
| 351 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a list of the specified type. | |
| 352 | + * <p> | |
| 263 | 353 | * Use this variant with nested collections, which produce a generic element type: |
| 264 | 354 | * <pre> |
| 265 | 355 | * {@code List<List<String>> l = row.getList("theColumn", new TypeToken<List<String>>() {});} |
| @@ -279,12 +369,16 @@ | ||
| 279 | 369 | * {@code T} objects. |
| 280 | 370 | * |
| 281 | 371 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 372 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 373 | + * type to a list. | |
| 282 | 374 | */ |
| 283 | 375 | public <T> List<T> getList(String name, TypeToken<T> elementsType); |
| 284 | 376 | |
| 285 | 377 | /** |
| 286 | 378 | * Returns the value for {@code name} as a set. |
| 287 | 379 | * <p> |
| 380 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a set of the specified type. | |
| 381 | + * <p> | |
| 288 | 382 | * If the type of the elements is generic, use {@link #getSet(String, TypeToken)}. |
| 289 | 383 | * <p> |
| 290 | 384 | * Implementation note: the actual {@link Set} implementation will depend |
| @@ -301,12 +395,16 @@ | ||
| 301 | 395 | * {@code T} objects. |
| 302 | 396 | * |
| 303 | 397 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 398 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 399 | + * type to a set. | |
| 304 | 400 | */ |
| 305 | 401 | public <T> Set<T> getSet(String name, Class<T> elementsClass); |
| 306 | 402 | |
| 307 | 403 | /** |
| 308 | 404 | * Returns the value for {@code name} as a set. |
| 309 | 405 | * <p> |
| 406 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a set of the specified type. | |
| 407 | + * <p> | |
| 310 | 408 | * Use this variant with nested collections, which produce a generic element type: |
| 311 | 409 | * <pre> |
| 312 | 410 | * {@code Set<List<String>> l = row.getSet("theColumn", new TypeToken<List<String>>() {});} |
| @@ -326,12 +424,16 @@ | ||
| 326 | 424 | * {@code T} objects. |
| 327 | 425 | * |
| 328 | 426 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 427 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 428 | + * type to a set. | |
| 329 | 429 | */ |
| 330 | 430 | public <T> Set<T> getSet(String name, TypeToken<T> elementsType); |
| 331 | 431 | |
| 332 | 432 | /** |
| 333 | 433 | * Returns the value for {@code name} as a map. |
| 334 | 434 | * <p> |
| 435 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a map of the specified types. | |
| 436 | + * <p> | |
| 335 | 437 | * If the type of the keys and/or values is generic, use {@link #getMap(String, TypeToken, TypeToken)}. |
| 336 | 438 | * <p> |
| 337 | 439 | * Implementation note: the actual {@link Map} implementation will depend |
| @@ -349,12 +451,16 @@ | ||
| 349 | 451 | * {@code K} to {@code V} objects. |
| 350 | 452 | * |
| 351 | 453 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 454 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 455 | + * type to a map. | |
| 352 | 456 | */ |
| 353 | 457 | public <K, V> Map<K, V> getMap(String name, Class<K> keysClass, Class<V> valuesClass); |
| 354 | 458 | |
| 355 | 459 | /** |
| 356 | 460 | * Returns the value for {@code name} as a map. |
| 357 | 461 | * <p> |
| 462 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a map of the specified types. | |
| 463 | + * <p> | |
| 358 | 464 | * Use this variant with nested collections, which produce a generic element type: |
| 359 | 465 | * <pre> |
| 360 | 466 | * {@code Map<Int, List<String>> l = row.getMap("theColumn", TypeToken.of(Integer.class), new TypeToken<List<String>>() {});} |
| @@ -375,40 +481,53 @@ | ||
| 375 | 481 | * {@code K} to {@code V} objects. |
| 376 | 482 | * |
| 377 | 483 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 484 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 485 | + * type to a map. | |
| 378 | 486 | */ |
| 379 | 487 | public <K, V> Map<K, V> getMap(String name, TypeToken<K> keysType, TypeToken<V> valuesType); |
| 380 | 488 | |
| 381 | 489 | /** |
| 382 | 490 | * Return the value for {@code name} as a UDT value. |
| 491 | + * <p> | |
| 492 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a {@code UDTValue} | |
| 493 | + * (if the CQL type is a UDT, the registry will generate a codec automatically). | |
| 383 | 494 | * |
| 384 | 495 | * @param name the name to retrieve. |
| 385 | 496 | * @return the value of {@code name} as a UDT value. If the value is NULL, |
| 386 | 497 | * then {@code null} will be returned. |
| 387 | 498 | * |
| 388 | 499 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 500 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 501 | + * type to a {@code UDTValue}. | |
| 389 | 502 | */ |
| 390 | 503 | public UDTValue getUDTValue(String name); |
| 391 | 504 | |
| 392 | 505 | /** |
| 393 | 506 | * Return the value for {@code name} as a tuple value. |
| 507 | + * <p> | |
| 508 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to a {@code TupleValue} | |
| 509 | + * (if the CQL type is a tuple, the registry will generate a codec automatically). | |
| 394 | 510 | * |
| 395 | 511 | * @param name the name to retrieve. |
| 396 | 512 | * @return the value of {@code name} as a tuple value. If the value is NULL, |
| 397 | 513 | * then {@code null} will be returned. |
| 398 | 514 | * |
| 399 | 515 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 516 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 517 | + * type to a {@code TupleValue}. | |
| 400 | 518 | */ |
| 401 | 519 | public TupleValue getTupleValue(String name); |
| 402 | 520 | |
| 403 | 521 | /** |
| 404 | 522 | * Returns the value for {@code name} as the Java type matching its CQL type. |
| 405 | 523 | * <p> |
| 406 | - * Note: if two or more codecs are available | |
| 407 | - * for the underlying CQL type, <em>the one that will be used will be | |
| 408 | - * the first one to be registered.</em>. | |
| 524 | + * This method uses the {@link CodecRegistry} to find the first codec that handles the underlying CQL type. The Java type | |
| 525 | + * of the returned object will be determined by the codec that was selected. | |
| 409 | 526 | * <p> |
| 410 | - * For these reasons, it is generally preferable to use the more | |
| 411 | - * deterministic methods {@link #get(String, Class)} or {@link #get(String, TypeToken)} instead. | |
| 527 | + * Use this method to dynamically inspect elements when types aren't known in advance, for instance if you're writing a | |
| 528 | + * generic row logger. If you know the target Java type, it is generally preferable to use typed getters, such as the | |
| 529 | + * ones for built-in types ({@link #getBool(String)}, {@link #getInt(String)}, etc.), or {@link #get(String, Class)} and | |
| 530 | + * {@link #get(String, TypeToken)} for custom types. | |
| 412 | 531 | * |
| 413 | 532 | * @param name the name to retrieve. |
| 414 | 533 | * @return the value of {@code name} as the Java type matching its CQL type. |
| @@ -416,19 +535,17 @@ | ||
| 416 | 535 | * If it is NULL and is a collection type, an empty (immutable) collection is returned. |
| 417 | 536 | * |
| 418 | 537 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 538 | + * | |
| 539 | + * @see CodecRegistry#codecFor(DataType) | |
| 419 | 540 | */ |
| 420 | 541 | Object getObject(String name); |
| 421 | 542 | |
| 422 | 543 | /** |
| 423 | 544 | * Returns the value for {@code name} converted to the given Java type. |
| 424 | 545 | * <p> |
| 425 | - * A suitable {@link TypeCodec} instance for for the underlying CQL type and {@code targetClass} must | |
| 426 | - * have been previously registered with the {@link CodecRegistry} currently in use. | |
| 546 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to the given Java type. | |
| 427 | 547 | * <p> |
| 428 | - * This method should be used instead of {@link #getObject(String)} in cases | |
| 429 | - * where more than one codec is registered for the same CQL type; specifying the Java class | |
| 430 | - * allows the {@link CodecRegistry} to narrow down the search and return only an exactly-matching codec (if any), | |
| 431 | - * thus avoiding any risk of ambiguity. | |
| 548 | + * If the target type is generic, use {@link #get(String, TypeToken)}. | |
| 432 | 549 | * <p> |
| 433 | 550 | * Implementation note: the actual object returned by this method will depend |
| 434 | 551 | * on the {@link TypeCodec codec} being used; therefore, callers should |
| @@ -441,22 +558,15 @@ | ||
| 441 | 558 | * @param targetClass The Java type the value should be converted to. |
| 442 | 559 | * @return the value for {@code name} value converted to the given Java type. |
| 443 | 560 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 444 | - * @throws com.datastax.driver.core.exceptions.CodecNotFoundException | |
| 445 | - * if no {@link TypeCodec} instance for {@code targetClass} could be found | |
| 446 | - * by the {@link CodecRegistry} currently in use. | |
| 561 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 562 | + * type to {@code targetClass}. | |
| 447 | 563 | */ |
| 448 | 564 | <T> T get(String name, Class<T> targetClass); |
| 449 | 565 | |
| 450 | 566 | /** |
| 451 | 567 | * Returns the value for {@code name} converted to the given Java type. |
| 452 | 568 | * <p> |
| 453 | - * A suitable {@link TypeCodec} instance for for the underlying CQL type and {@code targetType} must | |
| 454 | - * have been previously registered with the {@link CodecRegistry} currently in use. | |
| 455 | - * <p> | |
| 456 | - * This method should be used instead of {@link #getObject(String)} in cases | |
| 457 | - * where more than one codec is registered for the same CQL type; specifying the Java class | |
| 458 | - * allows the {@link CodecRegistry} to narrow down the search and return only an exactly-matching codec (if any), | |
| 459 | - * thus avoiding any risk of ambiguity. | |
| 569 | + * This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL type to the given Java type. | |
| 460 | 570 | * <p> |
| 461 | 571 | * Implementation note: the actual object returned by this method will depend |
| 462 | 572 | * on the {@link TypeCodec codec} being used; therefore, callers should |
| @@ -469,17 +579,17 @@ | ||
| 469 | 579 | * @param targetType The Java type the value should be converted to. |
| 470 | 580 | * @return the value for {@code name} value converted to the given Java type. |
| 471 | 581 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 472 | - * @throws com.datastax.driver.core.exceptions.CodecNotFoundException | |
| 473 | - * if no {@link TypeCodec} instance for {@code targetType} could be found | |
| 474 | - * by the {@link CodecRegistry} currently in use. | |
| 582 | + * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL | |
| 583 | + * type to {@code targetType}. | |
| 475 | 584 | */ |
| 476 | 585 | <T> T get(String name, TypeToken<T> targetType); |
| 477 | 586 | |
| 478 | 587 | /** |
| 479 | 588 | * Returns the value for {@code name} converted using the given {@link TypeCodec}. |
| 480 | 589 | * <p> |
| 481 | - * Note that this method allows to entirely bypass the {@link CodecRegistry} currently in use | |
| 482 | - * and forces the driver to use the given codec instead. | |
| 590 | + * This method entirely bypasses the {@link CodecRegistry} and forces the driver to use the given codec instead. | |
| 591 | + * This can be useful if the codec would collide with a previously registered one, or if you want to use the | |
| 592 | + * codec just once without registering it. | |
| 483 | 593 | * <p> |
| 484 | 594 | * It is the caller's responsibility to ensure that the given codec {@link TypeCodec#accepts(DataType) accepts} |
| 485 | 595 | * the underlying CQL type; failing to do so may result in {@link InvalidTypeException}s being thrown. |
modified driver-core/src/main/java/com/datastax/driver/core/SettableByIndexData.java +187 −90
| @@ -23,6 +23,7 @@ | ||
| 23 | 23 | |
| 24 | 24 | import com.google.common.reflect.TypeToken; |
| 25 | 25 | |
| 26 | +import com.datastax.driver.core.exceptions.CodecNotFoundException; | |
| 26 | 27 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 27 | 28 | |
| 28 | 29 | /** |
| @@ -32,146 +33,209 @@ | ||
| 32 | 33 | |
| 33 | 34 | /** |
| 34 | 35 | * Sets the {@code i}th value to the provided boolean. |
| 36 | + * <p> | |
| 37 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 38 | + * to the underlying CQL type (for CQL type {@code boolean}, this will be the built-in codec). | |
| 35 | 39 | * |
| 36 | 40 | * @param i the index of the value to set. |
| 37 | - * @param v the value to set. | |
| 41 | + * @param v the value to set. To set the value to NULL, use {@link #setToNull(int)} or | |
| 42 | + * {@code set(i, v, Boolean.class)} | |
| 38 | 43 | * @return this object. |
| 39 | 44 | * |
| 40 | 45 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 46 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 47 | + * underlying CQL type. | |
| 41 | 48 | */ |
| 42 | 49 | public T setBool(int i, boolean v); |
| 43 | 50 | |
| 44 | 51 | /** |
| 45 | 52 | * Set the {@code i}th value to the provided byte. |
| 53 | + * <p> | |
| 54 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 55 | + * to the underlying CQL type (for CQL type {@code tinyint}, this will be the built-in codec). | |
| 46 | 56 | * |
| 47 | 57 | * @param i the index of the value to set. |
| 48 | - * @param v the value to set. | |
| 58 | + * @param v the value to set. To set the value to NULL, use {@link #setToNull(int)} or | |
| 59 | + * {@code set(i, v, Byte.class)} | |
| 49 | 60 | * @return this object. |
| 50 | 61 | * |
| 51 | 62 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 63 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 64 | + * underlying CQL type. | |
| 52 | 65 | */ |
| 53 | 66 | public T setByte(int i, byte v); |
| 54 | 67 | |
| 55 | 68 | /** |
| 56 | 69 | * Set the {@code i}th value to the provided short. |
| 70 | + * <p> | |
| 71 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 72 | + * to the underlying CQL type (for CQL type {@code smallint}, this will be the built-in codec). | |
| 57 | 73 | * |
| 58 | 74 | * @param i the index of the value to set. |
| 59 | - * @param v the value to set. | |
| 75 | + * @param v the value to set. To set the value to NULL, use {@link #setToNull(int)} or | |
| 76 | + * {@code set(i, v, Short.class)} | |
| 60 | 77 | * @return this object. |
| 61 | 78 | * |
| 62 | 79 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 80 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 81 | + * underlying CQL type. | |
| 63 | 82 | */ |
| 64 | 83 | public T setShort(int i, short v); |
| 65 | 84 | |
| 66 | 85 | /** |
| 67 | 86 | * Set the {@code i}th value to the provided integer. |
| 87 | + * <p> | |
| 88 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 89 | + * to the underlying CQL type (for CQL type {@code int}, this will be the built-in codec). | |
| 68 | 90 | * |
| 69 | 91 | * @param i the index of the value to set. |
| 70 | - * @param v the value to set. | |
| 92 | + * @param v the value to set. To set the value to NULL, use {@link #setToNull(int)} or | |
| 93 | + * {@code set(i, v, Integer.class)} | |
| 71 | 94 | * @return this object. |
| 72 | 95 | * |
| 73 | 96 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 97 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 98 | + * underlying CQL type. | |
| 74 | 99 | */ |
| 75 | 100 | public T setInt(int i, int v); |
| 76 | 101 | |
| 77 | 102 | /** |
| 78 | 103 | * Sets the {@code i}th value to the provided long. |
| 104 | + * <p> | |
| 105 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 106 | + * to the underlying CQL type (for CQL type {@code bigint}, this will be the built-in codec). | |
| 79 | 107 | * |
| 80 | 108 | * @param i the index of the value to set. |
| 81 | - * @param v the value to set. | |
| 109 | + * @param v the value to set. To set the value to NULL, use {@link #setToNull(int)} or | |
| 110 | + * {@code set(i, v, Long.class)} | |
| 82 | 111 | * @return this object. |
| 83 | 112 | * |
| 84 | 113 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 114 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 115 | + * underlying CQL type. | |
| 85 | 116 | */ |
| 86 | 117 | public T setLong(int i, long v); |
| 87 | 118 | |
| 88 | 119 | /** |
| 89 | 120 | * Set the {@code i}th value to the provided date. |
| 121 | + * <p> | |
| 122 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 123 | + * to the underlying CQL type (for CQL type {@code timestamp}, this will be the built-in codec). | |
| 90 | 124 | * |
| 91 | 125 | * @param i the index of the value to set. |
| 92 | 126 | * @param v the value to set. |
| 93 | 127 | * @return this object. |
| 94 | 128 | * |
| 95 | 129 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 130 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 131 | + * underlying CQL type. | |
| 96 | 132 | */ |
| 97 | 133 | public T setTimestamp(int i, Date v); |
| 98 | 134 | |
| 99 | 135 | /** |
| 100 | 136 | * Set the {@code i}th value to the provided date (without time). |
| 137 | + * <p> | |
| 138 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 139 | + * to the underlying CQL type (for CQL type {@code date}, this will be the built-in codec). | |
| 101 | 140 | * |
| 102 | 141 | * @param i the index of the value to set. |
| 103 | 142 | * @param v the value to set. |
| 104 | 143 | * @return this object. |
| 105 | 144 | * |
| 106 | 145 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 146 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 147 | + * underlying CQL type. | |
| 107 | 148 | */ |
| 108 | 149 | public T setDate(int i, LocalDate v); |
| 109 | 150 | |
| 110 | 151 | /** |
| 111 | 152 | * Set the {@code i}th value to the provided time as a long in nanoseconds since midnight. |
| 153 | + * <p> | |
| 154 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 155 | + * to the underlying CQL type (for CQL type {@code time}, this will be the built-in codec). | |
| 112 | 156 | * |
| 113 | 157 | * @param i the index of the value to set. |
| 114 | 158 | * @param v the value to set. |
| 115 | 159 | * @return this object. |
| 116 | 160 | * |
| 117 | 161 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 162 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 163 | + * underlying CQL type. | |
| 118 | 164 | */ |
| 119 | 165 | public T setTime(int i, long v); |
| 120 | 166 | |
| 121 | 167 | /** |
| 122 | 168 | * Sets the {@code i}th value to the provided float. |
| 169 | + * <p> | |
| 170 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 171 | + * to the underlying CQL type (for CQL type {@code float}, this will be the built-in codec). | |
| 123 | 172 | * |
| 124 | 173 | * @param i the index of the value to set. |
| 125 | - * @param v the value to set. | |
| 174 | + * @param v the value to set. To set the value to NULL, use {@link #setToNull(int)} or | |
| 175 | + * {@code set(i, v, Float.class)} | |
| 126 | 176 | * @return this object. |
| 127 | 177 | * |
| 128 | 178 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 179 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 180 | + * underlying CQL type. | |
| 129 | 181 | */ |
| 130 | 182 | public T setFloat(int i, float v); |
| 131 | 183 | |
| 132 | 184 | /** |
| 133 | 185 | * Sets the {@code i}th value to the provided double. |
| 186 | + * <p> | |
| 187 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 188 | + * to the underlying CQL type (for CQL type {@code double}, this will be the built-in codec). | |
| 134 | 189 | * |
| 135 | 190 | * @param i the index of the value to set. |
| 136 | - * @param v the value to set. | |
| 191 | + * @param v the value to set. To set the value to NULL, use {@link #setToNull(int)} or | |
| 192 | + * {@code set(i, v, Double.class)}. | |
| 137 | 193 | * @return this object. |
| 138 | 194 | * |
| 139 | 195 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 196 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 197 | + * underlying CQL type. | |
| 140 | 198 | */ |
| 141 | 199 | public T setDouble(int i, double v); |
| 142 | 200 | |
| 143 | 201 | /** |
| 144 | 202 | * Sets the {@code i}th value to the provided string. |
| 203 | + * <p> | |
| 204 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 205 | + * to the underlying CQL type (for CQL types {@code text}, {@code varchar} and {@code ascii}, | |
| 206 | + * this will be the built-in codec). | |
| 145 | 207 | * |
| 146 | 208 | * @param i the index of the value to set. |
| 147 | 209 | * @param v the value to set. |
| 148 | 210 | * @return this object. |
| 149 | 211 | * |
| 150 | 212 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 213 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 214 | + * underlying CQL type. | |
| 151 | 215 | */ |
| 152 | 216 | public T setString(int i, String v); |
| 153 | 217 | |
| 154 | 218 | /** |
| 155 | 219 | * Sets the {@code i}th value to the provided byte buffer. |
| 156 | - * | |
| 157 | - * This method validate that the type of the column set is BLOB. If you | |
| 158 | - * want to insert manually serialized data into columns of another type, | |
| 159 | - * use {@link #setBytesUnsafe} instead. | |
| 220 | + * <p> | |
| 221 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 222 | + * to the underlying CQL type (for CQL type {@code blob}, this will be the built-in codec). | |
| 160 | 223 | * |
| 161 | 224 | * @param i the index of the value to set. |
| 162 | 225 | * @param v the value to set. |
| 163 | 226 | * @return this object. |
| 164 | 227 | * |
| 165 | 228 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 229 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 230 | + * underlying CQL type. | |
| 166 | 231 | */ |
| 167 | 232 | public T setBytes(int i, ByteBuffer v); |
| 168 | 233 | |
| 169 | 234 | /** |
| 170 | 235 | * Sets the {@code i}th value to the provided byte buffer. |
| 171 | - * | |
| 172 | - * Contrary to {@link #setBytes}, this method does not check the | |
| 173 | - * type of the column set. If you insert data that is not compatible with | |
| 174 | - * the type of the column, you will get an {@code InvalidQueryException} at | |
| 236 | + * <p> | |
| 237 | + * This method does not use any codec; it sets the value in its binary form directly. If you insert | |
| 238 | + * data that is not compatible with the underlying CQL type, you will get an {@code InvalidQueryException} at | |
| 175 | 239 | * execute time. |
| 176 | 240 | * |
| 177 | 241 | * @param i the index of the value to set. |
| @@ -184,148 +248,165 @@ | ||
| 184 | 248 | |
| 185 | 249 | /** |
| 186 | 250 | * Sets the {@code i}th value to the provided big integer. |
| 251 | + * <p> | |
| 252 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 253 | + * to the underlying CQL type (for CQL type {@code varint}, this will be the built-in codec). | |
| 187 | 254 | * |
| 188 | 255 | * @param i the index of the value to set. |
| 189 | 256 | * @param v the value to set. |
| 190 | 257 | * @return this object. |
| 191 | 258 | * |
| 192 | 259 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 260 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 261 | + * underlying CQL type. | |
| 193 | 262 | */ |
| 194 | 263 | public T setVarint(int i, BigInteger v); |
| 195 | 264 | |
| 196 | 265 | /** |
| 197 | 266 | * Sets the {@code i}th value to the provided big decimal. |
| 267 | + * <p> | |
| 268 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 269 | + * to the underlying CQL type (for CQL type {@code decimal}, this will be the built-in codec). | |
| 198 | 270 | * |
| 199 | 271 | * @param i the index of the value to set. |
| 200 | 272 | * @param v the value to set. |
| 201 | 273 | * @return this object. |
| 202 | 274 | * |
| 203 | 275 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 276 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 277 | + * underlying CQL type. | |
| 204 | 278 | */ |
| 205 | 279 | public T setDecimal(int i, BigDecimal v); |
| 206 | 280 | |
| 207 | 281 | /** |
| 208 | 282 | * Sets the {@code i}th value to the provided UUID. |
| 283 | + * <p> | |
| 284 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 285 | + * to the underlying CQL type (for CQL types {@code uuid} and {@code timeuuid}, this will | |
| 286 | + * be the built-in codec). | |
| 209 | 287 | * |
| 210 | 288 | * @param i the index of the value to set. |
| 211 | 289 | * @param v the value to set. |
| 212 | 290 | * @return this object. |
| 213 | 291 | * |
| 214 | 292 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 293 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 294 | + * underlying CQL type. | |
| 215 | 295 | */ |
| 216 | 296 | public T setUUID(int i, UUID v); |
| 217 | 297 | |
| 218 | 298 | /** |
| 219 | 299 | * Sets the {@code i}th value to the provided inet address. |
| 300 | + * <p> | |
| 301 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 302 | + * to the underlying CQL type (for CQL type {@code inet}, this will be the built-in codec). | |
| 220 | 303 | * |
| 221 | 304 | * @param i the index of the value to set. |
| 222 | 305 | * @param v the value to set. |
| 223 | 306 | * @return this object. |
| 224 | 307 | * |
| 225 | 308 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 309 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 310 | + * underlying CQL type. | |
| 226 | 311 | */ |
| 227 | 312 | public T setInet(int i, InetAddress v); |
| 228 | 313 | |
| 229 | 314 | /** |
| 230 | 315 | * Sets the {@code i}th value to the provided list. |
| 231 | 316 | * <p> |
| 232 | - * Please note that {@code null} values inside collections are not supported by CQL. | |
| 233 | - * <p> | |
| 234 | - * Note: if two or more codecs are available | |
| 235 | - * for the underlying CQL type, <em>the one that will be used will be | |
| 236 | - * the first one to be registered.</em>. | |
| 237 | - * <p> | |
| 238 | - * For these reasons, it is generally preferable to use the more | |
| 239 | - * deterministic methods {@link #setList(int, List, Class)} or | |
| 240 | - * {@link #setList(int, List, TypeToken)}. | |
| 317 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 318 | + * to the underlying CQL type (the type of the elements in the Java list is not considered). | |
| 319 | + * If two or more codecs target that CQL type, the one that was first registered will be used. | |
| 320 | + * For this reason, it is generally preferable to use the more deterministic methods | |
| 321 | + * {@link #setList(int, List, Class)} or {@link #setList(int, List, TypeToken)}. | |
| 241 | 322 | * |
| 242 | 323 | * @param i the index of the value to set. |
| 243 | - * @param v the value to set. | |
| 324 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 244 | 325 | * @return this object. |
| 245 | 326 | * |
| 246 | 327 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 247 | 328 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 248 | 329 | * by CQL. |
| 330 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 331 | + * underlying CQL type. | |
| 249 | 332 | */ |
| 250 | 333 | public <E> T setList(int i, List<E> v); |
| 251 | 334 | |
| 252 | 335 | /** |
| 253 | - * Sets the {@code i}th value to the provided list, whose elements are of the provided | |
| 336 | + * Sets the {@code i}th value to the provided list, which elements are of the provided | |
| 254 | 337 | * Java class. |
| 255 | 338 | * <p> |
| 256 | - * Please note that {@code null} values inside collections are not supported by CQL. | |
| 339 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of lists of the given | |
| 340 | + * Java type to the underlying CQL type. | |
| 257 | 341 | * <p> |
| 258 | - * Note about performance: this method is able to cache codecs used to serialize the list elements, | |
| 259 | - * and thus should be used instead of {@link #setList(int, List)} | |
| 260 | - * whenever possible, because it performs significantly better. | |
| 342 | + * If the type of the elements is generic, use {@link #setList(int, List, TypeToken)}. | |
| 261 | 343 | * |
| 262 | 344 | * @param i the index of the value to set. |
| 263 | - * @param v the value to set. | |
| 345 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 264 | 346 | * @param elementsClass the class for the elements of the list. |
| 265 | 347 | * @return this object. |
| 266 | 348 | * |
| 267 | 349 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 268 | 350 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 269 | 351 | * by CQL. |
| 352 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 353 | + * underlying CQL type. | |
| 270 | 354 | */ |
| 271 | 355 | public <E> T setList(int i, List<E> v, Class<E> elementsClass); |
| 272 | 356 | |
| 273 | 357 | /** |
| 274 | - * Sets the {@code i}th value to the provided list, whose elements are of the provided | |
| 358 | + * Sets the {@code i}th value to the provided list, which elements are of the provided | |
| 275 | 359 | * Java type. |
| 276 | 360 | * <p> |
| 277 | - * Please note that {@code null} values inside collections are not supported by CQL. | |
| 278 | - * <p> | |
| 279 | - * Note about performance: this method is able to cache codecs used to serialize the list elements, | |
| 280 | - * and thus should be used instead of {@link #setList(int, List)} | |
| 281 | - * whenever possible, because it performs significantly better. | |
| 361 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of lists of the given | |
| 362 | + * Java type to the underlying CQL type. | |
| 282 | 363 | * |
| 283 | 364 | * @param i the index of the value to set. |
| 284 | - * @param v the value to set. | |
| 365 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 285 | 366 | * @param elementsType the type for the elements of the list. |
| 286 | 367 | * @return this object. |
| 287 | 368 | * |
| 288 | 369 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 289 | 370 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 290 | 371 | * by CQL. |
| 372 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 373 | + * underlying CQL type. | |
| 291 | 374 | */ |
| 292 | 375 | public <E> T setList(int i, List<E> v, TypeToken<E> elementsType); |
| 293 | 376 | |
| 294 | 377 | /** |
| 295 | 378 | * Sets the {@code i}th value to the provided map. |
| 296 | 379 | * <p> |
| 297 | - * Please note that {@code null} values are not supported inside collection by CQL. | |
| 298 | - * <p> | |
| 299 | - * Note: if two or more codecs are available | |
| 300 | - * for the underlying CQL type, <em>the one that will be used will be | |
| 301 | - * the first one to be registered.</em>. | |
| 302 | - * <p> | |
| 303 | - * For these reasons, it is generally preferable to use the more | |
| 304 | - * deterministic methods {@link #setMap(int, Map, Class, Class)} or | |
| 305 | - * {@link #setMap(int, Map, TypeToken, TypeToken)}. | |
| 380 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 381 | + * to the underlying CQL type (the type of the elements in the Java map is not considered). | |
| 382 | + * If two or more codecs target that CQL type, the one that was first registered will be used. | |
| 383 | + * For this reason, it is generally preferable to use the more deterministic methods | |
| 384 | + * {@link #setMap(int, Map, Class, Class)} or {@link #setMap(int, Map, TypeToken, TypeToken)}. | |
| 306 | 385 | * |
| 307 | 386 | * @param i the index of the value to set. |
| 308 | - * @param v the value to set. | |
| 387 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 388 | + * @return this object. | |
| 309 | 389 | * @return this object. |
| 310 | 390 | * |
| 311 | 391 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 312 | 392 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 313 | 393 | * by CQL. |
| 394 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 395 | + * underlying CQL type. | |
| 314 | 396 | */ |
| 315 | 397 | public <K, V> T setMap(int i, Map<K, V> v); |
| 316 | 398 | |
| 317 | 399 | /** |
| 318 | - * Sets the {@code i}th value to the provided map, whose keys and values are of the provided | |
| 400 | + * Sets the {@code i}th value to the provided map, which keys and values are of the provided | |
| 319 | 401 | * Java classes. |
| 320 | 402 | * <p> |
| 321 | - * Please note that {@code null} values inside collections are not supported by CQL. | |
| 403 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of lists of the given | |
| 404 | + * Java types to the underlying CQL type. | |
| 322 | 405 | * <p> |
| 323 | - * Note about performance: this method is able to cache codecs used to serialize the map entries, | |
| 324 | - * and thus should be used instead of {@link #setMap(int, Map)} | |
| 325 | - * whenever possible, because it performs significantly better. | |
| 406 | + * If the type of the keys or values is generic, use {@link #setMap(int, Map, TypeToken, TypeToken)}. | |
| 326 | 407 | * |
| 327 | 408 | * @param i the index of the value to set. |
| 328 | - * @param v the value to set. | |
| 409 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 329 | 410 | * @param keysClass the class for the keys of the map. |
| 330 | 411 | * @param valuesClass the class for the values of the map. |
| 331 | 412 | * @return this object. |
| @@ -333,21 +414,20 @@ | ||
| 333 | 414 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 334 | 415 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 335 | 416 | * by CQL. |
| 417 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 418 | + * underlying CQL type. | |
| 336 | 419 | */ |
| 337 | 420 | public <K, V> T setMap(int i, Map<K, V> v, Class<K> keysClass, Class<V> valuesClass); |
| 338 | 421 | |
| 339 | 422 | /** |
| 340 | - * Sets the {@code i}th value to the provided map, whose keys and values are of the provided | |
| 423 | + * Sets the {@code i}th value to the provided map, which keys and values are of the provided | |
| 341 | 424 | * Java types. |
| 342 | 425 | * <p> |
| 343 | - * Please note that {@code null} values inside collections are not supported by CQL. | |
| 344 | - * <p> | |
| 345 | - * Note about performance: this method is able to cache codecs used to serialize the map entries, | |
| 346 | - * and thus should be used instead of {@link #setMap(int, Map)} | |
| 347 | - * whenever possible, because it performs significantly better. | |
| 426 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of lists of the given | |
| 427 | + * Java types to the underlying CQL type. | |
| 348 | 428 | * |
| 349 | 429 | * @param i the index of the value to set. |
| 350 | - * @param v the value to set. | |
| 430 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 351 | 431 | * @param keysType the type for the keys of the map. |
| 352 | 432 | * @param valuesType the type for the values of the map. |
| 353 | 433 | * @return this object. |
| @@ -355,93 +435,103 @@ | ||
| 355 | 435 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 356 | 436 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 357 | 437 | * by CQL. |
| 438 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 439 | + * underlying CQL type. | |
| 358 | 440 | */ |
| 359 | 441 | public <K, V> T setMap(int i, Map<K, V> v, TypeToken<K> keysType, TypeToken<V> valuesType); |
| 360 | 442 | |
| 361 | 443 | /** |
| 362 | 444 | * Sets the {@code i}th value to the provided set. |
| 363 | 445 | * <p> |
| 364 | - * Please note that {@code null} values are not supported inside collection by CQL. | |
| 365 | - * <p> | |
| 366 | - * Note: if two or more codecs are available | |
| 367 | - * for the underlying CQL type, <em>the one that will be used will be | |
| 368 | - * the first one to be registered.</em>. | |
| 369 | - * <p> | |
| 370 | - * For these reasons, it is generally preferable to use the more | |
| 371 | - * deterministic methods {@link #setSet(int, Set, Class)} or | |
| 372 | - * {@link #setSet(int, Set, TypeToken)}. | |
| 446 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 447 | + * to the underlying CQL type (the type of the elements in the Java set is not considered). | |
| 448 | + * If two or more codecs target that CQL type, the one that was first registered will be used. | |
| 449 | + * For this reason, it is generally preferable to use the more deterministic methods | |
| 450 | + * {@link #setSet(int, Set, Class)} or {@link #setSet(int, Set, TypeToken)}. | |
| 373 | 451 | * |
| 374 | 452 | * @param i the index of the value to set. |
| 375 | - * @param v the value to set. | |
| 453 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 376 | 454 | * @return this object. |
| 377 | 455 | * |
| 378 | 456 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 379 | 457 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 380 | 458 | * by CQL. |
| 459 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 460 | + * underlying CQL type. | |
| 381 | 461 | */ |
| 382 | 462 | public <E> T setSet(int i, Set<E> v); |
| 383 | 463 | |
| 384 | 464 | /** |
| 385 | - * Sets the {@code i}th value to the provided set, whose elements are of the provided | |
| 465 | + * Sets the {@code i}th value to the provided set, which elements are of the provided | |
| 386 | 466 | * Java class. |
| 387 | 467 | * <p> |
| 388 | - * Please note that {@code null} values inside collections are not supported by CQL. | |
| 468 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of sets of the given | |
| 469 | + * Java type to the underlying CQL type. | |
| 389 | 470 | * <p> |
| 390 | - * Note about performance: this method is able to cache codecs used to serialize the set elements, | |
| 391 | - * and thus should be used instead of {@link #setSet(int, Set)} | |
| 392 | - * whenever possible, because it performs significantly better. | |
| 471 | + * If the type of the elements is generic, use {@link #setSet(int, Set, TypeToken)}. | |
| 393 | 472 | * |
| 394 | 473 | * @param i the index of the value to set. |
| 395 | - * @param v the value to set. | |
| 474 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 396 | 475 | * @param elementsClass the class for the elements of the set. |
| 397 | 476 | * @return this object. |
| 398 | 477 | * |
| 399 | 478 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 400 | 479 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 401 | 480 | * by CQL. |
| 481 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 482 | + * underlying CQL type. | |
| 402 | 483 | */ |
| 403 | 484 | public <E> T setSet(int i, Set<E> v, Class<E> elementsClass); |
| 404 | 485 | |
| 405 | 486 | /** |
| 406 | - * Sets the {@code i}th value to the provided set, whose elements are of the provided | |
| 487 | + * Sets the {@code i}th value to the provided set, which elements are of the provided | |
| 407 | 488 | * Java type. |
| 408 | 489 | * <p> |
| 409 | - * Please note that {@code null} values inside collections are not supported by CQL. | |
| 410 | - * <p> | |
| 411 | - * Note about performance: this method is able to cache codecs used to serialize the set elements, | |
| 412 | - * and thus should be used instead of {@link #setSet(int, Set)} | |
| 413 | - * whenever possible, because it performs significantly better. | |
| 490 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of sets of the given | |
| 491 | + * Java type to the underlying CQL type. | |
| 414 | 492 | * |
| 415 | 493 | * @param i the index of the value to set. |
| 416 | - * @param v the value to set. | |
| 494 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 417 | 495 | * @param elementsType the type for the elements of the set. |
| 418 | 496 | * @return this object. |
| 419 | 497 | * |
| 420 | 498 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 421 | 499 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 422 | 500 | * by CQL. |
| 501 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 502 | + * underlying CQL type. | |
| 423 | 503 | */ |
| 424 | 504 | public <E> T setSet(int i, Set<E> v, TypeToken<E> elementsType); |
| 425 | 505 | |
| 426 | 506 | /** |
| 427 | 507 | * Sets the {@code i}th value to the provided UDT value. |
| 508 | + * <p> | |
| 509 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of {@code UDTValue} | |
| 510 | + * to the underlying CQL type. | |
| 428 | 511 | * |
| 429 | 512 | * @param i the index of the value to set. |
| 430 | 513 | * @param v the value to set. |
| 431 | 514 | * @return this object. |
| 432 | 515 | * |
| 433 | 516 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 517 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 518 | + * underlying CQL type. | |
| 434 | 519 | */ |
| 435 | 520 | public T setUDTValue(int i, UDTValue v); |
| 436 | 521 | |
| 437 | 522 | /** |
| 438 | 523 | * Sets the {@code i}th value to the provided tuple value. |
| 524 | + * <p> | |
| 525 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of {@code TupleValue} | |
| 526 | + * to the underlying CQL type. | |
| 439 | 527 | * |
| 440 | 528 | * @param i the index of the value to set. |
| 441 | 529 | * @param v the value to set. |
| 442 | 530 | * @return this object. |
| 443 | 531 | * |
| 444 | 532 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 533 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 534 | + * underlying CQL type. | |
| 445 | 535 | */ |
| 446 | 536 | public T setTupleValue(int i, TupleValue v); |
| 447 | 537 | |
| @@ -459,36 +549,43 @@ | ||
| 459 | 549 | /** |
| 460 | 550 | * Sets the {@code i}th value to the provided value of the provided Java class. |
| 461 | 551 | * <p> |
| 462 | - * A suitable {@link TypeCodec} instance for the underlying CQL type and the provided class must | |
| 463 | - * have been previously registered with the {@link CodecRegistry} currently in use. | |
| 552 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of the provided Java class | |
| 553 | + * to the underlying CQL type. | |
| 554 | + * <p> | |
| 555 | + * If the Java type is generic, use {@link #set(int, Object, TypeToken)} instead. | |
| 464 | 556 | * |
| 465 | 557 | * @param i the index of the value to set. |
| 466 | 558 | * @param v the value to set; may be {@code null}. |
| 467 | 559 | * @param targetClass The Java class to convert to; must not be {@code null}; |
| 468 | 560 | * @return this object. |
| 469 | 561 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 562 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 563 | + * underlying CQL type. | |
| 470 | 564 | */ |
| 471 | 565 | <V> T set(int i, V v, Class<V> targetClass); |
| 472 | 566 | |
| 473 | 567 | /** |
| 474 | 568 | * Sets the {@code i}th value to the provided value of the provided Java type. |
| 475 | 569 | * <p> |
| 476 | - * A suitable {@link TypeCodec} instance for the underlying CQL type and the provided class must | |
| 477 | - * have been previously registered with the {@link CodecRegistry} currently in use. | |
| 570 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of the provided Java type | |
| 571 | + * to the underlying CQL type. | |
| 478 | 572 | * |
| 479 | 573 | * @param i the index of the value to set. |
| 480 | 574 | * @param v the value to set; may be {@code null}. |
| 481 | 575 | * @param targetType The Java type to convert to; must not be {@code null}; |
| 482 | 576 | * @return this object. |
| 483 | 577 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 578 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 579 | + * underlying CQL type. | |
| 484 | 580 | */ |
| 485 | 581 | <V> T set(int i, V v, TypeToken<V> targetType); |
| 486 | 582 | |
| 487 | 583 | /** |
| 488 | 584 | * Sets the {@code i}th value to the provided value, converted using the given {@link TypeCodec}. |
| 489 | 585 | * <p> |
| 490 | - * Note that this method allows to entirely bypass the {@link CodecRegistry} currently in use | |
| 491 | - * and forces the driver to use the given codec instead. | |
| 586 | + * This method entirely bypasses the {@link CodecRegistry} and forces the driver to use the given codec instead. | |
| 587 | + * This can be useful if the codec would collide with a previously registered one, or if you want to use the | |
| 588 | + * codec just once without registering it. | |
| 492 | 589 | * <p> |
| 493 | 590 | * It is the caller's responsibility to ensure that the given codec {@link TypeCodec#accepts(DataType) accepts} |
| 494 | 591 | * the underlying CQL type; failing to do so may result in {@link InvalidTypeException}s being thrown. |
modified driver-core/src/main/java/com/datastax/driver/core/SettableByNameData.java +186 −91
| @@ -23,6 +23,7 @@ | ||
| 23 | 23 | |
| 24 | 24 | import com.google.common.reflect.TypeToken; |
| 25 | 25 | |
| 26 | +import com.datastax.driver.core.exceptions.CodecNotFoundException; | |
| 26 | 27 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 27 | 28 | |
| 28 | 29 | /** |
| @@ -33,71 +34,104 @@ | ||
| 33 | 34 | /** |
| 34 | 35 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 35 | 36 | * provided boolean. |
| 37 | + * <p> | |
| 38 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 39 | + * to the underlying CQL type (for CQL type {@code boolean}, this will be the built-in codec). | |
| 36 | 40 | * |
| 37 | 41 | * @param name the name of the value to set; if {@code name} is present multiple |
| 38 | 42 | * times, all its values are set. |
| 39 | - * @param v the value to set. | |
| 43 | + * @param v the value to set. To set the value to NULL, use {@link #setToNull(String)} or | |
| 44 | + * {@code set(name, v, Boolean.class)}. | |
| 40 | 45 | * @return this object. |
| 41 | 46 | * |
| 42 | 47 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 48 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 49 | + * underlying CQL type. | |
| 43 | 50 | */ |
| 44 | 51 | public T setBool(String name, boolean v); |
| 45 | 52 | |
| 46 | 53 | /** |
| 47 | 54 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 48 | 55 | * provided byte. |
| 56 | + * <p> | |
| 57 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 58 | + * to the underlying CQL type (for CQL type {@code tinyint}, this will be the built-in codec). | |
| 49 | 59 | * |
| 50 | 60 | * @param name the name of the value to set; if {@code name} is present multiple |
| 51 | 61 | * times, all its values are set. |
| 52 | - * @param v the value to set. | |
| 62 | + * @param v the value to set. To set the value to NULL, use {@link #setToNull(String)} or | |
| 63 | + * {@code set(name, v, Byte.class)}. | |
| 53 | 64 | * @return this object. |
| 54 | 65 | * |
| 55 | 66 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 67 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 68 | + * underlying CQL type. | |
| 56 | 69 | */ |
| 57 | 70 | public T setByte(String name, byte v); |
| 58 | 71 | |
| 59 | 72 | /** |
| 60 | 73 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 61 | 74 | * provided short. |
| 75 | + * <p> | |
| 76 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 77 | + * to the underlying CQL type (for CQL type {@code smallint}, this will be the built-in codec). | |
| 62 | 78 | * |
| 63 | 79 | * @param name the name of the value to set; if {@code name} is present multiple |
| 64 | 80 | * times, all its values are set. |
| 65 | - * @param v the value to set. | |
| 81 | + * @param v the value to set. To set the value to NULL, use {@link #setToNull(String)} or | |
| 82 | + * {@code set(name, v, Short.class)}. | |
| 66 | 83 | * @return this object. |
| 67 | 84 | * |
| 68 | 85 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 86 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 87 | + * underlying CQL type. | |
| 69 | 88 | */ |
| 70 | 89 | public T setShort(String name, short v); |
| 71 | 90 | |
| 72 | 91 | /** |
| 73 | 92 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 74 | 93 | * provided integer. |
| 94 | + * <p> | |
| 95 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 96 | + * to the underlying CQL type (for CQL type {@code int}, this will be the built-in codec). | |
| 75 | 97 | * |
| 76 | 98 | * @param name the name of the value to set; if {@code name} is present multiple |
| 77 | 99 | * times, all its values are set. |
| 78 | - * @param v the value to set. | |
| 100 | + * @param v the value to set. To set the value to NULL, use {@link #setToNull(String)} or | |
| 101 | + * {@code set(name, v, Integer.class)}. | |
| 79 | 102 | * @return this object. |
| 80 | 103 | * |
| 81 | 104 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 105 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 106 | + * underlying CQL type. | |
| 82 | 107 | */ |
| 83 | 108 | public T setInt(String name, int v); |
| 84 | 109 | |
| 85 | 110 | /** |
| 86 | 111 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 87 | 112 | * provided long. |
| 113 | + * <p> | |
| 114 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 115 | + * to the underlying CQL type (for CQL type {@code bigint}, this will be the built-in codec). | |
| 88 | 116 | * |
| 89 | 117 | * @param name the name of the value to set; if {@code name} is present multiple |
| 90 | 118 | * times, all its values are set. |
| 91 | - * @param v the value to set. | |
| 119 | + * @param v the value to set. To set the value to NULL, use {@link #setToNull(String)} or | |
| 120 | + * {@code set(name, v, Long.class)}. | |
| 92 | 121 | * @return this object. |
| 93 | 122 | * |
| 94 | 123 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 124 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 125 | + * underlying CQL type. | |
| 95 | 126 | */ |
| 96 | 127 | public T setLong(String name, long v); |
| 97 | 128 | |
| 98 | 129 | /** |
| 99 | 130 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 100 | 131 | * provided date. |
| 132 | + * <p> | |
| 133 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 134 | + * to the underlying CQL type (for CQL type {@code timestamp}, this will be the built-in codec). | |
| 101 | 135 | * |
| 102 | 136 | * @param name the name of the value to set; if {@code name} is present multiple |
| 103 | 137 | * times, all its values are set. |
| @@ -105,12 +139,17 @@ | ||
| 105 | 139 | * @return this object. |
| 106 | 140 | * |
| 107 | 141 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 142 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 143 | + * underlying CQL type. | |
| 108 | 144 | */ |
| 109 | 145 | public T setTimestamp(String name, Date v); |
| 110 | 146 | |
| 111 | 147 | /** |
| 112 | 148 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 113 | 149 | * provided date (without time). |
| 150 | + * <p> | |
| 151 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 152 | + * to the underlying CQL type (for CQL type {@code date}, this will be the built-in codec). | |
| 114 | 153 | * |
| 115 | 154 | * @param name the name of the value to set; if {@code name} is present multiple |
| 116 | 155 | * times, all its values are set. |
| @@ -118,12 +157,17 @@ | ||
| 118 | 157 | * @return this object. |
| 119 | 158 | * |
| 120 | 159 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 160 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 161 | + * underlying CQL type. | |
| 121 | 162 | */ |
| 122 | 163 | public T setDate(String name, LocalDate v); |
| 123 | 164 | |
| 124 | 165 | /** |
| 125 | 166 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 126 | 167 | * provided time as a long in nanoseconds since midnight. |
| 168 | + * <p> | |
| 169 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 170 | + * to the underlying CQL type (for CQL type {@code time}, this will be the built-in codec). | |
| 127 | 171 | * |
| 128 | 172 | * @param name the name of the value to set; if {@code name} is present multiple |
| 129 | 173 | * times, all its values are set. |
| @@ -131,38 +175,56 @@ | ||
| 131 | 175 | * @return this object. |
| 132 | 176 | * |
| 133 | 177 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 178 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 179 | + * underlying CQL type. | |
| 134 | 180 | */ |
| 135 | 181 | public T setTime(String name, long v); |
| 136 | 182 | |
| 137 | 183 | /** |
| 138 | 184 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 139 | 185 | * provided float. |
| 186 | + * <p> | |
| 187 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 188 | + * to the underlying CQL type (for CQL type {@code float}, this will be the built-in codec). | |
| 140 | 189 | * |
| 141 | 190 | * @param name the name of the value to set; if {@code name} is present multiple |
| 142 | 191 | * times, all its values are set. |
| 143 | - * @param v the value to set. | |
| 192 | + * @param v the value to set. To set the value to NULL, use {@link #setToNull(String)} or | |
| 193 | + * {@code set(name, v, Float.class)}. | |
| 144 | 194 | * @return this object. |
| 145 | 195 | * |
| 146 | 196 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 197 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 198 | + * underlying CQL type. | |
| 147 | 199 | */ |
| 148 | 200 | public T setFloat(String name, float v); |
| 149 | 201 | |
| 150 | 202 | /** |
| 151 | 203 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 152 | 204 | * provided double. |
| 205 | + * <p> | |
| 206 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 207 | + * to the underlying CQL type (for CQL type {@code double}, this will be the built-in codec). | |
| 153 | 208 | * |
| 154 | 209 | * @param name the name of the value to set; if {@code name} is present multiple |
| 155 | 210 | * times, all its values are set. |
| 156 | - * @param v the value to set. | |
| 211 | + * @param v the value to set. To set the value to NULL, use {@link #setToNull(String)} or | |
| 212 | + * {@code set(name, v, Double.class)}. | |
| 157 | 213 | * @return this object. |
| 158 | 214 | * |
| 159 | 215 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 216 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 217 | + * underlying CQL type. | |
| 160 | 218 | */ |
| 161 | 219 | public T setDouble(String name, double v); |
| 162 | 220 | |
| 163 | 221 | /** |
| 164 | 222 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 165 | 223 | * provided string. |
| 224 | + * <p> | |
| 225 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 226 | + * to the underlying CQL type (for CQL types {@code text}, {@code varchar} and {@code ascii}, | |
| 227 | + * this will be the built-in codec). | |
| 166 | 228 | * |
| 167 | 229 | * @param name the name of the value to set; if {@code name} is present multiple |
| 168 | 230 | * times, all its values are set. |
| @@ -170,16 +232,17 @@ | ||
| 170 | 232 | * @return this object. |
| 171 | 233 | * |
| 172 | 234 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 235 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 236 | + * underlying CQL type. | |
| 173 | 237 | */ |
| 174 | 238 | public T setString(String name, String v); |
| 175 | 239 | |
| 176 | 240 | /** |
| 177 | 241 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 178 | 242 | * provided byte buffer. |
| 179 | - * | |
| 180 | - * This method validate that the type of the column set is BLOB. If you | |
| 181 | - * want to insert manually serialized data into columns of another type, | |
| 182 | - * use {@link #setBytesUnsafe} instead. | |
| 243 | + * <p> | |
| 244 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 245 | + * to the underlying CQL type (for CQL type {@code blob}, this will be the built-in codec). | |
| 183 | 246 | * |
| 184 | 247 | * @param name the name of the value to set; if {@code name} is present multiple |
| 185 | 248 | * times, all its values are set. |
| @@ -187,16 +250,17 @@ | ||
| 187 | 250 | * @return this object. |
| 188 | 251 | * |
| 189 | 252 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 253 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 254 | + * underlying CQL type. | |
| 190 | 255 | */ |
| 191 | 256 | public T setBytes(String name, ByteBuffer v); |
| 192 | 257 | |
| 193 | 258 | /** |
| 194 | 259 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 195 | 260 | * provided byte buffer. |
| 196 | - * | |
| 197 | - * Contrary to {@link #setBytes}, this method does not check the | |
| 198 | - * type of the column set. If you insert data that is not compatible with | |
| 199 | - * the type of the column, you will get an {@code InvalidQueryException} at | |
| 261 | + * <p> | |
| 262 | + * This method does not use any codec; it sets the value in its binary form directly. If you insert | |
| 263 | + * data that is not compatible with the underlying CQL type, you will get an {@code InvalidQueryException} at | |
| 200 | 264 | * execute time. |
| 201 | 265 | * |
| 202 | 266 | * @param name the name of the value to set; if {@code name} is present multiple |
| @@ -211,6 +275,9 @@ | ||
| 211 | 275 | /** |
| 212 | 276 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 213 | 277 | * provided big integer. |
| 278 | + * <p> | |
| 279 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 280 | + * to the underlying CQL type (for CQL type {@code varint}, this will be the built-in codec). | |
| 214 | 281 | * |
| 215 | 282 | * @param name the name of the value to set; if {@code name} is present multiple |
| 216 | 283 | * times, all its values are set. |
| @@ -218,12 +285,17 @@ | ||
| 218 | 285 | * @return this object. |
| 219 | 286 | * |
| 220 | 287 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 288 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 289 | + * underlying CQL type. | |
| 221 | 290 | */ |
| 222 | 291 | public T setVarint(String name, BigInteger v); |
| 223 | 292 | |
| 224 | 293 | /** |
| 225 | 294 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 226 | 295 | * provided big decimal. |
| 296 | + * <p> | |
| 297 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 298 | + * to the underlying CQL type (for CQL type {@code decimal}, this will be the built-in codec). | |
| 227 | 299 | * |
| 228 | 300 | * @param name the name of the value to set; if {@code name} is present multiple |
| 229 | 301 | * times, all its values are set. |
| @@ -231,12 +303,18 @@ | ||
| 231 | 303 | * @return this object. |
| 232 | 304 | * |
| 233 | 305 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 306 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 307 | + * underlying CQL type. | |
| 234 | 308 | */ |
| 235 | 309 | public T setDecimal(String name, BigDecimal v); |
| 236 | 310 | |
| 237 | 311 | /** |
| 238 | 312 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 239 | 313 | * provided UUID. |
| 314 | + * <p> | |
| 315 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 316 | + * to the underlying CQL type (for CQL types {@code uuid} and {@code timeuuid}, this will | |
| 317 | + * be the built-in codec). | |
| 240 | 318 | * |
| 241 | 319 | * @param name the name of the value to set; if {@code name} is present multiple |
| 242 | 320 | * times, all its values are set. |
| @@ -244,12 +322,17 @@ | ||
| 244 | 322 | * @return this object. |
| 245 | 323 | * |
| 246 | 324 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 325 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 326 | + * underlying CQL type. | |
| 247 | 327 | */ |
| 248 | 328 | public T setUUID(String name, UUID v); |
| 249 | 329 | |
| 250 | 330 | /** |
| 251 | 331 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 252 | 332 | * provided inet address. |
| 333 | + * <p> | |
| 334 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 335 | + * to the underlying CQL type (for CQL type {@code inet}, this will be the built-in codec). | |
| 253 | 336 | * |
| 254 | 337 | * @param name the name of the value to set; if {@code name} is present multiple |
| 255 | 338 | * times, all its values are set. |
| @@ -257,6 +340,8 @@ | ||
| 257 | 340 | * @return this object. |
| 258 | 341 | * |
| 259 | 342 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 343 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 344 | + * underlying CQL type. | |
| 260 | 345 | */ |
| 261 | 346 | public T setInet(String name, InetAddress v); |
| 262 | 347 | |
| @@ -264,66 +349,64 @@ | ||
| 264 | 349 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 265 | 350 | * provided list. |
| 266 | 351 | * <p> |
| 267 | - * Please note that {@code null} values inside collections are not supported by CQL. | |
| 268 | - * <p> | |
| 269 | - * Note: if two or more codecs are available | |
| 270 | - * for the underlying CQL type, <em>the one that will be used will be | |
| 271 | - * the first one to be registered.</em>. | |
| 272 | - * <p> | |
| 273 | - * For these reasons, it is generally preferable to use the more | |
| 274 | - * deterministic methods {@link #setList(String, List, Class)} or | |
| 275 | - * {@link #setList(String, List, TypeToken)}. | |
| 352 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 353 | + * to the underlying CQL type (the type of the elements in the Java list is not considered). | |
| 354 | + * If two or more codecs target that CQL type, the one that was first registered will be used. | |
| 355 | + * For this reason, it is generally preferable to use the more deterministic methods | |
| 356 | + * {@link #setList(String, List, Class)} or {@link #setList(String, List, TypeToken)}. | |
| 276 | 357 | * |
| 277 | 358 | * @param name the name of the value to set; if {@code name} is present multiple |
| 278 | 359 | * times, all its values are set. |
| 279 | - * @param v the value to set. | |
| 360 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 280 | 361 | * @return this object. |
| 281 | 362 | * |
| 282 | 363 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 283 | 364 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 284 | 365 | * by CQL. |
| 366 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 367 | + * underlying CQL type. | |
| 285 | 368 | */ |
| 286 | 369 | public <E> T setList(String name, List<E> v); |
| 287 | 370 | |
| 288 | 371 | /** |
| 289 | 372 | * Sets the value for (all occurrences of) variable {@code name} to the provided list, |
| 290 | - * whose elements are of the provided Java class. | |
| 373 | + * which elements are of the provided Java class. | |
| 291 | 374 | * <p> |
| 292 | - * Please note that {@code null} values inside collections are not supported by CQL. | |
| 375 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of lists of the given | |
| 376 | + * Java type to the underlying CQL type. | |
| 293 | 377 | * <p> |
| 294 | - * Note about performance: this method is able to cache codecs used to serialize the list elements, | |
| 295 | - * and thus should be used instead of {@link #setList(String, List)} | |
| 296 | - * whenever possible, because it performs significantly better. | |
| 378 | + * If the type of the elements is generic, use {@link #setList(String, List, TypeToken)}. | |
| 297 | 379 | * |
| 298 | 380 | * @param name the name of the value to set; if {@code name} is present multiple |
| 299 | - * @param v the value to set. | |
| 381 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 300 | 382 | * @param elementsClass the class for the elements of the list. |
| 301 | 383 | * @return this object. |
| 302 | 384 | * |
| 303 | 385 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 304 | 386 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 305 | 387 | * by CQL. |
| 388 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 389 | + * underlying CQL type. | |
| 306 | 390 | */ |
| 307 | 391 | public <E> T setList(String name, List<E> v, Class<E> elementsClass); |
| 308 | 392 | |
| 309 | 393 | /** |
| 310 | 394 | * Sets the value for (all occurrences of) variable {@code name} to the provided list, |
| 311 | - * whose elements are of the provided Java type. | |
| 395 | + * which elements are of the provided Java type. | |
| 312 | 396 | * <p> |
| 313 | - * Please note that {@code null} values inside collections are not supported by CQL. | |
| 314 | - * <p> | |
| 315 | - * Note about performance: this method is able to cache codecs used to serialize the list elements, | |
| 316 | - * and thus should be used instead of {@link #setList(String, List)} | |
| 317 | - * whenever possible, because it performs significantly better. | |
| 397 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of lists of the given | |
| 398 | + * Java type to the underlying CQL type. | |
| 318 | 399 | * |
| 319 | 400 | * @param name the name of the value to set; if {@code name} is present multiple |
| 320 | - * @param v the value to set. | |
| 401 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 321 | 402 | * @param elementsType the type for the elements of the list. |
| 322 | 403 | * @return this object. |
| 323 | 404 | * |
| 324 | 405 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 325 | 406 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 326 | 407 | * by CQL. |
| 408 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 409 | + * underlying CQL type. | |
| 327 | 410 | */ |
| 328 | 411 | public <E> T setList(String name, List<E> v, TypeToken<E> elementsType); |
| 329 | 412 | |
| @@ -331,41 +414,37 @@ | ||
| 331 | 414 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 332 | 415 | * provided map. |
| 333 | 416 | * <p> |
| 334 | - * Please note that {@code null} values are not supported inside collection by CQL. | |
| 335 | - * <p> | |
| 336 | - * <p> | |
| 337 | - * Note: if two or more codecs are available | |
| 338 | - * for the underlying CQL type, <em>the one that will be used will be | |
| 339 | - * the first one to be registered.</em>. | |
| 340 | - * <p> | |
| 341 | - * For these reasons, it is generally preferable to use the more | |
| 342 | - * deterministic methods {@link #setMap(String, Map, Class, Class)} or | |
| 343 | - * {@link #setMap(String, Map, TypeToken, TypeToken)}. | |
| 417 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 418 | + * to the underlying CQL type (the type of the elements in the Java map is not considered). | |
| 419 | + * If two or more codecs target that CQL type, the one that was first registered will be used. | |
| 420 | + * For this reason, it is generally preferable to use the more deterministic methods | |
| 421 | + * {@link #setMap(String, Map, Class, Class)} or {@link #setMap(String, Map, TypeToken, TypeToken)}. | |
| 344 | 422 | * |
| 345 | 423 | * @param name the name of the value to set; if {@code name} is present multiple |
| 346 | 424 | * times, all its values are set. |
| 347 | - * @param v the value to set. | |
| 425 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 348 | 426 | * @return this object. |
| 349 | 427 | * |
| 350 | 428 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 351 | 429 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 352 | 430 | * by CQL. |
| 431 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 432 | + * underlying CQL type. | |
| 353 | 433 | */ |
| 354 | 434 | public <K, V> T setMap(String name, Map<K, V> v); |
| 355 | 435 | |
| 356 | 436 | /** |
| 357 | 437 | * Sets the value for (all occurrences of) variable {@code name} to the provided map, |
| 358 | - * whose keys and values are of the provided Java classes. | |
| 438 | + * which keys and values are of the provided Java classes. | |
| 359 | 439 | * <p> |
| 360 | - * Please note that {@code null} values inside collections are not supported by CQL. | |
| 440 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of lists of the given | |
| 441 | + * Java types to the underlying CQL type. | |
| 361 | 442 | * <p> |
| 362 | - * Note about performance: this method is able to cache codecs used to serialize the map entries, | |
| 363 | - * and thus should be used instead of {@link #setMap(String, Map)} | |
| 364 | - * whenever possible, because it performs significantly better. | |
| 443 | + * If the type of the keys or values is generic, use {@link #setMap(String, Map, TypeToken, TypeToken)}. | |
| 365 | 444 | * |
| 366 | 445 | * @param name the name of the value to set; if {@code name} is present multiple |
| 367 | 446 | * times, all its values are set. |
| 368 | - * @param v the value to set. | |
| 447 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 369 | 448 | * @param keysClass the class for the keys of the map. |
| 370 | 449 | * @param valuesClass the class for the values of the map. |
| 371 | 450 | * @return this object. |
| @@ -373,22 +452,21 @@ | ||
| 373 | 452 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 374 | 453 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 375 | 454 | * by CQL. |
| 455 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 456 | + * underlying CQL type. | |
| 376 | 457 | */ |
| 377 | 458 | public <K, V> T setMap(String name, Map<K, V> v, Class<K> keysClass, Class<V> valuesClass); |
| 378 | 459 | |
| 379 | 460 | /** |
| 380 | 461 | * Sets the value for (all occurrences of) variable {@code name} to the provided map, |
| 381 | - * whose keys and values are of the provided Java types. | |
| 462 | + * which keys and values are of the provided Java types. | |
| 382 | 463 | * <p> |
| 383 | - * Please note that {@code null} values inside collections are not supported by CQL. | |
| 384 | - * <p> | |
| 385 | - * Note about performance: this method is able to cache codecs used to serialize the map entries, | |
| 386 | - * and thus should be used instead of {@link #setMap(String, Map)} | |
| 387 | - * whenever possible, because it performs significantly better. | |
| 464 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of lists of the given | |
| 465 | + * Java types to the underlying CQL type. | |
| 388 | 466 | * |
| 389 | 467 | * @param name the name of the value to set; if {@code name} is present multiple |
| 390 | 468 | * times, all its values are set. |
| 391 | - * @param v the value to set. | |
| 469 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 392 | 470 | * @param keysType the type for the keys of the map. |
| 393 | 471 | * @param valuesType the type for the values of the map. |
| 394 | 472 | * @return this object. |
| @@ -396,6 +474,8 @@ | ||
| 396 | 474 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 397 | 475 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 398 | 476 | * by CQL. |
| 477 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 478 | + * underlying CQL type. | |
| 399 | 479 | */ |
| 400 | 480 | public <K, V> T setMap(String name, Map<K, V> v, TypeToken<K> keysType, TypeToken<V> valuesType); |
| 401 | 481 | |
| @@ -403,72 +483,73 @@ | ||
| 403 | 483 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 404 | 484 | * provided set. |
| 405 | 485 | * <p> |
| 406 | - * Please note that {@code null} values are not supported inside collection by CQL. | |
| 407 | - * <p> | |
| 408 | - * Note: if two or more codecs are available | |
| 409 | - * for the underlying CQL type, <em>the one that will be used will be | |
| 410 | - * the first one to be registered.</em>. | |
| 411 | - * <p> | |
| 412 | - * For these reasons, it is generally preferable to use the more | |
| 413 | - * deterministic methods {@link #setSet(String, Set, Class)} or | |
| 414 | - * {@link #setSet(String, Set, TypeToken)}. | |
| 486 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion | |
| 487 | + * to the underlying CQL type (the type of the elements in the Java set is not considered). | |
| 488 | + * If two or more codecs target that CQL type, the one that was first registered will be used. | |
| 489 | + * For this reason, it is generally preferable to use the more deterministic methods | |
| 490 | + * {@link #setSet(String, Set, Class)} or {@link #setSet(String, Set, TypeToken)}. | |
| 415 | 491 | * |
| 416 | 492 | * @param name the name of the value to set; if {@code name} is present multiple |
| 417 | 493 | * times, all its values are set. |
| 418 | - * @param v the value to set. | |
| 494 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 419 | 495 | * @return this object. |
| 420 | 496 | * |
| 421 | 497 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 422 | 498 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 423 | 499 | * by CQL. |
| 500 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 501 | + * underlying CQL type. | |
| 424 | 502 | */ |
| 425 | 503 | public <E> T setSet(String name, Set<E> v); |
| 426 | 504 | |
| 427 | 505 | /** |
| 428 | 506 | * Sets the value for (all occurrences of) variable {@code name} to the provided set, |
| 429 | - * whose elements are of the provided Java class. | |
| 507 | + * which elements are of the provided Java class. | |
| 430 | 508 | * <p> |
| 431 | - * Please note that {@code null} values inside collections are not supported by CQL. | |
| 509 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of sets of the given | |
| 510 | + * Java type to the underlying CQL type. | |
| 432 | 511 | * <p> |
| 433 | - * Note about performance: this method is able to cache codecs used to serialize the set elements, | |
| 434 | - * and thus should be used instead of {@link #setSet(String, Set)} | |
| 435 | - * whenever possible, because it performs significantly better. | |
| 512 | + * If the type of the elements is generic, use {@link #setSet(String, Set, TypeToken)}. | |
| 436 | 513 | * |
| 437 | 514 | * @param name the name of the value to set; if {@code name} is present multiple |
| 438 | - * @param v the value to set. | |
| 515 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 439 | 516 | * @param elementsClass the class for the elements of the set. |
| 440 | 517 | * @return this object. |
| 441 | 518 | * |
| 442 | 519 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 443 | 520 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 444 | 521 | * by CQL. |
| 522 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 523 | + * underlying CQL type. | |
| 445 | 524 | */ |
| 446 | 525 | public <E> T setSet(String name, Set<E> v, Class<E> elementsClass); |
| 447 | 526 | |
| 448 | 527 | /** |
| 449 | 528 | * Sets the value for (all occurrences of) variable {@code name} to the provided set, |
| 450 | - * whose elements are of the provided Java type. | |
| 529 | + * which elements are of the provided Java type. | |
| 451 | 530 | * <p> |
| 452 | - * Please note that {@code null} values inside collections are not supported by CQL. | |
| 453 | - * <p> | |
| 454 | - * Note about performance: this method is able to cache codecs used to serialize the set elements, | |
| 455 | - * and thus should be used instead of {@link #setSet(String, Set)} | |
| 456 | - * whenever possible, because it performs significantly better. | |
| 531 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of sets of the given | |
| 532 | + * Java type to the underlying CQL type. | |
| 457 | 533 | * |
| 458 | 534 | * @param name the name of the value to set; if {@code name} is present multiple |
| 459 | - * @param v the value to set. | |
| 535 | + * @param v the value to set. Note that {@code null} values inside collections are not supported by CQL. | |
| 460 | 536 | * @param elementsType the type for the elements of the set. |
| 461 | 537 | * @return this object. |
| 462 | 538 | * |
| 463 | 539 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 464 | 540 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 465 | 541 | * by CQL. |
| 542 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 543 | + * underlying CQL type. | |
| 466 | 544 | */ |
| 467 | 545 | public <E> T setSet(String name, Set<E> v, TypeToken<E> elementsType); |
| 468 | 546 | |
| 469 | 547 | /** |
| 470 | 548 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 471 | 549 | * provided UDT value. |
| 550 | + * <p> | |
| 551 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of {@code UDTValue} | |
| 552 | + * to the underlying CQL type. | |
| 472 | 553 | * |
| 473 | 554 | * @param name the name of the value to set; if {@code name} is present multiple |
| 474 | 555 | * times, all its values are set. |
| @@ -476,12 +557,17 @@ | ||
| 476 | 557 | * @return this object. |
| 477 | 558 | * |
| 478 | 559 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 560 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 561 | + * underlying CQL type. | |
| 479 | 562 | */ |
| 480 | 563 | public T setUDTValue(String name, UDTValue v); |
| 481 | 564 | |
| 482 | 565 | /** |
| 483 | 566 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 484 | 567 | * provided tuple value. |
| 568 | + * <p> | |
| 569 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of {@code TupleValue} | |
| 570 | + * to the underlying CQL type. | |
| 485 | 571 | * |
| 486 | 572 | * @param name the name of the value to set; if {@code name} is present multiple |
| 487 | 573 | * times, all its values are set. |
| @@ -489,6 +575,8 @@ | ||
| 489 | 575 | * @return this object. |
| 490 | 576 | * |
| 491 | 577 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 578 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 579 | + * underlying CQL type. | |
| 492 | 580 | */ |
| 493 | 581 | public T setTupleValue(String name, TupleValue v); |
| 494 | 582 | |
| @@ -507,8 +595,10 @@ | ||
| 507 | 595 | /** |
| 508 | 596 | * Sets the value for (all occurrences of) variable {@code name} to the provided value of the provided Java class. |
| 509 | 597 | * <p> |
| 510 | - * A suitable {@link TypeCodec} instance for the underlying CQL type and the provided class must | |
| 511 | - * have been previously registered with the {@link CodecRegistry} currently in use. | |
| 598 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of the provided Java class | |
| 599 | + * to the underlying CQL type. | |
| 600 | + * <p> | |
| 601 | + * If the Java type is generic, use {@link #set(String, Object, TypeToken)} instead. | |
| 512 | 602 | * |
| 513 | 603 | * @param name the name of the value to set; if {@code name} is present multiple |
| 514 | 604 | * times, all its values are set. |
| @@ -516,14 +606,16 @@ | ||
| 516 | 606 | * @param targetClass The Java class to convert to; must not be {@code null}; |
| 517 | 607 | * @return this object. |
| 518 | 608 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 609 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 610 | + * underlying CQL type. | |
| 519 | 611 | */ |
| 520 | 612 | <V> T set(String name, V v, Class<V> targetClass); |
| 521 | 613 | |
| 522 | 614 | /** |
| 523 | 615 | * Sets the value for (all occurrences of) variable {@code name} to the provided value of the provided Java type. |
| 524 | 616 | * <p> |
| 525 | - * A suitable {@link TypeCodec} instance for the underlying CQL type and the provided class must | |
| 526 | - * have been previously registered with the {@link CodecRegistry} currently in use. | |
| 617 | + * This method uses the {@link CodecRegistry} to find a codec to handle the conversion of the provided Java type | |
| 618 | + * to the underlying CQL type. | |
| 527 | 619 | * |
| 528 | 620 | * @param name the name of the value to set; if {@code name} is present multiple |
| 529 | 621 | * times, all its values are set. |
| @@ -531,6 +623,8 @@ | ||
| 531 | 623 | * @param targetType The Java type to convert to; must not be {@code null}; |
| 532 | 624 | * @return this object. |
| 533 | 625 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 626 | + * @throws CodecNotFoundException if there is no registered codec to convert the value to the | |
| 627 | + * underlying CQL type. | |
| 534 | 628 | */ |
| 535 | 629 | <V> T set(String name, V v, TypeToken<V> targetType); |
| 536 | 630 | |
| @@ -538,8 +632,9 @@ | ||
| 538 | 632 | * Sets the value for (all occurrences of) variable {@code name} to the provided value, |
| 539 | 633 | * converted using the given {@link TypeCodec}. |
| 540 | 634 | * <p> |
| 541 | - * Note that this method allows to entirely bypass the {@link CodecRegistry} currently in use | |
| 542 | - * and forces the driver to use the given codec instead. | |
| 635 | + * This method entirely bypasses the {@link CodecRegistry} and forces the driver to use the given codec instead. | |
| 636 | + * This can be useful if the codec would collide with a previously registered one, or if you want to use the | |
| 637 | + * codec just once without registering it. | |
| 543 | 638 | * <p> |
| 544 | 639 | * It is the caller's responsibility to ensure that the given codec {@link TypeCodec#accepts(DataType) accepts} |
| 545 | 640 | * the underlying CQL type; failing to do so may result in {@link InvalidTypeException}s being thrown. |