source: main/trunk/greenstone2/runtime-src/src/colservr/sqlfilter.cpp@ 31388

Last change on this file since 31388 was 31388, checked in by ak19, 7 years ago

Second commit to do with implementing OAI deletion policy for GS2. This commit is only loosely related, as it shifts functions duplicated in source.h and filter.h (and cpp files) into the new colserver.h and cpp files for sharing.

File size: 3.1 KB
Line 
1/**********************************************************************
2 *
3 * sqlfilter.cpp --
4 * Copyright (C) 2008 DL Consulting Ltd
5 * Copyright (C) 2010 The New Zealand Digital Library Project
6 *
7 * A component of the Greenstone digital library software
8 * from the New Zealand Digital Library Project at the
9 * University of Waikato, New Zealand.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 *********************************************************************/
26
27#include "fileutil.h"
28#include "colservertools.h"
29#include "sqlfilter.h"
30
31
32sqlfilterclass::sqlfilterclass ()
33 : filterclass()
34{}
35
36
37sqlfilterclass::~sqlfilterclass ()
38{}
39
40
41void sqlfilterclass::configure (const text_t &key, const text_tarray &cfgline)
42{
43 filterclass::configure (key, cfgline);
44
45 if (key == "indexstem")
46 {
47 indexstem = cfgline[0];
48 }
49}
50
51bool sqlfilterclass::init (ostream &logout)
52{
53 outconvertclass text_t2ascii;
54
55 if (!filterclass::init(logout)) return false;
56
57 if (sql_db_ptr == NULL)
58 {
59 // most likely a configuration problem
60 logout << text_t2ascii << "configuration error: sqlfilter contains a null sqldbclass\n\n";
61 return false;
62 }
63
64 if (indexstem.empty())
65 {
66 indexstem = collection;
67 }
68
69 // get the filename for the database and make sure it exists
70 sql_db_filename = resolve_db_filename(gsdlhome, dbhome, collecthome, collection,
71 indexstem,sql_db_ptr->getfileextension());
72 if (!file_exists(sql_db_filename))
73 {
74 logout << text_t2ascii << "warning: database \"" << sql_db_filename << "\" does not exist\n\n";
75 return false;
76 }
77
78 return true;
79}
80
81
82bool sqlfilterclass::connect_to_sqldb (FilterResponse_t &response,
83 comerror_t &err, ostream &logout)
84{
85 outconvertclass text_t2ascii;
86
87 response.clear();
88 err = noError;
89
90 if (sql_db_ptr == NULL) {
91 // most likely a configuration problem
92 logout << text_t2ascii << "configuration error: sqlbrowsefilter contains a null sqldbclass\n\n";
93 err = configurationError;
94 return false;
95 }
96
97 // open the database
98 sql_db_ptr->setlogout (&logout);
99 if (!sql_db_ptr->opendatabase (sql_db_filename, DB_READER, 100, false)) {
100 // most likely a system problem (we have already checked that the database exists)
101 logout << text_t2ascii << "system problem: open on database \"" << sql_db_filename << "\" failed\n\n";
102 err = systemProblem;
103 return false;
104 }
105
106 return true;
107}
108
109
110void sqlfilterclass::disconnect_from_sqldb ()
111{
112 sql_db_ptr->closedatabase(); // Important that local library doesn't leave any files open
113}
Note: See TracBrowser for help on using the repository browser.