/src/java/org/apache/cassandra/cql3/functions/types/GettableByNameData.java

https://github.com/beobal/cassandra · Java · 593 lines · 42 code · 34 blank · 517 comment · 0 complexity · 78c427b99c250c0b14bd410b303d69d5 MD5 · raw file

  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.apache.cassandra.cql3.functions.types;
  19. import java.math.BigDecimal;
  20. import java.math.BigInteger;
  21. import java.net.InetAddress;
  22. import java.nio.ByteBuffer;
  23. import java.util.*;
  24. import com.google.common.reflect.TypeToken;
  25. import org.apache.cassandra.cql3.functions.types.exceptions.CodecNotFoundException;
  26. import org.apache.cassandra.cql3.functions.types.exceptions.InvalidTypeException;
  27. /**
  28. * Collection of (typed) CQL values that can be retrieved by name.
  29. */
  30. public interface GettableByNameData
  31. {
  32. /**
  33. * Returns whether the value for {@code name} is NULL.
  34. *
  35. * @param name the name to check.
  36. * @return whether the value for {@code name} is NULL.
  37. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  38. */
  39. public boolean isNull(String name);
  40. /**
  41. * Returns the value for {@code name} as a boolean.
  42. *
  43. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  44. * type to a Java {@code boolean} (for CQL type {@code boolean}, this will be the built-in codec).
  45. *
  46. * @param name the name to retrieve.
  47. * @return the boolean value for {@code name}. If the value is NULL, {@code false} is returned. If
  48. * you need to distinguish NULL and false values, check first with {@link #isNull(String)} or
  49. * use {@code get(name, Boolean.class)}.
  50. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  51. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  52. * type to a boolean.
  53. */
  54. public boolean getBool(String name);
  55. /**
  56. * Returns the value for {@code name} as a byte.
  57. *
  58. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  59. * type to a Java {@code byte} (for CQL type {@code tinyint}, this will be the built-in codec).
  60. *
  61. * @param name the name to retrieve.
  62. * @return the value for {@code name} as a byte. If the value is NULL, {@code 0} is returned. If
  63. * you need to distinguish NULL and 0, check first with {@link #isNull(String)} or use {@code
  64. * get(name, Byte.class)}. {@code 0} is returned.
  65. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  66. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  67. * type to a byte.
  68. */
  69. public byte getByte(String name);
  70. /**
  71. * Returns the value for {@code name} as a short.
  72. *
  73. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  74. * type to a Java {@code short} (for CQL type {@code smallint}, this will be the built-in codec).
  75. *
  76. * @param name the name to retrieve.
  77. * @return the value for {@code name} as a short. If the value is NULL, {@code 0} is returned. If
  78. * you need to distinguish NULL and 0, check first with {@link #isNull(String)} or use {@code
  79. * get(name, Short.class)}. {@code 0} is returned.
  80. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  81. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  82. * type to a short.
  83. */
  84. public short getShort(String name);
  85. /**
  86. * Returns the value for {@code name} as an integer.
  87. *
  88. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  89. * type to a Java {@code int} (for CQL type {@code int}, this will be the built-in codec).
  90. *
  91. * @param name the name to retrieve.
  92. * @return the value for {@code name} as an integer. If the value is NULL, {@code 0} is returned.
  93. * If you need to distinguish NULL and 0, check first with {@link #isNull(String)} or use
  94. * {@code get(name, Integer.class)}. {@code 0} is returned.
  95. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  96. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  97. * type to an int.
  98. */
  99. public int getInt(String name);
  100. /**
  101. * Returns the value for {@code name} as a long.
  102. *
  103. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  104. * type to a Java {@code byte} (for CQL types {@code bigint} and {@code counter}, this will be the
  105. * built-in codec).
  106. *
  107. * @param name the name to retrieve.
  108. * @return the value for {@code name} as a long. If the value is NULL, {@code 0L} is returned. If
  109. * you need to distinguish NULL and 0L, check first with {@link #isNull(String)} or use {@code
  110. * get(name, Long.class)}.
  111. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  112. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  113. * type to a long.
  114. */
  115. public long getLong(String name);
  116. /**
  117. * Returns the value for {@code name} as a date.
  118. *
  119. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  120. * type to a {@code Date} (for CQL type {@code timestamp}, this will be the built-in codec).
  121. *
  122. * @param name the name to retrieve.
  123. * @return the value for {@code name} as a date. If the value is NULL, {@code null} is returned.
  124. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  125. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  126. * type to a {@code Date}.
  127. */
  128. public Date getTimestamp(String name);
  129. /**
  130. * Returns the value for {@code name} as a date (without time).
  131. *
  132. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  133. * type to a {@link LocalDate} (for CQL type {@code date}, this will be the built-in codec).
  134. *
  135. * @param name the name to retrieve.
  136. * @return the value for {@code name} as a date. If the value is NULL, {@code null} is returned.
  137. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  138. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  139. * type to a {@code LocalDate}.
  140. */
  141. public LocalDate getDate(String name);
  142. /**
  143. * Returns the value for {@code name} as a long in nanoseconds since midnight.
  144. *
  145. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  146. * type to a Java {@code long} (for CQL type {@code time}, this will be the built-in codec).
  147. *
  148. * @param name the name to retrieve.
  149. * @return the value for {@code name} as a long. If the value is NULL, {@code 0L} is returned.
  150. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  151. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  152. * type to a long.
  153. */
  154. public long getTime(String name);
  155. /**
  156. * Returns the value for {@code name} as a float.
  157. *
  158. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  159. * type to a Java {@code float} (for CQL type {@code float}, this will be the built-in codec).
  160. *
  161. * @param name the name to retrieve.
  162. * @return the value for {@code name} as a float. If the value is NULL, {@code 0.0f} is returned.
  163. * If you need to distinguish NULL and 0.0f, check first with {@link #isNull(String)} or use
  164. * {@code get(name, Float.class)}.
  165. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  166. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  167. * type to a float.
  168. */
  169. public float getFloat(String name);
  170. /**
  171. * Returns the value for {@code name} as a double.
  172. *
  173. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  174. * type to a Java {@code double} (for CQL type {@code double}, this will be the built-in codec).
  175. *
  176. * @param name the name to retrieve.
  177. * @return the value for {@code name} as a double. If the value is NULL, {@code 0.0} is returned.
  178. * If you need to distinguish NULL and 0.0, check first with {@link #isNull(String)} or use
  179. * {@code get(name, Double.class)}.
  180. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  181. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  182. * type to a double.
  183. */
  184. public double getDouble(String name);
  185. /**
  186. * Returns the value for {@code name} as a ByteBuffer.
  187. *
  188. * <p>This method does not use any codec; it returns a copy of the binary representation of the
  189. * value. It is up to the caller to convert the returned value appropriately.
  190. *
  191. * <p>Note: this method always return the bytes composing the value, even if the column is not of
  192. * type BLOB. That is, this method never throw an InvalidTypeException. However, if the type is
  193. * not BLOB, it is up to the caller to handle the returned value correctly.
  194. *
  195. * @param name the name to retrieve.
  196. * @return the value for {@code name} as a ByteBuffer. If the value is NULL, {@code null} is
  197. * returned.
  198. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  199. */
  200. public ByteBuffer getBytesUnsafe(String name);
  201. /**
  202. * Returns the value for {@code name} as a byte array.
  203. *
  204. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  205. * type to a Java {@code ByteBuffer} (for CQL type {@code blob}, this will be the built-in codec).
  206. *
  207. * @param name the name to retrieve.
  208. * @return the value for {@code name} as a byte array. If the value is NULL, {@code null} is
  209. * returned.
  210. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  211. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  212. * type to a {@code ByteBuffer}.
  213. */
  214. public ByteBuffer getBytes(String name);
  215. /**
  216. * Returns the value for {@code name} as a string.
  217. *
  218. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  219. * type to a Java string (for CQL types {@code text}, {@code varchar} and {@code ascii}, this will
  220. * be the built-in codec).
  221. *
  222. * @param name the name to retrieve.
  223. * @return the value for {@code name} as a string. If the value is NULL, {@code null} is returned.
  224. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  225. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  226. * type to a string.
  227. */
  228. public String getString(String name);
  229. /**
  230. * Returns the value for {@code name} as a variable length integer.
  231. *
  232. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  233. * type to a {@code BigInteger} (for CQL type {@code varint}, this will be the built-in codec).
  234. *
  235. * @param name the name to retrieve.
  236. * @return the value for {@code name} as a variable length integer. If the value is NULL, {@code
  237. * null} is returned.
  238. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  239. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  240. * type to a {@code BigInteger}.
  241. */
  242. public BigInteger getVarint(String name);
  243. /**
  244. * Returns the value for {@code name} as a variable length decimal.
  245. *
  246. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  247. * type to a {@code BigDecimal} (for CQL type {@code decimal}, this will be the built-in codec).
  248. *
  249. * @param name the name to retrieve.
  250. * @return the value for {@code name} as a variable length decimal. If the value is NULL, {@code
  251. * null} is returned.
  252. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  253. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  254. * type to a {@code BigDecimal}.
  255. */
  256. public BigDecimal getDecimal(String name);
  257. /**
  258. * Returns the value for {@code name} as a UUID.
  259. *
  260. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  261. * type to a {@code UUID} (for CQL types {@code uuid} and {@code timeuuid}, this will be the
  262. * built-in codec).
  263. *
  264. * @param name the name to retrieve.
  265. * @return the value for {@code name} as a UUID. If the value is NULL, {@code null} is returned.
  266. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  267. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  268. * type to a {@code UUID}.
  269. */
  270. public UUID getUUID(String name);
  271. /**
  272. * Returns the value for {@code name} as an InetAddress.
  273. *
  274. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  275. * type to an {@code InetAddress} (for CQL type {@code inet}, this will be the built-in codec).
  276. *
  277. * @param name the name to retrieve.
  278. * @return the value for {@code name} as an InetAddress. If the value is NULL, {@code null} is
  279. * returned.
  280. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  281. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  282. * type to a {@code InetAddress}.
  283. */
  284. public InetAddress getInet(String name);
  285. /**
  286. * Returns the value for {@code name} as a list.
  287. *
  288. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  289. * type to a list of the specified type.
  290. *
  291. * <p>If the type of the elements is generic, use {@link #getList(String, TypeToken)}.
  292. *
  293. * <p>Implementation note: the actual {@link List} implementation will depend on the {@link
  294. * TypeCodec codec} being used; therefore, callers should make no assumptions concerning its
  295. * mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQL
  296. * {@code NULL} values is also codec-dependent. By default, the driver will return mutable
  297. * instances, and a CQL {@code NULL} will mapped to an empty collection (note that Cassandra makes
  298. * no distinction between {@code NULL} and an empty collection).
  299. *
  300. * @param name the name to retrieve.
  301. * @param elementsClass the class for the elements of the list to retrieve.
  302. * @return the value of the {@code i}th element as a list of {@code T} objects.
  303. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  304. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  305. * type to a list.
  306. */
  307. public <T> List<T> getList(String name, Class<T> elementsClass);
  308. /**
  309. * Returns the value for {@code name} as a list.
  310. *
  311. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  312. * type to a list of the specified type.
  313. *
  314. * <p>Use this variant with nested collections, which produce a generic element type:
  315. *
  316. * <pre>
  317. * {@code List<List<String>> l = row.getList("theColumn", new TypeToken<List<String>>() {});}
  318. * </pre>
  319. *
  320. * <p>Implementation note: the actual {@link List} implementation will depend on the {@link
  321. * TypeCodec codec} being used; therefore, callers should make no assumptions concerning its
  322. * mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQL
  323. * {@code NULL} values is also codec-dependent. By default, the driver will return mutable
  324. * instances, and a CQL {@code NULL} will mapped to an empty collection (note that Cassandra makes
  325. * no distinction between {@code NULL} and an empty collection).
  326. *
  327. * @param name the name to retrieve.
  328. * @param elementsType the type for the elements of the list to retrieve.
  329. * @return the value of the {@code i}th element as a list of {@code T} objects.
  330. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  331. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  332. * type to a list.
  333. */
  334. public <T> List<T> getList(String name, TypeToken<T> elementsType);
  335. /**
  336. * Returns the value for {@code name} as a set.
  337. *
  338. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  339. * type to a set of the specified type.
  340. *
  341. * <p>If the type of the elements is generic, use {@link #getSet(String, TypeToken)}.
  342. *
  343. * <p>Implementation note: the actual {@link Set} implementation will depend on the {@link
  344. * TypeCodec codec} being used; therefore, callers should make no assumptions concerning its
  345. * mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQL
  346. * {@code NULL} values is also codec-dependent. By default, the driver will return mutable
  347. * instances, and a CQL {@code NULL} will mapped to an empty collection (note that Cassandra makes
  348. * no distinction between {@code NULL} and an empty collection).
  349. *
  350. * @param name the name to retrieve.
  351. * @param elementsClass the class for the elements of the set to retrieve.
  352. * @return the value of the {@code i}th element as a set of {@code T} objects.
  353. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  354. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  355. * type to a set.
  356. */
  357. public <T> Set<T> getSet(String name, Class<T> elementsClass);
  358. /**
  359. * Returns the value for {@code name} as a set.
  360. *
  361. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  362. * type to a set of the specified type.
  363. *
  364. * <p>Use this variant with nested collections, which produce a generic element type:
  365. *
  366. * <pre>
  367. * {@code Set<List<String>> l = row.getSet("theColumn", new TypeToken<List<String>>() {});}
  368. * </pre>
  369. *
  370. * <p>Implementation note: the actual {@link Set} implementation will depend on the {@link
  371. * TypeCodec codec} being used; therefore, callers should make no assumptions concerning its
  372. * mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQL
  373. * {@code NULL} values is also codec-dependent. By default, the driver will return mutable
  374. * instances, and a CQL {@code NULL} will mapped to an empty collection (note that Cassandra makes
  375. * no distinction between {@code NULL} and an empty collection).
  376. *
  377. * @param name the name to retrieve.
  378. * @param elementsType the type for the elements of the set to retrieve.
  379. * @return the value of the {@code i}th element as a set of {@code T} objects.
  380. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  381. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  382. * type to a set.
  383. */
  384. public <T> Set<T> getSet(String name, TypeToken<T> elementsType);
  385. /**
  386. * Returns the value for {@code name} as a map.
  387. *
  388. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  389. * type to a map of the specified types.
  390. *
  391. * <p>If the type of the keys and/or values is generic, use {@link #getMap(String, TypeToken,
  392. * TypeToken)}.
  393. *
  394. * <p>Implementation note: the actual {@link Map} implementation will depend on the {@link
  395. * TypeCodec codec} being used; therefore, callers should make no assumptions concerning its
  396. * mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQL
  397. * {@code NULL} values is also codec-dependent. By default, the driver will return mutable
  398. * instances, and a CQL {@code NULL} will mapped to an empty collection (note that Cassandra makes
  399. * no distinction between {@code NULL} and an empty collection).
  400. *
  401. * @param name the name to retrieve.
  402. * @param keysClass the class for the keys of the map to retrieve.
  403. * @param valuesClass the class for the values of the map to retrieve.
  404. * @return the value of {@code name} as a map of {@code K} to {@code V} objects.
  405. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  406. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  407. * type to a map.
  408. */
  409. public <K, V> Map<K, V> getMap(String name, Class<K> keysClass, Class<V> valuesClass);
  410. /**
  411. * Returns the value for {@code name} as a map.
  412. *
  413. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  414. * type to a map of the specified types.
  415. *
  416. * <p>Use this variant with nested collections, which produce a generic element type:
  417. *
  418. * <pre>
  419. * {@code Map<Int, List<String>> l = row.getMap("theColumn", TypeToken.of(Integer.class), new TypeToken<List<String>>() {});}
  420. * </pre>
  421. *
  422. * <p>Implementation note: the actual {@link Map} implementation will depend on the {@link
  423. * TypeCodec codec} being used; therefore, callers should make no assumptions concerning its
  424. * mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQL
  425. * {@code NULL} values is also codec-dependent. By default, the driver will return mutable
  426. * instances, and a CQL {@code NULL} will mapped to an empty collection (note that Cassandra makes
  427. * no distinction between {@code NULL} and an empty collection).
  428. *
  429. * @param name the name to retrieve.
  430. * @param keysType the class for the keys of the map to retrieve.
  431. * @param valuesType the class for the values of the map to retrieve.
  432. * @return the value of {@code name} as a map of {@code K} to {@code V} objects.
  433. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  434. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  435. * type to a map.
  436. */
  437. public <K, V> Map<K, V> getMap(String name, TypeToken<K> keysType, TypeToken<V> valuesType);
  438. /**
  439. * Return the value for {@code name} as a UDT value.
  440. *
  441. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  442. * type to a {@code UDTValue} (if the CQL type is a UDT, the registry will generate a codec
  443. * automatically).
  444. *
  445. * @param name the name to retrieve.
  446. * @return the value of {@code name} as a UDT value. If the value is NULL, then {@code null} will
  447. * be returned.
  448. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  449. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  450. * type to a {@code UDTValue}.
  451. */
  452. public UDTValue getUDTValue(String name);
  453. /**
  454. * Return the value for {@code name} as a tuple value.
  455. *
  456. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  457. * type to a {@code TupleValue} (if the CQL type is a tuple, the registry will generate a codec
  458. * automatically).
  459. *
  460. * @param name the name to retrieve.
  461. * @return the value of {@code name} as a tuple value. If the value is NULL, then {@code null}
  462. * will be returned.
  463. * @throws IllegalArgumentException if {@code name} is not valid name for this object.
  464. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  465. * type to a {@code TupleValue}.
  466. */
  467. public TupleValue getTupleValue(String name);
  468. /**
  469. * Returns the value for {@code name} as the Java type matching its CQL type.
  470. *
  471. * <p>This method uses the {@link CodecRegistry} to find the first codec that handles the
  472. * underlying CQL type. The Java type of the returned object will be determined by the codec that
  473. * was selected.
  474. *
  475. * <p>Use this method to dynamically inspect elements when types aren't known in advance, for
  476. * instance if you're writing a generic row logger. If you know the target Java type, it is
  477. * generally preferable to use typed getters, such as the ones for built-in types ({@link
  478. * #getBool(String)}, {@link #getInt(String)}, etc.), or {@link #get(String, Class)} and {@link
  479. * #get(String, TypeToken)} for custom types.
  480. *
  481. * @param name the name to retrieve.
  482. * @return the value of {@code name} as the Java type matching its CQL type. If the value is NULL
  483. * and is a simple type, UDT or tuple, {@code null} is returned. If it is NULL and is a
  484. * collection type, an empty (immutable) collection is returned.
  485. * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
  486. * @see CodecRegistry#codecFor(DataType)
  487. */
  488. Object getObject(String name);
  489. /**
  490. * Returns the value for {@code name} converted to the given Java type.
  491. *
  492. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  493. * type to the given Java type.
  494. *
  495. * <p>If the target type is generic, use {@link #get(String, TypeToken)}.
  496. *
  497. * <p>Implementation note: the actual object returned by this method will depend on the {@link
  498. * TypeCodec codec} being used; therefore, callers should make no assumptions concerning its
  499. * mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQL
  500. * {@code NULL} values is also codec-dependent; by default, a CQL {@code NULL} value translates to
  501. * {@code null} for simple CQL types, UDTs and tuples, and to empty collections for all CQL
  502. * collection types.
  503. *
  504. * @param name the name to retrieve.
  505. * @param targetClass The Java type the value should be converted to.
  506. * @return the value for {@code name} value converted to the given Java type.
  507. * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
  508. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  509. * type to {@code targetClass}.
  510. */
  511. <T> T get(String name, Class<T> targetClass);
  512. /**
  513. * Returns the value for {@code name} converted to the given Java type.
  514. *
  515. * <p>This method uses the {@link CodecRegistry} to find a codec to convert the underlying CQL
  516. * type to the given Java type.
  517. *
  518. * <p>Implementation note: the actual object returned by this method will depend on the {@link
  519. * TypeCodec codec} being used; therefore, callers should make no assumptions concerning its
  520. * mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQL
  521. * {@code NULL} values is also codec-dependent; by default, a CQL {@code NULL} value translates to
  522. * {@code null} for simple CQL types, UDTs and tuples, and to empty collections for all CQL
  523. * collection types.
  524. *
  525. * @param name the name to retrieve.
  526. * @param targetType The Java type the value should be converted to.
  527. * @return the value for {@code name} value converted to the given Java type.
  528. * @throws IllegalArgumentException if {@code name} is not a valid name for this object.
  529. * @throws CodecNotFoundException if there is no registered codec to convert the underlying CQL
  530. * type to {@code targetType}.
  531. */
  532. <T> T get(String name, TypeToken<T> targetType);
  533. /**
  534. * Returns the value for {@code name} converted using the given {@link TypeCodec}.
  535. *
  536. * <p>This method entirely bypasses the {@link CodecRegistry} and forces the driver to use the
  537. * given codec instead. This can be useful if the codec would collide with a previously registered
  538. * one, or if you want to use the codec just once without registering it.
  539. *
  540. * <p>It is the caller's responsibility to ensure that the given codec {@link
  541. * TypeCodec#accepts(DataType) accepts} the underlying CQL type; failing to do so may result in
  542. * {@link InvalidTypeException}s being thrown.
  543. *
  544. * <p>Implementation note: the actual object returned by this method will depend on the {@link
  545. * TypeCodec codec} being used; therefore, callers should make no assumptions concerning its
  546. * mutability nor its thread-safety. Furthermore, the behavior of this method in respect to CQL
  547. * {@code NULL} values is also codec-dependent; by default, a CQL {@code NULL} value translates to
  548. * {@code null} for simple CQL types, UDTs and tuples, and to empty collections for all CQL
  549. * collection types.
  550. *
  551. * @param name the name to retrieve.
  552. * @param codec The {@link TypeCodec} to use to deserialize the value; may not be {@code null}.
  553. * @return the value of the {@code i}th value converted using the given {@link TypeCodec}.
  554. * @throws InvalidTypeException if the given codec does not {@link TypeCodec#accepts(DataType)
  555. * accept} the underlying CQL type.
  556. * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object.
  557. */
  558. <T> T get(String name, TypeCodec<T> codec);
  559. }