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