1 package OpenILS::Application::Storage;
2 use OpenSRF::Application;
3 use base qw/OpenSRF::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 OpenILS::Application::WoRM->use;
53 $log->debug("FAILURE LOADING WORM! $@", ERROR);
54 throw OpenSRF::EX::PANIC ( "FAILURE LOADING WoRM! : $@" );
57 $log->debug("We seem to be OK...",DEBUG);
62 $log->debug('Running child_init for ' . __PACKAGE__ . '...', DEBUG);
64 my $conf = OpenSRF::Utils::SettingsClient->new;
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')
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);
77 $log->debug("FAILURE initializing driver!", ERROR);
87 $log->debug(" XACT --> 'BEGIN'ing transaction for session ".$client->session->session_id,DEBUG);
89 OpenILS::Application::Storage::CDBI->db_Main->begin_work;
90 $client->session->session_data( xact_id => $client->session->session_id );
92 throw OpenSRF::DomainObject::oilsException->new(
94 status => "Could not BEGIN transaction!",
100 __PACKAGE__->register_method(
101 method => 'begin_xaction',
102 api_name => 'open-ils.storage.transaction.begin',
107 sub savepoint_placeholder {
110 __PACKAGE__->register_method(
111 method => 'savepoint_placeholder',
112 api_name => 'open-ils.storage.savepoint.set',
116 __PACKAGE__->register_method(
117 method => 'savepoint_placeholder',
118 api_name => 'open-ils.storage.savepoint.release',
122 __PACKAGE__->register_method(
123 method => 'savepoint_placeholder',
124 api_name => 'open-ils.storage.savepoint.rollback',
136 OpenILS::Application::Storage::CDBI->db_Main->commit;
137 $client->session->session_data( xact_id => '' );
139 throw OpenSRF::DomainObject::oilsException->new(
141 status => "Could not COMMIT transaction!",
146 __PACKAGE__->register_method(
147 method => 'commit_xaction',
148 api_name => 'open-ils.storage.transaction.commit',
158 return $client->session->session_data( 'xact_id' );
160 __PACKAGE__->register_method(
161 method => 'current_xact',
162 api_name => 'open-ils.storage.transaction.current',
167 sub rollback_xaction {
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;
177 __PACKAGE__->register_method(
178 method => 'rollback_xaction',
179 api_name => 'open-ils.storage.transaction.rollback',
188 return { map { ( $_ => $obj->$_ ) } ($obj->columns('All')) };
194 return [ map { $self->_cdbi2Hash($_) } @objs ];