1 package OpenILS::Application::Storage;
2 use OpenILS::Application;
3 use base qw/OpenILS::Application/;
5 use OpenSRF::EX qw/:try/;
6 use OpenSRF::Utils::Logger qw/:level/;
8 # Pull this in so we can adjust it's @ISA
9 use OpenILS::Application::Storage::CDBI (1);
10 use OpenILS::Application::Storage::FTS;
13 # the easy way to get to the logger...
14 my $log = "OpenSRF::Utils::Logger";
17 our $IGNORE_XACT_ID_FAILURE = 0;
23 my $conf = OpenSRF::Utils::SettingsClient->new;
25 $log->debug('Initializing ' . __PACKAGE__ . '...', DEBUG);
27 my $driver = "OpenILS::Application::Storage::Driver::".
28 $conf->config_value( apps => 'open-ils.storage' => app_settings => databases => 'driver');
31 $log->debug("Attempting to load $driver ...", DEBUG);
35 $log->debug( "Can't load $driver! : $@", ERROR );
36 $log->error( "Can't load $driver! : $@");
37 throw OpenSRF::EX::PANIC ( "Can't load $driver! : $@" );
40 $log->debug("$driver loaded successfully", DEBUG);
42 # Suck in the method publishing modules
43 @OpenILS::Application::Storage::CDBI::ISA = ( $driver );
45 OpenILS::Application::Storage::Publisher->use;
47 $log->debug("FAILURE LOADING Publisher! $@", ERROR);
48 throw OpenSRF::EX::PANIC ( "FAILURE LOADING Publisher! : $@" );
51 $log->debug("We seem to be OK...",DEBUG);
56 $log->debug('Running child_init for ' . __PACKAGE__ . '...', DEBUG);
58 my $conf = OpenSRF::Utils::SettingsClient->new;
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')
65 if (OpenILS::Application::Storage::CDBI->db_Main()) {
66 $log->debug("Success initializing driver!", DEBUG);
70 $log->debug("FAILURE initializing driver!", ERROR);
80 $log->debug(" XACT --> 'BEGIN'ing transaction for session ".$client->session->session_id,DEBUG);
82 OpenILS::Application::Storage::CDBI->db_Main->begin_work;
83 $client->session->session_data( xact_id => $client->session->session_id );
85 throw OpenSRF::DomainObject::oilsException->new(
87 status => "Could not BEGIN transaction!",
93 __PACKAGE__->register_method(
94 method => 'begin_xaction',
95 api_name => 'open-ils.storage.transaction.begin',
100 sub savepoint_placeholder {
103 __PACKAGE__->register_method(
104 method => 'savepoint_placeholder',
105 api_name => 'open-ils.storage.savepoint.set',
109 __PACKAGE__->register_method(
110 method => 'savepoint_placeholder',
111 api_name => 'open-ils.storage.savepoint.release',
115 __PACKAGE__->register_method(
116 method => 'savepoint_placeholder',
117 api_name => 'open-ils.storage.savepoint.rollback',
129 OpenILS::Application::Storage::CDBI->db_Main->commit;
130 $client->session->session_data( xact_id => '' );
132 throw OpenSRF::DomainObject::oilsException->new(
134 status => "Could not COMMIT transaction!",
139 __PACKAGE__->register_method(
140 method => 'commit_xaction',
141 api_name => 'open-ils.storage.transaction.commit',
151 return $client->session->session_data( 'xact_id' );
153 __PACKAGE__->register_method(
154 method => 'current_xact',
155 api_name => 'open-ils.storage.transaction.current',
160 sub rollback_xaction {
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;
170 __PACKAGE__->register_method(
171 method => 'rollback_xaction',
172 api_name => 'open-ils.storage.transaction.rollback',
181 return { map { ( $_ => $obj->$_ ) } ($obj->columns('All')) };
187 return [ map { $self->_cdbi2Hash($_) } @objs ];