]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage.pm
added money.grocery retrieval method
[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 use OpenILS::Application::Storage::FTS;
11
12
13 # the easy way to get to the logger...
14 my $log = "OpenSRF::Utils::Logger";
15
16 our $WRITE = 0;
17 our $IGNORE_XACT_ID_FAILURE = 0;
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         $driver->use;
34         if ($@) {
35                 $log->debug( "Can't load $driver!  :  $@", ERROR );
36                 $log->error( "Can't load $driver!  :  $@");
37                 throw OpenSRF::EX::PANIC ( "Can't load $driver!  :  $@" );
38         }
39
40         $log->debug("$driver loaded successfully", DEBUG);
41
42         # Suck in the method publishing modules
43         @OpenILS::Application::Storage::CDBI::ISA = ( $driver );
44
45         OpenILS::Application::Storage::Publisher->use;
46         if ($@) {
47                 $log->debug("FAILURE LOADING Publisher!  $@", ERROR);
48                 throw OpenSRF::EX::PANIC ( "FAILURE LOADING Publisher!  :  $@" );
49         }
50
51         OpenILS::Application::WoRM->use;
52         if ($@) {
53                 $log->debug("FAILURE LOADING WORM!  $@", ERROR);
54                 throw OpenSRF::EX::PANIC ( "FAILURE LOADING WoRM!  :  $@" );
55         }
56
57         $log->debug("We seem to be OK...",DEBUG);
58 }
59
60 sub child_init {
61
62         $log->debug('Running child_init for ' . __PACKAGE__ . '...', DEBUG);
63
64         my $conf = OpenSRF::Utils::SettingsClient->new;
65
66         $log->debug('Calling the Driver child_init', DEBUG);
67         OpenILS::Application::Storage::CDBI->child_init(
68                 $conf->config_value( apps => 'open-ils.storage' => app_settings => databases => 'database')
69         );
70
71         if (OpenILS::Application::Storage::CDBI->db_Main()) {
72                 #OpenILS::Application::Storage::WORM->child_init();
73                 OpenILS::Application::WoRM->child_init();
74                 $log->debug("Success initializing driver!", DEBUG);
75                 return 1;
76         }
77         $log->debug("FAILURE initializing driver!", ERROR);
78         return 0;
79 }
80
81 sub begin_xaction {
82         my $self = shift;
83         my $client = shift;
84
85         local $WRITE = 1;
86
87         $log->debug(" XACT --> 'BEGIN'ing transaction for session ".$client->session->session_id,DEBUG);
88         try {
89                 OpenILS::Application::Storage::CDBI->db_Main->begin_work;
90                 $client->session->session_data( xact_id => $client->session->session_id );
91         } catch Error with {
92                 throw OpenSRF::DomainObject::oilsException->new(
93                         statusCode => 500,
94                         status => "Could not BEGIN transaction!",
95                 );
96         };
97         return 1;
98
99 }
100 __PACKAGE__->register_method(
101         method          => 'begin_xaction',
102         api_name        => 'open-ils.storage.transaction.begin',
103         api_level       => 1,
104         argc            => 0,
105 );
106
107 sub savepoint_placeholder {
108         return 1;
109 }
110 __PACKAGE__->register_method(
111         method          => 'savepoint_placeholder',
112         api_name        => 'open-ils.storage.savepoint.set',
113         api_level       => 1,
114         argc            => 1,
115 );
116 __PACKAGE__->register_method(
117         method          => 'savepoint_placeholder',
118         api_name        => 'open-ils.storage.savepoint.release',
119         api_level       => 1,
120         argc            => 1,
121 );
122 __PACKAGE__->register_method(
123         method          => 'savepoint_placeholder',
124         api_name        => 'open-ils.storage.savepoint.rollback',
125         api_level       => 1,
126         argc            => 1,
127 );
128
129 sub commit_xaction {
130         my $self = shift;
131         my $client = shift;
132
133         local $WRITE = 1;
134
135         try {
136                 OpenILS::Application::Storage::CDBI->db_Main->commit;
137                 $client->session->session_data( xact_id => '' );
138         } catch Error with {
139                 throw OpenSRF::DomainObject::oilsException->new(
140                         statusCode => 500,
141                         status => "Could not COMMIT  transaction!",
142                 );
143         };
144         return 1;
145 }
146 __PACKAGE__->register_method(
147         method          => 'commit_xaction',
148         api_name        => 'open-ils.storage.transaction.commit',
149         api_level       => 1,
150         argc            => 0,
151 );
152
153
154 sub current_xact {
155         my $self = shift;
156         my $client = shift;
157
158         return $client->session->session_data( 'xact_id' );
159 }
160 __PACKAGE__->register_method(
161         method          => 'current_xact',
162         api_name        => 'open-ils.storage.transaction.current',
163         api_level       => 1,
164         argc            => 0,
165 );
166
167 sub rollback_xaction {
168         my $self = shift;
169         my $client = shift;
170
171         local $WRITE = 1;
172
173         $log->debug(" XACT --> 'ROLLBACK'ing transaction for session ".$client->session->session_id,DEBUG);
174         $client->session->session_data( xact_id => '' );
175         return OpenILS::Application::Storage::CDBI->db_Main->rollback;
176 }
177 __PACKAGE__->register_method(
178         method          => 'rollback_xaction',
179         api_name        => 'open-ils.storage.transaction.rollback',
180         api_level       => 1,
181         argc            => 0,
182 );
183
184
185 sub _cdbi2Hash {
186         my $self = shift;
187         my $obj = shift;
188         return { map { ( $_ => $obj->$_ ) } ($obj->columns('All')) };
189 }
190
191 sub _cdbi_list2AoH {
192         my $self = shift;
193         my @objs = @_;
194         return [ map { $self->_cdbi2Hash($_) } @objs ];
195 }
196
197 1;