|
2 | 2 |
|
3 | 3 | import static com.google.common.base.Preconditions.checkNotNull; |
4 | 4 |
|
| 5 | +import com.google.common.collect.ImmutableSet; |
5 | 6 | import com.scalar.db.api.OperationBuilder.And; |
6 | 7 | import com.scalar.db.api.OperationBuilder.Buildable; |
7 | 8 | import com.scalar.db.api.OperationBuilder.ClearClusteringKey; |
@@ -135,15 +136,18 @@ public BuildableGet consistency(com.scalar.db.api.Consistency consistency) { |
135 | 136 |
|
136 | 137 | @Override |
137 | 138 | public Get build() { |
138 | | - Get get = new Get(partitionKey, clusteringKey); |
139 | | - get.forNamespace(namespaceName).forTable(tableName); |
140 | | - if (!projections.isEmpty()) { |
141 | | - get.withProjections(projections); |
142 | | - } |
143 | | - if (consistency != null) { |
144 | | - get.withConsistency(consistency); |
145 | | - } |
146 | | - return get; |
| 139 | + return build(ImmutableSet.of()); |
| 140 | + } |
| 141 | + |
| 142 | + private Get build(ImmutableSet<Conjunction> conjunctions) { |
| 143 | + return new Get( |
| 144 | + namespaceName, |
| 145 | + tableName, |
| 146 | + partitionKey, |
| 147 | + clusteringKey, |
| 148 | + consistency, |
| 149 | + projections, |
| 150 | + conjunctions); |
147 | 151 | } |
148 | 152 | } |
149 | 153 |
|
@@ -341,7 +345,7 @@ private BuildableGetWithWhere(BuildableGetWithOngoingWhere buildable) { |
341 | 345 |
|
342 | 346 | @Override |
343 | 347 | public Get build() { |
344 | | - return (Get) addConjunctionsTo(super.build(), where); |
| 348 | + return super.build(getConjunctions(where)); |
345 | 349 | } |
346 | 350 | } |
347 | 351 |
|
@@ -420,15 +424,12 @@ public BuildableGetWithIndexOngoingWhereOr whereOr(Set<AndConditionSet> andCondi |
420 | 424 | } |
421 | 425 |
|
422 | 426 | public Get build() { |
423 | | - GetWithIndex getWithIndex = new GetWithIndex(indexKey); |
424 | | - getWithIndex.forNamespace(namespaceName).forTable(tableName); |
425 | | - if (!projections.isEmpty()) { |
426 | | - getWithIndex.withProjections(projections); |
427 | | - } |
428 | | - if (consistency != null) { |
429 | | - getWithIndex.withConsistency(consistency); |
430 | | - } |
431 | | - return getWithIndex; |
| 427 | + return build(ImmutableSet.of()); |
| 428 | + } |
| 429 | + |
| 430 | + private Get build(ImmutableSet<Conjunction> conjunctions) { |
| 431 | + return new GetWithIndex( |
| 432 | + namespaceName, tableName, indexKey, consistency, projections, conjunctions); |
432 | 433 | } |
433 | 434 | } |
434 | 435 |
|
@@ -583,7 +584,7 @@ public BuildableGetWithIndexWhere consistency(com.scalar.db.api.Consistency cons |
583 | 584 | } |
584 | 585 |
|
585 | 586 | public Get build() { |
586 | | - return (Get) addConjunctionsTo(buildableGetWithIndex.build(), where); |
| 587 | + return buildableGetWithIndex.build(getConjunctions(where)); |
587 | 588 | } |
588 | 589 | } |
589 | 590 |
|
@@ -771,28 +772,24 @@ private void checkConditionsEmpty() { |
771 | 772 |
|
772 | 773 | @Override |
773 | 774 | public Get build() { |
774 | | - Get get; |
| 775 | + return build( |
| 776 | + conjunctions.stream().map(Conjunction::of).collect(ImmutableSet.toImmutableSet())); |
| 777 | + } |
775 | 778 |
|
| 779 | + private Get build(ImmutableSet<Conjunction> conjunctions) { |
776 | 780 | if (isGetWithIndex) { |
777 | | - get = new GetWithIndex(indexKey); |
| 781 | + return new GetWithIndex( |
| 782 | + namespaceName, tableName, indexKey, consistency, projections, conjunctions); |
778 | 783 | } else { |
779 | | - get = new Get(partitionKey, clusteringKey); |
780 | | - } |
781 | | - |
782 | | - if (!conjunctions.isEmpty()) { |
783 | | - get.withConjunctions( |
784 | | - conjunctions.stream().map(Conjunction::of).collect(Collectors.toSet())); |
| 784 | + return new Get( |
| 785 | + namespaceName, |
| 786 | + tableName, |
| 787 | + partitionKey, |
| 788 | + clusteringKey, |
| 789 | + consistency, |
| 790 | + projections, |
| 791 | + conjunctions); |
785 | 792 | } |
786 | | - |
787 | | - get.forNamespace(namespaceName).forTable(tableName); |
788 | | - if (!projections.isEmpty()) { |
789 | | - get.withProjections(projections); |
790 | | - } |
791 | | - if (consistency != null) { |
792 | | - get.withConsistency(consistency); |
793 | | - } |
794 | | - |
795 | | - return get; |
796 | 793 | } |
797 | 794 | } |
798 | 795 |
|
@@ -893,7 +890,7 @@ public BuildableGetFromExistingWithWhere clearNamespace() { |
893 | 890 | } |
894 | 891 |
|
895 | 892 | public Get build() { |
896 | | - return (Get) addConjunctionsTo(BuildableGetFromExisting.build(), where); |
| 893 | + return BuildableGetFromExisting.build(getConjunctions(where)); |
897 | 894 | } |
898 | 895 | } |
899 | 896 |
|
|
0 commit comments