Elffuss BraidHub

kikocis/java-driver public

Provide backward compatible alternatives to DataType.serialize methods and RegularStatement.getValues (JAVA-469).
Changeset4f462f06dec2ac492ccd1060b0ca28bdd85bc11237d1f47c3a6d9000acfcc6fd
Authorolim7t <omichallat+github@gmail.com> · 2014-10-08 09:48 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2014-10-08 14:39 +02:00
Parents06bb5a363293

Browse the files at this changeset

4 files changed

modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +6 −5
@@ -661,15 +661,16 @@
661661
662662 /**
663663 * The native protocol version to use, as a number.
664- * <p>
665- * This method is provided for backward-compatibility. Whenever possible,
666- * {@link #withProtocolVersion(ProtocolVersion)} should be preferred.
667664 *
668665 * @param version the native protocol version as a number.
669666 * @return this Builder.
670- * @throws DriverInternalError if the number does not correspond to any known native
671- * protocol version.
667+ * @throws IllegalArgumentException if the number does not correspond to any known
668+ * native protocol version.
669+ *
670+ * @deprecated This method is provided for backward compatibility. Use
671+ * {@link #withProtocolVersion(ProtocolVersion)} instead.
672672 */
673+ @Deprecated
673674 public Builder withProtocolVersion(int version) {
674675 this.protocolVersion = ProtocolVersion.fromInt(version);
675676 return this;
modified driver-core/src/main/java/com/datastax/driver/core/DataType.java +58 −9
@@ -560,21 +560,27 @@
560560 }
561561
562562 /**
563- * @deprecated This method is no longer supported, will be removed, and simply throws {@link UnsupportedOperationException}.
563+ * Serialize a value of this type to bytes, with the given numeric protocol version.
564+ *
565+ * @throws IllegalArgumentException if {@code protocolVersion} does not correspond to any known version.
566+ *
567+ * @deprecated This method is provided for backward compatibility. Use
568+ * {@link #serialize(Object, ProtocolVersion)} instead.
564569 */
565570 @Deprecated
566- public Object deserialize(ByteBuffer bytes) {
567- throw new UnsupportedOperationException("Method no longer supported; use deserialize(ByteBuffer,ProtocolVersion)");
571+ public ByteBuffer serialize(Object value, int protocolVersion) {
572+ return serialize(value, ProtocolVersion.fromInt(protocolVersion));
568573 }
569-
574+
570575 /**
571- * @deprecated Use {@link #deserialize(ByteBuffer,ProtocolVersion)}.
572- * @see #deserialize(ByteBuffer,ProtocolVersion)
576+ * @deprecated This method is provided for binary compatibility only. It is no longer supported, will be removed,
577+ * and simply throws {@link UnsupportedOperationException}. Use {@link #serialize(Object, ProtocolVersion)} instead.
573578 */
574- public Object deserialize(ByteBuffer bytes, int protocolVersion) {
575- return deserialize(bytes, ProtocolVersion.fromInt(protocolVersion));
579+ @Deprecated
580+ public ByteBuffer serialize(Object value) {
581+ throw new UnsupportedOperationException("Method no longer supported; use serialize(Object,ProtocolVersion)");
576582 }
577-
583+
578584 /**
579585 * Deserialize a value of this type from the provided bytes using the given protocol version.
580586 *
@@ -600,6 +606,27 @@
600606 return codec(protocolVersion).deserialize(bytes);
601607 }
602608
609+ /**
610+ * Deserialize a value of this type from the provided bytes using the given numeric protocol version.
611+ *
612+ * @throws IllegalArgumentException if {@code protocolVersion} does not correspond to any known version.
613+ *
614+ * @deprecated This method is provided for backward compatibility. Use
615+ * {@link #deserialize(ByteBuffer,ProtocolVersion)} instead.
616+ */
617+ public Object deserialize(ByteBuffer bytes, int protocolVersion) {
618+ return deserialize(bytes, ProtocolVersion.fromInt(protocolVersion));
619+ }
620+
621+ /**
622+ * @deprecated This method is provided for binary compatibility only. It is no longer supported, will be removed,
623+ * and simply throws {@link UnsupportedOperationException}. Use {@link #deserialize(ByteBuffer, ProtocolVersion)} instead.
624+ */
625+ @Deprecated
626+ public Object deserialize(ByteBuffer bytes) {
627+ throw new UnsupportedOperationException("Method no longer supported; use deserialize(ByteBuffer,ProtocolVersion)");
628+ }
629+
603630 /**
604631 * Serialize an object based on its java class.
605632 * <p>
@@ -639,6 +666,28 @@
639666 }
640667 }
641668
669+ /**
670+ * Serialize an object based on its java class, with the given numeric protocol version.
671+ *
672+ * @throws IllegalArgumentException if {@code protocolVersion} does not correspond to any known version.
673+ *
674+ * @deprecated This method is provided for backward compatibility. Use
675+ * {@link #serializeValue(Object, ProtocolVersion)} instead.
676+ */
677+ @Deprecated
678+ public static ByteBuffer serializeValue(Object value, int protocolVersion) {
679+ return serializeValue(value, ProtocolVersion.fromInt(protocolVersion));
680+ }
681+
682+ /**
683+ * @deprecated This method is provided for binary compatibility only. It is no longer supported, will be removed,
684+ * and simply throws {@link UnsupportedOperationException}. Use {@link #serializeValue(Object, ProtocolVersion)} instead.
685+ */
686+ @Deprecated
687+ public static ByteBuffer serializeValue(Object value) {
688+ throw new UnsupportedOperationException("Method no longer supported; use serializeValue(Object,ProtocolVersion)");
689+ }
690+
642691 private static class Native extends DataType {
643692 private Native(DataType.Name name) {
644693 super(name);
modified driver-core/src/main/java/com/datastax/driver/core/ProtocolVersion.java +12 −1
@@ -32,6 +32,9 @@
3232 V3("2.1.0", 3),
3333 ;
3434
35+ /**
36+ * The most recent protocol version supported by the driver.
37+ */
3538 public static ProtocolVersion NEWEST_SUPPORTED = V3;
3639
3740 private final VersionNumber minCassandraVersion;
@@ -72,10 +75,18 @@
7275 INT_TO_VERSION = builder.build();
7376 }
7477
78+ /**
79+ * Returns the value matching an integer version.
80+ *
81+ * @param i the version as an integer.
82+ * @return the matching enum value.
83+ *
84+ * @throws IllegalArgumentException if the argument doesn't match any known version.
85+ */
7586 public static ProtocolVersion fromInt(int i) {
7687 ProtocolVersion version = INT_TO_VERSION.get(i);
7788 if (version == null)
78- throw new DriverInternalError("No protocol version matching integer version " + i);
89+ throw new IllegalArgumentException("No protocol version matching integer version " + i);
7990 return version;
8091 }
8192 }
modified driver-core/src/main/java/com/datastax/driver/core/RegularStatement.java +22 −0
@@ -58,6 +58,28 @@
5858 */
5959 public abstract ByteBuffer[] getValues(ProtocolVersion protocolVersion);
6060
61+ /**
62+ * The values to use for this statement, for the given numeric protocol version.
63+ *
64+ * @throws IllegalArgumentException if {@code protocolVersion} does not correspond to any known version.
65+ *
66+ * @deprecated This method is provided for backward compatibility. Use
67+ * {@link #getValues(ProtocolVersion)} instead.
68+ */
69+ @Deprecated
70+ public ByteBuffer[] getValues(int protocolVersion) {
71+ return getValues(ProtocolVersion.fromInt(protocolVersion));
72+ }
73+
74+ /**
75+ * @deprecated This method is provided for binary compatibility only. It is no longer supported, will be removed,
76+ * and simply throws {@link UnsupportedOperationException}. Use {@link #getValues(ProtocolVersion)} instead.
77+ */
78+ @Deprecated
79+ public ByteBuffer[] getValues() {
80+ throw new UnsupportedOperationException("Method no longer supported; use getValues(ProtocolVersion)");
81+ }
82+
6183 /**
6284 * Whether or not this statement has values, that is if {@code getValues}
6385 * will return {@code null} or not.