1 /*
2 * #%L
3 * TextCallback.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
21 package com.allanbank.mongodb.client.callback;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import com.allanbank.mongodb.Callback;
27 import com.allanbank.mongodb.MongoIterator;
28 import com.allanbank.mongodb.bson.Document;
29 import com.allanbank.mongodb.builder.ConditionBuilder;
30 import com.allanbank.mongodb.client.SimpleMongoIteratorImpl;
31
32 /**
33 * TextCallback provides conversion from a
34 * {@link com.allanbank.mongodb.builder.Text text} command's result document to
35 * a {@link com.allanbank.mongodb.builder.TextResult}.
36 *
37 * @api.no This class is <b>NOT</b> part of the drivers API. This class may be
38 * mutated in incompatible ways between any two releases of the driver.
39 * @deprecated Support for the {@code text} command was deprecated in the 2.6
40 * version of MongoDB. Use the {@link ConditionBuilder#text(String)
41 * $text} query operator instead. This class will not be removed
42 * until two releases after the MongoDB 2.6 release (e.g. 2.10 if
43 * the releases are 2.8 and 2.10).
44 * @copyright 2013, Allanbank Consulting, Inc., All Rights Reserved
45 */
46 @Deprecated
47 public class TextCallback implements Callback<MongoIterator<Document>> {
48
49 /**
50 * The delegate callback to receive the
51 * {@link com.allanbank.mongodb.builder.TextResult}s.
52 *
53 * @deprecated Support for the {@code text} command was deprecated in the
54 * 2.6 version of MongoDB. Use the
55 * {@link ConditionBuilder#text(String) $text} query operator
56 * instead. This class will not be removed until two releases
57 * after the MongoDB 2.6 release (e.g. 2.10 if the releases are
58 * 2.8 and 2.10).
59 */
60 @Deprecated
61 private final Callback<MongoIterator<com.allanbank.mongodb.builder.TextResult>> myDelegate;
62
63 /**
64 * Creates a new TextCallback.
65 *
66 * @param delegate
67 * The delegate callback to receive the
68 * {@link com.allanbank.mongodb.builder.TextResult}s.
69 * @deprecated Support for the {@code text} command was deprecated in the
70 * 2.6 version of MongoDB. Use the
71 * {@link ConditionBuilder#text(String) $text} query operator
72 * instead. This class will not be removed until two releases
73 * after the MongoDB 2.6 release (e.g. 2.10 if the releases are
74 * 2.8 and 2.10).
75 */
76 @Deprecated
77 public TextCallback(
78 final Callback<MongoIterator<com.allanbank.mongodb.builder.TextResult>> delegate) {
79 myDelegate = delegate;
80 }
81
82 /**
83 * {@inheritDoc}
84 * <p>
85 * Overridden to convert each document into a
86 * {@link com.allanbank.mongodb.builder.TextResult} and forward to the
87 * delegate.
88 * </p>
89 *
90 * @deprecated Support for the {@code text} command was deprecated in the
91 * 2.6 version of MongoDB. Use the
92 * {@link ConditionBuilder#text(String) $text} query operator
93 * instead. This class will not be removed until two releases
94 * after the MongoDB 2.6 release (e.g. 2.10 if the releases are
95 * 2.8 and 2.10).
96 */
97 @Override
98 @Deprecated
99 public void callback(final MongoIterator<Document> result) {
100 final List<com.allanbank.mongodb.builder.TextResult> results = new ArrayList<com.allanbank.mongodb.builder.TextResult>();
101
102 for (final Document doc : result) {
103 results.add(new com.allanbank.mongodb.builder.TextResult(doc));
104 }
105
106 myDelegate
107 .callback(new SimpleMongoIteratorImpl<com.allanbank.mongodb.builder.TextResult>(
108 results));
109 }
110
111 /**
112 * {@inheritDoc}
113 * <p>
114 * Overridden to forward to the delegate callback.
115 * </p>
116 *
117 * @deprecated Support for the {@code text} command was deprecated in the
118 * 2.6 version of MongoDB. Use the
119 * {@link ConditionBuilder#text(String) $text} query operator
120 * instead. This class will not be removed until two releases
121 * after the MongoDB 2.6 release (e.g. 2.10 if the releases are
122 * 2.8 and 2.10).
123 */
124 @Override
125 @Deprecated
126 public void exception(final Throwable thrown) {
127 myDelegate.exception(thrown);
128 }
129 }