1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.allanbank.mongodb.client.message;
21
22 import java.io.IOException;
23
24 import com.allanbank.mongodb.ReadPreference;
25 import com.allanbank.mongodb.bson.io.BsonInputStream;
26 import com.allanbank.mongodb.bson.io.BsonOutputStream;
27 import com.allanbank.mongodb.bson.io.BufferingBsonOutputStream;
28 import com.allanbank.mongodb.bson.io.StringEncoder;
29 import com.allanbank.mongodb.client.Message;
30 import com.allanbank.mongodb.client.Operation;
31 import com.allanbank.mongodb.error.DocumentToLargeException;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 public class GetMore extends AbstractMessage {
56
57
58 private final long myCursorId;
59
60
61 private final int myNumberToReturn;
62
63
64
65
66
67
68
69
70
71 public GetMore(final BsonInputStream in) throws IOException {
72 in.readInt();
73 init(in.readCString());
74 myNumberToReturn = in.readInt();
75 myCursorId = in.readLong();
76 }
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 public GetMore(final String databaseName, final String collectionName,
93 final long cursorId, final int numberToReturn,
94 final ReadPreference readPreference) {
95 super(databaseName, collectionName, readPreference);
96
97 myCursorId = cursorId;
98 myNumberToReturn = numberToReturn;
99 }
100
101
102
103
104
105
106
107
108
109
110 @Override
111 public boolean equals(final Object object) {
112 boolean result = false;
113 if (this == object) {
114 result = true;
115 }
116 else if ((object != null) && (getClass() == object.getClass())) {
117 final GetMore other = (GetMore) object;
118
119 result = super.equals(object) && (myCursorId == other.myCursorId)
120 && (myNumberToReturn == other.myNumberToReturn);
121 }
122 return result;
123 }
124
125
126
127
128
129
130 public long getCursorId() {
131 return myCursorId;
132 }
133
134
135
136
137
138
139 public int getNumberToReturn() {
140 return myNumberToReturn;
141 }
142
143
144
145
146
147
148
149 @Override
150 public String getOperationName() {
151 return Operation.GET_MORE.name();
152 }
153
154
155
156
157
158
159 @Override
160 public int hashCode() {
161 int result = 1;
162 result = (31 * result) + super.hashCode();
163 result = (31 * result) + (int) (myCursorId >> Integer.SIZE);
164 result = (31 * result) + (int) myCursorId;
165 result = (31 * result) + myNumberToReturn;
166 return result;
167 }
168
169
170
171
172
173
174
175 @Override
176 public int size() {
177 int size = HEADER_SIZE + 18;
178
179 size += StringEncoder.utf8Size(myDatabaseName);
180
181 size += StringEncoder.utf8Size(myCollectionName);
182
183
184
185
186 return size;
187 }
188
189
190
191
192
193
194
195 @Override
196 public void validateSize(final int maxDocumentSize)
197 throws DocumentToLargeException {
198
199 }
200
201
202
203
204
205
206
207
208
209 @Override
210 public void write(final int messageId, final BsonOutputStream out)
211 throws IOException {
212 int size = HEADER_SIZE;
213 size += 4;
214 size += out.sizeOfCString(myDatabaseName, ".", myCollectionName);
215 size += 4;
216 size += 8;
217
218 writeHeader(out, messageId, 0, Operation.GET_MORE, size);
219 out.writeInt(0);
220 out.writeCString(myDatabaseName, ".", myCollectionName);
221 out.writeInt(myNumberToReturn);
222 out.writeLong(myCursorId);
223 }
224
225
226
227
228
229
230
231
232
233 @Override
234 public void write(final int messageId, final BufferingBsonOutputStream out)
235 throws IOException {
236
237 final long start = writeHeader(out, messageId, 0, Operation.GET_MORE);
238 out.writeInt(0);
239 out.writeCString(myDatabaseName, ".", myCollectionName);
240 out.writeInt(myNumberToReturn);
241 out.writeLong(myCursorId);
242 finishHeader(out, start);
243
244 out.flushBuffer();
245 }
246 }