updates
[torrus-plus.git] / src / lib / Torrus / DB.pm
bloba9a77bbd815506b85ae01a0d79a70c8d04958d82
1 # Copyright (C) 2002 Stanislav Sinyagin
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17 # $Id: DB.pm,v 1.1 2012/01/08 23:58:23 root Exp root $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
19 # Dean Hamstead <dean@fragfest.com.au>
21 package Torrus::DB;
23 use strict;
24 use warnings;
26 use Torrus::Log;
28 our $VERSION = 1.0;
30 our $dbType; # this is set in torrus-config.pl or torrus-siteconfig.pl
32 sub new
34 my $c = shift;
35 my @args = @_;
37 my $location = "Torrus/DB/${dbType}.pm";
38 my $class = "Torrus::DB::$dbType";
40 require $location;
42 return $class->new(@args)
46 # It is strongly inadvisable to do anything inside a signal handler when DB
47 # operation is in progress
49 our $interrupted = 0;
51 my $signalHandlersSet = 0;
52 my $safeSignals = 0;
58 sub setSignalHandlers
60 if( $signalHandlersSet )
62 return;
65 $SIG{'TERM'} = sub {
66 if( $safeSignals )
68 Warn('Received SIGTERM. Scheduling to exit.');
69 $interrupted = 1;
71 else
73 Warn('Received SIGTERM. Stopping the process.');
74 exit(1);
78 $SIG{'INT'} = sub {
79 if( $safeSignals )
81 Warn('Received SIGINT. Scheduling to exit.');
82 $interrupted = 1;
84 else
86 Warn('Received SIGINT. Stopping the process');
87 exit(1);
92 $SIG{'PIPE'} = sub {
93 if( $safeSignals )
95 Warn('Received SIGPIPE. Scheduling to exit.');
96 $interrupted = 1;
98 else
100 Warn('Received SIGPIPE. Stopping the process');
101 exit(1);
105 $SIG{'QUIT'} = sub {
106 if( $safeSignals )
108 Warn('Received SIGQUIT. Scheduling to exit.');
109 $interrupted = 1;
111 else
113 Warn('Received SIGQUIT. Stopping the process');
114 exit(1);
118 $signalHandlersSet = 1;
119 return;
123 sub setSafeSignalHandlers
125 setSignalHandlers();
126 $safeSignals = 1;
127 return;
131 sub setUnsafeSignalHandlers
133 setSignalHandlers();
134 $safeSignals = 0;
135 return;
138 =head2 checkInterrupted
140 If we were previously interrupted, gracefully exit now
142 =cut
144 sub checkInterrupted
146 if( $interrupted )
148 Warn('Stopping the process');
149 exit(1);
151 return;
156 sub closeNow
158 die 'This should be implemented in the DB/Foo.pm package';
161 sub cleanupEnvironment
163 # this is pretty crappy but will do for now
164 # a better approach would be to use the objects and let them
165 # clean themselves when they are destroyed
166 for my $janitor (@Torrus::DB::cleanUp)
168 $janitor->();
170 return
175 sub delay
177 my $self = shift;
178 $self->{'delay_list_commit'} = 1;
179 return
183 sub trunc
185 die 'This should be implemented in the DB/Foo.pm package';
189 sub put
191 die 'This should be implemented in the DB/Foo.pm package';
194 sub get
196 die 'This should be implemented in the DB/Foo.pm package';
200 sub del
202 die 'This should be implemented in the DB/Foo.pm package';
206 sub cursor
208 die 'This should be implemented in the DB/Foo.pm package';
212 sub next
214 die 'This should be implemented in the DB/Foo.pm package';
217 sub c_del
219 die 'This should be implemented in the DB/Foo.pm package';
223 sub c_get
225 die 'This should be implemented in the DB/Foo.pm package';
228 sub c_put
230 die 'This should be implemented in the DB/Foo.pm package';
234 sub c_close
236 die 'This should be implemented in the DB/Foo.pm package';
240 sub getBestMatch
242 die 'This should be implemented in the DB/Foo.pm package';
246 sub searchPrefix
248 die 'This should be implemented in the DB/Foo.pm package';
252 sub searchSubstring
254 die 'This should be implemented in the DB/Foo.pm package';
258 sub addToList
260 die 'This should be implemented in the DB/Foo.pm package';
264 sub searchList
266 die 'This should be implemented in the DB/Foo.pm package';
270 sub delFromList
272 die 'This should be implemented in the DB/Foo.pm package';
276 sub getListItems
278 die 'This should be implemented in the DB/Foo.pm package';
283 sub deleteList
285 die 'This should be implemented in the DB/Foo.pm package';
289 sub commit
291 die 'This should be implemented in the DB/Foo.pm package';
299 # Local Variables:
300 # mode: perl
301 # indent-tabs-mode: nil
302 # perl-indent-level: 4
303 # End: