Elffuss BraidHub

kikocis/java-driver public

JAVA-851: Improve UUIDs javadoc with regard to user-provided timestamps.

(cherry picked from 2.1)
Changeset1e93fea50873e996e6387ae52f7b19d69b39ac6e8edd3d1a8ea0815d383cdc39
AuthorOlivier Michallat <olim7t@users.noreply.github.com> · 2016-02-23 18:15 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2016-03-31 16:37 +02:00
Parents34f2d0656c1d

Browse the files at this changeset

2 files changed

modified changelog/README.md +1 −0
@@ -6,6 +6,7 @@
66
77 - [improvement] JAVA-1011: Expose PoolingOptions default values.
88 - [improvement] JAVA-630: Don't process DOWN events for nodes that have active connections.
9+- [improvement] JAVA-851: Improve UUIDs javadoc with regard to user-provided timestamps.
910
1011
1112 ### 3.0.0
modified driver-core/src/main/java/com/datastax/driver/core/utils/UUIDs.java +16 −20
@@ -141,6 +141,16 @@
141141 * UUID generated by this method are suitable for use with the
142142 * {@code timeuuid} Cassandra type. In particular the generated UUID
143143 * includes the timestamp of its generation.
144+ * <p/>
145+ * Note that there is no way to provide your own timestamp. This is deliberate, as we feel that this does not
146+ * conform to the UUID specification, and therefore don't want to encourage it through the API.
147+ * If you want to do it anyway, use the following workaround:
148+ * <pre>
149+ * Random random = new Random();
150+ * UUID uuid = new UUID(UUIDs.startOf(userProvidedTimestamp).getMostSignificantBits(), random.nextLong());
151+ * </pre>
152+ * If you simply need to perform a range query on a {@code timeuuid} column, use the "fake" UUID generated by
153+ * {@link #startOf(long)} and {@link #endOf(long)}.
144154 *
145155 * @return a new time-based UUID.
146156 */
@@ -157,14 +167,16 @@
157167 * <p/>
158168 * The UUID created by this method <b>are not unique</b> and as such are
159169 * <b>not</b> suitable for anything else than querying a specific time
160- * range. In particular, you should not insert such UUID.
170+ * range. In particular, you should not insert such UUID. "True" UUID from
171+ * user-provided timestamps are not supported (see {@link #timeBased()}
172+ * for more explanations).
161173 * <p/>
162174 * Also, the timestamp to provide as parameter must be a unix timestamp (as
163175 * returned by {@link System#currentTimeMillis} or {@link java.util.Date#getTime}),
164- * not a UUID 100-nanoseconds intervals since 15 October 1582. In other
176+ * not a UUID 100-nanoseconds interval since 15 October 1582. In other
165177 * words, given a UUID {@code uuid}, you should never do
166178 * {@code startOf(uuid.timestamp())} but rather
167- * {@code startOf(unixTimestamp(uuid.timestamp()))}.
179+ * {@code startOf(unixTimestamp(uuid))}.
168180 * <p/>
169181 * Lastly, please note that Cassandra's timeuuid sorting is not compatible
170182 * with {@link UUID#compareTo} and hence the UUID created by this method
@@ -182,23 +194,7 @@
182194 * Creates a "fake" time-based UUID that sorts as the biggest possible
183195 * version 1 UUID generated at the provided timestamp.
184196 * <p/>
185- * Such created UUID are useful in queries to select a time range of a
186- * {@code timeuuid} column.
187- * <p/>
188- * The UUID created by this method <b>are not unique</b> and as such are
189- * <b>not</b> suitable for anything else than querying a specific time
190- * range. In particular, you should not insert such UUID.
191- * <p/>
192- * Also, the timestamp to provide as parameter must be a unix timestamp (as
193- * returned by {@link System#currentTimeMillis} or {@link java.util.Date#getTime}),
194- * not a UUID 100-nanoseconds intervals since 15 October 1582. In other
195- * words, given a UUID {@code uuid}, you should never do
196- * {@code startOf(uuid.timestamp())} but rather
197- * {@code startOf(unixTimestamp(uuid.timestamp()))}.
198- * <p/>
199- * Lastly, please note that Cassandra's timeuuid sorting is not compatible
200- * with {@link UUID#compareTo} and hence the UUID created by this method
201- * are not necessarily upper bound for that latter method.
197+ * See {@link #startOf(long)} for explanations about the intended usage of such UUID.
202198 *
203199 * @param timestamp the unix timestamp for which the created UUID must be an
204200 * upper bound.