Elffuss BraidHub

kikocis/java-driver public

Allow typed getters/setters to target any CQL type (JAVA-940).
Changesetafde5547aef923de524301b0ac9644dbc98c50d7959274f0ccfd007c8d25c3dd
AuthorAlexandre Dutra <alexandre.dutra@datastax.com> · 2015-10-08 10:18 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2015-10-14 22:35 +02:00
Parents7726f0cb3c91

Browse the files at this changeset

12 files changed

modified changelog/README.md +1 −0
@@ -14,6 +14,7 @@
1414 - [bug] Make TypeCodec return mutable collections (JAVA-922)
1515 - [improvement] Limit visibility of codec internals (JAVA-932)
1616 - [improvement] Warn if a custom codec collides with an existing one (JAVA-934)
17+- [improvement] Allow typed getters/setters to target any CQL type (JAVA-940)
1718
1819
1920 ### 3.0.0-alpha3
modified driver-core/src/main/java/com/datastax/driver/core/AbstractAddressableByIndexData.java +3 −52
@@ -27,7 +27,6 @@
2727 import static com.datastax.driver.core.CodecUtils.listOf;
2828 import static com.datastax.driver.core.CodecUtils.mapOf;
2929 import static com.datastax.driver.core.CodecUtils.setOf;
30-import static com.datastax.driver.core.DataType.Name.*;
3130
3231 abstract class AbstractAddressableByIndexData<T extends SettableByIndexData<T>> extends AbstractGettableByIndexData implements SettableByIndexData<T> {
3332
@@ -49,7 +48,6 @@
4948 }
5049
5150 public T setBool(int i, boolean v) {
52- checkType(i, BOOLEAN);
5351 TypeCodec<Boolean> codec = codecFor(i, Boolean.class);
5452 ByteBuffer bb;
5553 if(codec instanceof TypeCodec.PrimitiveBooleanCodec)
@@ -60,7 +58,6 @@
6058 }
6159
6260 public T setByte(int i, byte v) {
63- checkType(i, TINYINT);
6461 TypeCodec<Byte> codec = codecFor(i, Byte.class);
6562 ByteBuffer bb;
6663 if(codec instanceof TypeCodec.PrimitiveByteCodec)
@@ -71,7 +68,6 @@
7168 }
7269
7370 public T setShort(int i, short v) {
74- checkType(i, SMALLINT);
7571 TypeCodec<Short> codec = codecFor(i, Short.class);
7672 ByteBuffer bb;
7773 if(codec instanceof TypeCodec.PrimitiveShortCodec)
@@ -82,7 +78,6 @@
8278 }
8379
8480 public T setInt(int i, int v) {
85- checkType(i, INT);
8681 TypeCodec<Integer> codec = codecFor(i, Integer.class);
8782 ByteBuffer bb;
8883 if(codec instanceof TypeCodec.PrimitiveIntCodec)
@@ -93,7 +88,6 @@
9388 }
9489
9590 public T setLong(int i, long v) {
96- checkType(i, BIGINT, COUNTER);
9791 TypeCodec<Long> codec = codecFor(i, Long.class);
9892 ByteBuffer bb;
9993 if(codec instanceof TypeCodec.PrimitiveLongCodec)
@@ -104,17 +98,14 @@
10498 }
10599
106100 public T setTimestamp(int i, Date v) {
107- checkType(i, TIMESTAMP);
108101 return setValue(i, codecFor(i, Date.class).serialize(v, protocolVersion));
109102 }
110103
111104 public T setDate(int i, LocalDate v) {
112- checkType(i, DATE);
113105 return setValue(i, codecFor(i, LocalDate.class).serialize(v, protocolVersion));
114106 }
115107
116108 public T setTime(int i, long v) {
117- checkType(i, TIME);
118109 TypeCodec<Long> codec = codecFor(i, Long.class);
119110 ByteBuffer bb;
120111 if(codec instanceof TypeCodec.PrimitiveLongCodec)
@@ -125,7 +116,6 @@
125116 }
126117
127118 public T setFloat(int i, float v) {
128- checkType(i, FLOAT);
129119 TypeCodec<Float> codec = codecFor(i, Float.class);
130120 ByteBuffer bb;
131121 if(codec instanceof TypeCodec.PrimitiveFloatCodec)
@@ -136,7 +126,6 @@
136126 }
137127
138128 public T setDouble(int i, double v) {
139- checkType(i, DOUBLE);
140129 TypeCodec<Double> codec = codecFor(i, Double.class);
141130 ByteBuffer bb;
142131 if(codec instanceof TypeCodec.PrimitiveDoubleCodec)
@@ -147,12 +136,10 @@
147136 }
148137
149138 public T setString(int i, String v) {
150- checkType(i, VARCHAR, TEXT, ASCII);
151139 return setValue(i, codecFor(i, String.class).serialize(v, protocolVersion));
152140 }
153141
154142 public T setBytes(int i, ByteBuffer v) {
155- checkType(i, BLOB);
156143 return setValue(i, codecFor(i, ByteBuffer.class).serialize(v, protocolVersion));
157144 }
158145
@@ -161,37 +148,24 @@
161148 }
162149
163150 public T setVarint(int i, BigInteger v) {
164- checkType(i, VARINT);
165151 return setValue(i, codecFor(i, BigInteger.class).serialize(v, protocolVersion));
166152 }
167153
168154 public T setDecimal(int i, BigDecimal v) {
169- checkType(i, DECIMAL);
170155 return setValue(i, codecFor(i, BigDecimal.class).serialize(v, protocolVersion));
171156 }
172157
173158 public T setUUID(int i, UUID v) {
174- checkType(i, UUID, TIMEUUID);
175159 return setValue(i, codecFor(i, UUID.class).serialize(v, protocolVersion));
176160 }
177161
178162 public T setInet(int i, InetAddress v) {
179- checkType(i, INET);
180163 return setValue(i, codecFor(i, InetAddress.class).serialize(v, protocolVersion));
181164 }
182165
183166 @SuppressWarnings("unchecked")
184167 public <E> T setList(int i, List<E> v) {
185- checkType(i, LIST);
186- if(v == null || v.isEmpty()) {
187- // no runtime inspection possible, rely on the underlying metadata
188- return setValue(i, codecFor(i).serialize(v, protocolVersion));
189- } else {
190- // inspect the first element and locate a codec that accepts both the underlying CQL type and the actual Java type
191- DataType eltCqlType = getType(i).getTypeArguments().get(0);
192- TypeToken<E> eltJavaType = getCodecRegistry().codecFor(eltCqlType, v.iterator().next()).getJavaType();
193- return setValue(i, codecFor(i, listOf(eltJavaType)).serialize(v, protocolVersion));
194- }
168+ return setValue(i, codecFor(i).serialize(v, protocolVersion));
195169 }
196170
197171 @Override
@@ -206,19 +180,7 @@
206180
207181 @SuppressWarnings("unchecked")
208182 public <K, V> T setMap(int i, Map<K, V> v) {
209- checkType(i, MAP);
210- if(v == null || v.isEmpty()) {
211- // no runtime inspection possible, rely on the underlying metadata
212- return setValue(i, codecFor(i).serialize(v, protocolVersion));
213- } else {
214- // inspect the first element and locate a codec that accepts both the underlying CQL type and the actual Java types for keys and values
215- DataType keysCqlType = getType(i).getTypeArguments().get(0);
216- DataType valuesCqlType = getType(i).getTypeArguments().get(1);
217- Map.Entry<K, V> entry = v.entrySet().iterator().next();
218- TypeToken<K> keysType = getCodecRegistry().codecFor(keysCqlType, entry.getKey()).getJavaType();
219- TypeToken<V> valuesType = getCodecRegistry().codecFor(valuesCqlType, entry.getValue()).getJavaType();
220- return setValue(i, codecFor(i, mapOf(keysType, valuesType)).serialize(v, protocolVersion));
221- }
183+ return setValue(i, codecFor(i).serialize(v, protocolVersion));
222184 }
223185
224186 @Override
@@ -233,16 +195,7 @@
233195
234196 @SuppressWarnings("unchecked")
235197 public <E> T setSet(int i, Set<E> v) {
236- checkType(i, SET);
237- if(v == null || v.isEmpty()) {
238- // no runtime inspection possible, rely on the underlying metadata
239- return setValue(i, codecFor(i).serialize(v, protocolVersion));
240- } else {
241- // inspect the first element and locate a codec that accepts both the underlying CQL type and the actual Java type
242- DataType eltCqlType = getType(i).getTypeArguments().get(0);
243- TypeToken<E> eltJavaType = getCodecRegistry().codecFor(eltCqlType, v.iterator().next()).getJavaType();
244- return setValue(i, codecFor(i, setOf(eltJavaType)).serialize(v, protocolVersion));
245- }
198+ return setValue(i, codecFor(i).serialize(v, protocolVersion));
246199 }
247200
248201 @Override
@@ -256,12 +209,10 @@
256209 }
257210
258211 public T setUDTValue(int i, UDTValue v) {
259- checkType(i, UDT);
260212 return setValue(i, codecFor(i, UDTValue.class).serialize(v, protocolVersion));
261213 }
262214
263215 public T setTupleValue(int i, TupleValue v) {
264- checkType(i, TUPLE);
265216 return setValue(i, codecFor(i, TupleValue.class).serialize(v, protocolVersion));
266217 }
267218
modified driver-core/src/main/java/com/datastax/driver/core/AbstractData.java +45 −52
@@ -27,7 +27,6 @@
2727 import static com.datastax.driver.core.CodecUtils.listOf;
2828 import static com.datastax.driver.core.CodecUtils.mapOf;
2929 import static com.datastax.driver.core.CodecUtils.setOf;
30-import static com.datastax.driver.core.DataType.Name.*;
3130
3231 // We don't want to expose this one: it's less useful externally and it's a bit ugly to expose anyway (but it's convenient).
3332 abstract class AbstractData<T extends SettableData<T>> extends AbstractGettableData implements SettableData<T> {
@@ -61,16 +60,18 @@
6160 return wrapped;
6261 }
6362
63+ @Override
6464 protected ByteBuffer getValue(int i) {
6565 return values[i];
6666 }
6767
68+ @Override
6869 protected int getIndexOf(String name) {
6970 return getAllIndexesOf(name)[0];
7071 }
7172
73+ @Override
7274 public T setBool(int i, boolean v) {
73- checkType(i, BOOLEAN);
7475 TypeCodec<Boolean> codec = codecFor(i, Boolean.class);
7576 ByteBuffer bb;
7677 if(codec instanceof TypeCodec.PrimitiveBooleanCodec)
@@ -80,6 +81,7 @@
8081 return setValue(i, bb);
8182 }
8283
84+ @Override
8385 public T setBool(String name, boolean v) {
8486 for (int i : getAllIndexesOf(name)) {
8587 setBool(i, v);
@@ -87,8 +89,8 @@
8789 return wrapped;
8890 }
8991
92+ @Override
9093 public T setByte(int i, byte v) {
91- checkType(i, TINYINT);
9294 TypeCodec<Byte> codec = codecFor(i, Byte.class);
9395 ByteBuffer bb;
9496 if(codec instanceof TypeCodec.PrimitiveByteCodec)
@@ -98,6 +100,7 @@
98100 return setValue(i, bb);
99101 }
100102
103+ @Override
101104 public T setByte(String name, byte v) {
102105 for (int i : getAllIndexesOf(name)) {
103106 setByte(i, v);
@@ -105,8 +108,8 @@
105108 return wrapped;
106109 }
107110
111+ @Override
108112 public T setShort(int i, short v) {
109- checkType(i, SMALLINT);
110113 TypeCodec<Short> codec = codecFor(i, Short.class);
111114 ByteBuffer bb;
112115 if(codec instanceof TypeCodec.PrimitiveShortCodec)
@@ -116,6 +119,7 @@
116119 return setValue(i, bb);
117120 }
118121
122+ @Override
119123 public T setShort(String name, short v) {
120124 for (int i : getAllIndexesOf(name)) {
121125 setShort(i, v);
@@ -123,8 +127,8 @@
123127 return wrapped;
124128 }
125129
130+ @Override
126131 public T setInt(int i, int v) {
127- checkType(i, INT);
128132 TypeCodec<Integer> codec = codecFor(i, Integer.class);
129133 ByteBuffer bb;
130134 if(codec instanceof TypeCodec.PrimitiveIntCodec)
@@ -134,6 +138,7 @@
134138 return setValue(i, bb);
135139 }
136140
141+ @Override
137142 public T setInt(String name, int v) {
138143 for (int i : getAllIndexesOf(name)) {
139144 setInt(i, v);
@@ -141,8 +146,8 @@
141146 return wrapped;
142147 }
143148
149+ @Override
144150 public T setLong(int i, long v) {
145- checkType(i, BIGINT, COUNTER);
146151 TypeCodec<Long> codec = codecFor(i, Long.class);
147152 ByteBuffer bb;
148153 if(codec instanceof TypeCodec.PrimitiveLongCodec)
@@ -152,6 +157,7 @@
152157 return setValue(i, bb);
153158 }
154159
160+ @Override
155161 public T setLong(String name, long v) {
156162 for (int i : getAllIndexesOf(name)) {
157163 setLong(i, v);
@@ -159,11 +165,12 @@
159165 return wrapped;
160166 }
161167
168+ @Override
162169 public T setTimestamp(int i, Date v) {
163- checkType(i, TIMESTAMP);
164170 return setValue(i, codecFor(i, Date.class).serialize(v, protocolVersion));
165171 }
166172
173+ @Override
167174 public T setTimestamp(String name, Date v) {
168175 for (int i : getAllIndexesOf(name)) {
169176 setTimestamp(i, v);
@@ -171,11 +178,12 @@
171178 return wrapped;
172179 }
173180
181+ @Override
174182 public T setDate(int i, LocalDate v) {
175- checkType(i, DATE);
176183 return setValue(i, codecFor(i, LocalDate.class).serialize(v, protocolVersion));
177184 }
178185
186+ @Override
179187 public T setDate(String name, LocalDate v) {
180188 for (int i : getAllIndexesOf(name)) {
181189 setDate(i, v);
@@ -183,8 +191,8 @@
183191 return wrapped;
184192 }
185193
194+ @Override
186195 public T setTime(int i, long v) {
187- checkType(i, TIME);
188196 TypeCodec<Long> codec = codecFor(i, Long.class);
189197 ByteBuffer bb;
190198 if(codec instanceof TypeCodec.PrimitiveLongCodec)
@@ -194,6 +202,7 @@
194202 return setValue(i, bb);
195203 }
196204
205+ @Override
197206 public T setTime(String name, long v) {
198207 for (int i : getAllIndexesOf(name)) {
199208 setTime(i, v);
@@ -201,8 +210,8 @@
201210 return wrapped;
202211 }
203212
213+ @Override
204214 public T setFloat(int i, float v) {
205- checkType(i, FLOAT);
206215 TypeCodec<Float> codec = codecFor(i, Float.class);
207216 ByteBuffer bb;
208217 if(codec instanceof TypeCodec.PrimitiveFloatCodec)
@@ -212,6 +221,7 @@
212221 return setValue(i, bb);
213222 }
214223
224+ @Override
215225 public T setFloat(String name, float v) {
216226 for (int i : getAllIndexesOf(name)) {
217227 setFloat(i, v);
@@ -219,8 +229,8 @@
219229 return wrapped;
220230 }
221231
232+ @Override
222233 public T setDouble(int i, double v) {
223- checkType(i, DOUBLE);
224234 TypeCodec<Double> codec = codecFor(i, Double.class);
225235 ByteBuffer bb;
226236 if(codec instanceof TypeCodec.PrimitiveDoubleCodec)
@@ -230,6 +240,7 @@
230240 return setValue(i, bb);
231241 }
232242
243+ @Override
233244 public T setDouble(String name, double v) {
234245 for (int i : getAllIndexesOf(name)) {
235246 setDouble(i, v);
@@ -237,11 +248,12 @@
237248 return wrapped;
238249 }
239250
251+ @Override
240252 public T setString(int i, String v) {
241- checkType(i, VARCHAR, TEXT, ASCII);
242253 return setValue(i, codecFor(i, String.class).serialize(v, protocolVersion));
243254 }
244255
256+ @Override
245257 public T setString(String name, String v) {
246258 for (int i : getAllIndexesOf(name)) {
247259 setString(i, v);
@@ -249,11 +261,12 @@
249261 return wrapped;
250262 }
251263
264+ @Override
252265 public T setBytes(int i, ByteBuffer v) {
253- checkType(i, BLOB);
254266 return setValue(i, codecFor(i, ByteBuffer.class).serialize(v, protocolVersion));
255267 }
256268
269+ @Override
257270 public T setBytes(String name, ByteBuffer v) {
258271 for (int i : getAllIndexesOf(name)) {
259272 setBytes(i, v);
@@ -261,10 +274,12 @@
261274 return wrapped;
262275 }
263276
277+ @Override
264278 public T setBytesUnsafe(int i, ByteBuffer v) {
265279 return setValue(i, v == null ? null : v.duplicate());
266280 }
267281
282+ @Override
268283 public T setBytesUnsafe(String name, ByteBuffer v) {
269284 ByteBuffer value = v == null ? null : v.duplicate();
270285 for (int i : getAllIndexesOf(name)) {
@@ -273,11 +288,12 @@
273288 return wrapped;
274289 }
275290
291+ @Override
276292 public T setVarint(int i, BigInteger v) {
277- checkType(i, VARINT);
278293 return setValue(i, codecFor(i, BigInteger.class).serialize(v, protocolVersion));
279294 }
280295
296+ @Override
281297 public T setVarint(String name, BigInteger v) {
282298 for (int i : getAllIndexesOf(name)) {
283299 setVarint(i, v);
@@ -285,11 +301,12 @@
285301 return wrapped;
286302 }
287303
304+ @Override
288305 public T setDecimal(int i, BigDecimal v) {
289- checkType(i, DECIMAL);
290306 return setValue(i, codecFor(i, BigDecimal.class).serialize(v, protocolVersion));
291307 }
292308
309+ @Override
293310 public T setDecimal(String name, BigDecimal v) {
294311 for (int i : getAllIndexesOf(name)) {
295312 setDecimal(i, v);
@@ -297,11 +314,12 @@
297314 return wrapped;
298315 }
299316
317+ @Override
300318 public T setUUID(int i, UUID v) {
301- checkType(i, UUID, TIMEUUID);
302319 return setValue(i, codecFor(i, UUID.class).serialize(v, protocolVersion));
303320 }
304321
322+ @Override
305323 public T setUUID(String name, UUID v) {
306324 for (int i : getAllIndexesOf(name)) {
307325 setUUID(i, v);
@@ -309,11 +327,12 @@
309327 return wrapped;
310328 }
311329
330+ @Override
312331 public T setInet(int i, InetAddress v) {
313- checkType(i, INET);
314332 return setValue(i, codecFor(i, InetAddress.class).serialize(v, protocolVersion));
315333 }
316334
335+ @Override
317336 public T setInet(String name, InetAddress v) {
318337 for (int i : getAllIndexesOf(name)) {
319338 setInet(i, v);
@@ -337,18 +356,10 @@
337356 return wrapped;
338357 }
339358
359+ @Override
340360 @SuppressWarnings("unchecked")
341361 public <E> T setList(int i, List<E> v) {
342- checkType(i, LIST);
343- if(v == null || v.isEmpty()) {
344- // no runtime inspection possible, rely on the underlying metadata
345- return setValue(i, codecFor(i).serialize(v, protocolVersion));
346- } else {
347- // inspect the first element and locate a codec that accepts both the underlying CQL type and the actual Java type
348- DataType eltCqlType = getType(i).getTypeArguments().get(0);
349- TypeToken<E> eltJavaType = getCodecRegistry().codecFor(eltCqlType, v.iterator().next()).getJavaType();
350- return setValue(i, codecFor(i, listOf(eltJavaType)).serialize(v, protocolVersion));
351- }
362+ return setValue(i, codecFor(i).serialize(v, protocolVersion));
352363 }
353364
354365 @Override
@@ -388,19 +399,7 @@
388399 @SuppressWarnings("unchecked")
389400 @Override
390401 public <K, V> T setMap(int i, Map<K, V> v) {
391- checkType(i, MAP);
392- if(v == null || v.isEmpty()) {
393- // no runtime inspection possible, rely on the underlying metadata
394- return setValue(i, codecFor(i).serialize(v, protocolVersion));
395- } else {
396- // inspect the first element and locate a codec that accepts both the underlying CQL type and the actual Java types for keys and values
397- DataType keysCqlType = getType(i).getTypeArguments().get(0);
398- DataType valuesCqlType = getType(i).getTypeArguments().get(1);
399- Map.Entry<K, V> entry = v.entrySet().iterator().next();
400- TypeToken<K> keysType = getCodecRegistry().codecFor(keysCqlType, entry.getKey()).getJavaType();
401- TypeToken<V> valuesType = getCodecRegistry().codecFor(valuesCqlType, entry.getValue()).getJavaType();
402- return setValue(i, codecFor(i, mapOf(keysType, valuesType)).serialize(v, protocolVersion));
403- }
402+ return setValue(i, codecFor(i).serialize(v, protocolVersion));
404403 }
405404
406405 @Override
@@ -437,18 +436,10 @@
437436 return wrapped;
438437 }
439438
439+ @Override
440440 @SuppressWarnings("unchecked")
441441 public <E> T setSet(int i, Set<E> v) {
442- checkType(i, SET);
443- if(v == null || v.isEmpty()) {
444- // no runtime inspection possible, rely on the underlying metadata
445- return setValue(i, codecFor(i).serialize(v, protocolVersion));
446- } else {
447- // inspect the first element and locate a codec that accepts both the underlying CQL type and the actual Java type
448- DataType eltCqlType = getType(i).getTypeArguments().get(0);
449- TypeToken<E> eltJavaType = getCodecRegistry().codecFor(eltCqlType, v.iterator().next()).getJavaType();
450- return setValue(i, codecFor(i, setOf(eltJavaType)).serialize(v, protocolVersion));
451- }
442+ return setValue(i, codecFor(i).serialize(v, protocolVersion));
452443 }
453444
454445 @Override
@@ -485,11 +476,12 @@
485476 return wrapped;
486477 }
487478
479+ @Override
488480 public T setUDTValue(int i, UDTValue v) {
489- checkType(i, UDT);
490481 return setValue(i, codecFor(i, UDTValue.class).serialize(v, protocolVersion));
491482 }
492483
484+ @Override
493485 public T setUDTValue(String name, UDTValue v) {
494486 for (int i : getAllIndexesOf(name)) {
495487 setUDTValue(i, v);
@@ -497,11 +489,12 @@
497489 return wrapped;
498490 }
499491
492+ @Override
500493 public T setTupleValue(int i, TupleValue v) {
501- checkType(i, TUPLE);
502494 return setValue(i, codecFor(i, TupleValue.class).serialize(v, protocolVersion));
503495 }
504496
497+ @Override
505498 public T setTupleValue(String name, TupleValue v) {
506499 for (int i : getAllIndexesOf(name)) {
507500 setTupleValue(i, v);
modified driver-core/src/main/java/com/datastax/driver/core/AbstractGettableByIndexData.java +1 −47
@@ -19,23 +19,15 @@
1919 import java.math.BigInteger;
2020 import java.net.InetAddress;
2121 import java.nio.ByteBuffer;
22-import java.util.Date;
23-import java.util.List;
24-import java.util.Map;
25-import java.util.Set;
26-import java.util.UUID;
22+import java.util.*;
2723
2824 import com.google.common.reflect.TypeToken;
2925
30-import static com.google.common.collect.Sets.newHashSet;
31-import static com.google.common.collect.Sets.newLinkedHashSet;
32-
3326 import com.datastax.driver.core.exceptions.InvalidTypeException;
3427
3528 import static com.datastax.driver.core.CodecUtils.listOf;
3629 import static com.datastax.driver.core.CodecUtils.mapOf;
3730 import static com.datastax.driver.core.CodecUtils.setOf;
38-import static com.datastax.driver.core.DataType.Name.*;
3931
4032 abstract class AbstractGettableByIndexData implements GettableByIndexData {
4133
@@ -93,25 +85,12 @@
9385 return getCodecRegistry().codecFor(getType(i), value);
9486 }
9587
96- // Note: we avoid having a vararg method to avoid the array allocation that comes with it.
9788 protected void checkType(int i, DataType.Name actual) {
9889 DataType.Name expected = getType(i).getName();
9990 if (!actual.isCompatibleWith(expected))
10091 throw new InvalidTypeException(String.format("Value %s is of type %s, not %s", getName(i), expected, actual));
10192 }
10293
103- protected void checkType(int i, DataType.Name actual1, DataType.Name actual2) {
104- DataType.Name expected = getType(i).getName();
105- if (!actual1.isCompatibleWith(expected) && !actual2.isCompatibleWith(expected))
106- throw new InvalidTypeException(String.format("Value %s is of type %s, not any of [%s, %s]", getName(i), expected, actual1, actual2));
107- }
108-
109- protected void checkType(int i, DataType.Name actual1, DataType.Name actual2, DataType.Name actual3) {
110- DataType.Name expected = getType(i).getName();
111- if (!actual1.isCompatibleWith(expected) && !actual2.isCompatibleWith(expected) && !actual3.isCompatibleWith(expected))
112- throw new InvalidTypeException(String.format("Value %s is of type %s, not any of [%s, %s, %s]", getName(i), expected, actual1, actual2, actual3));
113- }
114-
11594 /**
11695 * {@inheritDoc}
11796 */
@@ -125,12 +104,7 @@
125104 */
126105 @Override
127106 public boolean getBool(int i) {
128- checkType(i, BOOLEAN);
129-
130107 ByteBuffer value = getValue(i);
131- if (value == null || value.remaining() == 0)
132- return false;
133-
134108 TypeCodec<Boolean> codec = codecFor(i, Boolean.class);
135109 if(codec instanceof TypeCodec.PrimitiveBooleanCodec)
136110 return ((TypeCodec.PrimitiveBooleanCodec) codec).deserializeNoBoxing(value, protocolVersion);
@@ -143,7 +117,6 @@
143117 */
144118 @Override
145119 public byte getByte(int i) {
146- checkType(i, TINYINT);
147120 ByteBuffer value = getValue(i);
148121 TypeCodec<Byte> codec = codecFor(i, Byte.class);
149122 if(codec instanceof TypeCodec.PrimitiveByteCodec)
@@ -157,7 +130,6 @@
157130 */
158131 @Override
159132 public short getShort(int i) {
160- checkType(i, SMALLINT);
161133 ByteBuffer value = getValue(i);
162134 TypeCodec<Short> codec = codecFor(i, Short.class);
163135 if(codec instanceof TypeCodec.PrimitiveShortCodec)
@@ -171,7 +143,6 @@
171143 */
172144 @Override
173145 public int getInt(int i) {
174- checkType(i, INT);
175146 ByteBuffer value = getValue(i);
176147 TypeCodec<Integer> codec = codecFor(i, Integer.class);
177148 if(codec instanceof TypeCodec.PrimitiveIntCodec)
@@ -185,7 +156,6 @@
185156 */
186157 @Override
187158 public long getLong(int i) {
188- checkType(i, BIGINT, COUNTER);
189159 ByteBuffer value = getValue(i);
190160 TypeCodec<Long> codec = codecFor(i, Long.class);
191161 if(codec instanceof TypeCodec.PrimitiveLongCodec)
@@ -199,7 +169,6 @@
199169 */
200170 @Override
201171 public Date getTimestamp(int i) {
202- checkType(i, TIMESTAMP);
203172 ByteBuffer value = getValue(i);
204173 return codecFor(i, Date.class).deserialize(value, protocolVersion);
205174 }
@@ -209,7 +178,6 @@
209178 */
210179 @Override
211180 public LocalDate getDate(int i) {
212- checkType(i, DATE);
213181 ByteBuffer value = getValue(i);
214182 return codecFor(i, LocalDate.class).deserialize(value, protocolVersion);
215183 }
@@ -219,7 +187,6 @@
219187 */
220188 @Override
221189 public long getTime(int i) {
222- checkType(i, TIME);
223190 ByteBuffer value = getValue(i);
224191 TypeCodec<Long> codec = codecFor(i, Long.class);
225192 if(codec instanceof TypeCodec.PrimitiveLongCodec)
@@ -233,7 +200,6 @@
233200 */
234201 @Override
235202 public float getFloat(int i) {
236- checkType(i, FLOAT);
237203 ByteBuffer value = getValue(i);
238204 TypeCodec<Float> codec = codecFor(i, Float.class);
239205 if(codec instanceof TypeCodec.PrimitiveFloatCodec)
@@ -247,7 +213,6 @@
247213 */
248214 @Override
249215 public double getDouble(int i) {
250- checkType(i, DOUBLE);
251216 ByteBuffer value = getValue(i);
252217 TypeCodec<Double> codec = codecFor(i, Double.class);
253218 if(codec instanceof TypeCodec.PrimitiveDoubleCodec)
@@ -272,7 +237,6 @@
272237 */
273238 @Override
274239 public ByteBuffer getBytes(int i) {
275- checkType(i, BLOB);
276240 ByteBuffer value = getValue(i);
277241 return codecFor(i, ByteBuffer.class).deserialize(value, protocolVersion);
278242 }
@@ -282,7 +246,6 @@
282246 */
283247 @Override
284248 public String getString(int i) {
285- checkType(i, VARCHAR, ASCII);
286249 ByteBuffer value = getValue(i);
287250 return codecFor(i, String.class).deserialize(value, protocolVersion);
288251 }
@@ -292,7 +255,6 @@
292255 */
293256 @Override
294257 public BigInteger getVarint(int i) {
295- checkType(i, VARINT);
296258 ByteBuffer value = getValue(i);
297259 return codecFor(i, BigInteger.class).deserialize(value, protocolVersion);
298260 }
@@ -302,7 +264,6 @@
302264 */
303265 @Override
304266 public BigDecimal getDecimal(int i) {
305- checkType(i, DECIMAL);
306267 ByteBuffer value = getValue(i);
307268 return codecFor(i, BigDecimal.class).deserialize(value, protocolVersion);
308269 }
@@ -312,7 +273,6 @@
312273 */
313274 @Override
314275 public UUID getUUID(int i) {
315- checkType(i, UUID, TIMEUUID);
316276 ByteBuffer value = getValue(i);
317277 return codecFor(i, UUID.class).deserialize(value, protocolVersion);
318278 }
@@ -322,7 +282,6 @@
322282 */
323283 @Override
324284 public InetAddress getInet(int i) {
325- checkType(i, INET);
326285 ByteBuffer value = getValue(i);
327286 return codecFor(i, InetAddress.class).deserialize(value, protocolVersion);
328287 }
@@ -342,7 +301,6 @@
342301 @Override
343302 @SuppressWarnings("unchecked")
344303 public <T> List<T> getList(int i, TypeToken<T> elementsType) {
345- checkType(i, LIST);
346304 ByteBuffer value = getValue(i);
347305 TypeToken<List<T>> javaType = listOf(elementsType);
348306 return codecFor(i, javaType).deserialize(value, protocolVersion);
@@ -363,7 +321,6 @@
363321 @Override
364322 @SuppressWarnings("unchecked")
365323 public <T> Set<T> getSet(int i, TypeToken<T> elementsType) {
366- checkType(i, SET);
367324 ByteBuffer value = getValue(i);
368325 TypeToken<Set<T>> javaType = setOf(elementsType);
369326 return codecFor(i, javaType).deserialize(value, protocolVersion);
@@ -384,7 +341,6 @@
384341 @Override
385342 @SuppressWarnings("unchecked")
386343 public <K, V> Map<K, V> getMap(int i, TypeToken<K> keysType, TypeToken<V> valuesType) {
387- checkType(i, MAP);
388344 ByteBuffer value = getValue(i);
389345 TypeToken<Map<K, V>> javaType = mapOf(keysType, valuesType);
390346 return codecFor(i, javaType).deserialize(value, protocolVersion);
@@ -396,7 +352,6 @@
396352 @Override
397353 @SuppressWarnings("unchecked")
398354 public UDTValue getUDTValue(int i) {
399- checkType(i, UDT);
400355 ByteBuffer value = getValue(i);
401356 return codecFor(i, UDTValue.class).deserialize(value, protocolVersion);
402357 }
@@ -407,7 +362,6 @@
407362 @Override
408363 @SuppressWarnings("unchecked")
409364 public TupleValue getTupleValue(int i) {
410- checkType(i, TUPLE);
411365 ByteBuffer value = getValue(i);
412366 return codecFor(i, TupleValue.class).deserialize(value, protocolVersion);
413367 }
modified driver-core/src/main/java/com/datastax/driver/core/DataType.java +4 −2
@@ -47,6 +47,7 @@
4747 INET (16),
4848 INT (9),
4949 TEXT (10){
50+ @Override
5051 public boolean isCompatibleWith(Name that) {
5152 return this == that || that == VARCHAR;
5253 }
@@ -54,6 +55,7 @@
5455 TIMESTAMP (11),
5556 UUID (12),
5657 VARCHAR (13){
58+ @Override
5759 public boolean isCompatibleWith(Name that) {
5860 return this == that || that == TEXT;
5961 }
@@ -637,7 +639,7 @@
637639
638640 @Override
639641 public final int hashCode() {
640- return Arrays.hashCode(new Object[]{ name, typeArguments });
642+ return Objects.hashCode(name, typeArguments);
641643 }
642644
643645 @Override
@@ -682,7 +684,7 @@
682684
683685 @Override
684686 public final int hashCode() {
685- return Arrays.hashCode(new Object[]{ name, customClassName });
687+ return Objects.hashCode(name, customClassName);
686688 }
687689
688690 @Override
modified driver-core/src/main/java/com/datastax/driver/core/GettableByIndexData.java +5 −46
@@ -49,7 +49,6 @@
4949 * value is NULL, {@code false} is returned.
5050 *
5151 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
52- * @throws InvalidTypeException if value {@code i} is not of type BOOLEAN.
5352 */
5453 public boolean getBool(int i);
5554
@@ -61,7 +60,6 @@
6160 * value is NULL, {@code 0} is returned.
6261 *
6362 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
64- * @throws InvalidTypeException if value {@code i} is not of type TINYINT.
6563 */
6664 public byte getByte(int i);
6765
@@ -73,7 +71,6 @@
7371 * value is NULL, {@code 0} is returned.
7472 *
7573 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
76- * @throws InvalidTypeException if value {@code i} is not of type SMALLINT.
7774 */
7875 public short getShort(int i);
7976
@@ -85,7 +82,6 @@
8582 * value is NULL, {@code 0} is returned.
8683 *
8784 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
88- * @throws InvalidTypeException if value {@code i} is not of type INT.
8985 */
9086 public int getInt(int i);
9187
@@ -97,7 +93,6 @@
9793 * value is NULL, {@code 0L} is returned.
9894 *
9995 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
100- * @throws InvalidTypeException if value {@code i} is not of type BIGINT or COUNTER.
10196 */
10297 public long getLong(int i);
10398
@@ -109,7 +104,6 @@
109104 * value is NULL, {@code null} is returned.
110105 *
111106 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
112- * @throws InvalidTypeException if value {@code i} is not of type TIMESTAMP.
113107 */
114108 public Date getTimestamp(int i);
115109
@@ -121,7 +115,6 @@
121115 * value is NULL, {@code null} is returned.
122116 *
123117 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
124- * @throws InvalidTypeException if value {@code i} is not of type DATE.
125118 */
126119 public LocalDate getDate(int i);
127120
@@ -133,7 +126,6 @@
133126 * value is NULL, {@code 0L} is returned.
134127 *
135128 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
136- * @throws InvalidTypeException if value {@code i} is not of type TIME.
137129 */
138130 public long getTime(int i);
139131
@@ -145,7 +137,6 @@
145137 * value is NULL, {@code 0.0f} is returned.
146138 *
147139 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
148- * @throws InvalidTypeException if value {@code i} is not of type FLOAT.
149140 */
150141 public float getFloat(int i);
151142
@@ -157,7 +148,6 @@
157148 * value is NULL, {@code 0.0} is returned.
158149 *
159150 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
160- * @throws InvalidTypeException if value {@code i} is not of type DOUBLE.
161151 */
162152 public double getDouble(int i);
163153
@@ -188,7 +178,6 @@
188178 * value is NULL, {@code null} is returned.
189179 *
190180 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
191- * @throws InvalidTypeException if value {@code i} type is not of type BLOB.
192181 */
193182 public ByteBuffer getBytes(int i);
194183
@@ -200,8 +189,6 @@
200189 * value is NULL, {@code null} is returned.
201190 *
202191 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
203- * @throws InvalidTypeException if value {@code i} type is none of:
204- * VARCHAR, TEXT or ASCII.
205192 */
206193 public String getString(int i);
207194
@@ -213,7 +200,6 @@
213200 * length integer. If the value is NULL, {@code null} is returned.
214201 *
215202 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
216- * @throws InvalidTypeException if value {@code i} is not of type VARINT.
217203 */
218204 public BigInteger getVarint(int i);
219205
@@ -225,7 +211,6 @@
225211 * length decimal. If the value is NULL, {@code null} is returned.
226212 *
227213 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
228- * @throws InvalidTypeException if value {@code i} is not of type DECIMAL.
229214 */
230215 public BigDecimal getDecimal(int i);
231216
@@ -237,8 +222,6 @@
237222 * If the value is NULL, {@code null} is returned.
238223 *
239224 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
240- * @throws InvalidTypeException if value {@code i} is not of type UUID
241- * or TIMEUUID.
242225 */
243226 public UUID getUUID(int i);
244227
@@ -250,7 +233,6 @@
250233 * If the value is NULL, {@code null} is returned.
251234 *
252235 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
253- * @throws InvalidTypeException if value {@code i} is not of type INET.
254236 */
255237 public InetAddress getInet(int i);
256238
@@ -273,8 +255,6 @@
273255 * {@code T} objects.
274256 *
275257 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
276- * @throws InvalidTypeException if value {@code i} is not a list or if its
277- * elements are not of class {@code T}.
278258 */
279259 public <T> List<T> getList(int i, Class<T> elementsClass);
280260
@@ -300,8 +280,6 @@
300280 * {@code T} objects.
301281 *
302282 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
303- * @throws InvalidTypeException if value {@code i} is not a list or if its
304- * elements are not of class {@code T}.
305283 */
306284 public <T> List<T> getList(int i, TypeToken<T> elementsType);
307285
@@ -324,8 +302,6 @@
324302 * {@code T} objects.
325303 *
326304 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
327- * @throws InvalidTypeException if value {@code i} is not a set or if its
328- * elements are not of class {@code T}.
329305 */
330306 public <T> Set<T> getSet(int i, Class<T> elementsClass);
331307
@@ -351,8 +327,6 @@
351327 * {@code T} objects.
352328 *
353329 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
354- * @throws InvalidTypeException if value {@code i} is not a set or if its
355- * elements are not of class {@code T}.
356330 */
357331 public <T> Set<T> getSet(int i, TypeToken<T> elementsType);
358332
@@ -376,9 +350,6 @@
376350 * {@code K} to {@code V} objects.
377351 *
378352 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
379- * @throws InvalidTypeException if value {@code i} is not a map, if its
380- * keys are not of class {@code K} or if its values are not of
381- * class {@code V}.
382353 */
383354 public <K, V> Map<K, V> getMap(int i, Class<K> keysClass, Class<V> valuesClass);
384355
@@ -406,9 +377,6 @@
406377 * {@code K} to {@code V} objects.
407378 *
408379 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
409- * @throws InvalidTypeException if value {@code i} is not a map, if its
410- * keys are not of class {@code K} or if its values are not of
411- * class {@code V}.
412380 */
413381 public <K, V> Map<K, V> getMap(int i, TypeToken<K> keysType, TypeToken<V> valuesType);
414382
@@ -420,7 +388,6 @@
420388 * then {@code null} will be returned.
421389 *
422390 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
423- * @throws InvalidTypeException if value {@code i} is not a UDT value.
424391 */
425392 public UDTValue getUDTValue(int i);
426393
@@ -432,26 +399,18 @@
432399 * then {@code null} will be returned.
433400 *
434401 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
435- * @throws InvalidTypeException if value {@code i} is not a tuple value.
436402 */
437403 public TupleValue getTupleValue(int i);
438404
439405 /**
440406 * Returns the {@code i}th value as the Java type matching its CQL type.
441407 * <p>
442- * This method uses the default codec for the underlying CQL type
443- * to perform deserialization, and is safe to be used
444- * <em>as long as only default codecs are in use</em>.
445- * If a second, custom codec for the same CQL type is registered, which one will
446- * be used is unspecified; in such cases, it is preferable to use
447- * the more deterministic methods {@link #get(int, Class)} or {@link #get(int, TypeToken)} instead.
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>.
448411 * <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.
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.
455414 *
456415 * @param i the index to retrieve.
457416 * @return the value of the {@code i}th value as the Java type matching its CQL type.
modified driver-core/src/main/java/com/datastax/driver/core/GettableByNameData.java +8 −48
@@ -48,7 +48,6 @@
4848 * {@code false} is returned.
4949 *
5050 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
51- * @throws InvalidTypeException if value {@code name} is not of type BOOLEAN.
5251 */
5352 public boolean getBool(String name);
5453
@@ -60,7 +59,6 @@
6059 * {@code 0} is returned.
6160 *
6261 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
63- * @throws InvalidTypeException if value {@code name} is not of type TINYINT.
6462 */
6563 public byte getByte(String name);
6664
@@ -72,7 +70,6 @@
7270 * {@code 0} is returned.
7371 *
7472 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
75- * @throws InvalidTypeException if value {@code name} is not of type SMALLINT.
7673 */
7774 public short getShort(String name);
7875
@@ -84,7 +81,6 @@
8481 * {@code 0} is returned.
8582 *
8683 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
87- * @throws InvalidTypeException if value {@code name} is not of type INT.
8884 */
8985 public int getInt(String name);
9086
@@ -96,7 +92,6 @@
9692 * {@code 0L} is returned.
9793 *
9894 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
99- * @throws InvalidTypeException if value {@code i} is not of type BIGINT or COUNTER.
10095 */
10196 public long getLong(String name);
10297
@@ -108,7 +103,6 @@
108103 * {@code null} is returned.
109104 *
110105 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
111- * @throws InvalidTypeException if value {@code name} is not of type TIMESTAMP.
112106 */
113107 public Date getTimestamp(String name);
114108
@@ -120,7 +114,6 @@
120114 * {@code null} is returned.
121115 *
122116 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
123- * @throws InvalidTypeException if value {@code name} is not of type DATE.
124117 */
125118 public LocalDate getDate(String name);
126119
@@ -132,7 +125,6 @@
132125 * {@code 0L} is returned.
133126 *
134127 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
135- * @throws InvalidTypeException if value {@code name} is not of type TIME.
136128 */
137129 public long getTime(String name);
138130
@@ -144,7 +136,6 @@
144136 * {@code 0.0f} is returned.
145137 *
146138 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
147- * @throws InvalidTypeException if value {@code name} is not of type FLOAT.
148139 */
149140 public float getFloat(String name);
150141
@@ -156,7 +147,6 @@
156147 * {@code 0.0} is returned.
157148 *
158149 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
159- * @throws InvalidTypeException if value {@code name} is not of type DOUBLE.
160150 */
161151 public double getDouble(String name);
162152
@@ -187,7 +177,6 @@
187177 * {@code null} is returned.
188178 *
189179 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
190- * @throws InvalidTypeException if value {@code i} type is not of type BLOB.
191180 */
192181 public ByteBuffer getBytes(String name);
193182
@@ -199,8 +188,6 @@
199188 * {@code null} is returned.
200189 *
201190 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
202- * @throws InvalidTypeException if value {@code name} type is none of:
203- * VARCHAR, TEXT or ASCII.
204191 */
205192 public String getString(String name);
206193
@@ -212,7 +199,6 @@
212199 * If the value is NULL, {@code null} is returned.
213200 *
214201 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
215- * @throws InvalidTypeException if value {@code name} is not of type VARINT.
216202 */
217203 public BigInteger getVarint(String name);
218204
@@ -224,7 +210,6 @@
224210 * If the value is NULL, {@code null} is returned.
225211 *
226212 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
227- * @throws InvalidTypeException if value {@code name} is not of type DECIMAL.
228213 */
229214 public BigDecimal getDecimal(String name);
230215
@@ -236,8 +221,6 @@
236221 * If the value is NULL, {@code null} is returned.
237222 *
238223 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
239- * @throws InvalidTypeException if value {@code name} is not of type
240- * UUID or TIMEUUID.
241224 */
242225 public UUID getUUID(String name);
243226
@@ -249,8 +232,6 @@
249232 * If the value is NULL, {@code null} is returned.
250233 *
251234 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
252- * @throws InvalidTypeException if value {@code name} is not of type
253- * INET.
254235 */
255236 public InetAddress getInet(String name);
256237
@@ -273,8 +254,6 @@
273254 * {@code T} objects.
274255 *
275256 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
276- * @throws InvalidTypeException if value {@code name} is not a list or if its
277- * elements are not of class {@code T}.
278257 */
279258 public <T> List<T> getList(String name, Class<T> elementsClass);
280259
@@ -300,8 +279,6 @@
300279 * {@code T} objects.
301280 *
302281 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
303- * @throws InvalidTypeException if value {@code name} is not a list or if its
304- * elements are not of class {@code T}.
305282 */
306283 public <T> List<T> getList(String name, TypeToken<T> elementsType);
307284
@@ -324,8 +301,6 @@
324301 * {@code T} objects.
325302 *
326303 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
327- * @throws InvalidTypeException if value {@code name} is not a set or if its
328- * elements are not of class {@code T}.
329304 */
330305 public <T> Set<T> getSet(String name, Class<T> elementsClass);
331306
@@ -351,8 +326,6 @@
351326 * {@code T} objects.
352327 *
353328 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
354- * @throws InvalidTypeException if value {@code name} is not a set or if its
355- * elements are not of class {@code T}.
356329 */
357330 public <T> Set<T> getSet(String name, TypeToken<T> elementsType);
358331
@@ -376,9 +349,6 @@
376349 * {@code K} to {@code V} objects.
377350 *
378351 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
379- * @throws InvalidTypeException if value {@code name} is not a map, if its
380- * keys are not of class {@code K} or if its values are not of
381- * class {@code V}.
382352 */
383353 public <K, V> Map<K, V> getMap(String name, Class<K> keysClass, Class<V> valuesClass);
384354
@@ -405,9 +375,6 @@
405375 * {@code K} to {@code V} objects.
406376 *
407377 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
408- * @throws InvalidTypeException if value {@code name} is not a map, if its
409- * keys are not of class {@code K} or if its values are not of
410- * class {@code V}.
411378 */
412379 public <K, V> Map<K, V> getMap(String name, TypeToken<K> keysType, TypeToken<V> valuesType);
413380
@@ -419,7 +386,6 @@
419386 * then {@code null} will be returned.
420387 *
421388 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
422- * @throws InvalidTypeException if value {@code i} is not a UDT value.
423389 */
424390 public UDTValue getUDTValue(String name);
425391
@@ -431,29 +397,23 @@
431397 * then {@code null} will be returned.
432398 *
433399 * @throws IllegalArgumentException if {@code name} is not valid name for this object.
434- * @throws InvalidTypeException if value {@code i} is not a tuple value.
435400 */
436401 public TupleValue getTupleValue(String name);
437402
438403 /**
439404 * Returns the value for {@code name} as the Java type matching its CQL type.
440405 * <p>
441- * This method uses the default codec for the underlying CQL type
442- * to perform deserialization, and is safe to be used
443- * <em>as long as only default codecs are in use</em>.
444- * If a second, custom codec for the same CQL type is registered, which one will
445- * be used is unspecified; in such cases, it is preferable to use
446- * the more deterministic methods {@link #get(String, Class)} or {@link #get(String, TypeToken)} instead.
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>.
447409 * <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.
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.
454412 *
455413 * @param name the name to retrieve.
456- * @return the value of the {@code i}th value as the Java type matching its CQL type.
414+ * @return the value of {@code name} as the Java type matching its CQL type.
415+ * If the value is NULL and is a simple type, UDT or tuple, {@code null} is returned.
416+ * If it is NULL and is a collection type, an empty (immutable) collection is returned.
457417 *
458418 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
459419 */
modified driver-core/src/main/java/com/datastax/driver/core/SettableByIndexData.java +9 −72
@@ -38,7 +38,6 @@
3838 * @return this object.
3939 *
4040 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
41- * @throws InvalidTypeException if value {@code i} is not of type BOOLEAN.
4241 */
4342 public T setBool(int i, boolean v);
4443
@@ -50,7 +49,6 @@
5049 * @return this object.
5150 *
5251 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
53- * @throws InvalidTypeException if value {@code i} is not of type TINYINT.
5452 */
5553 public T setByte(int i, byte v);
5654
@@ -62,7 +60,6 @@
6260 * @return this object.
6361 *
6462 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
65- * @throws InvalidTypeException if value {@code i} is not of type SMALLINT.
6663 */
6764 public T setShort(int i, short v);
6865
@@ -74,7 +71,6 @@
7471 * @return this object.
7572 *
7673 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
77- * @throws InvalidTypeException if value {@code i} is not of type INT.
7874 */
7975 public T setInt(int i, int v);
8076
@@ -86,7 +82,6 @@
8682 * @return this object.
8783 *
8884 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
89- * @throws InvalidTypeException if value {@code i} is not of type BIGINT or COUNTER.
9085 */
9186 public T setLong(int i, long v);
9287
@@ -98,7 +93,6 @@
9893 * @return this object.
9994 *
10095 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
101- * @throws InvalidTypeException if value {@code i} is not of type TIMESTAMP.
10296 */
10397 public T setTimestamp(int i, Date v);
10498
@@ -110,7 +104,6 @@
110104 * @return this object.
111105 *
112106 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
113- * @throws InvalidTypeException if value {@code i} is not of type DATE.
114107 */
115108 public T setDate(int i, LocalDate v);
116109
@@ -122,7 +115,6 @@
122115 * @return this object.
123116 *
124117 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
125- * @throws InvalidTypeException if value {@code i} is not of type TIME.
126118 */
127119 public T setTime(int i, long v);
128120
@@ -134,7 +126,6 @@
134126 * @return this object.
135127 *
136128 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
137- * @throws InvalidTypeException if value {@code i} is not of type FLOAT.
138129 */
139130 public T setFloat(int i, float v);
140131
@@ -146,7 +137,6 @@
146137 * @return this object.
147138 *
148139 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
149- * @throws InvalidTypeException if value {@code i} is not of type DOUBLE.
150140 */
151141 public T setDouble(int i, double v);
152142
@@ -158,8 +148,6 @@
158148 * @return this object.
159149 *
160150 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
161- * @throws InvalidTypeException if value {@code i} is of neither of the
162- * following types: VARCHAR, TEXT or ASCII.
163151 */
164152 public T setString(int i, String v);
165153
@@ -175,7 +163,6 @@
175163 * @return this object.
176164 *
177165 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
178- * @throws InvalidTypeException if value {@code i} is not of type BLOB.
179166 */
180167 public T setBytes(int i, ByteBuffer v);
181168
@@ -203,7 +190,6 @@
203190 * @return this object.
204191 *
205192 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
206- * @throws InvalidTypeException if value {@code i} is not of type VARINT.
207193 */
208194 public T setVarint(int i, BigInteger v);
209195
@@ -215,7 +201,6 @@
215201 * @return this object.
216202 *
217203 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
218- * @throws InvalidTypeException if value {@code i} is not of type DECIMAL.
219204 */
220205 public T setDecimal(int i, BigDecimal v);
221206
@@ -227,9 +212,6 @@
227212 * @return this object.
228213 *
229214 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
230- * @throws InvalidTypeException if value {@code i} is not of type UUID or
231- * TIMEUUID, or if value {@code i} is of type TIMEUUID but {@code v} is
232- * not a type 1 UUID.
233215 */
234216 public T setUUID(int i, UUID v);
235217
@@ -241,7 +223,6 @@
241223 * @return this object.
242224 *
243225 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
244- * @throws InvalidTypeException if value {@code i} is not of type INET.
245226 */
246227 public T setInet(int i, InetAddress v);
247228
@@ -250,12 +231,9 @@
250231 * <p>
251232 * Please note that {@code null} values inside collections are not supported by CQL.
252233 * <p>
253- * Note about performance: this method must perform a runtime inspection of the provided list,
254- * in order to guess the best codec to serialize the list elements.
255- * <p>
256- * Furthermore, if two or more codecs are available
257- * for the underlying CQL type ({@code list}), <em>which one will be used will depend
258- * on the actual object being serialized</em>.
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>.
259237 * <p>
260238 * For these reasons, it is generally preferable to use the more
261239 * deterministic methods {@link #setList(int, List, Class)} or
@@ -266,9 +244,6 @@
266244 * @return this object.
267245 *
268246 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
269- * @throws InvalidTypeException if value {@code i} is not a list type or
270- * if the elements of {@code v} are not of the type of the elements of
271- * column {@code i}.
272247 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
273248 * by CQL.
274249 */
@@ -290,9 +265,6 @@
290265 * @return this object.
291266 *
292267 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
293- * @throws InvalidTypeException if value {@code i} is not a list type or
294- * if the elements of {@code v} are not of the type of the elements of
295- * column {@code i}.
296268 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
297269 * by CQL.
298270 */
@@ -314,9 +286,6 @@
314286 * @return this object.
315287 *
316288 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
317- * @throws InvalidTypeException if value {@code i} is not a list type or
318- * if the elements of {@code v} are not of the type of the elements of
319- * column {@code i}.
320289 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
321290 * by CQL.
322291 */
@@ -327,14 +296,9 @@
327296 * <p>
328297 * Please note that {@code null} values are not supported inside collection by CQL.
329298 * <p>
330- * Note about performance: this method must perform a runtime inspection of the provided map,
331- * in order to guess the best codec to serialize the map entries.
332- * The result of such inspection cannot be cached and thus must be performed for each invocation
333- * of this method, which may incur in a performance penalty.
334- * <p>
335- * Furthermore, if two or more codecs are available
336- * for the underlying CQL type ({@code map}), <em>which one will be used will depend
337- * on the actual object being serialized</em>.
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>.
338302 * <p>
339303 * For these reasons, it is generally preferable to use the more
340304 * deterministic methods {@link #setMap(int, Map, Class, Class)} or
@@ -345,9 +309,6 @@
345309 * @return this object.
346310 *
347311 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
348- * @throws InvalidTypeException if value {@code i} is not a map type or
349- * if the elements (keys or values) of {@code v} are not of the type of the
350- * elements of column {@code i}.
351312 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
352313 * by CQL.
353314 */
@@ -370,9 +331,6 @@
370331 * @return this object.
371332 *
372333 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
373- * @throws InvalidTypeException if value {@code i} is not a map type or
374- * if the elements of {@code v} are not of the type of the elements of
375- * column {@code i}.
376334 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
377335 * by CQL.
378336 */
@@ -395,9 +353,6 @@
395353 * @return this object.
396354 *
397355 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
398- * @throws InvalidTypeException if value {@code i} is not a map type or
399- * if the elements of {@code v} are not of the type of the elements of
400- * column {@code i}.
401356 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
402357 * by CQL.
403358 */
@@ -408,14 +363,9 @@
408363 * <p>
409364 * Please note that {@code null} values are not supported inside collection by CQL.
410365 * <p>
411- * Note about performance: this method must perform a runtime inspection of the provided set,
412- * in order to guess the best codec to serialize the set elements.
413- * The result of such inspection cannot be cached and thus must be performed for each invocation
414- * of this method, which may incur in a performance penalty.
415- * <p>
416- * Furthermore, if two or more codecs are available
417- * for the underlying CQL type ({@code set}), <em>which one will be used will depend
418- * on the actual object being serialized</em>.
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>.
419369 * <p>
420370 * For these reasons, it is generally preferable to use the more
421371 * deterministic methods {@link #setSet(int, Set, Class)} or
@@ -426,9 +376,6 @@
426376 * @return this object.
427377 *
428378 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
429- * @throws InvalidTypeException if value {@code i} is not a set type or
430- * if the elements of {@code v} are not of the type of the elements of
431- * column {@code i}.
432379 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
433380 * by CQL.
434381 */
@@ -450,9 +397,6 @@
450397 * @return this object.
451398 *
452399 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
453- * @throws InvalidTypeException if value {@code i} is not a set type or
454- * if the elements of {@code v} are not of the type of the elements of
455- * column {@code i}.
456400 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
457401 * by CQL.
458402 */
@@ -474,9 +418,6 @@
474418 * @return this object.
475419 *
476420 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
477- * @throws InvalidTypeException if value {@code i} is not a set type or
478- * if the elements of {@code v} are not of the type of the elements of
479- * column {@code i}.
480421 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
481422 * by CQL.
482423 */
@@ -490,8 +431,6 @@
490431 * @return this object.
491432 *
492433 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
493- * @throws InvalidTypeException if value {@code i} is not a UDT value or if its definition
494- * does not correspond to the one of {@code v}.
495434 */
496435 public T setUDTValue(int i, UDTValue v);
497436
@@ -503,8 +442,6 @@
503442 * @return this object.
504443 *
505444 * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
506- * @throws InvalidTypeException if value {@code i} is not a tuple value or if its types
507- * do not correspond to the ones of {@code v}.
508445 */
509446 public T setTupleValue(int i, TupleValue v);
510447
modified driver-core/src/main/java/com/datastax/driver/core/SettableByNameData.java +14 −92
@@ -40,7 +40,6 @@
4040 * @return this object.
4141 *
4242 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
43- * @throws InvalidTypeException if (any one occurrence of) {@code name} is not of type BOOLEAN.
4443 */
4544 public T setBool(String name, boolean v);
4645
@@ -54,7 +53,6 @@
5453 * @return this object.
5554 *
5655 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
57- * @throws InvalidTypeException if (any one occurrence of) {@code name} is not of type TINYINT.
5856 */
5957 public T setByte(String name, byte v);
6058
@@ -68,7 +66,6 @@
6866 * @return this object.
6967 *
7068 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
71- * @throws InvalidTypeException if (any one occurrence of) {@code name} is not of type SMALLINT.
7269 */
7370 public T setShort(String name, short v);
7471
@@ -82,7 +79,6 @@
8279 * @return this object.
8380 *
8481 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
85- * @throws InvalidTypeException if (any one occurrence of) {@code name} is not of type INT.
8682 */
8783 public T setInt(String name, int v);
8884
@@ -96,8 +92,6 @@
9692 * @return this object.
9793 *
9894 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
99- * @throws InvalidTypeException if (any occurrence of) {@code name} is
100- * not of type BIGINT or COUNTER.
10195 */
10296 public T setLong(String name, long v);
10397
@@ -111,8 +105,6 @@
111105 * @return this object.
112106 *
113107 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
114- * @throws InvalidTypeException if (any occurrence of) {@code name} is
115- * not of type TIMESTAMP.
116108 */
117109 public T setTimestamp(String name, Date v);
118110
@@ -126,8 +118,6 @@
126118 * @return this object.
127119 *
128120 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
129- * @throws InvalidTypeException if (any occurrence of) {@code name} is
130- * not of type DATE.
131121 */
132122 public T setDate(String name, LocalDate v);
133123
@@ -141,8 +131,6 @@
141131 * @return this object.
142132 *
143133 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
144- * @throws InvalidTypeException if (any occurrence of) {@code name} is
145- * not of type TIME.
146134 */
147135 public T setTime(String name, long v);
148136
@@ -156,8 +144,6 @@
156144 * @return this object.
157145 *
158146 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
159- * @throws InvalidTypeException if (any occurrence of) {@code name} is
160- * not of type FLOAT.
161147 */
162148 public T setFloat(String name, float v);
163149
@@ -171,8 +157,6 @@
171157 * @return this object.
172158 *
173159 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
174- * @throws InvalidTypeException if (any occurrence of) {@code name} is
175- * not of type DOUBLE.
176160 */
177161 public T setDouble(String name, double v);
178162
@@ -186,8 +170,6 @@
186170 * @return this object.
187171 *
188172 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
189- * @throws InvalidTypeException if (any occurrence of) {@code name} is
190- * of neither of the following types: VARCHAR, TEXT or ASCII.
191173 */
192174 public T setString(String name, String v);
193175
@@ -205,7 +187,6 @@
205187 * @return this object.
206188 *
207189 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
208- * @throws InvalidTypeException if (any occurrence of) {@code name} is not of type BLOB.
209190 */
210191 public T setBytes(String name, ByteBuffer v);
211192
@@ -237,8 +218,6 @@
237218 * @return this object.
238219 *
239220 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
240- * @throws InvalidTypeException if (any occurrence of) {@code name} is
241- * not of type VARINT.
242221 */
243222 public T setVarint(String name, BigInteger v);
244223
@@ -252,8 +231,6 @@
252231 * @return this object.
253232 *
254233 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
255- * @throws InvalidTypeException if (any occurrence of) {@code name} is
256- * not of type DECIMAL.
257234 */
258235 public T setDecimal(String name, BigDecimal v);
259236
@@ -267,9 +244,6 @@
267244 * @return this object.
268245 *
269246 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
270- * @throws InvalidTypeException if (any occurrence of) {@code name} is
271- * not of type UUID or TIMEUUID, or if value {@code name} is of type
272- * TIMEUUID but {@code v} is not a type 1 UUID.
273247 */
274248 public T setUUID(String name, UUID v);
275249
@@ -283,8 +257,6 @@
283257 * @return this object.
284258 *
285259 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
286- * @throws InvalidTypeException if (any occurrence of) {@code name} is
287- * not of type INET.
288260 */
289261 public T setInet(String name, InetAddress v);
290262
@@ -294,14 +266,9 @@
294266 * <p>
295267 * Please note that {@code null} values inside collections are not supported by CQL.
296268 * <p>
297- * Note about performance: this method must perform a runtime inspection of the provided list,
298- * in order to guess the best codec to serialize the list elements.
299- * The result of such inspection cannot be cached and thus must be performed for each invocation
300- * of this method, which may incur in a performance penalty.
301- * <p>
302- * Furthermore, if two or more codecs are available
303- * for the underlying CQL type ({@code list}), <em>which one will be used will depend
304- * on the actual object being serialized</em>.
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>.
305272 * <p>
306273 * For these reasons, it is generally preferable to use the more
307274 * deterministic methods {@link #setList(String, List, Class)} or
@@ -313,9 +280,6 @@
313280 * @return this object.
314281 *
315282 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
316- * @throws InvalidTypeException if (any occurrence of) {@code name} is
317- * not a list type or if the elements of {@code v} are not of the type of
318- * the elements of column {@code name}.
319283 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
320284 * by CQL.
321285 */
@@ -336,10 +300,7 @@
336300 * @param elementsClass the class for the elements of the list.
337301 * @return this object.
338302 *
339- * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
340- * @throws InvalidTypeException if value {@code i} is not a list type or
341- * if the elements of {@code v} are not of the type of the elements of
342- * column {@code i}.
303+ * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
343304 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
344305 * by CQL.
345306 */
@@ -360,10 +321,7 @@
360321 * @param elementsType the type for the elements of the list.
361322 * @return this object.
362323 *
363- * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
364- * @throws InvalidTypeException if value {@code i} is not a list type or
365- * if the elements of {@code v} are not of the type of the elements of
366- * column {@code i}.
324+ * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
367325 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
368326 * by CQL.
369327 */
@@ -375,14 +333,10 @@
375333 * <p>
376334 * Please note that {@code null} values are not supported inside collection by CQL.
377335 * <p>
378- * Note about performance: this method must perform a runtime inspection of the provided map,
379- * in order to guess the best codec to serialize the map entries.
380- * The result of such inspection cannot be cached and thus must be performed for each invocation
381- * of this method, which may incur in a performance penalty.
382336 * <p>
383- * Furthermore, if two or more codecs are available
384- * for the underlying CQL type ({@code map}), <em>which one will be used will depend
385- * on the actual object being serialized</em>.
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>.
386340 * <p>
387341 * For these reasons, it is generally preferable to use the more
388342 * deterministic methods {@link #setMap(String, Map, Class, Class)} or
@@ -394,9 +348,6 @@
394348 * @return this object.
395349 *
396350 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
397- * @throws InvalidTypeException if (any occurrence of) {@code name} is
398- * not a map type or if the elements (keys or values) of {@code v} are not of
399- * the type of the elements of column {@code name}.
400351 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
401352 * by CQL.
402353 */
@@ -420,9 +371,6 @@
420371 * @return this object.
421372 *
422373 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
423- * @throws InvalidTypeException if (any occurrence of) {@code name} is
424- * not a map type or if the elements (keys or values) of {@code v} are not of
425- * the type of the elements of column {@code name}.
426374 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
427375 * by CQL.
428376 */
@@ -446,9 +394,6 @@
446394 * @return this object.
447395 *
448396 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
449- * @throws InvalidTypeException if (any occurrence of) {@code name} is
450- * not a map type or if the elements (keys or values) of {@code v} are not of
451- * the type of the elements of column {@code name}.
452397 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
453398 * by CQL.
454399 */
@@ -460,14 +405,9 @@
460405 * <p>
461406 * Please note that {@code null} values are not supported inside collection by CQL.
462407 * <p>
463- * Note about performance: this method must perform a runtime inspection of the provided map,
464- * in order to guess the best codec to serialize the set elements.
465- * The result of such inspection cannot be cached and thus must be performed for each invocation
466- * of this method, which may incur in a performance penalty.
467- * <p>
468- * Furthermore, if two or more codecs are available
469- * for the underlying CQL type ({@code set}), <em>which one will be used will depend
470- * on the actual object being serialized</em>.
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>.
471411 * <p>
472412 * For these reasons, it is generally preferable to use the more
473413 * deterministic methods {@link #setSet(String, Set, Class)} or
@@ -479,9 +419,6 @@
479419 * @return this object.
480420 *
481421 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
482- * @throws InvalidTypeException if (any occurrence of) {@code name} is
483- * not a map type or if the elements of {@code v} are not of the type of
484- * the elements of column {@code name}.
485422 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
486423 * by CQL.
487424 */
@@ -503,9 +440,6 @@
503440 * @return this object.
504441 *
505442 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
506- * @throws InvalidTypeException if (any occurrence of) {@code name} is
507- * not a map type or if the elements (keys or values) of {@code v} are not of
508- * the type of the elements of column {@code name}.
509443 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
510444 * by CQL.
511445 */
@@ -527,9 +461,6 @@
527461 * @return this object.
528462 *
529463 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
530- * @throws InvalidTypeException if (any occurrence of) {@code name} is
531- * not a map type or if the elements (keys or values) of {@code v} are not of
532- * the type of the elements of column {@code name}.
533464 * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections
534465 * by CQL.
535466 */
@@ -545,11 +476,6 @@
545476 * @return this object.
546477 *
547478 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
548- * @throws InvalidTypeException if value {@code i} is not a UDT value or if its definition
549- * does not correspond to the one of {@code v}.
550- * @throws InvalidTypeException if (any occurrence of) {@code name} is
551- * not a UDT value or if the definition of column {@code name} does not correspond to
552- * the one of {@code v}.
553479 */
554480 public T setUDTValue(String name, UDTValue v);
555481
@@ -563,9 +489,6 @@
563489 * @return this object.
564490 *
565491 * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
566- * @throws InvalidTypeException if (any occurrence of) {@code name} is
567- * not a tuple value or if the types of column {@code name} do not correspond to
568- * the ones of {@code v}.
569492 */
570493 public T setTupleValue(String name, TupleValue v);
571494
@@ -592,7 +515,7 @@
592515 * @param v the value to set; may be {@code null}.
593516 * @param targetClass The Java class to convert to; must not be {@code null};
594517 * @return this object.
595- * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
518+ * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
596519 */
597520 <V> T set(String name, V v, Class<V> targetClass);
598521
@@ -607,7 +530,7 @@
607530 * @param v the value to set; may be {@code null}.
608531 * @param targetType The Java type to convert to; must not be {@code null};
609532 * @return this object.
610- * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
533+ * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
611534 */
612535 <V> T set(String name, V v, TypeToken<V> targetType);
613536
@@ -627,9 +550,8 @@
627550 * @param codec The {@link TypeCodec} to use to serialize the value; may not be {@code null}.
628551 * @return this object.
629552 * @throws InvalidTypeException if the given codec does not {@link TypeCodec#accepts(DataType) accept} the underlying CQL type.
630- * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
553+ * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
631554 */
632555 <V> T set(String name, V v, TypeCodec<V> codec);
633556
634-
635557 }
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecJsonIntegrationTest.java +1 −1
@@ -123,7 +123,7 @@
123123 session.execute(session.prepare(insertQuery).bind()
124124 .setString(0, notAJsonString)
125125 .set(1, alice, User.class)
126- .setList(2, bobAndCharlie)
126+ .setList(2, bobAndCharlie, User.class)
127127 );
128128 PreparedStatement ps = session.prepare(selectQuery);
129129 ResultSet rows = session.execute(ps.bind()
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecUDTIntegrationTest.java +1 −1
@@ -154,7 +154,7 @@
154154
155155 @Override
156156 protected UDTValue serialize(Address value) {
157- return value == null ? null : userType.newValue().setString("street", value.street).setInt("zipcode", value.zipcode).setList("phones", value.phones);
157+ return value == null ? null : userType.newValue().setString("street", value.street).setInt("zipcode", value.zipcode).setList("phones", value.phones, Phone.class);
158158 }
159159 }
160160
modified features/custom_codecs/README.md +6 −7
@@ -440,14 +440,13 @@
440440
441441 The following situations are exceptions where it is not possible to cache lookup results:
442442
443-* With [SimpleStatement] instances and [BuiltStatement] instances (created via the Query Builder); in these places, the driver has
444- no way to determine the right CQL type to use, so it performs a best-effort heuristic to guess which codec to use.
445-* When using "ambiguous" methods of `BoundStatement` and `Row`, such as [setList()][setList],
446- [setSet()][setSet], [setMap()][setMap], [setObject()][setObject];
447- these methods are "ambiguous" because they do not convey enough compile-time information about the object
448- to serialize, so the driver performs the same heuristic to guess which codec to use.
443+* With [SimpleStatement] instances;
444+* With [BuiltStatement] instances (created via the Query Builder).
445+
446+In these places, the driver has no way to determine the right CQL type to use, so it performs
447+a best-effort heuristic to guess which codec to use.
449448
450-Beware that in these cases the lookup performs in average 10x worse. If performance is a key factor for your application,
449+Beware that in these cases, the lookup performs in average 10x worse. If performance is a key factor for your application,
451450 consider using prepared statements all the time, and avoid calling ambiguous methods (prefer `get()` and `set()`).
452451
453452 [JAVA-721]: https://datastax-oss.atlassian.net/browse/JAVA-721