Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AggregateCommand |
|
| 1.6;1.6 |
1 | /* | |
2 | * #%L | |
3 | * AggregateCommand.java - mongodb-async-driver - Allanbank Consulting, Inc. | |
4 | * %% | |
5 | * Copyright (C) 2011 - 2014 Allanbank Consulting, Inc. | |
6 | * %% | |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
8 | * you may not use this file except in compliance with the License. | |
9 | * You may obtain a copy of the License at | |
10 | * | |
11 | * http://www.apache.org/licenses/LICENSE-2.0 | |
12 | * | |
13 | * Unless required by applicable law or agreed to in writing, software | |
14 | * distributed under the License is distributed on an "AS IS" BASIS, | |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
16 | * See the License for the specific language governing permissions and | |
17 | * limitations under the License. | |
18 | * #L% | |
19 | */ | |
20 | package com.allanbank.mongodb.client.message; | |
21 | ||
22 | import com.allanbank.mongodb.ReadPreference; | |
23 | import com.allanbank.mongodb.bson.Document; | |
24 | import com.allanbank.mongodb.builder.Aggregate; | |
25 | import com.allanbank.mongodb.client.VersionRange; | |
26 | ||
27 | /** | |
28 | * Helper class for the aggregation commands. | |
29 | * | |
30 | * @api.no This class is <b>NOT</b> part of the drivers API. This class may be | |
31 | * mutated in incompatible ways between any two releases of the driver. | |
32 | * @copyright 2011-2013, Allanbank Consulting, Inc., All Rights Reserved | |
33 | */ | |
34 | public class AggregateCommand extends Command implements CursorableMessage { | |
35 | ||
36 | /** The original aggregation. */ | |
37 | private final Aggregate myAggregate; | |
38 | ||
39 | /** | |
40 | * Create a new AggregateCommand. | |
41 | * | |
42 | * @param aggregation | |
43 | * The original aggregation. | |
44 | * @param databaseName | |
45 | * The name of the database. | |
46 | * @param collectionName | |
47 | * The name of the collection to run the aggregation on. | |
48 | * @param commandDocument | |
49 | * The command document containing the command and options. | |
50 | * @param readPreference | |
51 | * The preference for which servers to use to retrieve the | |
52 | * results. | |
53 | * @param requiredServerVersion | |
54 | * The required version of the server to support processing the | |
55 | * message. | |
56 | */ | |
57 | public AggregateCommand(final Aggregate aggregation, | |
58 | final String databaseName, final String collectionName, | |
59 | final Document commandDocument, | |
60 | final ReadPreference readPreference, | |
61 | final VersionRange requiredServerVersion) { | |
62 | 93 | super(databaseName, collectionName, commandDocument, readPreference, |
63 | requiredServerVersion); | |
64 | ||
65 | 93 | myAggregate = aggregation; |
66 | 93 | } |
67 | ||
68 | /** | |
69 | * Determines if the passed object is of this same type as this object and | |
70 | * if so that its fields are equal. | |
71 | * | |
72 | * @param object | |
73 | * The object to compare to. | |
74 | * | |
75 | * @see java.lang.Object#equals(java.lang.Object) | |
76 | */ | |
77 | @Override | |
78 | public boolean equals(final Object object) { | |
79 | 505 | boolean result = false; |
80 | 505 | if (this == object) { |
81 | 27 | result = true; |
82 | } | |
83 | 478 | else if ((object != null) && (getClass() == object.getClass())) { |
84 | 397 | result = super.equals(object); |
85 | } | |
86 | 505 | return result; |
87 | } | |
88 | ||
89 | /** | |
90 | * {@inheritDoc} | |
91 | * <p> | |
92 | * Overridden to return the batch size from the {@link Aggregate}. | |
93 | * </p> | |
94 | */ | |
95 | @Override | |
96 | public int getBatchSize() { | |
97 | 10 | return myAggregate.getBatchSize(); |
98 | } | |
99 | ||
100 | /** | |
101 | * {@inheritDoc} | |
102 | * <p> | |
103 | * Overridden to return the limit from the {@link Aggregate}. | |
104 | * </p> | |
105 | */ | |
106 | @Override | |
107 | public int getLimit() { | |
108 | 10 | return myAggregate.getCursorLimit(); |
109 | } | |
110 | ||
111 | /** | |
112 | * Computes a reasonable hash code. | |
113 | * | |
114 | * @return The hash code value. | |
115 | */ | |
116 | @Override | |
117 | public int hashCode() { | |
118 | 756 | int result = 1; |
119 | 756 | result = (31 * result) + super.hashCode(); |
120 | 756 | return result; |
121 | } | |
122 | } |