[15699] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
[21411] | 3 | # dbutil.pm -- gateway to utilities for reading/writing to different databases
|
---|
[15699] | 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 |
|
---|
| 26 | package dbutil;
|
---|
| 27 |
|
---|
| 28 | use strict;
|
---|
| 29 |
|
---|
| 30 |
|
---|
[21411] | 31 | use dbutil::gdbmtxtgz;
|
---|
| 32 | use dbutil::gdbm;
|
---|
| 33 | use dbutil::jdbm;
|
---|
| 34 | use dbutil::sqlite;
|
---|
| 35 | use dbutil::mssql;
|
---|
| 36 |
|
---|
[17087] | 37 | sub open_infodb_write_handle
|
---|
| 38 | {
|
---|
[17476] | 39 | my $infodb_type = shift(@_);
|
---|
| 40 | my $infodb_file_path = shift(@_);
|
---|
| 41 |
|
---|
| 42 | if ($infodb_type eq "sqlite")
|
---|
| 43 | {
|
---|
[21411] | 44 | return &dbutil::sqlite::open_infodb_write_handle($infodb_file_path);
|
---|
[17476] | 45 | }
|
---|
| 46 | elsif ($infodb_type eq "gdbm-txtgz")
|
---|
| 47 | {
|
---|
[21411] | 48 | return &dbutil::gdbmtxtgz::open_infodb_write_handle($infodb_file_path);
|
---|
[17476] | 49 | }
|
---|
[21411] | 50 | elsif ($infodb_type eq "jdbm")
|
---|
| 51 | {
|
---|
| 52 | return &dbutil::jdbm::open_infodb_write_handle($infodb_file_path);
|
---|
| 53 | }
|
---|
[17476] | 54 | elsif ($infodb_type eq "mssql")
|
---|
| 55 | {
|
---|
[21411] | 56 | return &dbutil::mssql::open_infodb_write_handle($infodb_file_path);
|
---|
[17476] | 57 | }
|
---|
[17087] | 58 |
|
---|
[17476] | 59 | # Use GDBM if the infodb type is empty or not one of the values above
|
---|
[21411] | 60 | return &dbutil::gdbm::open_infodb_write_handle($infodb_file_path);
|
---|
[17087] | 61 | }
|
---|
| 62 |
|
---|
| 63 |
|
---|
[16176] | 64 | sub close_infodb_write_handle
|
---|
| 65 | {
|
---|
[17476] | 66 | my $infodb_type = shift(@_);
|
---|
| 67 | my $infodb_handle = shift(@_);
|
---|
[16176] | 68 |
|
---|
[17476] | 69 | if ($infodb_type eq "sqlite")
|
---|
| 70 | {
|
---|
[21411] | 71 | return &dbutil::sqlite::close_infodb_write_handle($infodb_handle);
|
---|
[17476] | 72 | }
|
---|
| 73 | elsif ($infodb_type eq "gdbm-txtgz")
|
---|
| 74 | {
|
---|
[21411] | 75 | return &dbutil::gdbmtxtgz::close_infodb_write_handle($infodb_handle);
|
---|
[17476] | 76 | }
|
---|
[21411] | 77 | elsif ($infodb_type eq "jdbm")
|
---|
| 78 | {
|
---|
| 79 | return &dbutil::jdbm::close_infodb_write_handle($infodb_handle);
|
---|
| 80 | }
|
---|
[17476] | 81 | elsif ($infodb_type eq "mssql")
|
---|
| 82 | {
|
---|
[21411] | 83 | return &dbutil::mssql::close_infodb_write_handle($infodb_handle);
|
---|
[17476] | 84 | }
|
---|
| 85 |
|
---|
| 86 | # Use GDBM if the infodb type is empty or not one of the values above
|
---|
[21411] | 87 | return &dbutil::gdbm::close_infodb_write_handle($infodb_handle);
|
---|
[17104] | 88 | }
|
---|
[16176] | 89 |
|
---|
| 90 |
|
---|
[15727] | 91 | sub get_default_infodb_type
|
---|
| 92 | {
|
---|
[17476] | 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";
|
---|
[15727] | 96 | }
|
---|
| 97 |
|
---|
| 98 |
|
---|
[15710] | 99 | sub get_infodb_file_path
|
---|
| 100 | {
|
---|
[17476] | 101 | my $infodb_type = shift(@_);
|
---|
| 102 | my $collection_name = shift(@_);
|
---|
| 103 | my $infodb_directory_path = shift(@_);
|
---|
[15710] | 104 |
|
---|
[17476] | 105 | if ($infodb_type eq "sqlite")
|
---|
| 106 | {
|
---|
[21411] | 107 | return &dbutil::sqlite::get_infodb_file_path($collection_name, $infodb_directory_path);
|
---|
[17476] | 108 | }
|
---|
| 109 | elsif ($infodb_type eq "gdbm-txtgz")
|
---|
| 110 | {
|
---|
[21411] | 111 | return &dbutil::gdbmtxtgz::get_infodb_file_path($collection_name, $infodb_directory_path);
|
---|
[17476] | 112 | }
|
---|
[21411] | 113 | elsif ($infodb_type eq "jdbm")
|
---|
| 114 | {
|
---|
| 115 | return &dbutil::jdbm::get_infodb_file_path($collection_name, $infodb_directory_path);
|
---|
| 116 | }
|
---|
[17476] | 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.
|
---|
[21411] | 127 | # At the moment the information is hard coded in dbutil::mssql::open_infodb_write_handle
|
---|
[17476] | 128 | # the this might need some tidy up sometime.
|
---|
| 129 | #==================================================================================================#
|
---|
[21411] | 130 | return &dbutil::mssql::get_infodb_file_path($collection_name, $infodb_directory_path);
|
---|
[17476] | 131 | }
|
---|
| 132 |
|
---|
| 133 | # Use GDBM if the infodb type is empty or not one of the values above
|
---|
[21411] | 134 | return &dbutil::gdbm::get_infodb_file_path($collection_name, $infodb_directory_path);
|
---|
[15710] | 135 | }
|
---|
| 136 |
|
---|
| 137 |
|
---|
[15705] | 138 | sub read_infodb_file
|
---|
| 139 | {
|
---|
[17476] | 140 | my $infodb_type = shift(@_);
|
---|
| 141 | my $infodb_file_path = shift(@_);
|
---|
| 142 | my $infodb_map = shift(@_);
|
---|
[15705] | 143 |
|
---|
[17476] | 144 | if ($infodb_type eq "sqlite")
|
---|
| 145 | {
|
---|
[21411] | 146 | return &dbutil::sqlite::read_infodb_file($infodb_file_path, $infodb_map);
|
---|
[17476] | 147 | }
|
---|
| 148 | elsif ($infodb_type eq "gdbm-txtgz")
|
---|
| 149 | {
|
---|
[21411] | 150 | return &dbutil::gdbmtxtgz::read_infodb_file($infodb_file_path, $infodb_map);
|
---|
[17476] | 151 | }
|
---|
[21411] | 152 | elsif ($infodb_type eq "jdbm")
|
---|
| 153 | {
|
---|
| 154 | return &dbutil::jdbm::read_infodb_file($infodb_file_path, $infodb_map);
|
---|
| 155 | }
|
---|
[17476] | 156 | elsif ($infodb_type eq "mssql")
|
---|
| 157 | {
|
---|
[21411] | 158 | return &dbutil::mssql::read_infodb_file($infodb_file_path, $infodb_map);
|
---|
[17476] | 159 | }
|
---|
| 160 |
|
---|
| 161 | # Use GDBM if the infodb type is empty or not one of the values above
|
---|
[21411] | 162 | return &dbutil::gdbm::read_infodb_file($infodb_file_path, $infodb_map);
|
---|
[15705] | 163 | }
|
---|
| 164 |
|
---|
| 165 |
|
---|
[15699] | 166 | sub write_infodb_entry
|
---|
| 167 | {
|
---|
[17476] | 168 | my $infodb_type = shift(@_);
|
---|
| 169 | my $infodb_handle = shift(@_);
|
---|
| 170 | my $infodb_key = shift(@_);
|
---|
| 171 | my $infodb_map = shift(@_);
|
---|
[15699] | 172 |
|
---|
[17476] | 173 | if ($infodb_type eq "sqlite")
|
---|
| 174 | {
|
---|
[21411] | 175 | return &dbutil::sqlite::write_infodb_entry($infodb_handle, $infodb_key, $infodb_map);
|
---|
[17476] | 176 | }
|
---|
| 177 | elsif ($infodb_type eq "gdbm-txtgz")
|
---|
| 178 | {
|
---|
[21411] | 179 | return &dbutil::gdbmtxtgz::write_infodb_entry($infodb_handle, $infodb_key, $infodb_map);
|
---|
[17476] | 180 | }
|
---|
[21411] | 181 | elsif ($infodb_type eq "jdbm")
|
---|
| 182 | {
|
---|
| 183 | return &dbutil::jdbm::write_infodb_entry($infodb_handle, $infodb_key, $infodb_map);
|
---|
| 184 | }
|
---|
[17476] | 185 | elsif ($infodb_type eq "mssql")
|
---|
| 186 | {
|
---|
[21411] | 187 | return &dbutil::mssql::write_infodb_entry($infodb_handle, $infodb_key, $infodb_map);
|
---|
[17476] | 188 | }
|
---|
[15725] | 189 |
|
---|
[17476] | 190 | # Use GDBM if the infodb type is empty or not one of the values above
|
---|
[21411] | 191 | return &dbutil::gdbm::write_infodb_entry($infodb_handle, $infodb_key, $infodb_map);
|
---|
[15699] | 192 | }
|
---|
| 193 |
|
---|
[15705] | 194 |
|
---|
[18467] | 195 | sub delete_infodb_entry
|
---|
| 196 | {
|
---|
| 197 | my $infodb_type = shift(@_);
|
---|
| 198 | my $infodb_handle = shift(@_);
|
---|
| 199 | my $infodb_key = shift(@_);
|
---|
[15705] | 200 |
|
---|
[18467] | 201 | if ($infodb_type eq "sqlite")
|
---|
| 202 | {
|
---|
[21411] | 203 | return &dbutil::sqlite::delete_infodb_entry($infodb_handle, $infodb_key);
|
---|
[18467] | 204 | }
|
---|
| 205 | elsif ($infodb_type eq "gdbm-txtgz")
|
---|
| 206 | {
|
---|
[21411] | 207 | return &dbutil::gdbmtxtgz::delete_infodb_entry($infodb_handle, $infodb_key);
|
---|
[18467] | 208 | }
|
---|
[21411] | 209 | elsif ($infodb_type eq "jdbm")
|
---|
| 210 | {
|
---|
| 211 | return &dbutil::jdbm::delete_infodb_entry($infodb_handle, $infodb_key);
|
---|
| 212 | }
|
---|
[18467] | 213 | elsif ($infodb_type eq "mssql")
|
---|
| 214 | {
|
---|
[21411] | 215 | return &dbutil::mssql::delete_infodb_entry($infodb_handle, $infodb_key);
|
---|
[18467] | 216 | }
|
---|
| 217 |
|
---|
| 218 | # Use GDBM if the infodb type is empty or not one of the values above
|
---|
[21411] | 219 | return &dbutil::gdbm::delete_infodb_entry($infodb_handle, $infodb_key);
|
---|
[18467] | 220 | }
|
---|
| 221 |
|
---|
| 222 |
|
---|
[15699] | 223 | 1;
|
---|