1 /** @file const_database_wrapper.cc
2  * @brief Wrapper which exposes only the const methods of database internals.
3  */
4 /* Copyright 2009 Lemur Consulting Ltd
5  * Copyright 2009 Olly Betts
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
20  * USA
21  */
22 
23 #include <config.h>
24 
25 #include "const_database_wrapper.h"
26 
27 #include "xapian/error.h"
28 
29 void
nonconst_access() const30 ConstDatabaseWrapper::nonconst_access() const
31 {
32     throw Xapian::UnimplementedError("Access to non-const method of database "
33 				     "not supported in this context");
34 }
35 
ConstDatabaseWrapper(Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> realdb_)36 ConstDatabaseWrapper::ConstDatabaseWrapper(
37 	Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> realdb_)
38 	: realdb(realdb_)
39 {
40 }
41 
42 Xapian::doccount
get_doccount() const43 ConstDatabaseWrapper::get_doccount() const
44 {
45     return realdb->get_doccount();
46 }
47 
48 Xapian::docid
get_lastdocid() const49 ConstDatabaseWrapper::get_lastdocid() const
50 {
51     return realdb->get_lastdocid();
52 }
53 
54 totlen_t
get_total_length() const55 ConstDatabaseWrapper::get_total_length() const
56 {
57     return realdb->get_total_length();
58 }
59 
60 Xapian::termcount
get_doclength(Xapian::docid did) const61 ConstDatabaseWrapper::get_doclength(Xapian::docid did) const
62 {
63     return realdb->get_doclength(did);
64 }
65 
66 Xapian::doccount
get_termfreq(const string & tname) const67 ConstDatabaseWrapper::get_termfreq(const string & tname) const
68 {
69     return realdb->get_termfreq(tname);
70 }
71 
72 Xapian::termcount
get_collection_freq(const string & tname) const73 ConstDatabaseWrapper::get_collection_freq(const string & tname) const
74 {
75     return realdb->get_collection_freq(tname);
76 }
77 
78 Xapian::doccount
get_value_freq(Xapian::valueno slot) const79 ConstDatabaseWrapper::get_value_freq(Xapian::valueno slot) const
80 {
81     return realdb->get_value_freq(slot);
82 }
83 
84 std::string
get_value_lower_bound(Xapian::valueno slot) const85 ConstDatabaseWrapper::get_value_lower_bound(Xapian::valueno slot) const
86 {
87     return realdb->get_value_lower_bound(slot);
88 }
89 
90 std::string
get_value_upper_bound(Xapian::valueno slot) const91 ConstDatabaseWrapper::get_value_upper_bound(Xapian::valueno slot) const
92 {
93     return realdb->get_value_upper_bound(slot);
94 }
95 
96 bool
term_exists(const string & tname) const97 ConstDatabaseWrapper::term_exists(const string & tname) const
98 {
99     return realdb->term_exists(tname);
100 }
101 
102 bool
has_positions() const103 ConstDatabaseWrapper::has_positions() const
104 {
105     return realdb->has_positions();
106 }
107 
108 LeafPostList *
open_post_list(const string & tname) const109 ConstDatabaseWrapper::open_post_list(const string & tname) const
110 {
111     return realdb->open_post_list(tname);
112 }
113 
114 ValueList *
open_value_list(Xapian::valueno slot) const115 ConstDatabaseWrapper::open_value_list(Xapian::valueno slot) const
116 {
117     return realdb->open_value_list(slot);
118 }
119 
120 TermList *
open_term_list(Xapian::docid did) const121 ConstDatabaseWrapper::open_term_list(Xapian::docid did) const
122 {
123     return realdb->open_term_list(did);
124 }
125 
126 TermList *
open_allterms(const string & prefix) const127 ConstDatabaseWrapper::open_allterms(const string & prefix) const
128 {
129     return realdb->open_allterms(prefix);
130 }
131 
132 PositionList *
open_position_list(Xapian::docid did,const string & tname) const133 ConstDatabaseWrapper::open_position_list(Xapian::docid did,
134 					 const string & tname) const
135 {
136     return realdb->open_position_list(did, tname);
137 }
138 
139 Xapian::Document::Internal *
open_document(Xapian::docid did,bool lazy) const140 ConstDatabaseWrapper::open_document(Xapian::docid did, bool lazy) const
141 {
142     return realdb->open_document(did, lazy);
143 }
144 
145 TermList *
open_spelling_termlist(const string & word) const146 ConstDatabaseWrapper::open_spelling_termlist(const string & word) const
147 {
148     return realdb->open_spelling_termlist(word);
149 }
150 
151 TermList *
open_spelling_wordlist() const152 ConstDatabaseWrapper::open_spelling_wordlist() const
153 {
154     return realdb->open_spelling_wordlist();
155 }
156 
157 Xapian::doccount
get_spelling_frequency(const string & word) const158 ConstDatabaseWrapper::get_spelling_frequency(const string & word) const
159 {
160     return realdb->get_spelling_frequency(word);
161 }
162 
163 TermList *
open_synonym_termlist(const string & term) const164 ConstDatabaseWrapper::open_synonym_termlist(const string & term) const
165 {
166     return realdb->open_synonym_termlist(term);
167 }
168 
169 TermList *
open_synonym_keylist(const string & prefix) const170 ConstDatabaseWrapper::open_synonym_keylist(const string & prefix) const
171 {
172     return realdb->open_synonym_keylist(prefix);
173 }
174 
175 string
get_metadata(const string & key) const176 ConstDatabaseWrapper::get_metadata(const string & key) const
177 {
178     return realdb->get_metadata(key);
179 }
180 
181 TermList *
open_metadata_keylist(const std::string & prefix) const182 ConstDatabaseWrapper::open_metadata_keylist(const std::string &prefix) const
183 {
184     return realdb->open_metadata_keylist(prefix);
185 }
186 
187 void
request_document(Xapian::docid did) const188 ConstDatabaseWrapper::request_document(Xapian::docid did) const
189 {
190     return realdb->request_document(did);
191 }
192 
193 Xapian::Document::Internal *
collect_document(Xapian::docid did) const194 ConstDatabaseWrapper::collect_document(Xapian::docid did) const
195 {
196     return realdb->collect_document(did);
197 }
198 
199 string
get_revision_info() const200 ConstDatabaseWrapper::get_revision_info() const
201 {
202     return realdb->get_revision_info();
203 }
204 
205 string
get_uuid() const206 ConstDatabaseWrapper::get_uuid() const
207 {
208     return realdb->get_uuid();
209 }
210 
211 void
invalidate_doc_object(Xapian::Document::Internal * obj) const212 ConstDatabaseWrapper::invalidate_doc_object(Xapian::Document::Internal * obj) const
213 {
214     return realdb->invalidate_doc_object(obj);
215 }
216 
217 // Non-const methods: these raise Xapian::InvalidOperationError
218 void
add_spelling(const string &,Xapian::termcount) const219 ConstDatabaseWrapper::add_spelling(const string &, Xapian::termcount) const
220 {
221     nonconst_access();
222 }
223 
224 void
remove_spelling(const string &,Xapian::termcount) const225 ConstDatabaseWrapper::remove_spelling(const string &, Xapian::termcount) const
226 {
227     nonconst_access();
228 }
229 
230 void
add_synonym(const string &,const string &) const231 ConstDatabaseWrapper::add_synonym(const string &, const string &) const
232 {
233     nonconst_access();
234 }
235 
236 void
remove_synonym(const string &,const string &) const237 ConstDatabaseWrapper::remove_synonym(const string &, const string &) const
238 {
239     nonconst_access();
240 }
241 
242 void
clear_synonyms(const string &) const243 ConstDatabaseWrapper::clear_synonyms(const string &) const
244 {
245     nonconst_access();
246 }
247 
248 void
set_metadata(const string &,const string &)249 ConstDatabaseWrapper::set_metadata(const string &, const string &)
250 {
251     nonconst_access();
252 }
253 
254 void
reopen()255 ConstDatabaseWrapper::reopen()
256 {
257     nonconst_access();
258 }
259 
260 void
close()261 ConstDatabaseWrapper::close()
262 {
263     nonconst_access();
264 }
265 
266 void
commit()267 ConstDatabaseWrapper::commit()
268 {
269     nonconst_access();
270 }
271 
272 void
cancel()273 ConstDatabaseWrapper::cancel()
274 {
275     nonconst_access();
276 }
277 
278 void
begin_transaction(bool)279 ConstDatabaseWrapper::begin_transaction(bool)
280 {
281     nonconst_access();
282 }
283 
284 void
commit_transaction()285 ConstDatabaseWrapper::commit_transaction()
286 {
287     nonconst_access();
288 }
289 
290 void
cancel_transaction()291 ConstDatabaseWrapper::cancel_transaction()
292 {
293     nonconst_access();
294 }
295 
296 Xapian::docid
add_document(const Xapian::Document &)297 ConstDatabaseWrapper::add_document(const Xapian::Document &)
298 {
299     nonconst_access();
300     return 0;
301 }
302 
303 void
delete_document(Xapian::docid)304 ConstDatabaseWrapper::delete_document(Xapian::docid)
305 {
306     nonconst_access();
307 }
308 
309 void
delete_document(const string &)310 ConstDatabaseWrapper::delete_document(const string &)
311 {
312     nonconst_access();
313 }
314 
315 void
replace_document(Xapian::docid,const Xapian::Document &)316 ConstDatabaseWrapper::replace_document(Xapian::docid, const Xapian::Document &)
317 {
318     nonconst_access();
319 }
320 
321 Xapian::docid
replace_document(const string &,const Xapian::Document &)322 ConstDatabaseWrapper::replace_document(const string &,
323 				       const Xapian::Document &)
324 {
325     nonconst_access();
326     return 0;
327 }
328 
329 void
write_changesets_to_fd(int,const std::string &,bool,Xapian::ReplicationInfo *)330 ConstDatabaseWrapper::write_changesets_to_fd(int, const std::string &, bool,
331 					     Xapian::ReplicationInfo *)
332 {
333     nonconst_access();
334 }
335 
336 RemoteDatabase *
as_remotedatabase()337 ConstDatabaseWrapper::as_remotedatabase()
338 {
339     nonconst_access();
340     return NULL;
341 }
342