kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | afde5547aef923de524301b0ac9644dbc98c50d7959274f0ccfd007c8d25c3dd |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-10-08 10:18 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-10-14 22:35 +02:00 |
| Parents | 7726f0cb3c91 |
12 files changed
modified changelog/README.md +1 −0
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | - [bug] Make TypeCodec return mutable collections (JAVA-922) |
| 15 | 15 | - [improvement] Limit visibility of codec internals (JAVA-932) |
| 16 | 16 | - [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) | |
| 17 | 18 | |
| 18 | 19 | |
| 19 | 20 | ### 3.0.0-alpha3 |
modified driver-core/src/main/java/com/datastax/driver/core/AbstractAddressableByIndexData.java +3 −52
| @@ -27,7 +27,6 @@ | ||
| 27 | 27 | import static com.datastax.driver.core.CodecUtils.listOf; |
| 28 | 28 | import static com.datastax.driver.core.CodecUtils.mapOf; |
| 29 | 29 | import static com.datastax.driver.core.CodecUtils.setOf; |
| 30 | -import static com.datastax.driver.core.DataType.Name.*; | |
| 31 | 30 | |
| 32 | 31 | abstract class AbstractAddressableByIndexData<T extends SettableByIndexData<T>> extends AbstractGettableByIndexData implements SettableByIndexData<T> { |
| 33 | 32 | |
| @@ -49,7 +48,6 @@ | ||
| 49 | 48 | } |
| 50 | 49 | |
| 51 | 50 | public T setBool(int i, boolean v) { |
| 52 | - checkType(i, BOOLEAN); | |
| 53 | 51 | TypeCodec<Boolean> codec = codecFor(i, Boolean.class); |
| 54 | 52 | ByteBuffer bb; |
| 55 | 53 | if(codec instanceof TypeCodec.PrimitiveBooleanCodec) |
| @@ -60,7 +58,6 @@ | ||
| 60 | 58 | } |
| 61 | 59 | |
| 62 | 60 | public T setByte(int i, byte v) { |
| 63 | - checkType(i, TINYINT); | |
| 64 | 61 | TypeCodec<Byte> codec = codecFor(i, Byte.class); |
| 65 | 62 | ByteBuffer bb; |
| 66 | 63 | if(codec instanceof TypeCodec.PrimitiveByteCodec) |
| @@ -71,7 +68,6 @@ | ||
| 71 | 68 | } |
| 72 | 69 | |
| 73 | 70 | public T setShort(int i, short v) { |
| 74 | - checkType(i, SMALLINT); | |
| 75 | 71 | TypeCodec<Short> codec = codecFor(i, Short.class); |
| 76 | 72 | ByteBuffer bb; |
| 77 | 73 | if(codec instanceof TypeCodec.PrimitiveShortCodec) |
| @@ -82,7 +78,6 @@ | ||
| 82 | 78 | } |
| 83 | 79 | |
| 84 | 80 | public T setInt(int i, int v) { |
| 85 | - checkType(i, INT); | |
| 86 | 81 | TypeCodec<Integer> codec = codecFor(i, Integer.class); |
| 87 | 82 | ByteBuffer bb; |
| 88 | 83 | if(codec instanceof TypeCodec.PrimitiveIntCodec) |
| @@ -93,7 +88,6 @@ | ||
| 93 | 88 | } |
| 94 | 89 | |
| 95 | 90 | public T setLong(int i, long v) { |
| 96 | - checkType(i, BIGINT, COUNTER); | |
| 97 | 91 | TypeCodec<Long> codec = codecFor(i, Long.class); |
| 98 | 92 | ByteBuffer bb; |
| 99 | 93 | if(codec instanceof TypeCodec.PrimitiveLongCodec) |
| @@ -104,17 +98,14 @@ | ||
| 104 | 98 | } |
| 105 | 99 | |
| 106 | 100 | public T setTimestamp(int i, Date v) { |
| 107 | - checkType(i, TIMESTAMP); | |
| 108 | 101 | return setValue(i, codecFor(i, Date.class).serialize(v, protocolVersion)); |
| 109 | 102 | } |
| 110 | 103 | |
| 111 | 104 | public T setDate(int i, LocalDate v) { |
| 112 | - checkType(i, DATE); | |
| 113 | 105 | return setValue(i, codecFor(i, LocalDate.class).serialize(v, protocolVersion)); |
| 114 | 106 | } |
| 115 | 107 | |
| 116 | 108 | public T setTime(int i, long v) { |
| 117 | - checkType(i, TIME); | |
| 118 | 109 | TypeCodec<Long> codec = codecFor(i, Long.class); |
| 119 | 110 | ByteBuffer bb; |
| 120 | 111 | if(codec instanceof TypeCodec.PrimitiveLongCodec) |
| @@ -125,7 +116,6 @@ | ||
| 125 | 116 | } |
| 126 | 117 | |
| 127 | 118 | public T setFloat(int i, float v) { |
| 128 | - checkType(i, FLOAT); | |
| 129 | 119 | TypeCodec<Float> codec = codecFor(i, Float.class); |
| 130 | 120 | ByteBuffer bb; |
| 131 | 121 | if(codec instanceof TypeCodec.PrimitiveFloatCodec) |
| @@ -136,7 +126,6 @@ | ||
| 136 | 126 | } |
| 137 | 127 | |
| 138 | 128 | public T setDouble(int i, double v) { |
| 139 | - checkType(i, DOUBLE); | |
| 140 | 129 | TypeCodec<Double> codec = codecFor(i, Double.class); |
| 141 | 130 | ByteBuffer bb; |
| 142 | 131 | if(codec instanceof TypeCodec.PrimitiveDoubleCodec) |
| @@ -147,12 +136,10 @@ | ||
| 147 | 136 | } |
| 148 | 137 | |
| 149 | 138 | public T setString(int i, String v) { |
| 150 | - checkType(i, VARCHAR, TEXT, ASCII); | |
| 151 | 139 | return setValue(i, codecFor(i, String.class).serialize(v, protocolVersion)); |
| 152 | 140 | } |
| 153 | 141 | |
| 154 | 142 | public T setBytes(int i, ByteBuffer v) { |
| 155 | - checkType(i, BLOB); | |
| 156 | 143 | return setValue(i, codecFor(i, ByteBuffer.class).serialize(v, protocolVersion)); |
| 157 | 144 | } |
| 158 | 145 | |
| @@ -161,37 +148,24 @@ | ||
| 161 | 148 | } |
| 162 | 149 | |
| 163 | 150 | public T setVarint(int i, BigInteger v) { |
| 164 | - checkType(i, VARINT); | |
| 165 | 151 | return setValue(i, codecFor(i, BigInteger.class).serialize(v, protocolVersion)); |
| 166 | 152 | } |
| 167 | 153 | |
| 168 | 154 | public T setDecimal(int i, BigDecimal v) { |
| 169 | - checkType(i, DECIMAL); | |
| 170 | 155 | return setValue(i, codecFor(i, BigDecimal.class).serialize(v, protocolVersion)); |
| 171 | 156 | } |
| 172 | 157 | |
| 173 | 158 | public T setUUID(int i, UUID v) { |
| 174 | - checkType(i, UUID, TIMEUUID); | |
| 175 | 159 | return setValue(i, codecFor(i, UUID.class).serialize(v, protocolVersion)); |
| 176 | 160 | } |
| 177 | 161 | |
| 178 | 162 | public T setInet(int i, InetAddress v) { |
| 179 | - checkType(i, INET); | |
| 180 | 163 | return setValue(i, codecFor(i, InetAddress.class).serialize(v, protocolVersion)); |
| 181 | 164 | } |
| 182 | 165 | |
| 183 | 166 | @SuppressWarnings("unchecked") |
| 184 | 167 | 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)); | |
| 195 | 169 | } |
| 196 | 170 | |
| 197 | 171 | @Override |
| @@ -206,19 +180,7 @@ | ||
| 206 | 180 | |
| 207 | 181 | @SuppressWarnings("unchecked") |
| 208 | 182 | 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)); | |
| 222 | 184 | } |
| 223 | 185 | |
| 224 | 186 | @Override |
| @@ -233,16 +195,7 @@ | ||
| 233 | 195 | |
| 234 | 196 | @SuppressWarnings("unchecked") |
| 235 | 197 | 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)); | |
| 246 | 199 | } |
| 247 | 200 | |
| 248 | 201 | @Override |
| @@ -256,12 +209,10 @@ | ||
| 256 | 209 | } |
| 257 | 210 | |
| 258 | 211 | public T setUDTValue(int i, UDTValue v) { |
| 259 | - checkType(i, UDT); | |
| 260 | 212 | return setValue(i, codecFor(i, UDTValue.class).serialize(v, protocolVersion)); |
| 261 | 213 | } |
| 262 | 214 | |
| 263 | 215 | public T setTupleValue(int i, TupleValue v) { |
| 264 | - checkType(i, TUPLE); | |
| 265 | 216 | return setValue(i, codecFor(i, TupleValue.class).serialize(v, protocolVersion)); |
| 266 | 217 | } |
| 267 | 218 |
modified driver-core/src/main/java/com/datastax/driver/core/AbstractData.java +45 −52
| @@ -27,7 +27,6 @@ | ||
| 27 | 27 | import static com.datastax.driver.core.CodecUtils.listOf; |
| 28 | 28 | import static com.datastax.driver.core.CodecUtils.mapOf; |
| 29 | 29 | import static com.datastax.driver.core.CodecUtils.setOf; |
| 30 | -import static com.datastax.driver.core.DataType.Name.*; | |
| 31 | 30 | |
| 32 | 31 | // 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). |
| 33 | 32 | abstract class AbstractData<T extends SettableData<T>> extends AbstractGettableData implements SettableData<T> { |
| @@ -61,16 +60,18 @@ | ||
| 61 | 60 | return wrapped; |
| 62 | 61 | } |
| 63 | 62 | |
| 63 | + @Override | |
| 64 | 64 | protected ByteBuffer getValue(int i) { |
| 65 | 65 | return values[i]; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | + @Override | |
| 68 | 69 | protected int getIndexOf(String name) { |
| 69 | 70 | return getAllIndexesOf(name)[0]; |
| 70 | 71 | } |
| 71 | 72 | |
| 73 | + @Override | |
| 72 | 74 | public T setBool(int i, boolean v) { |
| 73 | - checkType(i, BOOLEAN); | |
| 74 | 75 | TypeCodec<Boolean> codec = codecFor(i, Boolean.class); |
| 75 | 76 | ByteBuffer bb; |
| 76 | 77 | if(codec instanceof TypeCodec.PrimitiveBooleanCodec) |
| @@ -80,6 +81,7 @@ | ||
| 80 | 81 | return setValue(i, bb); |
| 81 | 82 | } |
| 82 | 83 | |
| 84 | + @Override | |
| 83 | 85 | public T setBool(String name, boolean v) { |
| 84 | 86 | for (int i : getAllIndexesOf(name)) { |
| 85 | 87 | setBool(i, v); |
| @@ -87,8 +89,8 @@ | ||
| 87 | 89 | return wrapped; |
| 88 | 90 | } |
| 89 | 91 | |
| 92 | + @Override | |
| 90 | 93 | public T setByte(int i, byte v) { |
| 91 | - checkType(i, TINYINT); | |
| 92 | 94 | TypeCodec<Byte> codec = codecFor(i, Byte.class); |
| 93 | 95 | ByteBuffer bb; |
| 94 | 96 | if(codec instanceof TypeCodec.PrimitiveByteCodec) |
| @@ -98,6 +100,7 @@ | ||
| 98 | 100 | return setValue(i, bb); |
| 99 | 101 | } |
| 100 | 102 | |
| 103 | + @Override | |
| 101 | 104 | public T setByte(String name, byte v) { |
| 102 | 105 | for (int i : getAllIndexesOf(name)) { |
| 103 | 106 | setByte(i, v); |
| @@ -105,8 +108,8 @@ | ||
| 105 | 108 | return wrapped; |
| 106 | 109 | } |
| 107 | 110 | |
| 111 | + @Override | |
| 108 | 112 | public T setShort(int i, short v) { |
| 109 | - checkType(i, SMALLINT); | |
| 110 | 113 | TypeCodec<Short> codec = codecFor(i, Short.class); |
| 111 | 114 | ByteBuffer bb; |
| 112 | 115 | if(codec instanceof TypeCodec.PrimitiveShortCodec) |
| @@ -116,6 +119,7 @@ | ||
| 116 | 119 | return setValue(i, bb); |
| 117 | 120 | } |
| 118 | 121 | |
| 122 | + @Override | |
| 119 | 123 | public T setShort(String name, short v) { |
| 120 | 124 | for (int i : getAllIndexesOf(name)) { |
| 121 | 125 | setShort(i, v); |
| @@ -123,8 +127,8 @@ | ||
| 123 | 127 | return wrapped; |
| 124 | 128 | } |
| 125 | 129 | |
| 130 | + @Override | |
| 126 | 131 | public T setInt(int i, int v) { |
| 127 | - checkType(i, INT); | |
| 128 | 132 | TypeCodec<Integer> codec = codecFor(i, Integer.class); |
| 129 | 133 | ByteBuffer bb; |
| 130 | 134 | if(codec instanceof TypeCodec.PrimitiveIntCodec) |
| @@ -134,6 +138,7 @@ | ||
| 134 | 138 | return setValue(i, bb); |
| 135 | 139 | } |
| 136 | 140 | |
| 141 | + @Override | |
| 137 | 142 | public T setInt(String name, int v) { |
| 138 | 143 | for (int i : getAllIndexesOf(name)) { |
| 139 | 144 | setInt(i, v); |
| @@ -141,8 +146,8 @@ | ||
| 141 | 146 | return wrapped; |
| 142 | 147 | } |
| 143 | 148 | |
| 149 | + @Override | |
| 144 | 150 | public T setLong(int i, long v) { |
| 145 | - checkType(i, BIGINT, COUNTER); | |
| 146 | 151 | TypeCodec<Long> codec = codecFor(i, Long.class); |
| 147 | 152 | ByteBuffer bb; |
| 148 | 153 | if(codec instanceof TypeCodec.PrimitiveLongCodec) |
| @@ -152,6 +157,7 @@ | ||
| 152 | 157 | return setValue(i, bb); |
| 153 | 158 | } |
| 154 | 159 | |
| 160 | + @Override | |
| 155 | 161 | public T setLong(String name, long v) { |
| 156 | 162 | for (int i : getAllIndexesOf(name)) { |
| 157 | 163 | setLong(i, v); |
| @@ -159,11 +165,12 @@ | ||
| 159 | 165 | return wrapped; |
| 160 | 166 | } |
| 161 | 167 | |
| 168 | + @Override | |
| 162 | 169 | public T setTimestamp(int i, Date v) { |
| 163 | - checkType(i, TIMESTAMP); | |
| 164 | 170 | return setValue(i, codecFor(i, Date.class).serialize(v, protocolVersion)); |
| 165 | 171 | } |
| 166 | 172 | |
| 173 | + @Override | |
| 167 | 174 | public T setTimestamp(String name, Date v) { |
| 168 | 175 | for (int i : getAllIndexesOf(name)) { |
| 169 | 176 | setTimestamp(i, v); |
| @@ -171,11 +178,12 @@ | ||
| 171 | 178 | return wrapped; |
| 172 | 179 | } |
| 173 | 180 | |
| 181 | + @Override | |
| 174 | 182 | public T setDate(int i, LocalDate v) { |
| 175 | - checkType(i, DATE); | |
| 176 | 183 | return setValue(i, codecFor(i, LocalDate.class).serialize(v, protocolVersion)); |
| 177 | 184 | } |
| 178 | 185 | |
| 186 | + @Override | |
| 179 | 187 | public T setDate(String name, LocalDate v) { |
| 180 | 188 | for (int i : getAllIndexesOf(name)) { |
| 181 | 189 | setDate(i, v); |
| @@ -183,8 +191,8 @@ | ||
| 183 | 191 | return wrapped; |
| 184 | 192 | } |
| 185 | 193 | |
| 194 | + @Override | |
| 186 | 195 | public T setTime(int i, long v) { |
| 187 | - checkType(i, TIME); | |
| 188 | 196 | TypeCodec<Long> codec = codecFor(i, Long.class); |
| 189 | 197 | ByteBuffer bb; |
| 190 | 198 | if(codec instanceof TypeCodec.PrimitiveLongCodec) |
| @@ -194,6 +202,7 @@ | ||
| 194 | 202 | return setValue(i, bb); |
| 195 | 203 | } |
| 196 | 204 | |
| 205 | + @Override | |
| 197 | 206 | public T setTime(String name, long v) { |
| 198 | 207 | for (int i : getAllIndexesOf(name)) { |
| 199 | 208 | setTime(i, v); |
| @@ -201,8 +210,8 @@ | ||
| 201 | 210 | return wrapped; |
| 202 | 211 | } |
| 203 | 212 | |
| 213 | + @Override | |
| 204 | 214 | public T setFloat(int i, float v) { |
| 205 | - checkType(i, FLOAT); | |
| 206 | 215 | TypeCodec<Float> codec = codecFor(i, Float.class); |
| 207 | 216 | ByteBuffer bb; |
| 208 | 217 | if(codec instanceof TypeCodec.PrimitiveFloatCodec) |
| @@ -212,6 +221,7 @@ | ||
| 212 | 221 | return setValue(i, bb); |
| 213 | 222 | } |
| 214 | 223 | |
| 224 | + @Override | |
| 215 | 225 | public T setFloat(String name, float v) { |
| 216 | 226 | for (int i : getAllIndexesOf(name)) { |
| 217 | 227 | setFloat(i, v); |
| @@ -219,8 +229,8 @@ | ||
| 219 | 229 | return wrapped; |
| 220 | 230 | } |
| 221 | 231 | |
| 232 | + @Override | |
| 222 | 233 | public T setDouble(int i, double v) { |
| 223 | - checkType(i, DOUBLE); | |
| 224 | 234 | TypeCodec<Double> codec = codecFor(i, Double.class); |
| 225 | 235 | ByteBuffer bb; |
| 226 | 236 | if(codec instanceof TypeCodec.PrimitiveDoubleCodec) |
| @@ -230,6 +240,7 @@ | ||
| 230 | 240 | return setValue(i, bb); |
| 231 | 241 | } |
| 232 | 242 | |
| 243 | + @Override | |
| 233 | 244 | public T setDouble(String name, double v) { |
| 234 | 245 | for (int i : getAllIndexesOf(name)) { |
| 235 | 246 | setDouble(i, v); |
| @@ -237,11 +248,12 @@ | ||
| 237 | 248 | return wrapped; |
| 238 | 249 | } |
| 239 | 250 | |
| 251 | + @Override | |
| 240 | 252 | public T setString(int i, String v) { |
| 241 | - checkType(i, VARCHAR, TEXT, ASCII); | |
| 242 | 253 | return setValue(i, codecFor(i, String.class).serialize(v, protocolVersion)); |
| 243 | 254 | } |
| 244 | 255 | |
| 256 | + @Override | |
| 245 | 257 | public T setString(String name, String v) { |
| 246 | 258 | for (int i : getAllIndexesOf(name)) { |
| 247 | 259 | setString(i, v); |
| @@ -249,11 +261,12 @@ | ||
| 249 | 261 | return wrapped; |
| 250 | 262 | } |
| 251 | 263 | |
| 264 | + @Override | |
| 252 | 265 | public T setBytes(int i, ByteBuffer v) { |
| 253 | - checkType(i, BLOB); | |
| 254 | 266 | return setValue(i, codecFor(i, ByteBuffer.class).serialize(v, protocolVersion)); |
| 255 | 267 | } |
| 256 | 268 | |
| 269 | + @Override | |
| 257 | 270 | public T setBytes(String name, ByteBuffer v) { |
| 258 | 271 | for (int i : getAllIndexesOf(name)) { |
| 259 | 272 | setBytes(i, v); |
| @@ -261,10 +274,12 @@ | ||
| 261 | 274 | return wrapped; |
| 262 | 275 | } |
| 263 | 276 | |
| 277 | + @Override | |
| 264 | 278 | public T setBytesUnsafe(int i, ByteBuffer v) { |
| 265 | 279 | return setValue(i, v == null ? null : v.duplicate()); |
| 266 | 280 | } |
| 267 | 281 | |
| 282 | + @Override | |
| 268 | 283 | public T setBytesUnsafe(String name, ByteBuffer v) { |
| 269 | 284 | ByteBuffer value = v == null ? null : v.duplicate(); |
| 270 | 285 | for (int i : getAllIndexesOf(name)) { |
| @@ -273,11 +288,12 @@ | ||
| 273 | 288 | return wrapped; |
| 274 | 289 | } |
| 275 | 290 | |
| 291 | + @Override | |
| 276 | 292 | public T setVarint(int i, BigInteger v) { |
| 277 | - checkType(i, VARINT); | |
| 278 | 293 | return setValue(i, codecFor(i, BigInteger.class).serialize(v, protocolVersion)); |
| 279 | 294 | } |
| 280 | 295 | |
| 296 | + @Override | |
| 281 | 297 | public T setVarint(String name, BigInteger v) { |
| 282 | 298 | for (int i : getAllIndexesOf(name)) { |
| 283 | 299 | setVarint(i, v); |
| @@ -285,11 +301,12 @@ | ||
| 285 | 301 | return wrapped; |
| 286 | 302 | } |
| 287 | 303 | |
| 304 | + @Override | |
| 288 | 305 | public T setDecimal(int i, BigDecimal v) { |
| 289 | - checkType(i, DECIMAL); | |
| 290 | 306 | return setValue(i, codecFor(i, BigDecimal.class).serialize(v, protocolVersion)); |
| 291 | 307 | } |
| 292 | 308 | |
| 309 | + @Override | |
| 293 | 310 | public T setDecimal(String name, BigDecimal v) { |
| 294 | 311 | for (int i : getAllIndexesOf(name)) { |
| 295 | 312 | setDecimal(i, v); |
| @@ -297,11 +314,12 @@ | ||
| 297 | 314 | return wrapped; |
| 298 | 315 | } |
| 299 | 316 | |
| 317 | + @Override | |
| 300 | 318 | public T setUUID(int i, UUID v) { |
| 301 | - checkType(i, UUID, TIMEUUID); | |
| 302 | 319 | return setValue(i, codecFor(i, UUID.class).serialize(v, protocolVersion)); |
| 303 | 320 | } |
| 304 | 321 | |
| 322 | + @Override | |
| 305 | 323 | public T setUUID(String name, UUID v) { |
| 306 | 324 | for (int i : getAllIndexesOf(name)) { |
| 307 | 325 | setUUID(i, v); |
| @@ -309,11 +327,12 @@ | ||
| 309 | 327 | return wrapped; |
| 310 | 328 | } |
| 311 | 329 | |
| 330 | + @Override | |
| 312 | 331 | public T setInet(int i, InetAddress v) { |
| 313 | - checkType(i, INET); | |
| 314 | 332 | return setValue(i, codecFor(i, InetAddress.class).serialize(v, protocolVersion)); |
| 315 | 333 | } |
| 316 | 334 | |
| 335 | + @Override | |
| 317 | 336 | public T setInet(String name, InetAddress v) { |
| 318 | 337 | for (int i : getAllIndexesOf(name)) { |
| 319 | 338 | setInet(i, v); |
| @@ -337,18 +356,10 @@ | ||
| 337 | 356 | return wrapped; |
| 338 | 357 | } |
| 339 | 358 | |
| 359 | + @Override | |
| 340 | 360 | @SuppressWarnings("unchecked") |
| 341 | 361 | 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)); | |
| 352 | 363 | } |
| 353 | 364 | |
| 354 | 365 | @Override |
| @@ -388,19 +399,7 @@ | ||
| 388 | 399 | @SuppressWarnings("unchecked") |
| 389 | 400 | @Override |
| 390 | 401 | 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)); | |
| 404 | 403 | } |
| 405 | 404 | |
| 406 | 405 | @Override |
| @@ -437,18 +436,10 @@ | ||
| 437 | 436 | return wrapped; |
| 438 | 437 | } |
| 439 | 438 | |
| 439 | + @Override | |
| 440 | 440 | @SuppressWarnings("unchecked") |
| 441 | 441 | 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)); | |
| 452 | 443 | } |
| 453 | 444 | |
| 454 | 445 | @Override |
| @@ -485,11 +476,12 @@ | ||
| 485 | 476 | return wrapped; |
| 486 | 477 | } |
| 487 | 478 | |
| 479 | + @Override | |
| 488 | 480 | public T setUDTValue(int i, UDTValue v) { |
| 489 | - checkType(i, UDT); | |
| 490 | 481 | return setValue(i, codecFor(i, UDTValue.class).serialize(v, protocolVersion)); |
| 491 | 482 | } |
| 492 | 483 | |
| 484 | + @Override | |
| 493 | 485 | public T setUDTValue(String name, UDTValue v) { |
| 494 | 486 | for (int i : getAllIndexesOf(name)) { |
| 495 | 487 | setUDTValue(i, v); |
| @@ -497,11 +489,12 @@ | ||
| 497 | 489 | return wrapped; |
| 498 | 490 | } |
| 499 | 491 | |
| 492 | + @Override | |
| 500 | 493 | public T setTupleValue(int i, TupleValue v) { |
| 501 | - checkType(i, TUPLE); | |
| 502 | 494 | return setValue(i, codecFor(i, TupleValue.class).serialize(v, protocolVersion)); |
| 503 | 495 | } |
| 504 | 496 | |
| 497 | + @Override | |
| 505 | 498 | public T setTupleValue(String name, TupleValue v) { |
| 506 | 499 | for (int i : getAllIndexesOf(name)) { |
| 507 | 500 | setTupleValue(i, v); |
modified driver-core/src/main/java/com/datastax/driver/core/AbstractGettableByIndexData.java +1 −47
| @@ -19,23 +19,15 @@ | ||
| 19 | 19 | import java.math.BigInteger; |
| 20 | 20 | import java.net.InetAddress; |
| 21 | 21 | 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.*; | |
| 27 | 23 | |
| 28 | 24 | import com.google.common.reflect.TypeToken; |
| 29 | 25 | |
| 30 | -import static com.google.common.collect.Sets.newHashSet; | |
| 31 | -import static com.google.common.collect.Sets.newLinkedHashSet; | |
| 32 | - | |
| 33 | 26 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 34 | 27 | |
| 35 | 28 | import static com.datastax.driver.core.CodecUtils.listOf; |
| 36 | 29 | import static com.datastax.driver.core.CodecUtils.mapOf; |
| 37 | 30 | import static com.datastax.driver.core.CodecUtils.setOf; |
| 38 | -import static com.datastax.driver.core.DataType.Name.*; | |
| 39 | 31 | |
| 40 | 32 | abstract class AbstractGettableByIndexData implements GettableByIndexData { |
| 41 | 33 | |
| @@ -93,25 +85,12 @@ | ||
| 93 | 85 | return getCodecRegistry().codecFor(getType(i), value); |
| 94 | 86 | } |
| 95 | 87 | |
| 96 | - // Note: we avoid having a vararg method to avoid the array allocation that comes with it. | |
| 97 | 88 | protected void checkType(int i, DataType.Name actual) { |
| 98 | 89 | DataType.Name expected = getType(i).getName(); |
| 99 | 90 | if (!actual.isCompatibleWith(expected)) |
| 100 | 91 | throw new InvalidTypeException(String.format("Value %s is of type %s, not %s", getName(i), expected, actual)); |
| 101 | 92 | } |
| 102 | 93 | |
| 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 | - | |
| 115 | 94 | /** |
| 116 | 95 | * {@inheritDoc} |
| 117 | 96 | */ |
| @@ -125,12 +104,7 @@ | ||
| 125 | 104 | */ |
| 126 | 105 | @Override |
| 127 | 106 | public boolean getBool(int i) { |
| 128 | - checkType(i, BOOLEAN); | |
| 129 | - | |
| 130 | 107 | ByteBuffer value = getValue(i); |
| 131 | - if (value == null || value.remaining() == 0) | |
| 132 | - return false; | |
| 133 | - | |
| 134 | 108 | TypeCodec<Boolean> codec = codecFor(i, Boolean.class); |
| 135 | 109 | if(codec instanceof TypeCodec.PrimitiveBooleanCodec) |
| 136 | 110 | return ((TypeCodec.PrimitiveBooleanCodec) codec).deserializeNoBoxing(value, protocolVersion); |
| @@ -143,7 +117,6 @@ | ||
| 143 | 117 | */ |
| 144 | 118 | @Override |
| 145 | 119 | public byte getByte(int i) { |
| 146 | - checkType(i, TINYINT); | |
| 147 | 120 | ByteBuffer value = getValue(i); |
| 148 | 121 | TypeCodec<Byte> codec = codecFor(i, Byte.class); |
| 149 | 122 | if(codec instanceof TypeCodec.PrimitiveByteCodec) |
| @@ -157,7 +130,6 @@ | ||
| 157 | 130 | */ |
| 158 | 131 | @Override |
| 159 | 132 | public short getShort(int i) { |
| 160 | - checkType(i, SMALLINT); | |
| 161 | 133 | ByteBuffer value = getValue(i); |
| 162 | 134 | TypeCodec<Short> codec = codecFor(i, Short.class); |
| 163 | 135 | if(codec instanceof TypeCodec.PrimitiveShortCodec) |
| @@ -171,7 +143,6 @@ | ||
| 171 | 143 | */ |
| 172 | 144 | @Override |
| 173 | 145 | public int getInt(int i) { |
| 174 | - checkType(i, INT); | |
| 175 | 146 | ByteBuffer value = getValue(i); |
| 176 | 147 | TypeCodec<Integer> codec = codecFor(i, Integer.class); |
| 177 | 148 | if(codec instanceof TypeCodec.PrimitiveIntCodec) |
| @@ -185,7 +156,6 @@ | ||
| 185 | 156 | */ |
| 186 | 157 | @Override |
| 187 | 158 | public long getLong(int i) { |
| 188 | - checkType(i, BIGINT, COUNTER); | |
| 189 | 159 | ByteBuffer value = getValue(i); |
| 190 | 160 | TypeCodec<Long> codec = codecFor(i, Long.class); |
| 191 | 161 | if(codec instanceof TypeCodec.PrimitiveLongCodec) |
| @@ -199,7 +169,6 @@ | ||
| 199 | 169 | */ |
| 200 | 170 | @Override |
| 201 | 171 | public Date getTimestamp(int i) { |
| 202 | - checkType(i, TIMESTAMP); | |
| 203 | 172 | ByteBuffer value = getValue(i); |
| 204 | 173 | return codecFor(i, Date.class).deserialize(value, protocolVersion); |
| 205 | 174 | } |
| @@ -209,7 +178,6 @@ | ||
| 209 | 178 | */ |
| 210 | 179 | @Override |
| 211 | 180 | public LocalDate getDate(int i) { |
| 212 | - checkType(i, DATE); | |
| 213 | 181 | ByteBuffer value = getValue(i); |
| 214 | 182 | return codecFor(i, LocalDate.class).deserialize(value, protocolVersion); |
| 215 | 183 | } |
| @@ -219,7 +187,6 @@ | ||
| 219 | 187 | */ |
| 220 | 188 | @Override |
| 221 | 189 | public long getTime(int i) { |
| 222 | - checkType(i, TIME); | |
| 223 | 190 | ByteBuffer value = getValue(i); |
| 224 | 191 | TypeCodec<Long> codec = codecFor(i, Long.class); |
| 225 | 192 | if(codec instanceof TypeCodec.PrimitiveLongCodec) |
| @@ -233,7 +200,6 @@ | ||
| 233 | 200 | */ |
| 234 | 201 | @Override |
| 235 | 202 | public float getFloat(int i) { |
| 236 | - checkType(i, FLOAT); | |
| 237 | 203 | ByteBuffer value = getValue(i); |
| 238 | 204 | TypeCodec<Float> codec = codecFor(i, Float.class); |
| 239 | 205 | if(codec instanceof TypeCodec.PrimitiveFloatCodec) |
| @@ -247,7 +213,6 @@ | ||
| 247 | 213 | */ |
| 248 | 214 | @Override |
| 249 | 215 | public double getDouble(int i) { |
| 250 | - checkType(i, DOUBLE); | |
| 251 | 216 | ByteBuffer value = getValue(i); |
| 252 | 217 | TypeCodec<Double> codec = codecFor(i, Double.class); |
| 253 | 218 | if(codec instanceof TypeCodec.PrimitiveDoubleCodec) |
| @@ -272,7 +237,6 @@ | ||
| 272 | 237 | */ |
| 273 | 238 | @Override |
| 274 | 239 | public ByteBuffer getBytes(int i) { |
| 275 | - checkType(i, BLOB); | |
| 276 | 240 | ByteBuffer value = getValue(i); |
| 277 | 241 | return codecFor(i, ByteBuffer.class).deserialize(value, protocolVersion); |
| 278 | 242 | } |
| @@ -282,7 +246,6 @@ | ||
| 282 | 246 | */ |
| 283 | 247 | @Override |
| 284 | 248 | public String getString(int i) { |
| 285 | - checkType(i, VARCHAR, ASCII); | |
| 286 | 249 | ByteBuffer value = getValue(i); |
| 287 | 250 | return codecFor(i, String.class).deserialize(value, protocolVersion); |
| 288 | 251 | } |
| @@ -292,7 +255,6 @@ | ||
| 292 | 255 | */ |
| 293 | 256 | @Override |
| 294 | 257 | public BigInteger getVarint(int i) { |
| 295 | - checkType(i, VARINT); | |
| 296 | 258 | ByteBuffer value = getValue(i); |
| 297 | 259 | return codecFor(i, BigInteger.class).deserialize(value, protocolVersion); |
| 298 | 260 | } |
| @@ -302,7 +264,6 @@ | ||
| 302 | 264 | */ |
| 303 | 265 | @Override |
| 304 | 266 | public BigDecimal getDecimal(int i) { |
| 305 | - checkType(i, DECIMAL); | |
| 306 | 267 | ByteBuffer value = getValue(i); |
| 307 | 268 | return codecFor(i, BigDecimal.class).deserialize(value, protocolVersion); |
| 308 | 269 | } |
| @@ -312,7 +273,6 @@ | ||
| 312 | 273 | */ |
| 313 | 274 | @Override |
| 314 | 275 | public UUID getUUID(int i) { |
| 315 | - checkType(i, UUID, TIMEUUID); | |
| 316 | 276 | ByteBuffer value = getValue(i); |
| 317 | 277 | return codecFor(i, UUID.class).deserialize(value, protocolVersion); |
| 318 | 278 | } |
| @@ -322,7 +282,6 @@ | ||
| 322 | 282 | */ |
| 323 | 283 | @Override |
| 324 | 284 | public InetAddress getInet(int i) { |
| 325 | - checkType(i, INET); | |
| 326 | 285 | ByteBuffer value = getValue(i); |
| 327 | 286 | return codecFor(i, InetAddress.class).deserialize(value, protocolVersion); |
| 328 | 287 | } |
| @@ -342,7 +301,6 @@ | ||
| 342 | 301 | @Override |
| 343 | 302 | @SuppressWarnings("unchecked") |
| 344 | 303 | public <T> List<T> getList(int i, TypeToken<T> elementsType) { |
| 345 | - checkType(i, LIST); | |
| 346 | 304 | ByteBuffer value = getValue(i); |
| 347 | 305 | TypeToken<List<T>> javaType = listOf(elementsType); |
| 348 | 306 | return codecFor(i, javaType).deserialize(value, protocolVersion); |
| @@ -363,7 +321,6 @@ | ||
| 363 | 321 | @Override |
| 364 | 322 | @SuppressWarnings("unchecked") |
| 365 | 323 | public <T> Set<T> getSet(int i, TypeToken<T> elementsType) { |
| 366 | - checkType(i, SET); | |
| 367 | 324 | ByteBuffer value = getValue(i); |
| 368 | 325 | TypeToken<Set<T>> javaType = setOf(elementsType); |
| 369 | 326 | return codecFor(i, javaType).deserialize(value, protocolVersion); |
| @@ -384,7 +341,6 @@ | ||
| 384 | 341 | @Override |
| 385 | 342 | @SuppressWarnings("unchecked") |
| 386 | 343 | public <K, V> Map<K, V> getMap(int i, TypeToken<K> keysType, TypeToken<V> valuesType) { |
| 387 | - checkType(i, MAP); | |
| 388 | 344 | ByteBuffer value = getValue(i); |
| 389 | 345 | TypeToken<Map<K, V>> javaType = mapOf(keysType, valuesType); |
| 390 | 346 | return codecFor(i, javaType).deserialize(value, protocolVersion); |
| @@ -396,7 +352,6 @@ | ||
| 396 | 352 | @Override |
| 397 | 353 | @SuppressWarnings("unchecked") |
| 398 | 354 | public UDTValue getUDTValue(int i) { |
| 399 | - checkType(i, UDT); | |
| 400 | 355 | ByteBuffer value = getValue(i); |
| 401 | 356 | return codecFor(i, UDTValue.class).deserialize(value, protocolVersion); |
| 402 | 357 | } |
| @@ -407,7 +362,6 @@ | ||
| 407 | 362 | @Override |
| 408 | 363 | @SuppressWarnings("unchecked") |
| 409 | 364 | public TupleValue getTupleValue(int i) { |
| 410 | - checkType(i, TUPLE); | |
| 411 | 365 | ByteBuffer value = getValue(i); |
| 412 | 366 | return codecFor(i, TupleValue.class).deserialize(value, protocolVersion); |
| 413 | 367 | } |
modified driver-core/src/main/java/com/datastax/driver/core/DataType.java +4 −2
| @@ -47,6 +47,7 @@ | ||
| 47 | 47 | INET (16), |
| 48 | 48 | INT (9), |
| 49 | 49 | TEXT (10){ |
| 50 | + @Override | |
| 50 | 51 | public boolean isCompatibleWith(Name that) { |
| 51 | 52 | return this == that || that == VARCHAR; |
| 52 | 53 | } |
| @@ -54,6 +55,7 @@ | ||
| 54 | 55 | TIMESTAMP (11), |
| 55 | 56 | UUID (12), |
| 56 | 57 | VARCHAR (13){ |
| 58 | + @Override | |
| 57 | 59 | public boolean isCompatibleWith(Name that) { |
| 58 | 60 | return this == that || that == TEXT; |
| 59 | 61 | } |
| @@ -637,7 +639,7 @@ | ||
| 637 | 639 | |
| 638 | 640 | @Override |
| 639 | 641 | public final int hashCode() { |
| 640 | - return Arrays.hashCode(new Object[]{ name, typeArguments }); | |
| 642 | + return Objects.hashCode(name, typeArguments); | |
| 641 | 643 | } |
| 642 | 644 | |
| 643 | 645 | @Override |
| @@ -682,7 +684,7 @@ | ||
| 682 | 684 | |
| 683 | 685 | @Override |
| 684 | 686 | public final int hashCode() { |
| 685 | - return Arrays.hashCode(new Object[]{ name, customClassName }); | |
| 687 | + return Objects.hashCode(name, customClassName); | |
| 686 | 688 | } |
| 687 | 689 | |
| 688 | 690 | @Override |
modified driver-core/src/main/java/com/datastax/driver/core/GettableByIndexData.java +5 −46
| @@ -49,7 +49,6 @@ | ||
| 49 | 49 | * value is NULL, {@code false} is returned. |
| 50 | 50 | * |
| 51 | 51 | * @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. | |
| 53 | 52 | */ |
| 54 | 53 | public boolean getBool(int i); |
| 55 | 54 | |
| @@ -61,7 +60,6 @@ | ||
| 61 | 60 | * value is NULL, {@code 0} is returned. |
| 62 | 61 | * |
| 63 | 62 | * @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. | |
| 65 | 63 | */ |
| 66 | 64 | public byte getByte(int i); |
| 67 | 65 | |
| @@ -73,7 +71,6 @@ | ||
| 73 | 71 | * value is NULL, {@code 0} is returned. |
| 74 | 72 | * |
| 75 | 73 | * @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. | |
| 77 | 74 | */ |
| 78 | 75 | public short getShort(int i); |
| 79 | 76 | |
| @@ -85,7 +82,6 @@ | ||
| 85 | 82 | * value is NULL, {@code 0} is returned. |
| 86 | 83 | * |
| 87 | 84 | * @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. | |
| 89 | 85 | */ |
| 90 | 86 | public int getInt(int i); |
| 91 | 87 | |
| @@ -97,7 +93,6 @@ | ||
| 97 | 93 | * value is NULL, {@code 0L} is returned. |
| 98 | 94 | * |
| 99 | 95 | * @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. | |
| 101 | 96 | */ |
| 102 | 97 | public long getLong(int i); |
| 103 | 98 | |
| @@ -109,7 +104,6 @@ | ||
| 109 | 104 | * value is NULL, {@code null} is returned. |
| 110 | 105 | * |
| 111 | 106 | * @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. | |
| 113 | 107 | */ |
| 114 | 108 | public Date getTimestamp(int i); |
| 115 | 109 | |
| @@ -121,7 +115,6 @@ | ||
| 121 | 115 | * value is NULL, {@code null} is returned. |
| 122 | 116 | * |
| 123 | 117 | * @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. | |
| 125 | 118 | */ |
| 126 | 119 | public LocalDate getDate(int i); |
| 127 | 120 | |
| @@ -133,7 +126,6 @@ | ||
| 133 | 126 | * value is NULL, {@code 0L} is returned. |
| 134 | 127 | * |
| 135 | 128 | * @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. | |
| 137 | 129 | */ |
| 138 | 130 | public long getTime(int i); |
| 139 | 131 | |
| @@ -145,7 +137,6 @@ | ||
| 145 | 137 | * value is NULL, {@code 0.0f} is returned. |
| 146 | 138 | * |
| 147 | 139 | * @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. | |
| 149 | 140 | */ |
| 150 | 141 | public float getFloat(int i); |
| 151 | 142 | |
| @@ -157,7 +148,6 @@ | ||
| 157 | 148 | * value is NULL, {@code 0.0} is returned. |
| 158 | 149 | * |
| 159 | 150 | * @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. | |
| 161 | 151 | */ |
| 162 | 152 | public double getDouble(int i); |
| 163 | 153 | |
| @@ -188,7 +178,6 @@ | ||
| 188 | 178 | * value is NULL, {@code null} is returned. |
| 189 | 179 | * |
| 190 | 180 | * @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. | |
| 192 | 181 | */ |
| 193 | 182 | public ByteBuffer getBytes(int i); |
| 194 | 183 | |
| @@ -200,8 +189,6 @@ | ||
| 200 | 189 | * value is NULL, {@code null} is returned. |
| 201 | 190 | * |
| 202 | 191 | * @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. | |
| 205 | 192 | */ |
| 206 | 193 | public String getString(int i); |
| 207 | 194 | |
| @@ -213,7 +200,6 @@ | ||
| 213 | 200 | * length integer. If the value is NULL, {@code null} is returned. |
| 214 | 201 | * |
| 215 | 202 | * @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. | |
| 217 | 203 | */ |
| 218 | 204 | public BigInteger getVarint(int i); |
| 219 | 205 | |
| @@ -225,7 +211,6 @@ | ||
| 225 | 211 | * length decimal. If the value is NULL, {@code null} is returned. |
| 226 | 212 | * |
| 227 | 213 | * @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. | |
| 229 | 214 | */ |
| 230 | 215 | public BigDecimal getDecimal(int i); |
| 231 | 216 | |
| @@ -237,8 +222,6 @@ | ||
| 237 | 222 | * If the value is NULL, {@code null} is returned. |
| 238 | 223 | * |
| 239 | 224 | * @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. | |
| 242 | 225 | */ |
| 243 | 226 | public UUID getUUID(int i); |
| 244 | 227 | |
| @@ -250,7 +233,6 @@ | ||
| 250 | 233 | * If the value is NULL, {@code null} is returned. |
| 251 | 234 | * |
| 252 | 235 | * @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. | |
| 254 | 236 | */ |
| 255 | 237 | public InetAddress getInet(int i); |
| 256 | 238 | |
| @@ -273,8 +255,6 @@ | ||
| 273 | 255 | * {@code T} objects. |
| 274 | 256 | * |
| 275 | 257 | * @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}. | |
| 278 | 258 | */ |
| 279 | 259 | public <T> List<T> getList(int i, Class<T> elementsClass); |
| 280 | 260 | |
| @@ -300,8 +280,6 @@ | ||
| 300 | 280 | * {@code T} objects. |
| 301 | 281 | * |
| 302 | 282 | * @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}. | |
| 305 | 283 | */ |
| 306 | 284 | public <T> List<T> getList(int i, TypeToken<T> elementsType); |
| 307 | 285 | |
| @@ -324,8 +302,6 @@ | ||
| 324 | 302 | * {@code T} objects. |
| 325 | 303 | * |
| 326 | 304 | * @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}. | |
| 329 | 305 | */ |
| 330 | 306 | public <T> Set<T> getSet(int i, Class<T> elementsClass); |
| 331 | 307 | |
| @@ -351,8 +327,6 @@ | ||
| 351 | 327 | * {@code T} objects. |
| 352 | 328 | * |
| 353 | 329 | * @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}. | |
| 356 | 330 | */ |
| 357 | 331 | public <T> Set<T> getSet(int i, TypeToken<T> elementsType); |
| 358 | 332 | |
| @@ -376,9 +350,6 @@ | ||
| 376 | 350 | * {@code K} to {@code V} objects. |
| 377 | 351 | * |
| 378 | 352 | * @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}. | |
| 382 | 353 | */ |
| 383 | 354 | public <K, V> Map<K, V> getMap(int i, Class<K> keysClass, Class<V> valuesClass); |
| 384 | 355 | |
| @@ -406,9 +377,6 @@ | ||
| 406 | 377 | * {@code K} to {@code V} objects. |
| 407 | 378 | * |
| 408 | 379 | * @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}. | |
| 412 | 380 | */ |
| 413 | 381 | public <K, V> Map<K, V> getMap(int i, TypeToken<K> keysType, TypeToken<V> valuesType); |
| 414 | 382 | |
| @@ -420,7 +388,6 @@ | ||
| 420 | 388 | * then {@code null} will be returned. |
| 421 | 389 | * |
| 422 | 390 | * @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. | |
| 424 | 391 | */ |
| 425 | 392 | public UDTValue getUDTValue(int i); |
| 426 | 393 | |
| @@ -432,26 +399,18 @@ | ||
| 432 | 399 | * then {@code null} will be returned. |
| 433 | 400 | * |
| 434 | 401 | * @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. | |
| 436 | 402 | */ |
| 437 | 403 | public TupleValue getTupleValue(int i); |
| 438 | 404 | |
| 439 | 405 | /** |
| 440 | 406 | * Returns the {@code i}th value as the Java type matching its CQL type. |
| 441 | 407 | * <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>. | |
| 448 | 411 | * <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. | |
| 455 | 414 | * |
| 456 | 415 | * @param i the index to retrieve. |
| 457 | 416 | * @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 @@ | ||
| 48 | 48 | * {@code false} is returned. |
| 49 | 49 | * |
| 50 | 50 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 51 | - * @throws InvalidTypeException if value {@code name} is not of type BOOLEAN. | |
| 52 | 51 | */ |
| 53 | 52 | public boolean getBool(String name); |
| 54 | 53 | |
| @@ -60,7 +59,6 @@ | ||
| 60 | 59 | * {@code 0} is returned. |
| 61 | 60 | * |
| 62 | 61 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 63 | - * @throws InvalidTypeException if value {@code name} is not of type TINYINT. | |
| 64 | 62 | */ |
| 65 | 63 | public byte getByte(String name); |
| 66 | 64 | |
| @@ -72,7 +70,6 @@ | ||
| 72 | 70 | * {@code 0} is returned. |
| 73 | 71 | * |
| 74 | 72 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 75 | - * @throws InvalidTypeException if value {@code name} is not of type SMALLINT. | |
| 76 | 73 | */ |
| 77 | 74 | public short getShort(String name); |
| 78 | 75 | |
| @@ -84,7 +81,6 @@ | ||
| 84 | 81 | * {@code 0} is returned. |
| 85 | 82 | * |
| 86 | 83 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 87 | - * @throws InvalidTypeException if value {@code name} is not of type INT. | |
| 88 | 84 | */ |
| 89 | 85 | public int getInt(String name); |
| 90 | 86 | |
| @@ -96,7 +92,6 @@ | ||
| 96 | 92 | * {@code 0L} is returned. |
| 97 | 93 | * |
| 98 | 94 | * @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. | |
| 100 | 95 | */ |
| 101 | 96 | public long getLong(String name); |
| 102 | 97 | |
| @@ -108,7 +103,6 @@ | ||
| 108 | 103 | * {@code null} is returned. |
| 109 | 104 | * |
| 110 | 105 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 111 | - * @throws InvalidTypeException if value {@code name} is not of type TIMESTAMP. | |
| 112 | 106 | */ |
| 113 | 107 | public Date getTimestamp(String name); |
| 114 | 108 | |
| @@ -120,7 +114,6 @@ | ||
| 120 | 114 | * {@code null} is returned. |
| 121 | 115 | * |
| 122 | 116 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 123 | - * @throws InvalidTypeException if value {@code name} is not of type DATE. | |
| 124 | 117 | */ |
| 125 | 118 | public LocalDate getDate(String name); |
| 126 | 119 | |
| @@ -132,7 +125,6 @@ | ||
| 132 | 125 | * {@code 0L} is returned. |
| 133 | 126 | * |
| 134 | 127 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 135 | - * @throws InvalidTypeException if value {@code name} is not of type TIME. | |
| 136 | 128 | */ |
| 137 | 129 | public long getTime(String name); |
| 138 | 130 | |
| @@ -144,7 +136,6 @@ | ||
| 144 | 136 | * {@code 0.0f} is returned. |
| 145 | 137 | * |
| 146 | 138 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 147 | - * @throws InvalidTypeException if value {@code name} is not of type FLOAT. | |
| 148 | 139 | */ |
| 149 | 140 | public float getFloat(String name); |
| 150 | 141 | |
| @@ -156,7 +147,6 @@ | ||
| 156 | 147 | * {@code 0.0} is returned. |
| 157 | 148 | * |
| 158 | 149 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 159 | - * @throws InvalidTypeException if value {@code name} is not of type DOUBLE. | |
| 160 | 150 | */ |
| 161 | 151 | public double getDouble(String name); |
| 162 | 152 | |
| @@ -187,7 +177,6 @@ | ||
| 187 | 177 | * {@code null} is returned. |
| 188 | 178 | * |
| 189 | 179 | * @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. | |
| 191 | 180 | */ |
| 192 | 181 | public ByteBuffer getBytes(String name); |
| 193 | 182 | |
| @@ -199,8 +188,6 @@ | ||
| 199 | 188 | * {@code null} is returned. |
| 200 | 189 | * |
| 201 | 190 | * @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. | |
| 204 | 191 | */ |
| 205 | 192 | public String getString(String name); |
| 206 | 193 | |
| @@ -212,7 +199,6 @@ | ||
| 212 | 199 | * If the value is NULL, {@code null} is returned. |
| 213 | 200 | * |
| 214 | 201 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 215 | - * @throws InvalidTypeException if value {@code name} is not of type VARINT. | |
| 216 | 202 | */ |
| 217 | 203 | public BigInteger getVarint(String name); |
| 218 | 204 | |
| @@ -224,7 +210,6 @@ | ||
| 224 | 210 | * If the value is NULL, {@code null} is returned. |
| 225 | 211 | * |
| 226 | 212 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 227 | - * @throws InvalidTypeException if value {@code name} is not of type DECIMAL. | |
| 228 | 213 | */ |
| 229 | 214 | public BigDecimal getDecimal(String name); |
| 230 | 215 | |
| @@ -236,8 +221,6 @@ | ||
| 236 | 221 | * If the value is NULL, {@code null} is returned. |
| 237 | 222 | * |
| 238 | 223 | * @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. | |
| 241 | 224 | */ |
| 242 | 225 | public UUID getUUID(String name); |
| 243 | 226 | |
| @@ -249,8 +232,6 @@ | ||
| 249 | 232 | * If the value is NULL, {@code null} is returned. |
| 250 | 233 | * |
| 251 | 234 | * @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. | |
| 254 | 235 | */ |
| 255 | 236 | public InetAddress getInet(String name); |
| 256 | 237 | |
| @@ -273,8 +254,6 @@ | ||
| 273 | 254 | * {@code T} objects. |
| 274 | 255 | * |
| 275 | 256 | * @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}. | |
| 278 | 257 | */ |
| 279 | 258 | public <T> List<T> getList(String name, Class<T> elementsClass); |
| 280 | 259 | |
| @@ -300,8 +279,6 @@ | ||
| 300 | 279 | * {@code T} objects. |
| 301 | 280 | * |
| 302 | 281 | * @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}. | |
| 305 | 282 | */ |
| 306 | 283 | public <T> List<T> getList(String name, TypeToken<T> elementsType); |
| 307 | 284 | |
| @@ -324,8 +301,6 @@ | ||
| 324 | 301 | * {@code T} objects. |
| 325 | 302 | * |
| 326 | 303 | * @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}. | |
| 329 | 304 | */ |
| 330 | 305 | public <T> Set<T> getSet(String name, Class<T> elementsClass); |
| 331 | 306 | |
| @@ -351,8 +326,6 @@ | ||
| 351 | 326 | * {@code T} objects. |
| 352 | 327 | * |
| 353 | 328 | * @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}. | |
| 356 | 329 | */ |
| 357 | 330 | public <T> Set<T> getSet(String name, TypeToken<T> elementsType); |
| 358 | 331 | |
| @@ -376,9 +349,6 @@ | ||
| 376 | 349 | * {@code K} to {@code V} objects. |
| 377 | 350 | * |
| 378 | 351 | * @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}. | |
| 382 | 352 | */ |
| 383 | 353 | public <K, V> Map<K, V> getMap(String name, Class<K> keysClass, Class<V> valuesClass); |
| 384 | 354 | |
| @@ -405,9 +375,6 @@ | ||
| 405 | 375 | * {@code K} to {@code V} objects. |
| 406 | 376 | * |
| 407 | 377 | * @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}. | |
| 411 | 378 | */ |
| 412 | 379 | public <K, V> Map<K, V> getMap(String name, TypeToken<K> keysType, TypeToken<V> valuesType); |
| 413 | 380 | |
| @@ -419,7 +386,6 @@ | ||
| 419 | 386 | * then {@code null} will be returned. |
| 420 | 387 | * |
| 421 | 388 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 422 | - * @throws InvalidTypeException if value {@code i} is not a UDT value. | |
| 423 | 389 | */ |
| 424 | 390 | public UDTValue getUDTValue(String name); |
| 425 | 391 | |
| @@ -431,29 +397,23 @@ | ||
| 431 | 397 | * then {@code null} will be returned. |
| 432 | 398 | * |
| 433 | 399 | * @throws IllegalArgumentException if {@code name} is not valid name for this object. |
| 434 | - * @throws InvalidTypeException if value {@code i} is not a tuple value. | |
| 435 | 400 | */ |
| 436 | 401 | public TupleValue getTupleValue(String name); |
| 437 | 402 | |
| 438 | 403 | /** |
| 439 | 404 | * Returns the value for {@code name} as the Java type matching its CQL type. |
| 440 | 405 | * <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>. | |
| 447 | 409 | * <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. | |
| 454 | 412 | * |
| 455 | 413 | * @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. | |
| 457 | 417 | * |
| 458 | 418 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 459 | 419 | */ |
modified driver-core/src/main/java/com/datastax/driver/core/SettableByIndexData.java +9 −72
| @@ -38,7 +38,6 @@ | ||
| 38 | 38 | * @return this object. |
| 39 | 39 | * |
| 40 | 40 | * @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. | |
| 42 | 41 | */ |
| 43 | 42 | public T setBool(int i, boolean v); |
| 44 | 43 | |
| @@ -50,7 +49,6 @@ | ||
| 50 | 49 | * @return this object. |
| 51 | 50 | * |
| 52 | 51 | * @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. | |
| 54 | 52 | */ |
| 55 | 53 | public T setByte(int i, byte v); |
| 56 | 54 | |
| @@ -62,7 +60,6 @@ | ||
| 62 | 60 | * @return this object. |
| 63 | 61 | * |
| 64 | 62 | * @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. | |
| 66 | 63 | */ |
| 67 | 64 | public T setShort(int i, short v); |
| 68 | 65 | |
| @@ -74,7 +71,6 @@ | ||
| 74 | 71 | * @return this object. |
| 75 | 72 | * |
| 76 | 73 | * @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. | |
| 78 | 74 | */ |
| 79 | 75 | public T setInt(int i, int v); |
| 80 | 76 | |
| @@ -86,7 +82,6 @@ | ||
| 86 | 82 | * @return this object. |
| 87 | 83 | * |
| 88 | 84 | * @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. | |
| 90 | 85 | */ |
| 91 | 86 | public T setLong(int i, long v); |
| 92 | 87 | |
| @@ -98,7 +93,6 @@ | ||
| 98 | 93 | * @return this object. |
| 99 | 94 | * |
| 100 | 95 | * @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. | |
| 102 | 96 | */ |
| 103 | 97 | public T setTimestamp(int i, Date v); |
| 104 | 98 | |
| @@ -110,7 +104,6 @@ | ||
| 110 | 104 | * @return this object. |
| 111 | 105 | * |
| 112 | 106 | * @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. | |
| 114 | 107 | */ |
| 115 | 108 | public T setDate(int i, LocalDate v); |
| 116 | 109 | |
| @@ -122,7 +115,6 @@ | ||
| 122 | 115 | * @return this object. |
| 123 | 116 | * |
| 124 | 117 | * @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. | |
| 126 | 118 | */ |
| 127 | 119 | public T setTime(int i, long v); |
| 128 | 120 | |
| @@ -134,7 +126,6 @@ | ||
| 134 | 126 | * @return this object. |
| 135 | 127 | * |
| 136 | 128 | * @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. | |
| 138 | 129 | */ |
| 139 | 130 | public T setFloat(int i, float v); |
| 140 | 131 | |
| @@ -146,7 +137,6 @@ | ||
| 146 | 137 | * @return this object. |
| 147 | 138 | * |
| 148 | 139 | * @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. | |
| 150 | 140 | */ |
| 151 | 141 | public T setDouble(int i, double v); |
| 152 | 142 | |
| @@ -158,8 +148,6 @@ | ||
| 158 | 148 | * @return this object. |
| 159 | 149 | * |
| 160 | 150 | * @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. | |
| 163 | 151 | */ |
| 164 | 152 | public T setString(int i, String v); |
| 165 | 153 | |
| @@ -175,7 +163,6 @@ | ||
| 175 | 163 | * @return this object. |
| 176 | 164 | * |
| 177 | 165 | * @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. | |
| 179 | 166 | */ |
| 180 | 167 | public T setBytes(int i, ByteBuffer v); |
| 181 | 168 | |
| @@ -203,7 +190,6 @@ | ||
| 203 | 190 | * @return this object. |
| 204 | 191 | * |
| 205 | 192 | * @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. | |
| 207 | 193 | */ |
| 208 | 194 | public T setVarint(int i, BigInteger v); |
| 209 | 195 | |
| @@ -215,7 +201,6 @@ | ||
| 215 | 201 | * @return this object. |
| 216 | 202 | * |
| 217 | 203 | * @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. | |
| 219 | 204 | */ |
| 220 | 205 | public T setDecimal(int i, BigDecimal v); |
| 221 | 206 | |
| @@ -227,9 +212,6 @@ | ||
| 227 | 212 | * @return this object. |
| 228 | 213 | * |
| 229 | 214 | * @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. | |
| 233 | 215 | */ |
| 234 | 216 | public T setUUID(int i, UUID v); |
| 235 | 217 | |
| @@ -241,7 +223,6 @@ | ||
| 241 | 223 | * @return this object. |
| 242 | 224 | * |
| 243 | 225 | * @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. | |
| 245 | 226 | */ |
| 246 | 227 | public T setInet(int i, InetAddress v); |
| 247 | 228 | |
| @@ -250,12 +231,9 @@ | ||
| 250 | 231 | * <p> |
| 251 | 232 | * Please note that {@code null} values inside collections are not supported by CQL. |
| 252 | 233 | * <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>. | |
| 259 | 237 | * <p> |
| 260 | 238 | * For these reasons, it is generally preferable to use the more |
| 261 | 239 | * deterministic methods {@link #setList(int, List, Class)} or |
| @@ -266,9 +244,6 @@ | ||
| 266 | 244 | * @return this object. |
| 267 | 245 | * |
| 268 | 246 | * @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}. | |
| 272 | 247 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 273 | 248 | * by CQL. |
| 274 | 249 | */ |
| @@ -290,9 +265,6 @@ | ||
| 290 | 265 | * @return this object. |
| 291 | 266 | * |
| 292 | 267 | * @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}. | |
| 296 | 268 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 297 | 269 | * by CQL. |
| 298 | 270 | */ |
| @@ -314,9 +286,6 @@ | ||
| 314 | 286 | * @return this object. |
| 315 | 287 | * |
| 316 | 288 | * @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}. | |
| 320 | 289 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 321 | 290 | * by CQL. |
| 322 | 291 | */ |
| @@ -327,14 +296,9 @@ | ||
| 327 | 296 | * <p> |
| 328 | 297 | * Please note that {@code null} values are not supported inside collection by CQL. |
| 329 | 298 | * <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>. | |
| 338 | 302 | * <p> |
| 339 | 303 | * For these reasons, it is generally preferable to use the more |
| 340 | 304 | * deterministic methods {@link #setMap(int, Map, Class, Class)} or |
| @@ -345,9 +309,6 @@ | ||
| 345 | 309 | * @return this object. |
| 346 | 310 | * |
| 347 | 311 | * @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}. | |
| 351 | 312 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 352 | 313 | * by CQL. |
| 353 | 314 | */ |
| @@ -370,9 +331,6 @@ | ||
| 370 | 331 | * @return this object. |
| 371 | 332 | * |
| 372 | 333 | * @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}. | |
| 376 | 334 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 377 | 335 | * by CQL. |
| 378 | 336 | */ |
| @@ -395,9 +353,6 @@ | ||
| 395 | 353 | * @return this object. |
| 396 | 354 | * |
| 397 | 355 | * @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}. | |
| 401 | 356 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 402 | 357 | * by CQL. |
| 403 | 358 | */ |
| @@ -408,14 +363,9 @@ | ||
| 408 | 363 | * <p> |
| 409 | 364 | * Please note that {@code null} values are not supported inside collection by CQL. |
| 410 | 365 | * <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>. | |
| 419 | 369 | * <p> |
| 420 | 370 | * For these reasons, it is generally preferable to use the more |
| 421 | 371 | * deterministic methods {@link #setSet(int, Set, Class)} or |
| @@ -426,9 +376,6 @@ | ||
| 426 | 376 | * @return this object. |
| 427 | 377 | * |
| 428 | 378 | * @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}. | |
| 432 | 379 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 433 | 380 | * by CQL. |
| 434 | 381 | */ |
| @@ -450,9 +397,6 @@ | ||
| 450 | 397 | * @return this object. |
| 451 | 398 | * |
| 452 | 399 | * @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}. | |
| 456 | 400 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 457 | 401 | * by CQL. |
| 458 | 402 | */ |
| @@ -474,9 +418,6 @@ | ||
| 474 | 418 | * @return this object. |
| 475 | 419 | * |
| 476 | 420 | * @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}. | |
| 480 | 421 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 481 | 422 | * by CQL. |
| 482 | 423 | */ |
| @@ -490,8 +431,6 @@ | ||
| 490 | 431 | * @return this object. |
| 491 | 432 | * |
| 492 | 433 | * @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}. | |
| 495 | 434 | */ |
| 496 | 435 | public T setUDTValue(int i, UDTValue v); |
| 497 | 436 | |
| @@ -503,8 +442,6 @@ | ||
| 503 | 442 | * @return this object. |
| 504 | 443 | * |
| 505 | 444 | * @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}. | |
| 508 | 445 | */ |
| 509 | 446 | public T setTupleValue(int i, TupleValue v); |
| 510 | 447 |
modified driver-core/src/main/java/com/datastax/driver/core/SettableByNameData.java +14 −92
| @@ -40,7 +40,6 @@ | ||
| 40 | 40 | * @return this object. |
| 41 | 41 | * |
| 42 | 42 | * @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. | |
| 44 | 43 | */ |
| 45 | 44 | public T setBool(String name, boolean v); |
| 46 | 45 | |
| @@ -54,7 +53,6 @@ | ||
| 54 | 53 | * @return this object. |
| 55 | 54 | * |
| 56 | 55 | * @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. | |
| 58 | 56 | */ |
| 59 | 57 | public T setByte(String name, byte v); |
| 60 | 58 | |
| @@ -68,7 +66,6 @@ | ||
| 68 | 66 | * @return this object. |
| 69 | 67 | * |
| 70 | 68 | * @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. | |
| 72 | 69 | */ |
| 73 | 70 | public T setShort(String name, short v); |
| 74 | 71 | |
| @@ -82,7 +79,6 @@ | ||
| 82 | 79 | * @return this object. |
| 83 | 80 | * |
| 84 | 81 | * @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. | |
| 86 | 82 | */ |
| 87 | 83 | public T setInt(String name, int v); |
| 88 | 84 | |
| @@ -96,8 +92,6 @@ | ||
| 96 | 92 | * @return this object. |
| 97 | 93 | * |
| 98 | 94 | * @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. | |
| 101 | 95 | */ |
| 102 | 96 | public T setLong(String name, long v); |
| 103 | 97 | |
| @@ -111,8 +105,6 @@ | ||
| 111 | 105 | * @return this object. |
| 112 | 106 | * |
| 113 | 107 | * @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. | |
| 116 | 108 | */ |
| 117 | 109 | public T setTimestamp(String name, Date v); |
| 118 | 110 | |
| @@ -126,8 +118,6 @@ | ||
| 126 | 118 | * @return this object. |
| 127 | 119 | * |
| 128 | 120 | * @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. | |
| 131 | 121 | */ |
| 132 | 122 | public T setDate(String name, LocalDate v); |
| 133 | 123 | |
| @@ -141,8 +131,6 @@ | ||
| 141 | 131 | * @return this object. |
| 142 | 132 | * |
| 143 | 133 | * @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. | |
| 146 | 134 | */ |
| 147 | 135 | public T setTime(String name, long v); |
| 148 | 136 | |
| @@ -156,8 +144,6 @@ | ||
| 156 | 144 | * @return this object. |
| 157 | 145 | * |
| 158 | 146 | * @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. | |
| 161 | 147 | */ |
| 162 | 148 | public T setFloat(String name, float v); |
| 163 | 149 | |
| @@ -171,8 +157,6 @@ | ||
| 171 | 157 | * @return this object. |
| 172 | 158 | * |
| 173 | 159 | * @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. | |
| 176 | 160 | */ |
| 177 | 161 | public T setDouble(String name, double v); |
| 178 | 162 | |
| @@ -186,8 +170,6 @@ | ||
| 186 | 170 | * @return this object. |
| 187 | 171 | * |
| 188 | 172 | * @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. | |
| 191 | 173 | */ |
| 192 | 174 | public T setString(String name, String v); |
| 193 | 175 | |
| @@ -205,7 +187,6 @@ | ||
| 205 | 187 | * @return this object. |
| 206 | 188 | * |
| 207 | 189 | * @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. | |
| 209 | 190 | */ |
| 210 | 191 | public T setBytes(String name, ByteBuffer v); |
| 211 | 192 | |
| @@ -237,8 +218,6 @@ | ||
| 237 | 218 | * @return this object. |
| 238 | 219 | * |
| 239 | 220 | * @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. | |
| 242 | 221 | */ |
| 243 | 222 | public T setVarint(String name, BigInteger v); |
| 244 | 223 | |
| @@ -252,8 +231,6 @@ | ||
| 252 | 231 | * @return this object. |
| 253 | 232 | * |
| 254 | 233 | * @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. | |
| 257 | 234 | */ |
| 258 | 235 | public T setDecimal(String name, BigDecimal v); |
| 259 | 236 | |
| @@ -267,9 +244,6 @@ | ||
| 267 | 244 | * @return this object. |
| 268 | 245 | * |
| 269 | 246 | * @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. | |
| 273 | 247 | */ |
| 274 | 248 | public T setUUID(String name, UUID v); |
| 275 | 249 | |
| @@ -283,8 +257,6 @@ | ||
| 283 | 257 | * @return this object. |
| 284 | 258 | * |
| 285 | 259 | * @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. | |
| 288 | 260 | */ |
| 289 | 261 | public T setInet(String name, InetAddress v); |
| 290 | 262 | |
| @@ -294,14 +266,9 @@ | ||
| 294 | 266 | * <p> |
| 295 | 267 | * Please note that {@code null} values inside collections are not supported by CQL. |
| 296 | 268 | * <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>. | |
| 305 | 272 | * <p> |
| 306 | 273 | * For these reasons, it is generally preferable to use the more |
| 307 | 274 | * deterministic methods {@link #setList(String, List, Class)} or |
| @@ -313,9 +280,6 @@ | ||
| 313 | 280 | * @return this object. |
| 314 | 281 | * |
| 315 | 282 | * @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}. | |
| 319 | 283 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 320 | 284 | * by CQL. |
| 321 | 285 | */ |
| @@ -336,10 +300,7 @@ | ||
| 336 | 300 | * @param elementsClass the class for the elements of the list. |
| 337 | 301 | * @return this object. |
| 338 | 302 | * |
| 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. | |
| 343 | 304 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 344 | 305 | * by CQL. |
| 345 | 306 | */ |
| @@ -360,10 +321,7 @@ | ||
| 360 | 321 | * @param elementsType the type for the elements of the list. |
| 361 | 322 | * @return this object. |
| 362 | 323 | * |
| 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. | |
| 367 | 325 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 368 | 326 | * by CQL. |
| 369 | 327 | */ |
| @@ -375,14 +333,10 @@ | ||
| 375 | 333 | * <p> |
| 376 | 334 | * Please note that {@code null} values are not supported inside collection by CQL. |
| 377 | 335 | * <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. | |
| 382 | 336 | * <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>. | |
| 386 | 340 | * <p> |
| 387 | 341 | * For these reasons, it is generally preferable to use the more |
| 388 | 342 | * deterministic methods {@link #setMap(String, Map, Class, Class)} or |
| @@ -394,9 +348,6 @@ | ||
| 394 | 348 | * @return this object. |
| 395 | 349 | * |
| 396 | 350 | * @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}. | |
| 400 | 351 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 401 | 352 | * by CQL. |
| 402 | 353 | */ |
| @@ -420,9 +371,6 @@ | ||
| 420 | 371 | * @return this object. |
| 421 | 372 | * |
| 422 | 373 | * @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}. | |
| 426 | 374 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 427 | 375 | * by CQL. |
| 428 | 376 | */ |
| @@ -446,9 +394,6 @@ | ||
| 446 | 394 | * @return this object. |
| 447 | 395 | * |
| 448 | 396 | * @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}. | |
| 452 | 397 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 453 | 398 | * by CQL. |
| 454 | 399 | */ |
| @@ -460,14 +405,9 @@ | ||
| 460 | 405 | * <p> |
| 461 | 406 | * Please note that {@code null} values are not supported inside collection by CQL. |
| 462 | 407 | * <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>. | |
| 471 | 411 | * <p> |
| 472 | 412 | * For these reasons, it is generally preferable to use the more |
| 473 | 413 | * deterministic methods {@link #setSet(String, Set, Class)} or |
| @@ -479,9 +419,6 @@ | ||
| 479 | 419 | * @return this object. |
| 480 | 420 | * |
| 481 | 421 | * @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}. | |
| 485 | 422 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 486 | 423 | * by CQL. |
| 487 | 424 | */ |
| @@ -503,9 +440,6 @@ | ||
| 503 | 440 | * @return this object. |
| 504 | 441 | * |
| 505 | 442 | * @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}. | |
| 509 | 443 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 510 | 444 | * by CQL. |
| 511 | 445 | */ |
| @@ -527,9 +461,6 @@ | ||
| 527 | 461 | * @return this object. |
| 528 | 462 | * |
| 529 | 463 | * @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}. | |
| 533 | 464 | * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections |
| 534 | 465 | * by CQL. |
| 535 | 466 | */ |
| @@ -545,11 +476,6 @@ | ||
| 545 | 476 | * @return this object. |
| 546 | 477 | * |
| 547 | 478 | * @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}. | |
| 553 | 479 | */ |
| 554 | 480 | public T setUDTValue(String name, UDTValue v); |
| 555 | 481 | |
| @@ -563,9 +489,6 @@ | ||
| 563 | 489 | * @return this object. |
| 564 | 490 | * |
| 565 | 491 | * @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}. | |
| 569 | 492 | */ |
| 570 | 493 | public T setTupleValue(String name, TupleValue v); |
| 571 | 494 | |
| @@ -592,7 +515,7 @@ | ||
| 592 | 515 | * @param v the value to set; may be {@code null}. |
| 593 | 516 | * @param targetClass The Java class to convert to; must not be {@code null}; |
| 594 | 517 | * @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. | |
| 596 | 519 | */ |
| 597 | 520 | <V> T set(String name, V v, Class<V> targetClass); |
| 598 | 521 | |
| @@ -607,7 +530,7 @@ | ||
| 607 | 530 | * @param v the value to set; may be {@code null}. |
| 608 | 531 | * @param targetType The Java type to convert to; must not be {@code null}; |
| 609 | 532 | * @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. | |
| 611 | 534 | */ |
| 612 | 535 | <V> T set(String name, V v, TypeToken<V> targetType); |
| 613 | 536 | |
| @@ -627,9 +550,8 @@ | ||
| 627 | 550 | * @param codec The {@link TypeCodec} to use to serialize the value; may not be {@code null}. |
| 628 | 551 | * @return this object. |
| 629 | 552 | * @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. | |
| 631 | 554 | */ |
| 632 | 555 | <V> T set(String name, V v, TypeCodec<V> codec); |
| 633 | 556 | |
| 634 | - | |
| 635 | 557 | } |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecJsonIntegrationTest.java +1 −1
| @@ -123,7 +123,7 @@ | ||
| 123 | 123 | session.execute(session.prepare(insertQuery).bind() |
| 124 | 124 | .setString(0, notAJsonString) |
| 125 | 125 | .set(1, alice, User.class) |
| 126 | - .setList(2, bobAndCharlie) | |
| 126 | + .setList(2, bobAndCharlie, User.class) | |
| 127 | 127 | ); |
| 128 | 128 | PreparedStatement ps = session.prepare(selectQuery); |
| 129 | 129 | ResultSet rows = session.execute(ps.bind() |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecUDTIntegrationTest.java +1 −1
| @@ -154,7 +154,7 @@ | ||
| 154 | 154 | |
| 155 | 155 | @Override |
| 156 | 156 | 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); | |
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 |
modified features/custom_codecs/README.md +6 −7
| @@ -440,14 +440,13 @@ | ||
| 440 | 440 | |
| 441 | 441 | The following situations are exceptions where it is not possible to cache lookup results: |
| 442 | 442 | |
| 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. | |
| 449 | 448 | |
| 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, | |
| 451 | 450 | consider using prepared statements all the time, and avoid calling ambiguous methods (prefer `get()` and `set()`). |
| 452 | 451 | |
| 453 | 452 | [JAVA-721]: https://datastax-oss.atlassian.net/browse/JAVA-721 |