Elffuss BraidHub

kikocis/java-driver public

Merge pull request #496 from datastax/java958

JAVA-958: Make TableOrView.Order visible.
Changeset52598c92fd080ea7eef274f50c828456cec2bfde8098af2742668f9eb9ee1b27
AuthorAlexandre Dutra <alexdut@gmail.com> · 2015-10-28 11:51 +01:00
CommitterAlexandre Dutra <alexdut@gmail.com> · 2015-10-28 11:51 +01:00
Parentsf5b832a93d1e, 646c6986220f

Browse the files at this changeset

8 files changed

modified changelog/README.md +5 −0
@@ -1,5 +1,10 @@
11 ## Changelog
22
3+### 3.0.0-beta1 (in progress)
4+
5+ - [improvement] JAVA-958: Make TableOrView.Order visible.
6+ - [improvement] JAVA-968: Update metrics to the latest version.
7+
38 ### 3.0.0-alpha4
49
510 - [improvement] Change default consistency level to LOCAL_QUORUM (JAVA-926)
added driver-core/src/main/java/com/datastax/driver/core/ClusteringOrder.java +28 −0
@@ -0,0 +1,28 @@
1+/*
2+ * Copyright (C) 2012-2015 DataStax Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package com.datastax.driver.core;
17+
18+/**
19+ * Clustering orders.
20+ * <p>
21+ * This is used by metadata classes to indicate the clustering
22+ * order of a clustering column in a table or materialized view.
23+ */
24+public enum ClusteringOrder {
25+
26+ ASC, DESC;
27+
28+}
modified driver-core/src/main/java/com/datastax/driver/core/MaterializedViewMetadata.java +3 −3
@@ -48,7 +48,7 @@
4848 boolean includeAllColumns,
4949 String whereClause,
5050 TableOptionsMetadata options,
51- List<Order> clusteringOrder,
51+ List<ClusteringOrder> clusteringOrder,
5252 VersionNumber cassandraVersion) {
5353 super(keyspace, name, id, partitionKey, clusteringColumns, columns, options, clusteringOrder, cassandraVersion);
5454 this.baseTable = baseTable;
@@ -77,7 +77,7 @@
7777
7878 List<ColumnMetadata> partitionKey = new ArrayList<ColumnMetadata>(Collections.<ColumnMetadata>nCopies(partitionKeySize, null));
7979 List<ColumnMetadata> clusteringColumns = new ArrayList<ColumnMetadata>(Collections.<ColumnMetadata>nCopies(clusteringSize, null));
80- List<Order> clusteringOrder = new ArrayList<Order>(Collections.<Order>nCopies(clusteringSize, null));
80+ List<ClusteringOrder> clusteringOrder = new ArrayList<ClusteringOrder>(Collections.<ClusteringOrder>nCopies(clusteringSize, null));
8181
8282 // We use a linked hashmap because we will keep this in the order of a 'SELECT * FROM ...'.
8383 LinkedHashMap<String, ColumnMetadata> columns = new LinkedHashMap<String, ColumnMetadata>();
@@ -108,7 +108,7 @@
108108 break;
109109 case CLUSTERING_COLUMN:
110110 clusteringColumns.set(rawCol.position, col);
111- clusteringOrder.set(rawCol.position, rawCol.isReversed ? Order.DESC : Order.ASC);
111+ clusteringOrder.set(rawCol.position, rawCol.isReversed ? ClusteringOrder.DESC : ClusteringOrder.ASC);
112112 break;
113113 default:
114114 otherColumns.add(col);
modified driver-core/src/main/java/com/datastax/driver/core/TableMetadata.java +4 −4
@@ -62,7 +62,7 @@
6262 Map<String, ColumnMetadata> columns,
6363 Map<String, IndexMetadata> indexes,
6464 TableOptionsMetadata options,
65- List<Order> clusteringOrder,
65+ List<ClusteringOrder> clusteringOrder,
6666 VersionNumber cassandraVersion) {
6767 super(keyspace, name, id, partitionKey, clusteringColumns, columns, options, clusteringOrder, cassandraVersion);
6868 this.indexes = indexes;
@@ -123,7 +123,7 @@
123123
124124 List<ColumnMetadata> partitionKey = new ArrayList<ColumnMetadata>(Collections.<ColumnMetadata>nCopies(partitionKeySize, null));
125125 List<ColumnMetadata> clusteringColumns = new ArrayList<ColumnMetadata>(Collections.<ColumnMetadata>nCopies(clusteringSize, null));
126- List<Order> clusteringOrder = new ArrayList<Order>(Collections.<Order>nCopies(clusteringSize, null));
126+ List<ClusteringOrder> clusteringOrder = new ArrayList<ClusteringOrder>(Collections.<ClusteringOrder>nCopies(clusteringSize, null));
127127
128128 // We use a linked hashmap because we will keep this in the order of a 'SELECT * FROM ...'.
129129 LinkedHashMap<String, ColumnMetadata> columns = new LinkedHashMap<String, ColumnMetadata>();
@@ -165,7 +165,7 @@
165165 for (int i = 0; i < clusteringSize; i++) {
166166 String alias = columnAliases.size() > i ? columnAliases.get(i) : DEFAULT_COLUMN_ALIAS + (i + 1);
167167 clusteringColumns.set(i, ColumnMetadata.forAlias(tm, alias, comparator.types.get(i)));
168- clusteringOrder.set(i, comparator.reversed.get(i) ? Order.DESC : Order.ASC);
168+ clusteringOrder.set(i, comparator.reversed.get(i) ? ClusteringOrder.DESC : ClusteringOrder.ASC);
169169 }
170170
171171 // if we're dense, chances are that we have a single regular "value" column with an alias
@@ -187,7 +187,7 @@
187187 break;
188188 case CLUSTERING_COLUMN:
189189 clusteringColumns.set(rawCol.position, col);
190- clusteringOrder.set(rawCol.position, rawCol.isReversed ? Order.DESC : Order.ASC);
190+ clusteringOrder.set(rawCol.position, rawCol.isReversed ? ClusteringOrder.DESC : ClusteringOrder.ASC);
191191 break;
192192 default:
193193 otherColumns.add(col);
modified driver-core/src/main/java/com/datastax/driver/core/TableOrView.java +11 −21
@@ -32,6 +32,12 @@
3232 }
3333 };
3434
35+ static final Predicate<ClusteringOrder> isAscending = new Predicate<ClusteringOrder>() {
36+ public boolean apply(ClusteringOrder o) {
37+ return o == ClusteringOrder.ASC;
38+ }
39+ };
40+
3541 protected final KeyspaceMetadata keyspace;
3642 protected final String name;
3743 protected final UUID id;
@@ -39,25 +45,9 @@
3945 protected final List<ColumnMetadata> clusteringColumns;
4046 protected final Map<String, ColumnMetadata> columns;
4147 protected final TableOptionsMetadata options;
42- protected final List<Order> clusteringOrder;
48+ protected final List<ClusteringOrder> clusteringOrder;
4349 protected final VersionNumber cassandraVersion;
4450
45- /**
46- * Clustering orders.
47- * <p>
48- * This is used by {@link #getClusteringOrder} to indicate the clustering
49- * order of a table.
50- */
51- public enum Order {
52- ASC, DESC;
53-
54- static final Predicate<Order> isAscending = new Predicate<Order>() {
55- public boolean apply(Order o) {
56- return o == ASC;
57- }
58- };
59- }
60-
6151 TableOrView(KeyspaceMetadata keyspace,
6252 String name,
6353 UUID id,
@@ -65,7 +55,7 @@
6555 List<ColumnMetadata> clusteringColumns,
6656 Map<String, ColumnMetadata> columns,
6757 TableOptionsMetadata options,
68- List<Order> clusteringOrder,
58+ List<ClusteringOrder> clusteringOrder,
6959 VersionNumber cassandraVersion) {
7060 this.keyspace = keyspace;
7161 this.name = name;
@@ -182,11 +172,11 @@
182172 * descending) of the {@code i}th clustering column (see
183173 * {@link #getClusteringColumns}). Note that a table defined without any
184174 * particular clustering order is equivalent to one for which all the
185- * clustering key are in ascending order.
175+ * clustering keys are in ascending order.
186176 *
187177 * @return a list with the clustering order for each clustering column.
188178 */
189- public List<Order> getClusteringOrder() {
179+ public List<ClusteringOrder> getClusteringOrder() {
190180 return clusteringOrder;
191181 }
192182
@@ -248,7 +238,7 @@
248238 sb.append(" WITH ");
249239 if (options.isCompactStorage())
250240 and(sb.append("COMPACT STORAGE"), formatted);
251- if (!Iterables.all(clusteringOrder, Order.isAscending))
241+ if (!Iterables.all(clusteringOrder, isAscending))
252242 and(appendClusteringOrder(sb), formatted);
253243 sb.append("read_repair_chance = ").append(options.getReadRepairChance());
254244 and(sb, formatted).append("dclocal_read_repair_chance = ").append(options.getLocalReadRepairChance());
modified driver-core/src/test/java/com/datastax/driver/core/ColumnMetadataAssert.java +2 −2
@@ -55,8 +55,8 @@
5555 return this;
5656 }
5757
58- public ColumnMetadataAssert hasClusteringOrder(TableOrView.Order order) {
59- assertThat(actual.getParent().getClusteringOrder().get(actual.getParent().getClusteringColumns().indexOf(actual))).isEqualTo(order);
58+ public ColumnMetadataAssert hasClusteringOrder(ClusteringOrder clusteringOrder) {
59+ assertThat(actual.getParent().getClusteringOrder().get(actual.getParent().getClusteringColumns().indexOf(actual))).isEqualTo(clusteringOrder);
6060 return this;
6161 }
6262
modified driver-core/src/test/java/com/datastax/driver/core/MaterializedViewMetadataTest.java +1 −1
@@ -24,7 +24,7 @@
2424
2525 import static com.datastax.driver.core.Assertions.assertThat;
2626 import static com.datastax.driver.core.DataType.*;
27-import static com.datastax.driver.core.TableOrView.Order.DESC;
27+import static com.datastax.driver.core.ClusteringOrder.DESC;
2828
2929 @CassandraVersion(major = 3)
3030 public class MaterializedViewMetadataTest extends CCMBridge.PerClassSingleNodeCluster {
modified driver-core/src/test/java/com/datastax/driver/core/TableMetadataTest.java +2 −2
@@ -28,8 +28,8 @@
2828
2929 import static com.datastax.driver.core.Assertions.assertThat;
3030 import static com.datastax.driver.core.DataType.*;
31-import static com.datastax.driver.core.TableOrView.Order.ASC;
32-import static com.datastax.driver.core.TableOrView.Order.DESC;
31+import static com.datastax.driver.core.ClusteringOrder.ASC;
32+import static com.datastax.driver.core.ClusteringOrder.DESC;
3333
3434 public class TableMetadataTest extends CCMBridge.PerClassSingleNodeCluster {
3535 @Override