Elffuss BraidHub

kikocis/java-driver public

JAVA-922: Make TypeCodec return mutable collections.

This commit relaxes the postconditions on immutability stated in the javadocs for some methods in these classes.
This commit also updates the javadocs of GettableByIndexData and GettableByNameData accordingly.
It also prunes Row class and removes all duplicated method declarations.
The Upgrade guide is updated with behavioral changes introduced by this commit.
Changeset0788d958beb962a51db38d2394c1c1645ff063ebab212a433b522769edacac3f
AuthorAlexandre Dutra <alexandre.dutra@datastax.com> · 2015-09-30 15:37 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2015-10-14 22:35 +02:00
Parents16505233fda0

Browse the files at this changeset

6 files changed

modified changelog/README.md +1 −0
@@ -11,6 +11,7 @@
1111 - [new feature] Add BoundStatement#unset (JAVA-930)
1212 - [bug] Make table metadata options class visible (JAVA-946)
1313 - [bug] Add crcCheckChance to TableOptionsMetadata#equals/hashCode (JAVA-939)
14+- [bug] Make TypeCodec return mutable collections (JAVA-922)
1415
1516
1617 ### 3.0.0-alpha3
modified driver-core/src/main/java/com/datastax/driver/core/GettableByIndexData.java +82 −27
@@ -258,13 +258,19 @@
258258 * Returns the {@code i}th value as a list.
259259 * <p>
260260 * If the type of the elements is generic, use {@link #getList(int, TypeToken)}.
261+ * <p>
262+ * Implementation note: the actual {@link List} implementation will depend
263+ * on the {@link TypeCodec codec} being used; therefore, callers should
264+ * make no assumptions concerning its mutability nor its thread-safety.
265+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
266+ * codec-dependent. By default, the driver will return mutable instances, and
267+ * a CQL {@code NULL} will mapped to an empty collection (note that Cassandra
268+ * makes no distinction between {@code NULL} and an empty collection).
261269 *
262270 * @param i the index ({@code 0 <= i < size()}) to retrieve.
263271 * @param elementsClass the class for the elements of the list to retrieve.
264272 * @return the value of the {@code i}th element as a list of
265- * {@code T} objects. If the value is NULL, an empty list is
266- * returned (note that Cassandra makes no difference between an empty list
267- * and column of type list that is not set). The returned list is immutable.
273+ * {@code T} objects.
268274 *
269275 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
270276 * @throws InvalidTypeException if value {@code i} is not a list or if its
@@ -279,13 +285,19 @@
279285 * <pre>
280286 * {@code List<List<String>> l = row.getList(1, new TypeToken<List<String>>() {});}
281287 * </pre>
288+ * <p>
289+ * Implementation note: the actual {@link List} implementation will depend
290+ * on the {@link TypeCodec codec} being used; therefore, callers should
291+ * make no assumptions concerning its mutability nor its thread-safety.
292+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
293+ * codec-dependent. By default, the driver will return mutable instances, and
294+ * a CQL {@code NULL} will mapped to an empty collection (note that Cassandra
295+ * makes no distinction between {@code NULL} and an empty collection).
282296 *
283297 * @param i the index ({@code 0 <= i < size()}) to retrieve.
284298 * @param elementsType the type of the elements of the list to retrieve.
285299 * @return the value of the {@code i}th element as a list of
286- * {@code T} objects. If the value is NULL, an empty list is
287- * returned (note that Cassandra makes no difference between an empty list
288- * and column of type list that is not set). The returned list is immutable.
300+ * {@code T} objects.
289301 *
290302 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
291303 * @throws InvalidTypeException if value {@code i} is not a list or if its
@@ -297,13 +309,19 @@
297309 * Returns the {@code i}th value as a set.
298310 * <p>
299311 * If the type of the elements is generic, use {@link #getSet(int, TypeToken)}.
312+ * <p>
313+ * Implementation note: the actual {@link Set} implementation will depend
314+ * on the {@link TypeCodec codec} being used; therefore, callers should
315+ * make no assumptions concerning its mutability nor its thread-safety.
316+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
317+ * codec-dependent. By default, the driver will return mutable instances, and
318+ * a CQL {@code NULL} will mapped to an empty collection (note that Cassandra
319+ * makes no distinction between {@code NULL} and an empty collection).
300320 *
301321 * @param i the index ({@code 0 <= i < size()}) to retrieve.
302322 * @param elementsClass the class for the elements of the set to retrieve.
303323 * @return the value of the {@code i}th element as a set of
304- * {@code T} objects. If the value is NULL, an empty set is
305- * returned (note that Cassandra makes no difference between an empty set
306- * and column of type set that is not set). The returned set is immutable.
324+ * {@code T} objects.
307325 *
308326 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
309327 * @throws InvalidTypeException if value {@code i} is not a set or if its
@@ -318,13 +336,19 @@
318336 * <pre>
319337 * {@code Set<List<String>> l = row.getSet(1, new TypeToken<List<String>>() {});}
320338 * </pre>
339+ * <p>
340+ * Implementation note: the actual {@link Set} implementation will depend
341+ * on the {@link TypeCodec codec} being used; therefore, callers should
342+ * make no assumptions concerning its mutability nor its thread-safety.
343+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
344+ * codec-dependent. By default, the driver will return mutable instances, and
345+ * a CQL {@code NULL} will mapped to an empty collection (note that Cassandra
346+ * makes no distinction between {@code NULL} and an empty collection).
321347 *
322348 * @param i the index ({@code 0 <= i < size()}) to retrieve.
323349 * @param elementsType the type for the elements of the set to retrieve.
324350 * @return the value of the {@code i}th element as a set of
325- * {@code T} objects. If the value is NULL, an empty set is
326- * returned (note that Cassandra makes no difference between an empty set
327- * and column of type set that is not set). The returned set is immutable.
351+ * {@code T} objects.
328352 *
329353 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
330354 * @throws InvalidTypeException if value {@code i} is not a set or if its
@@ -336,15 +360,20 @@
336360 * Returns the {@code i}th value as a map.
337361 * <p>
338362 * If the type of the keys and/or values is generic, use {@link #getMap(int, TypeToken, TypeToken)}.
363+ * <p>
364+ * Implementation note: the actual {@link Map} implementation will depend
365+ * on the {@link TypeCodec codec} being used; therefore, callers should
366+ * make no assumptions concerning its mutability nor its thread-safety.
367+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
368+ * codec-dependent. By default, the driver will return mutable instances, and
369+ * a CQL {@code NULL} will mapped to an empty collection (note that Cassandra
370+ * makes no distinction between {@code NULL} and an empty collection).
339371 *
340372 * @param i the index ({@code 0 <= i < size()}) to retrieve.
341373 * @param keysClass the class for the keys of the map to retrieve.
342374 * @param valuesClass the class for the values of the map to retrieve.
343375 * @return the value of the {@code i}th element as a map of
344- * {@code K} to {@code V} objects. If the value is NULL,
345- * an empty map is returned (note that Cassandra makes no difference
346- * between an empty map and column of type map that is not set). The
347- * returned map is immutable.
376+ * {@code K} to {@code V} objects.
348377 *
349378 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
350379 * @throws InvalidTypeException if value {@code i} is not a map, if its
@@ -361,15 +390,20 @@
361390 * <pre>
362391 * {@code Map<Int, List<String>> l = row.getMap(1, TypeToken.of(Integer.class), new TypeToken<List<String>>() {});}
363392 * </pre>
393+ * <p>
394+ * Implementation note: the actual {@link Map} implementation will depend
395+ * on the {@link TypeCodec codec} being used; therefore, callers should
396+ * make no assumptions concerning its mutability nor its thread-safety.
397+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
398+ * codec-dependent. By default, the driver will return mutable instances, and
399+ * a CQL {@code NULL} will mapped to an empty collection (note that Cassandra
400+ * makes no distinction between {@code NULL} and an empty collection).
364401 *
365402 * @param i the index ({@code 0 <= i < size()}) to retrieve.
366403 * @param keysType the type for the keys of the map to retrieve.
367404 * @param valuesType the type for the values of the map to retrieve.
368405 * @return the value of the {@code i}th element as a map of
369- * {@code K} to {@code V} objects. If the value is NULL,
370- * an empty map is returned (note that Cassandra makes no difference
371- * between an empty map and column of type map that is not set). The
372- * returned map is immutable.
406+ * {@code K} to {@code V} objects.
373407 *
374408 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
375409 * @throws InvalidTypeException if value {@code i} is not a map, if its
@@ -411,12 +445,16 @@
411445 * If a second, custom codec for the same CQL type is registered, which one will
412446 * be used is unspecified; in such cases, it is preferable to use
413447 * the more deterministic methods {@link #get(int, Class)} or {@link #get(int, TypeToken)} instead.
448+ * <p>
449+ * Implementation note: the actual object returned by this method will depend
450+ * on the {@link TypeCodec codec} being used; therefore, callers should
451+ * make no assumptions concerning its mutability nor its thread-safety.
452+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
453+ * codec-dependent; by default, a CQL {@code NULL} value translates to {@code null} for
454+ * simple types, UDTs and tuples, and to empty collections for all CQL collection types.
414455 *
415456 * @param i the index to retrieve.
416457 * @return the value of the {@code i}th value as the Java type matching its CQL type.
417- * If the value is NULL and is a simple type, UDT or tuple, {@code null} is returned.
418- * If it is NULL and is a collection type, an empty (immutable) collection is returned.
419- *
420458 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
421459 */
422460 public Object getObject(int i);
@@ -431,12 +469,17 @@
431469 * where more than one codec is registered for the same CQL type; specifying the Java class
432470 * allows the {@link CodecRegistry} to narrow down the search and return only an exactly-matching codec (if any),
433471 * thus avoiding any risk of ambiguity.
472+ * <p>
473+ * Implementation note: the actual object returned by this method will depend
474+ * on the {@link TypeCodec codec} being used; therefore, callers should
475+ * make no assumptions concerning its mutability nor its thread-safety.
476+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
477+ * codec-dependent; by default, a CQL {@code NULL} value translates to {@code null} for
478+ * simple CQL types, UDTs and tuples, and to empty collections for all CQL collection types.
434479 *
435480 * @param i the index to retrieve.
436481 * @param targetClass The Java type the value should be converted to.
437482 * @return the value of the {@code i}th value converted to the given Java type.
438- * If the CQL value is {@code NULL}, this method will return {@code null}
439- * for a simple type, UDT or tuple, and an empty (immutable) collection for collection types.
440483 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
441484 * @throws com.datastax.driver.core.exceptions.CodecNotFoundException
442485 * if no {@link TypeCodec} instance for {@code targetClass} could be found
@@ -454,12 +497,17 @@
454497 * where more than one codec is registered for the same CQL type; specifying the Java class
455498 * allows the {@link CodecRegistry} to narrow down the search and return only an exactly-matching codec (if any),
456499 * thus avoiding any risk of ambiguity.
500+ * <p>
501+ * Implementation note: the actual object returned by this method will depend
502+ * on the {@link TypeCodec codec} being used; therefore, callers should
503+ * make no assumptions concerning its mutability nor its thread-safety.
504+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
505+ * codec-dependent; by default, a CQL {@code NULL} value translates to {@code null} for
506+ * simple CQL types, UDTs and tuples, and to empty collections for all CQL collection types.
457507 *
458508 * @param i the index to retrieve.
459509 * @param targetType The Java type the value should be converted to.
460510 * @return the value of the {@code i}th value converted to the given Java type.
461- * If the CQL value is {@code NULL}, the default set of codecs will return {@code null}
462- * for a simple type, UDT or tuple, and an empty (immutable) collection for collection types.
463511 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
464512 * @throws com.datastax.driver.core.exceptions.CodecNotFoundException
465513 * if no {@link TypeCodec} instance for {@code targetType} could be found
@@ -475,6 +523,13 @@
475523 * <p>
476524 * It is the caller's responsibility to ensure that the given codec {@link TypeCodec#accepts(DataType) accepts}
477525 * the underlying CQL type; failing to do so may result in {@link InvalidTypeException}s being thrown.
526+ * <p>
527+ * Implementation note: the actual object returned by this method will depend
528+ * on the {@link TypeCodec codec} being used; therefore, callers should
529+ * make no assumptions concerning its mutability nor its thread-safety.
530+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
531+ * codec-dependent; by default, a CQL {@code NULL} value translates to {@code null} for
532+ * simple CQL types, UDTs and tuples, and to empty collections for all CQL collection types.
478533 *
479534 * @param i the index to retrieve.
480535 * @param codec The {@link TypeCodec} to use to deserialize the value; may not be {@code null}.
modified driver-core/src/main/java/com/datastax/driver/core/GettableByNameData.java +82 −24
@@ -258,13 +258,19 @@
258258 * Returns the value for {@code name} as a list.
259259 * <p>
260260 * If the type of the elements is generic, use {@link #getList(String, TypeToken)}.
261+ * <p>
262+ * Implementation note: the actual {@link List} implementation will depend
263+ * on the {@link TypeCodec codec} being used; therefore, callers should
264+ * make no assumptions concerning its mutability nor its thread-safety.
265+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
266+ * codec-dependent. By default, the driver will return mutable instances, and
267+ * a CQL {@code NULL} will mapped to an empty collection (note that Cassandra
268+ * makes no distinction between {@code NULL} and an empty collection).
261269 *
262270 * @param name the name to retrieve.
263271 * @param elementsClass the class for the elements of the list to retrieve.
264272 * @return the value of the {@code i}th element as a list of
265- * {@code T} objects. If the value is NULL, an empty list is
266- * returned (note that Cassandra makes no difference between an empty list
267- * and column of type list that is not set). The returned list is immutable.
273+ * {@code T} objects.
268274 *
269275 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
270276 * @throws InvalidTypeException if value {@code name} is not a list or if its
@@ -279,13 +285,19 @@
279285 * <pre>
280286 * {@code List<List<String>> l = row.getList("theColumn", new TypeToken<List<String>>() {});}
281287 * </pre>
288+ * <p>
289+ * Implementation note: the actual {@link List} implementation will depend
290+ * on the {@link TypeCodec codec} being used; therefore, callers should
291+ * make no assumptions concerning its mutability nor its thread-safety.
292+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
293+ * codec-dependent. By default, the driver will return mutable instances, and
294+ * a CQL {@code NULL} will mapped to an empty collection (note that Cassandra
295+ * makes no distinction between {@code NULL} and an empty collection).
282296 *
283297 * @param name the name to retrieve.
284298 * @param elementsType the type for the elements of the list to retrieve.
285299 * @return the value of the {@code i}th element as a list of
286- * {@code T} objects. If the value is NULL, an empty list is
287- * returned (note that Cassandra makes no difference between an empty list
288- * and column of type list that is not set). The returned list is immutable.
300+ * {@code T} objects.
289301 *
290302 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
291303 * @throws InvalidTypeException if value {@code name} is not a list or if its
@@ -297,13 +309,19 @@
297309 * Returns the value for {@code name} as a set.
298310 * <p>
299311 * If the type of the elements is generic, use {@link #getSet(String, TypeToken)}.
312+ * <p>
313+ * Implementation note: the actual {@link Set} implementation will depend
314+ * on the {@link TypeCodec codec} being used; therefore, callers should
315+ * make no assumptions concerning its mutability nor its thread-safety.
316+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
317+ * codec-dependent. By default, the driver will return mutable instances, and
318+ * a CQL {@code NULL} will mapped to an empty collection (note that Cassandra
319+ * makes no distinction between {@code NULL} and an empty collection).
300320 *
301321 * @param name the name to retrieve.
302322 * @param elementsClass the class for the elements of the set to retrieve.
303323 * @return the value of the {@code i}th element as a set of
304- * {@code T} objects. If the value is NULL, an empty set is
305- * returned (note that Cassandra makes no difference between an empty set
306- * and column of type set that is not set). The returned set is immutable.
324+ * {@code T} objects.
307325 *
308326 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
309327 * @throws InvalidTypeException if value {@code name} is not a set or if its
@@ -318,13 +336,19 @@
318336 * <pre>
319337 * {@code Set<List<String>> l = row.getSet("theColumn", new TypeToken<List<String>>() {});}
320338 * </pre>
339+ * <p>
340+ * Implementation note: the actual {@link Set} implementation will depend
341+ * on the {@link TypeCodec codec} being used; therefore, callers should
342+ * make no assumptions concerning its mutability nor its thread-safety.
343+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
344+ * codec-dependent. By default, the driver will return mutable instances, and
345+ * a CQL {@code NULL} will mapped to an empty collection (note that Cassandra
346+ * makes no distinction between {@code NULL} and an empty collection).
321347 *
322348 * @param name the name to retrieve.
323349 * @param elementsType the type for the elements of the set to retrieve.
324350 * @return the value of the {@code i}th element as a set of
325- * {@code T} objects. If the value is NULL, an empty set is
326- * returned (note that Cassandra makes no difference between an empty set
327- * and column of type set that is not set). The returned set is immutable.
351+ * {@code T} objects.
328352 *
329353 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
330354 * @throws InvalidTypeException if value {@code name} is not a set or if its
@@ -336,15 +360,20 @@
336360 * Returns the value for {@code name} as a map.
337361 * <p>
338362 * If the type of the keys and/or values is generic, use {@link #getMap(String, TypeToken, TypeToken)}.
363+ * <p>
364+ * Implementation note: the actual {@link Map} implementation will depend
365+ * on the {@link TypeCodec codec} being used; therefore, callers should
366+ * make no assumptions concerning its mutability nor its thread-safety.
367+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
368+ * codec-dependent. By default, the driver will return mutable instances, and
369+ * a CQL {@code NULL} will mapped to an empty collection (note that Cassandra
370+ * makes no distinction between {@code NULL} and an empty collection).
339371 *
340372 * @param name the name to retrieve.
341373 * @param keysClass the class for the keys of the map to retrieve.
342374 * @param valuesClass the class for the values of the map to retrieve.
343375 * @return the value of {@code name} as a map of
344- * {@code K} to {@code V} objects. If the value is NULL,
345- * an empty map is returned (note that Cassandra makes no difference
346- * between an empty map and column of type map that is not set). The
347- * returned map is immutable.
376+ * {@code K} to {@code V} objects.
348377 *
349378 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
350379 * @throws InvalidTypeException if value {@code name} is not a map, if its
@@ -360,15 +389,20 @@
360389 * <pre>
361390 * {@code Map<Int, List<String>> l = row.getMap("theColumn", TypeToken.of(Integer.class), new TypeToken<List<String>>() {});}
362391 * </pre>
392+ * <p>
393+ * Implementation note: the actual {@link Map} implementation will depend
394+ * on the {@link TypeCodec codec} being used; therefore, callers should
395+ * make no assumptions concerning its mutability nor its thread-safety.
396+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
397+ * codec-dependent. By default, the driver will return mutable instances, and
398+ * a CQL {@code NULL} will mapped to an empty collection (note that Cassandra
399+ * makes no distinction between {@code NULL} and an empty collection).
363400 *
364401 * @param name the name to retrieve.
365402 * @param keysType the class for the keys of the map to retrieve.
366403 * @param valuesType the class for the values of the map to retrieve.
367404 * @return the value of {@code name} as a map of
368- * {@code K} to {@code V} objects. If the value is NULL,
369- * an empty map is returned (note that Cassandra makes no difference
370- * between an empty map and column of type map that is not set). The
371- * returned map is immutable.
405+ * {@code K} to {@code V} objects.
372406 *
373407 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
374408 * @throws InvalidTypeException if value {@code name} is not a map, if its
@@ -410,11 +444,16 @@
410444 * If a second, custom codec for the same CQL type is registered, which one will
411445 * be used is unspecified; in such cases, it is preferable to use
412446 * the more deterministic methods {@link #get(String, Class)} or {@link #get(String, TypeToken)} instead.
447+ * <p>
448+ * Implementation note: the actual object returned by this method will depend
449+ * on the {@link TypeCodec codec} being used; therefore, callers should
450+ * make no assumptions concerning its mutability nor its thread-safety.
451+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
452+ * codec-dependent; by default, a CQL {@code NULL} value translates to {@code null} for
453+ * simple CQL types, UDTs and tuples, and to empty collections for all CQL collection types.
413454 *
414455 * @param name the name to retrieve.
415456 * @return the value of the {@code i}th value as the Java type matching its CQL type.
416- * If the value is NULL and is a simple type, UDT or tuple, {@code null} is returned.
417- * If it is NULL and is a collection type, an empty (immutable) collection is returned.
418457 *
419458 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
420459 */
@@ -430,11 +469,17 @@
430469 * where more than one codec is registered for the same CQL type; specifying the Java class
431470 * allows the {@link CodecRegistry} to narrow down the search and return only an exactly-matching codec (if any),
432471 * thus avoiding any risk of ambiguity.
472+ * <p>
473+ * Implementation note: the actual object returned by this method will depend
474+ * on the {@link TypeCodec codec} being used; therefore, callers should
475+ * make no assumptions concerning its mutability nor its thread-safety.
476+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
477+ * codec-dependent; by default, a CQL {@code NULL} value translates to {@code null} for
478+ * simple CQL types, UDTs and tuples, and to empty collections for all CQL collection types.
433479 *
434480 * @param name the name to retrieve.
435481 * @param targetClass The Java type the value should be converted to.
436482 * @return the value for {@code name} value converted to the given Java type.
437- * If the CQL value is {@code NULL}, then {@code null} is returned.
438483 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
439484 * @throws com.datastax.driver.core.exceptions.CodecNotFoundException
440485 * if no {@link TypeCodec} instance for {@code targetClass} could be found
@@ -452,11 +497,17 @@
452497 * where more than one codec is registered for the same CQL type; specifying the Java class
453498 * allows the {@link CodecRegistry} to narrow down the search and return only an exactly-matching codec (if any),
454499 * thus avoiding any risk of ambiguity.
500+ * <p>
501+ * Implementation note: the actual object returned by this method will depend
502+ * on the {@link TypeCodec codec} being used; therefore, callers should
503+ * make no assumptions concerning its mutability nor its thread-safety.
504+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
505+ * codec-dependent; by default, a CQL {@code NULL} value translates to {@code null} for
506+ * simple CQL types, UDTs and tuples, and to empty collections for all CQL collection types.
455507 *
456508 * @param name the name to retrieve.
457509 * @param targetType The Java type the value should be converted to.
458510 * @return the value for {@code name} value converted to the given Java type.
459- * If the CQL value is {@code NULL}, then {@code null} is returned.
460511 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
461512 * @throws com.datastax.driver.core.exceptions.CodecNotFoundException
462513 * if no {@link TypeCodec} instance for {@code targetType} could be found
@@ -472,6 +523,13 @@
472523 * <p>
473524 * It is the caller's responsibility to ensure that the given codec {@link TypeCodec#accepts(DataType) accepts}
474525 * the underlying CQL type; failing to do so may result in {@link InvalidTypeException}s being thrown.
526+ * <p>
527+ * Implementation note: the actual object returned by this method will depend
528+ * on the {@link TypeCodec codec} being used; therefore, callers should
529+ * make no assumptions concerning its mutability nor its thread-safety.
530+ * Furthermore, the behavior of this method in respect to CQL {@code NULL} values is also
531+ * codec-dependent; by default, a CQL {@code NULL} value translates to {@code null} for
532+ * simple CQL types, UDTs and tuples, and to empty collections for all CQL collection types.
475533 *
476534 * @param name the name to retrieve.
477535 * @param codec The {@link TypeCodec} to use to deserialize the value; may not be {@code null}.
modified driver-core/src/main/java/com/datastax/driver/core/Row.java +0 −624
@@ -15,12 +15,6 @@
1515 */
1616 package com.datastax.driver.core;
1717
18-import java.math.BigDecimal;
19-import java.math.BigInteger;
20-import java.net.InetAddress;
21-import java.nio.ByteBuffer;
22-import java.util.*;
23-
2418 import com.datastax.driver.core.exceptions.InvalidTypeException;
2519
2620 /**
@@ -31,7 +25,6 @@
3125 * rules explained in {@link ColumnDefinitions}.
3226 */
3327 public interface Row extends GettableData {
34- // Note that we re-include all the methods of GettableData just for the sake of better javadoc
3528
3629 /**
3730 * Returns the columns contained in this Row.
@@ -40,505 +33,6 @@
4033 */
4134 public ColumnDefinitions getColumnDefinitions();
4235
43- /**
44- * Returns whether the {@code i}th value of this row is NULL.
45- *
46- * @param i the index ({@code 0 <= i < size()}) of the column to check.
47- * @return whether the {@code i}th value of this row is NULL.
48- *
49- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
50- */
51- @Override
52- public boolean isNull(int i);
53-
54- /**
55- * Returns whether the value for column {@code name} in this row is NULL.
56- *
57- * @param name the name of the column to check.
58- * @return whether the value of column {@code name} is NULL.
59- *
60- * @throws IllegalArgumentException if {@code name} is not part of the
61- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
62- */
63- @Override
64- public boolean isNull(String name);
65-
66- /**
67- * Returns the {@code i}th value of this row as a boolean.
68- *
69- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
70- * @return the boolean value of the {@code i}th column in this row. If the
71- * value is NULL, {@code false} is returned.
72- *
73- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
74- * @throws InvalidTypeException if column {@code i} is not of type BOOLEAN.
75- */
76- @Override
77- public boolean getBool(int i);
78-
79- /**
80- * Returns the value of column {@code name} as a boolean.
81- *
82- * @param name the name of the column to retrieve.
83- * @return the boolean value of column {@code name}. If the value is NULL,
84- * {@code false} is returned.
85- *
86- * @throws IllegalArgumentException if {@code name} is not part of the
87- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
88- * @throws InvalidTypeException if column {@code name} is not of type BOOLEAN.
89- */
90- @Override
91- public boolean getBool(String name);
92-
93- /**
94- * Returns the {@code i}th value of this row as a byte.
95- *
96- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
97- * @return the value of the {@code i}th column in this row as a byte. If the
98- * value is NULL, {@code 0} is returned.
99- *
100- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
101- * @throws InvalidTypeException if column {@code i} is not of type TINYINT.
102- */
103- @Override
104- public byte getByte(int i);
105-
106- /**
107- * Returns the value of column {@code name} as a byte.
108- *
109- * @param name the name of the column to retrieve.
110- * @return the value of column {@code name} as a byte. If the value is NULL,
111- * {@code 0} is returned.
112- *
113- * @throws IllegalArgumentException if {@code name} is not part of the
114- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
115- * @throws InvalidTypeException if column {@code name} is not of type TINYINT.
116- */
117- @Override
118- public byte getByte(String name);
119-
120- /**
121- * Returns the {@code i}th value of this row as a short.
122- *
123- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
124- * @return the value of the {@code i}th column in this row as a short. If the
125- * value is NULL, {@code 0} is returned.
126- *
127- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
128- * @throws InvalidTypeException if column {@code i} is not of type SMALLINT.
129- */
130- @Override
131- public short getShort(int i);
132-
133- /**
134- * Returns the value of column {@code name} as a short.
135- *
136- * @param name the name of the column to retrieve.
137- * @return the value of column {@code name} as a short. If the value is NULL,
138- * {@code 0} is returned.
139- *
140- * @throws IllegalArgumentException if {@code name} is not part of the
141- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
142- * @throws InvalidTypeException if column {@code name} is not of type SMALLINT.
143- */
144- @Override
145- public short getShort(String name);
146-
147- /**
148- * Returns the {@code i}th value of this row as an integer.
149- *
150- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
151- * @return the value of the {@code i}th column in this row as an integer. If the
152- * value is NULL, {@code 0} is returned.
153- *
154- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
155- * @throws InvalidTypeException if column {@code i} is not of type INT.
156- */
157- @Override
158- public int getInt(int i);
159-
160- /**
161- * Returns the value of column {@code name} as an integer.
162- *
163- * @param name the name of the column to retrieve.
164- * @return the value of column {@code name} as an integer. If the value is NULL,
165- * {@code 0} is returned.
166- *
167- * @throws IllegalArgumentException if {@code name} is not part of the
168- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
169- * @throws InvalidTypeException if column {@code name} is not of type INT.
170- */
171- @Override
172- public int getInt(String name);
173-
174- /**
175- * Returns the {@code i}th value of this row as a long.
176- *
177- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
178- * @return the value of the {@code i}th column in this row as a long. If the
179- * value is NULL, {@code 0L} is returned.
180- *
181- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
182- * @throws InvalidTypeException if column {@code i} is not of type BIGINT or COUNTER.
183- */
184- @Override
185- public long getLong(int i);
186-
187- /**
188- * Returns the value of column {@code name} as a long.
189- *
190- * @param name the name of the column to retrieve.
191- * @return the value of column {@code name} as a long. If the value is NULL,
192- * {@code 0L} is returned.
193- *
194- * @throws IllegalArgumentException if {@code name} is not part of the
195- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
196- * @throws InvalidTypeException if column {@code i} is not of type BIGINT or COUNTER.
197- */
198- @Override
199- public long getLong(String name);
200-
201- /**
202- * Returns the {@code i}th value of this row as a date.
203- *
204- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
205- * @return the value of the {@code i}th column in this row as a data. If the
206- * value is NULL, {@code null} is returned.
207- *
208- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
209- * @throws InvalidTypeException if column {@code i} is not of type TIMESTAMP.
210- */
211- @Override
212- public Date getTimestamp(int i);
213-
214- /**
215- * Returns the value of column {@code name} as a date.
216- *
217- * @param name the name of the column to retrieve.
218- * @return the value of column {@code name} as a date. If the value is NULL,
219- * {@code null} is returned.
220- *
221- * @throws IllegalArgumentException if {@code name} is not part of the
222- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
223- * @throws InvalidTypeException if column {@code name} is not of type TIMESTAMP.
224- */
225- @Override
226- public Date getTimestamp(String name);
227-
228- /**
229- * Returns the {@code i}th value as a date (without time).
230- *
231- * @param i the index ({@code 0 <= i < size()}) to retrieve.
232- * @return the value of the {@code i}th element as a date. If the
233- * value is NULL, {@code null} is returned.
234- *
235- * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
236- * @throws InvalidTypeException if value {@code i} is not of type DATE.
237- */
238- @Override
239- public LocalDate getDate(int i);
240-
241- /**
242- * Returns the value for {@code name} as a date (without time).
243- *
244- * @param name the name to retrieve.
245- * @return the value for {@code name} as a date. If the value is NULL,
246- * {@code null} is returned.
247- *
248- * @throws IllegalArgumentException if {@code name} is not valid name for this object.
249- * @throws InvalidTypeException if value {@code name} is not of type DATE.
250- */
251- @Override
252- public LocalDate getDate(String name);
253-
254- /**
255- * Returns the {@code i}th value as a long in nanoseconds since midnight.
256- *
257- * @param i the index ({@code 0 <= i < size()}) to retrieve.
258- * @return the value of the {@code i}th element as a long. If the
259- * value is NULL, {@code 0L} is returned.
260- *
261- * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
262- * @throws InvalidTypeException if value {@code i} is not of type TIME.
263- */
264- @Override
265- public long getTime(int i);
266-
267- /**
268- * Returns the value for {@code name} as a long in nanoseconds since midnight.
269- *
270- * @param name the name to retrieve.
271- * @return the value for {@code name} as a long. If the value is NULL,
272- * {@code 0L} is returned.
273- *
274- * @throws IllegalArgumentException if {@code name} is not valid name for this object.
275- * @throws InvalidTypeException if value {@code name} is not of type TIME.
276- */
277- @Override
278- public long getTime(String name);
279-
280- /**
281- * Returns the {@code i}th value of this row as a float.
282- *
283- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
284- * @return the value of the {@code i}th column in this row as a float. If the
285- * value is NULL, {@code 0.0f} is returned.
286- *
287- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
288- * @throws InvalidTypeException if column {@code i} is not of type FLOAT.
289- */
290- @Override
291- public float getFloat(int i);
292-
293- /**
294- * Returns the value of column {@code name} as a float.
295- *
296- * @param name the name of the column to retrieve.
297- * @return the value of column {@code name} as a float. If the value is NULL,
298- * {@code 0.0f} is returned.
299- *
300- * @throws IllegalArgumentException if {@code name} is not part of the
301- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
302- * @throws InvalidTypeException if column {@code name} is not of type FLOAT.
303- */
304- @Override
305- public float getFloat(String name);
306-
307- /**
308- * Returns the {@code i}th value of this row as a double.
309- *
310- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
311- * @return the value of the {@code i}th column in this row as a double. If the
312- * value is NULL, {@code 0.0} is returned.
313- *
314- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
315- * @throws InvalidTypeException if column {@code i} is not of type DOUBLE.
316- */
317- @Override
318- public double getDouble(int i);
319-
320- /**
321- * Returns the value of column {@code name} as a double.
322- *
323- * @param name the name of the column to retrieve.
324- * @return the value of column {@code name} as a double. If the value is NULL,
325- * {@code 0.0} is returned.
326- *
327- * @throws IllegalArgumentException if {@code name} is not part of the
328- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
329- * @throws InvalidTypeException if column {@code name} is not of type DOUBLE.
330- */
331- @Override
332- public double getDouble(String name);
333-
334- /**
335- * Returns the {@code i}th value of this row as a ByteBuffer.
336- *
337- * Note: this method always return the bytes composing the value, even if
338- * the column is not of type BLOB. That is, this method never throw an
339- * InvalidTypeException. However, if the type is not BLOB, it is up to the
340- * caller to handle the returned value correctly.
341- *
342- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
343- * @return the value of the {@code i}th column in this row as a ByteBuffer. If the
344- * value is NULL, {@code null} is returned.
345- *
346- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
347- */
348- @Override
349- public ByteBuffer getBytesUnsafe(int i);
350-
351- /**
352- * Returns the value of column {@code name} as a ByteBuffer.
353- *
354- * Note: this method always return the bytes composing the value, even if
355- * the column is not of type BLOB. That is, this method never throw an
356- * InvalidTypeException. However, if the type is not BLOB, it is up to the
357- * caller to handle the returned value correctly.
358- *
359- * @param name the name of the column to retrieve.
360- * @return the value of column {@code name} as a ByteBuffer. If the value is NULL,
361- * {@code null} is returned.
362- *
363- * @throws IllegalArgumentException if {@code name} is not part of the
364- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
365- */
366- @Override
367- public ByteBuffer getBytesUnsafe(String name);
368-
369- /**
370- * Returns the {@code i}th value of this row as a byte array.
371- * <p>
372- * Note that this method validate that the column is of type BLOB. If you want to retrieve
373- * the bytes for any type of columns, use {@link #getBytesUnsafe(int)} instead.
374- *
375- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
376- * @return the value of the {@code i}th column in this row as a byte array. If the
377- * value is NULL, {@code null} is returned.
378- *
379- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
380- * @throws InvalidTypeException if column {@code i} type is not of type BLOB.
381- */
382- @Override
383- public ByteBuffer getBytes(int i);
384-
385- /**
386- * Returns the value of column {@code name} as a byte array.
387- * <p>
388- * Note that this method validate that the column is of type BLOB. If you want to retrieve
389- * the bytes for any type of columns, use {@link #getBytesUnsafe(String)} instead.
390- *
391- * @param name the name of the column to retrieve.
392- * @return the value of column {@code name} as a byte array. If the value is NULL,
393- * {@code null} is returned.
394- *
395- * @throws IllegalArgumentException if {@code name} is not part of the
396- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
397- * @throws InvalidTypeException if column {@code i} type is not of type BLOB.
398- */
399- @Override
400- public ByteBuffer getBytes(String name);
401-
402- /**
403- * Returns the {@code i}th value of this row as a string.
404- *
405- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
406- * @return the value of the {@code i}th column in this row as a string. If the
407- * value is NULL, {@code null} is returned.
408- *
409- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
410- * @throws InvalidTypeException if column {@code i} type is none of:
411- * VARCHAR, TEXT or ASCII.
412- */
413- @Override
414- public String getString(int i);
415-
416- /**
417- * Returns the value of column {@code name} as a string.
418- *
419- * @param name the name of the column to retrieve.
420- * @return the value of column {@code name} as a string. If the value is NULL,
421- * {@code null} is returned.
422- *
423- * @throws IllegalArgumentException if {@code name} is not part of the
424- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
425- * @throws InvalidTypeException if column {@code name} type is none of:
426- * VARCHAR, TEXT or ASCII.
427- */
428- @Override
429- public String getString(String name);
430-
431- /**
432- * Returns the {@code i}th value of this row as a variable length integer.
433- *
434- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
435- * @return the value of the {@code i}th column in this row as a variable
436- * length integer. If the value is NULL, {@code null} is returned.
437- *
438- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
439- * @throws InvalidTypeException if column {@code i} is not of type VARINT.
440- */
441- @Override
442- public BigInteger getVarint(int i);
443-
444- /**
445- * Returns the value of column {@code name} as a variable length integer.
446- *
447- * @param name the name of the column to retrieve.
448- * @return the value of column {@code name} as a variable length integer.
449- * If the value is NULL, {@code null} is returned.
450- *
451- * @throws IllegalArgumentException if {@code name} is not part of the
452- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
453- * @throws InvalidTypeException if column {@code name} is not of type VARINT.
454- */
455- @Override
456- public BigInteger getVarint(String name);
457-
458- /**
459- * Returns the {@code i}th value of this row as a variable length decimal.
460- *
461- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
462- * @return the value of the {@code i}th column in this row as a variable
463- * length decimal. If the value is NULL, {@code null} is returned.
464- *
465- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
466- * @throws InvalidTypeException if column {@code i} is not of type DECIMAL.
467- */
468- @Override
469- public BigDecimal getDecimal(int i);
470-
471- /**
472- * Returns the value of column {@code name} as a variable length decimal.
473- *
474- * @param name the name of the column to retrieve.
475- * @return the value of column {@code name} as a variable length decimal.
476- * If the value is NULL, {@code null} is returned.
477- *
478- * @throws IllegalArgumentException if {@code name} is not part of the
479- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
480- * @throws InvalidTypeException if column {@code name} is not of type DECIMAL.
481- */
482- @Override
483- public BigDecimal getDecimal(String name);
484-
485- /**
486- * Returns the {@code i}th value of this row as a UUID.
487- *
488- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
489- * @return the value of the {@code i}th column in this row as a UUID.
490- * If the value is NULL, {@code null} is returned.
491- *
492- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
493- * @throws InvalidTypeException if column {@code i} is not of type UUID
494- * or TIMEUUID.
495- */
496- @Override
497- public UUID getUUID(int i);
498-
499- /**
500- * Returns the value of column {@code name} as a UUID.
501- *
502- * @param name the name of the column to retrieve.
503- * @return the value of column {@code name} as a UUID.
504- * If the value is NULL, {@code null} is returned.
505- *
506- * @throws IllegalArgumentException if {@code name} is not part of the
507- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
508- * @throws InvalidTypeException if column {@code name} is not of type
509- * UUID or TIMEUUID.
510- */
511- @Override
512- public UUID getUUID(String name);
513-
514- /**
515- * Returns the {@code i}th value of this row as an InetAddress.
516- *
517- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
518- * @return the value of the {@code i}th column in this row as an InetAddress.
519- * If the value is NULL, {@code null} is returned.
520- *
521- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
522- * @throws InvalidTypeException if column {@code i} is not of type INET.
523- */
524- @Override
525- public InetAddress getInet(int i);
526-
527- /**
528- * Returns the value of column {@code name} as an InetAddress.
529- *
530- * @param name the name of the column to retrieve.
531- * @return the value of column {@code name} as an InetAddress.
532- * If the value is NULL, {@code null} is returned.
533- *
534- * @throws IllegalArgumentException if {@code name} is not part of the
535- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
536- * @throws InvalidTypeException if column {@code name} is not of type
537- * INET.
538- */
539- @Override
540- public InetAddress getInet(String name);
541-
54236 /**
54337 * Returns the {@code i}th value of this row as a {@link Token}.
54438 * <p>
@@ -593,122 +87,4 @@
59387 */
59488 public Token getPartitionKeyToken();
59589
596- /**
597- * Returns the {@code i}th value of this row as a list.
598- *
599- * @param <T> the type of the elements of the list to return.
600- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
601- * @param elementsClass the class for the elements of the list to retrieve.
602- * @return the value of the {@code i}th column in this row as a list of
603- * {@code elementsClass} objects. If the value is NULL, an empty list is
604- * returned (note that Cassandra makes no difference between an empty list
605- * and column of type list that is not set). The returned list is immutable.
606- *
607- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
608- * @throws InvalidTypeException if column {@code i} is not a list or if its
609- * elements are not of class {@code elementsClass}.
610- */
611- @Override
612- public <T> List<T> getList(int i, Class<T> elementsClass);
613-
614- /**
615- * Returns the value of column {@code name} as a list.
616- *
617- * @param <T> the type of the elements of the list to return.
618- * @param name the name of the column to retrieve.
619- * @param elementsClass the class for the elements of the list to retrieve.
620- * @return the value of the {@code i}th column in this row as a list of
621- * {@code elementsClass} objects. If the value is NULL, an empty list is
622- * returned (note that Cassandra makes no difference between an empty list
623- * and column of type list that is not set). The returned list is immutable.
624- *
625- * @throws IllegalArgumentException if {@code name} is not part of the
626- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
627- * @throws InvalidTypeException if column {@code name} is not a list or if its
628- * elements are not of class {@code elementsClass}.
629- */
630- @Override
631- public <T> List<T> getList(String name, Class<T> elementsClass);
632-
633- /**
634- * Returns the {@code i}th value of this row as a set.
635- *
636- * @param <T> the type of the elements of the set to return.
637- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
638- * @param elementsClass the class for the elements of the set to retrieve.
639- * @return the value of the {@code i}th column in this row as a set of
640- * {@code elementsClass} objects. If the value is NULL, an empty set is
641- * returned (note that Cassandra makes no difference between an empty set
642- * and column of type set that is not set). The returned set is immutable.
643- *
644- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
645- * @throws InvalidTypeException if column {@code i} is not a set or if its
646- * elements are not of class {@code elementsClass}.
647- */
648- @Override
649- public <T> Set<T> getSet(int i, Class<T> elementsClass);
650-
651- /**
652- * Returns the value of column {@code name} as a set.
653- *
654- * @param <T> the type of the elements of the set to return.
655- * @param name the name of the column to retrieve.
656- * @param elementsClass the class for the elements of the set to retrieve.
657- * @return the value of the {@code i}th column in this row as a set of
658- * {@code elementsClass} objects. If the value is NULL, an empty set is
659- * returned (note that Cassandra makes no difference between an empty set
660- * and column of type set that is not set). The returned set is immutable.
661- *
662- * @throws IllegalArgumentException if {@code name} is not part of the
663- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
664- * @throws InvalidTypeException if column {@code name} is not a set or if its
665- * elements are not of class {@code elementsClass}.
666- */
667- @Override
668- public <T> Set<T> getSet(String name, Class<T> elementsClass);
669-
670- /**
671- * Returns the {@code i}th value of this row as a map.
672- *
673- * @param <K> the type of the keys of the map to return.
674- * @param <V> the type of the values of the map to return.
675- * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
676- * @param keysClass the class for the keys of the map to retrieve.
677- * @param valuesClass the class for the values of the map to retrieve.
678- * @return the value of the {@code i}th column in this row as a map of
679- * {@code keysClass} to {@code valuesClass} objects. If the value is NULL,
680- * an empty map is returned (note that Cassandra makes no difference
681- * between an empty map and column of type map that is not set). The
682- * returned map is immutable.
683- *
684- * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
685- * @throws InvalidTypeException if column {@code i} is not a map, if its
686- * keys are not of class {@code keysClass} or if its values are not of
687- * class {@code valuesClass}.
688- */
689- @Override
690- public <K, V> Map<K, V> getMap(int i, Class<K> keysClass, Class<V> valuesClass);
691-
692- /**
693- * Returns the value of column {@code name} as a map.
694- *
695- * @param <K> the type of the keys of the map to return.
696- * @param <V> the type of the values of the map to return.
697- * @param name the name of the column to retrieve.
698- * @param keysClass the class for the keys of the map to retrieve.
699- * @param valuesClass the class for the values of the map to retrieve.
700- * @return the value of the {@code i}th column in this row as a map of
701- * {@code keysClass} to {@code valuesClass} objects. If the value is NULL,
702- * an empty map is returned (note that Cassandra makes no difference
703- * between an empty map and column of type map that is not set). The
704- * returned map is immutable.
705- *
706- * @throws IllegalArgumentException if {@code name} is not part of the
707- * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}.
708- * @throws InvalidTypeException if column {@code name} is not a map, if its
709- * keys are not of class {@code keysClass} or if its values are not of
710- * class {@code valuesClass}.
711- */
712- @Override
713- public <K, V> Map<K, V> getMap(String name, Class<K> keysClass, Class<V> valuesClass);
71490 }
modified driver-core/src/main/java/com/datastax/driver/core/TypeCodec.java +11 −19
@@ -192,9 +192,10 @@
192192 * <li>Null or empty buffers should be gracefully handled and no exception should be raised;
193193 * these should be considered as the equivalent of a NULL CQL value and, in most cases, should
194194 * map to {@code null} or a default value for the corresponding Java type, if applicable;</li>
195- * <li>Codecs for CQL collection types should return unmodifiable collections;</li>
195+ * <li>Codecs for CQL collection types should clearly document whether they return immutable collections or not
196+ * (note that the driver's default collection codecs return <em>mutable</em> collections);</li>
196197 * <li>Codecs for CQL collection types should avoid returning {@code null};
197- * they should return empty collections instead.</li>
198+ * they should return empty collections instead (the driver's default collection codecs all comply with this rule).</li>
198199 * </ol>
199200 *
200201 * @param bytes A {@link ByteBuffer} instance containing the serialized form of T;
@@ -1598,7 +1599,7 @@
15981599 @Override
15991600 public C deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) {
16001601 if (bytes == null || bytes.remaining() == 0)
1601- return unmodifiable(newInstance(0));
1602+ return newInstance(0);
16021603 try {
16031604 ByteBuffer input = bytes.duplicate();
16041605 int n = CodecUtils.readCollectionSize(input, protocolVersion);
@@ -1607,7 +1608,7 @@
16071608 ByteBuffer databb = CodecUtils.readCollectionValue(input, protocolVersion);
16081609 coll.add(eltCodec.deserialize(databb, protocolVersion));
16091610 }
1610- return unmodifiable(coll);
1611+ return coll;
16111612 } catch (BufferUnderflowException e) {
16121613 throw new InvalidTypeException("Not enough bytes to deserialize list");
16131614 }
@@ -1681,8 +1682,6 @@
16811682
16821683 protected abstract C newInstance(int capacity);
16831684
1684- protected abstract C unmodifiable(C coll);
1685-
16861685 protected abstract char getOpeningChar();
16871686
16881687 protected abstract char getClosingChar();
@@ -1691,6 +1690,7 @@
16911690
16921691 /**
16931692 * This codec maps a CQL {@link DataType#list(DataType) list type} to a Java {@link List}.
1693+ * Implementation note: this codec returns mutable, non thread-safe {@link ArrayList} instances.
16941694 */
16951695 public static class ListCodec<T> extends CollectionCodec<T, List<T>> {
16961696
@@ -1703,11 +1703,6 @@
17031703 return new ArrayList<T>(capacity);
17041704 }
17051705
1706- @Override
1707- protected List<T> unmodifiable(List<T> coll) {
1708- return Collections.unmodifiableList(coll);
1709- }
1710-
17111706 @Override
17121707 protected char getOpeningChar() {
17131708 return '[';
@@ -1722,6 +1717,7 @@
17221717
17231718 /**
17241719 * This codec maps a CQL {@link DataType#set(DataType) set type} to a Java {@link Set}.
1720+ * Implementation note: this codec returns mutable, non thread-safe {@link LinkedHashSet} instances.
17251721 */
17261722 public static class SetCodec<T> extends CollectionCodec<T, Set<T>> {
17271723
@@ -1734,11 +1730,6 @@
17341730 return new LinkedHashSet<T>(capacity);
17351731 }
17361732
1737- @Override
1738- protected Set<T> unmodifiable(Set<T> coll) {
1739- return Collections.unmodifiableSet(coll);
1740- }
1741-
17421733 @Override
17431734 protected char getOpeningChar() {
17441735 return '{';
@@ -1752,6 +1743,7 @@
17521743
17531744 /**
17541745 * This codec maps a CQL {@link DataType#map(DataType, DataType) map type} to a Java {@link Map}.
1746+ * Implementation note: this codec returns mutable, non thread-safe {@link LinkedHashMap} instances.
17551747 */
17561748 public static class MapCodec<K, V> extends TypeCodec<Map<K, V>> {
17571749
@@ -1790,7 +1782,7 @@
17901782 idx = ParseUtils.skipSpaces(value, idx);
17911783
17921784 if (value.charAt(idx) == '}')
1793- return Collections.emptyMap();
1785+ return new LinkedHashMap<K, V>(0);
17941786
17951787 Map<K, V> m = new HashMap<K, V>();
17961788 while (idx < value.length()) {
@@ -1885,7 +1877,7 @@
18851877 @Override
18861878 public Map<K, V> deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) {
18871879 if (bytes == null || bytes.remaining() == 0)
1888- return Collections.emptyMap();
1880+ return new LinkedHashMap<K, V>(0);
18891881 try {
18901882 ByteBuffer input = bytes.duplicate();
18911883 int n = CodecUtils.readCollectionSize(input, protocolVersion);
@@ -1895,7 +1887,7 @@
18951887 ByteBuffer vbb = CodecUtils.readCollectionValue(input, protocolVersion);
18961888 m.put(keyCodec.deserialize(kbb, protocolVersion), valueCodec.deserialize(vbb, protocolVersion));
18971889 }
1898- return Collections.unmodifiableMap(m);
1890+ return m;
18991891 } catch (BufferUnderflowException e) {
19001892 throw new InvalidTypeException("Not enough bytes to deserialize a map");
19011893 }
modified upgrade_guide/README.md +3 −0
@@ -61,6 +61,9 @@
6161 * `TupleType of(DataType... types)`; users should now use `Metadata.newTupleType(DataType...)`.
6262
6363 <p>The driver runtime behavior changes in the following situations:</p>
64+ * By default, the driver now returns _mutable_, _non thread-safe_ instances for CQL collection types;
65+ This affects methods `getList`, `getSet`, `getMap`, `getObject` and `get` for all instances of
66+ `GettableByIndexData` and `GettableByNameData` (`Row`, `BoundStatement`, `TupleValue` and `UDTValue`)
6467 * `RuntimeException`s thrown during serialization or deserialization might not be
6568 the same ones as before, due to the newly-introduced `CodecNotFoundException`
6669 and to the dynamic nature of codec search introduced by JAVA-721.