source: main/trunk/greenstone2/perllib/dbutil.pm@ 21411

Last change on this file since 21411 was 21411, checked in by davidb, 12 years ago

Separation of different database back-ends into individual files

File size: 6.8 KB
Line 
1###########################################################################
2#
3# dbutil.pm -- gateway to utilities for reading/writing to different databases
4# Copyright (C) 2008 DL Consulting Ltd
5#
6# A component of the Greenstone digital library software
7# from the New Zealand Digital Library Project at the
8# University of Waikato, New Zealand.
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24###########################################################################
25
26package dbutil;
27
28use strict;
29
30
31use dbutil::gdbmtxtgz;
32use dbutil::gdbm;
33use dbutil::jdbm;
34use dbutil::sqlite;
35use dbutil::mssql;
36
37sub open_infodb_write_handle
38{
39 my $infodb_type = shift(@_);
40 my $infodb_file_path = shift(@_);
41
42 if ($infodb_type eq "sqlite")
43 {
44 return &dbutil::sqlite::open_infodb_write_handle($infodb_file_path);
45 }
46 elsif ($infodb_type eq "gdbm-txtgz")
47 {
48 return &dbutil::gdbmtxtgz::open_infodb_write_handle($infodb_file_path);
49 }
50 elsif ($infodb_type eq "jdbm")
51 {
52 return &dbutil::jdbm::open_infodb_write_handle($infodb_file_path);
53 }
54 elsif ($infodb_type eq "mssql")
55 {
56 return &dbutil::mssql::open_infodb_write_handle($infodb_file_path);
57 }
58
59 # Use GDBM if the infodb type is empty or not one of the values above
60 return &dbutil::gdbm::open_infodb_write_handle($infodb_file_path);
61}
62
63
64sub close_infodb_write_handle
65{
66 my $infodb_type = shift(@_);
67 my $infodb_handle = shift(@_);
68
69 if ($infodb_type eq "sqlite")
70 {
71 return &dbutil::sqlite::close_infodb_write_handle($infodb_handle);
72 }
73 elsif ($infodb_type eq "gdbm-txtgz")
74 {
75 return &dbutil::gdbmtxtgz::close_infodb_write_handle($infodb_handle);
76 }
77 elsif ($infodb_type eq "jdbm")
78 {
79 return &dbutil::jdbm::close_infodb_write_handle($infodb_handle);
80 }
81 elsif ($infodb_type eq "mssql")
82 {
83 return &dbutil::mssql::close_infodb_write_handle($infodb_handle);
84 }
85
86 # Use GDBM if the infodb type is empty or not one of the values above
87 return &dbutil::gdbm::close_infodb_write_handle($infodb_handle);
88}
89
90
91sub get_default_infodb_type
92{
93 # The default is GDBM so everything works the same for existing collections
94 # To use something else, specify the "infodbtype" in the collection's collect.cfg file
95 return "gdbm";
96}
97
98
99sub get_infodb_file_path
100{
101 my $infodb_type = shift(@_);
102 my $collection_name = shift(@_);
103 my $infodb_directory_path = shift(@_);
104
105 if ($infodb_type eq "sqlite")
106 {
107 return &dbutil::sqlite::get_infodb_file_path($collection_name, $infodb_directory_path);
108 }
109 elsif ($infodb_type eq "gdbm-txtgz")
110 {
111 return &dbutil::gdbmtxtgz::get_infodb_file_path($collection_name, $infodb_directory_path);
112 }
113 elsif ($infodb_type eq "jdbm")
114 {
115 return &dbutil::jdbm::get_infodb_file_path($collection_name, $infodb_directory_path);
116 }
117 elsif ($infodb_type eq "mssql")
118 {
119 #==================================================================================================#
120 # Updated by Jeffrey (2008/08/25 Monday)
121 # After look into the run-time code, it seems we should still create a database file.
122 # Since the run-time code is always try to read a database file, the easiest way here is not
123 # to change the whole structure, but to give whatever the system is looking for.
124 #==================================================================================================#
125 # Added by Jeffrey (2008/08/15 Friday)
126 # No file path required for MS SQL, it is a server-client connection.
127 # At the moment the information is hard coded in dbutil::mssql::open_infodb_write_handle
128 # the this might need some tidy up sometime.
129 #==================================================================================================#
130 return &dbutil::mssql::get_infodb_file_path($collection_name, $infodb_directory_path);
131 }
132
133 # Use GDBM if the infodb type is empty or not one of the values above
134 return &dbutil::gdbm::get_infodb_file_path($collection_name, $infodb_directory_path);
135}
136
137
138sub read_infodb_file
139{
140 my $infodb_type = shift(@_);
141 my $infodb_file_path = shift(@_);
142 my $infodb_map = shift(@_);
143
144 if ($infodb_type eq "sqlite")
145 {
146 return &dbutil::sqlite::read_infodb_file($infodb_file_path, $infodb_map);
147 }
148 elsif ($infodb_type eq "gdbm-txtgz")
149 {
150 return &dbutil::gdbmtxtgz::read_infodb_file($infodb_file_path, $infodb_map);
151 }
152 elsif ($infodb_type eq "jdbm")
153 {
154 return &dbutil::jdbm::read_infodb_file($infodb_file_path, $infodb_map);
155 }
156 elsif ($infodb_type eq "mssql")
157 {
158 return &dbutil::mssql::read_infodb_file($infodb_file_path, $infodb_map);
159 }
160
161 # Use GDBM if the infodb type is empty or not one of the values above
162 return &dbutil::gdbm::read_infodb_file($infodb_file_path, $infodb_map);
163}
164
165
166sub write_infodb_entry
167{
168 my $infodb_type = shift(@_);
169 my $infodb_handle = shift(@_);
170 my $infodb_key = shift(@_);
171 my $infodb_map = shift(@_);
172
173 if ($infodb_type eq "sqlite")
174 {
175 return &dbutil::sqlite::write_infodb_entry($infodb_handle, $infodb_key, $infodb_map);
176 }
177 elsif ($infodb_type eq "gdbm-txtgz")
178 {
179 return &dbutil::gdbmtxtgz::write_infodb_entry($infodb_handle, $infodb_key, $infodb_map);
180 }
181 elsif ($infodb_type eq "jdbm")
182 {
183 return &dbutil::jdbm::write_infodb_entry($infodb_handle, $infodb_key, $infodb_map);
184 }
185 elsif ($infodb_type eq "mssql")
186 {
187 return &dbutil::mssql::write_infodb_entry($infodb_handle, $infodb_key, $infodb_map);
188 }
189
190 # Use GDBM if the infodb type is empty or not one of the values above
191 return &dbutil::gdbm::write_infodb_entry($infodb_handle, $infodb_key, $infodb_map);
192}
193
194
195sub delete_infodb_entry
196{
197 my $infodb_type = shift(@_);
198 my $infodb_handle = shift(@_);
199 my $infodb_key = shift(@_);
200
201 if ($infodb_type eq "sqlite")
202 {
203 return &dbutil::sqlite::delete_infodb_entry($infodb_handle, $infodb_key);
204 }
205 elsif ($infodb_type eq "gdbm-txtgz")
206 {
207 return &dbutil::gdbmtxtgz::delete_infodb_entry($infodb_handle, $infodb_key);
208 }
209 elsif ($infodb_type eq "jdbm")
210 {
211 return &dbutil::jdbm::delete_infodb_entry($infodb_handle, $infodb_key);
212 }
213 elsif ($infodb_type eq "mssql")
214 {
215 return &dbutil::mssql::delete_infodb_entry($infodb_handle, $infodb_key);
216 }
217
218 # Use GDBM if the infodb type is empty or not one of the values above
219 return &dbutil::gdbm::delete_infodb_entry($infodb_handle, $infodb_key);
220}
221
222
2231;
Note: See TracBrowser for help on using the repository browser.