]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage.pm
getAttribute is for elements, not xpath contexts
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Storage.pm
1 package OpenILS::Application::Storage;
2 use OpenILS::Application;
3 use base qw/OpenILS::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         $log->debug("We seem to be OK...",DEBUG);
52 }
53
54 sub child_init {
55
56         $log->debug('Running child_init for ' . __PACKAGE__ . '...', DEBUG);
57
58         my $conf = OpenSRF::Utils::SettingsClient->new;
59
60         $log->debug('Calling the Driver child_init', DEBUG);
61         OpenILS::Application::Storage::CDBI->child_init(
62                 $conf->config_value( apps => 'open-ils.storage' => app_settings => databases => 'database')
63         );
64
65         if (OpenILS::Application::Storage::CDBI->db_Main()) {
66                 $log->debug("Success initializing driver!", DEBUG);
67                 return 1;
68         }
69
70         $log->debug("FAILURE initializing driver!", ERROR);
71         return 0;
72 }
73
74 sub begin_xaction {
75         my $self = shift;
76         my $client = shift;
77
78         local $WRITE = 1;
79
80         $log->debug(" XACT --> 'BEGIN'ing transaction for session ".$client->session->session_id,DEBUG);
81         try {
82                 OpenILS::Application::Storage::CDBI->db_Main->begin_work;
83                 $client->session->session_data( xact_id => $client->session->session_id );
84         } catch Error with {
85                 throw OpenSRF::DomainObject::oilsException->new(
86                         statusCode => 500,
87                         status => "Could not BEGIN transaction!",
88                 );
89         };
90         return 1;
91
92 }
93 __PACKAGE__->register_method(
94         method          => 'begin_xaction',
95         api_name        => 'open-ils.storage.transaction.begin',
96         api_level       => 1,
97         argc            => 0,
98 );
99
100 sub savepoint_placeholder {
101         return 1;
102 }
103 __PACKAGE__->register_method(
104         method          => 'savepoint_placeholder',
105         api_name        => 'open-ils.storage.savepoint.set',
106         api_level       => 1,
107         argc            => 1,
108 );
109 __PACKAGE__->register_method(
110         method          => 'savepoint_placeholder',
111         api_name        => 'open-ils.storage.savepoint.release',
112         api_level       => 1,
113         argc            => 1,
114 );
115 __PACKAGE__->register_method(
116         method          => 'savepoint_placeholder',
117         api_name        => 'open-ils.storage.savepoint.rollback',
118         api_level       => 1,
119         argc            => 1,
120 );
121
122 sub commit_xaction {
123         my $self = shift;
124         my $client = shift;
125
126         local $WRITE = 1;
127
128         try {
129                 OpenILS::Application::Storage::CDBI->db_Main->commit;
130                 $client->session->session_data( xact_id => '' );
131         } catch Error with {
132                 throw OpenSRF::DomainObject::oilsException->new(
133                         statusCode => 500,
134                         status => "Could not COMMIT  transaction!",
135                 );
136         };
137         return 1;
138 }
139 __PACKAGE__->register_method(
140         method          => 'commit_xaction',
141         api_name        => 'open-ils.storage.transaction.commit',
142         api_level       => 1,
143         argc            => 0,
144 );
145
146
147 sub current_xact {
148         my $self = shift;
149         my $client = shift;
150
151         return $client->session->session_data( 'xact_id' );
152 }
153 __PACKAGE__->register_method(
154         method          => 'current_xact',
155         api_name        => 'open-ils.storage.transaction.current',
156         api_level       => 1,
157         argc            => 0,
158 );
159
160 sub rollback_xaction {
161         my $self = shift;
162         my $client = shift;
163
164         local $WRITE = 1;
165
166         $log->debug(" XACT --> 'ROLLBACK'ing transaction for session ".$client->session->session_id,DEBUG);
167         $client->session->session_data( xact_id => '' );
168         return OpenILS::Application::Storage::CDBI->db_Main->rollback;
169 }
170 __PACKAGE__->register_method(
171         method          => 'rollback_xaction',
172         api_name        => 'open-ils.storage.transaction.rollback',
173         api_level       => 1,
174         argc            => 0,
175 );
176
177
178 sub _cdbi2Hash {
179         my $self = shift;
180         my $obj = shift;
181         return { map { ( $_ => $obj->$_ ) } ($obj->columns('All')) };
182 }
183
184 sub _cdbi_list2AoH {
185         my $self = shift;
186         my @objs = @_;
187         return [ map { $self->_cdbi2Hash($_) } @objs ];
188 }
189
190 1;