]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage.pm
tons of storage server changes... see diffs
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Storage.pm
1 package OpenILS::Application::Storage;
2 use OpenSRF::Application;
3 use base qw/OpenSRF::Application/;
4
5 use OpenSRF::EX qw/:try/;
6 use OpenSRF::Utils::Logger qw/:level/;
7
8 # Pull this in so we can adjust it's @ISA
9 use OpenILS::Application::Storage::CDBI (1);
10
11 use OpenILS::Application::Storage::FTS;
12
13 # Suck in the method publishing modules
14 use OpenILS::Application::Storage::Publisher;
15 use OpenILS::Application::Storage::WORM;
16
17 # the easy way to get to the logger...
18 my $log = "OpenSRF::Utils::Logger";
19
20 sub DESTROY {};
21
22 sub initialize {
23
24         my $conf = OpenSRF::Utils::SettingsClient->new;
25
26         $log->debug('Initializing ' . __PACKAGE__ . '...', DEBUG);
27
28         my $driver = "OpenILS::Application::Storage::Driver::".
29                 $conf->config_value( apps => 'open-ils.storage' => app_settings => databases => 'driver');
30
31
32         $log->debug("Attempting to load $driver ...", DEBUG);
33
34         eval "use $driver;";
35         if ($@) {
36                 $log->debug( "Can't load $driver!  :  $@", ERROR );
37                 $log->error( "Can't load $driver!  :  $@");
38                 throw OpenILS::EX::PANIC ( "Can't load $driver!  :  $@" );
39         }
40
41         $log->debug("$driver loaded successfully", DEBUG);
42
43         @OpenILS::Application::Storage::CDBI::ISA = ( $driver );
44 }
45
46 sub child_init {
47
48         $log->debug('Running child_init for ' . __PACKAGE__ . '...', DEBUG);
49
50         my $conf = OpenSRF::Utils::SettingsClient->new;
51
52         # XXX -- this died... router down?
53         #$log->debug('Prepopulating method_lookup cache', DEBUG);
54         #OpenSRF::Application->method_lookup('crappola');
55
56         $log->debug('Calling the Driver child_init', DEBUG);
57         OpenILS::Application::Storage::CDBI->child_init(
58                 $conf->config_value( apps => 'open-ils.storage' => app_settings => databases => 'database')
59         );
60
61         if (OpenILS::Application::Storage::CDBI->db_Main()) {
62                 OpenILS::Application::Storage::WORM->child_init();
63                 $log->debug("Success initializing driver!", DEBUG);
64                 return 1;
65         }
66         return 0;
67 }
68
69 sub begin_xaction {
70         my $self = shift;
71         my $client = shift;
72
73         $log->debug(" XACT --> 'BEGIN'ing transaction for session ".$client->session->session_id,DEBUG);
74         return OpenILS::Application::Storage::CDBI->db_Main->begin_work;
75 }
76 __PACKAGE__->register_method(
77         method          => 'begin_xaction',
78         api_name        => 'open-ils.storage.transaction.begin',
79         api_level       => 1,
80         argc            => 0,
81 );
82
83 sub commit_xaction {
84         my $self = shift;
85         my $client = shift;
86
87         $log->debug(" XACT --> 'COMMIT'ing transaction for session ".$client->session->session_id,DEBUG);
88         return OpenILS::Application::Storage::CDBI->db_Main->commit;
89 }
90 __PACKAGE__->register_method(
91         method          => 'commit_xaction',
92         api_name        => 'open-ils.storage.transaction.commit',
93         api_level       => 1,
94         argc            => 0,
95 );
96
97
98 sub rollback_xaction {
99         my $self = shift;
100         my $client = shift;
101
102         $log->debug(" XACT --> 'ROLLBACK'ing transaction for session ".$client->session->session_id,DEBUG);
103         return OpenILS::Application::Storage::CDBI->db_Main->rollback;
104 }
105 __PACKAGE__->register_method(
106         method          => 'rollback_xaction',
107         api_name        => 'open-ils.storage.transaction.rollback',
108         api_level       => 1,
109         argc            => 0,
110 );
111
112
113 sub _cdbi2Hash {
114         my $self = shift;
115         my $obj = shift;
116         return { map { ( $_ => $obj->$_ ) } ($obj->columns('All')) };
117 }
118
119 sub _cdbi_list2AoH {
120         my $self = shift;
121         my @objs = @_;
122         return [ map { $self->_cdbi2Hash($_) } @objs ];
123 }
124
125 1;