Elffuss BraidHub

kikocis/java-driver public

JAVA-982: Introduce new method ConsistencyLevel.isSerial().
Changesetbb1e664492002b9858d980f29f657bba0d8125c5f0cf118fa545174fba5518de
AuthorAlexandre Dutra <alexandre.dutra@datastax.com> · 2016-03-01 12:04 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2016-03-07 16:57 +01:00
Parents1880c9980a0f

Browse the files at this changeset

6 files changed

modified changelog/README.md +1 −0
@@ -32,6 +32,7 @@
3232 - [improvement] JAVA-923: Position idempotent flag on object mapper queries.
3333 - [new feature] JAVA-1019: SchemaBuilder support for CREATE/ALTER/DROP KEYSPACE.
3434 - [bug] JAVA-1070: The Mapper should not prepare queries synchronously.
35+- [new feature] JAVA-982: Introduce new method ConsistencyLevel.isSerial().
3536
3637 Merged from 2.0 branch:
3738
modified driver-core/src/main/java/com/datastax/driver/core/ConsistencyLevel.java +20 −1
@@ -58,11 +58,30 @@
5858 }
5959
6060 /**
61- * Whether or not the the consistency level applies to the local data-center only.
61+ * Whether or not this consistency level applies to the local data-center only.
6262 *
6363 * @return whether this consistency level is {@code LOCAL_ONE} or {@code LOCAL_QUORUM}.
6464 */
6565 public boolean isDCLocal() {
6666 return this == LOCAL_ONE || this == LOCAL_QUORUM;
6767 }
68+
69+ /**
70+ * Whether or not this consistency level is serial, that is,
71+ * applies only to the "paxos" phase of a
72+ * <a href="https://docs.datastax.com/en/cassandra/2.1/cassandra/dml/dml_ltwt_transaction_c.html">Lightweight transaction</a>.
73+ * <p/>
74+ * Serial consistency levels are only meaningful when executing conditional updates ({@code INSERT}, {@code UPDATE}
75+ * or {@code DELETE} statements with an {@code IF} condition).
76+ * <p/>
77+ * Two consistency levels belong to this category: {@link #SERIAL} and {@link #LOCAL_SERIAL}.
78+ *
79+ * @return whether this consistency level is {@link #SERIAL} or {@link #LOCAL_SERIAL}.
80+ * @see Statement#setSerialConsistencyLevel(ConsistencyLevel)
81+ * @see <a href="https://docs.datastax.com/en/cassandra/2.1/cassandra/dml/dml_ltwt_transaction_c.html">Lightweight transactions</a>
82+ */
83+ public boolean isSerial() {
84+ return this == SERIAL || this == LOCAL_SERIAL;
85+ }
86+
6887 }
modified driver-core/src/main/java/com/datastax/driver/core/DefaultPreparedStatement.java +1 −1
@@ -141,7 +141,7 @@
141141
142142 @Override
143143 public PreparedStatement setSerialConsistencyLevel(ConsistencyLevel serialConsistency) {
144- if (serialConsistency != ConsistencyLevel.SERIAL && serialConsistency != ConsistencyLevel.LOCAL_SERIAL)
144+ if (!serialConsistency.isSerial())
145145 throw new IllegalArgumentException();
146146 this.serialConsistency = serialConsistency;
147147 return this;
modified driver-core/src/main/java/com/datastax/driver/core/Statement.java +9 −8
@@ -82,8 +82,9 @@
8282 /**
8383 * Sets the serial consistency level for the query.
8484 * <p/>
85- * The serial consistency level is only used by conditional updates (so INSERT, UPDATE
86- * and DELETE with an IF condition). For those, the serial consistency level defines
85+ * The serial consistency level is only used by conditional updates ({@code INSERT}, {@code UPDATE}
86+ * or {@code DELETE} statements with an {@code IF} condition).
87+ * For those, the serial consistency level defines
8788 * the consistency level of the serial phase (or "paxos" phase) while the
8889 * normal consistency level defines the consistency for the "learn" phase, i.e. what
8990 * type of reads will be guaranteed to see the update right away. For instance, if
@@ -106,8 +107,8 @@
106107 * {@code ConsistencyLevel.SERIAL} or {@code ConsistencyLevel.LOCAL_SERIAL}.
107108 */
108109 public Statement setSerialConsistencyLevel(ConsistencyLevel serialConsistency) {
109- if (serialConsistency != ConsistencyLevel.SERIAL && serialConsistency != ConsistencyLevel.LOCAL_SERIAL)
110- throw new IllegalArgumentException();
110+ if (!serialConsistency.isSerial())
111+ throw new IllegalArgumentException("Supplied consistency level is not serial: " + serialConsistency);
111112 this.serialConsistency = serialConsistency;
112113 return this;
113114 }
@@ -115,10 +116,10 @@
115116 /**
116117 * The serial consistency level for this query.
117118 * <p/>
118- * See {@link #setSerialConsistencyLevel} for more detail on the serial consistency level.
119+ * See {@link #setSerialConsistencyLevel(ConsistencyLevel)} for more detail on the serial consistency level.
119120 *
120- * @return the consistency level for this query, or {@code null} if no serial
121- * consistency level has been specified (through {@code setSerialConsistencyLevel}).
121+ * @return the serial consistency level for this query, or {@code null} if no serial
122+ * consistency level has been specified (through {@link #setSerialConsistencyLevel(ConsistencyLevel)}).
122123 * In the latter case, the default serial consistency level will be used.
123124 */
124125 public ConsistencyLevel getSerialConsistencyLevel() {
@@ -446,4 +447,4 @@
446447 else
447448 return queryOptions.getDefaultIdempotence();
448449 }
449-}
No newline at the end of the file
450+}
modified driver-core/src/main/java/com/datastax/driver/core/policies/DowngradingConsistencyRetryPolicy.java +1 −1
@@ -114,7 +114,7 @@
114114 // normal consistency levels on the committing phase. So the main use case for CAS reads is probably for
115115 // when you've timed out on a CAS write and want to make sure what happened. Downgrading in that case
116116 // would be always wrong so we just special case to rethrow.
117- if (cl == ConsistencyLevel.SERIAL || cl == ConsistencyLevel.LOCAL_SERIAL)
117+ if (cl.isSerial())
118118 return RetryDecision.rethrow();
119119
120120 if (receivedResponses < requiredResponses) {
modified driver-core/src/test/java/com/datastax/driver/core/DataProviders.java +1 −1
@@ -33,7 +33,7 @@
3333 @Override
3434 public boolean apply(ConsistencyLevel input) {
3535 // filter out serial CLs.
36- return !input.equals(ConsistencyLevel.SERIAL) && !input.equals(ConsistencyLevel.LOCAL_SERIAL);
36+ return !input.isSerial();
3737 }
3838 }).iterator();
3939