]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage.pm
updated Storage server
[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                 $log->debug("Success initializing driver!", DEBUG);
63                 return 1;
64         }
65         return 0;
66 }
67
68 sub begin_xaction {
69         my $self = shift;
70         my $client = shift;
71
72         $log->debug(" XACT --> 'BEGIN'ing transaction for session ".$client->session->session_id,DEBUG);
73         return OpenILS::Application::Storage::CDBI->db_Main->begin_work;
74 }
75 __PACKAGE__->register_method(
76         method          => 'begin_xaction',
77         api_name        => 'open-ils.storage.transaction.begin',
78         api_level       => 1,
79         argc            => 0,
80 );
81
82 sub commit_xaction {
83         my $self = shift;
84         my $client = shift;
85
86         $log->debug(" XACT --> 'COMMIT'ing transaction for session ".$client->session->session_id,DEBUG);
87         return OpenILS::Application::Storage::CDBI->db_Main->commit;
88 }
89 __PACKAGE__->register_method(
90         method          => 'commit_xaction',
91         api_name        => 'open-ils.storage.transaction.commit',
92         api_level       => 1,
93         argc            => 0,
94 );
95
96
97 sub rollback_xaction {
98         my $self = shift;
99         my $client = shift;
100
101         $log->debug(" XACT --> 'ROLLBACK'ing transaction for session ".$client->session->session_id,DEBUG);
102         return OpenILS::Application::Storage::CDBI->db_Main->rollback;
103 }
104 __PACKAGE__->register_method(
105         method          => 'rollback_xaction',
106         api_name        => 'open-ils.storage.transaction.rollback',
107         api_level       => 1,
108         argc            => 0,
109 );
110
111
112 sub _cdbi2Hash {
113         my $self = shift;
114         my $obj = shift;
115         return { map { ( $_ => $obj->$_ ) } ($obj->columns('All')) };
116 }
117
118 sub _cdbi_list2AoH {
119         my $self = shift;
120         my @objs = @_;
121         return [ map { $self->_cdbi2Hash($_) } @objs ];
122 }
123
124 1;