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;
11 use OpenILS::Application::Storage::FTS;
13 # Suck in the method publishing modules
14 use OpenILS::Application::Storage::Publisher;
16 # the easy way to get to the logger...
17 my $log = "OpenSRF::Utils::Logger";
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);
34 throw OpenILS::EX::PANIC ( "Can't load $driver! : $@" ) if ($@);
36 $log->debug("$driver loaded successfully", DEBUG);
38 @OpenILS::Application::Storage::CDBI::ISA = ( $driver );
43 my $conf = OpenSRF::Utils::SettingsClient->new;
45 $log->debug('Running child_init for ' . __PACKAGE__ . '...', DEBUG);
47 OpenILS::Application::Storage::CDBI->child_init(
48 $conf->config_value( apps => 'open-ils.storage' => app_settings => databases => 'database')
51 return 1 if (OpenILS::Application::Storage::CDBI->db_Main());
59 my $dbh = OpenILS::Application::Storage::CDBI->db_Main;
61 $client->session->registger_callback( disconnect => sub { $dbh->commit; } )
62 if ($self->api_name =~ /autocommit$/o);
64 $client->session->registger_callback( death => sub { $dbh->rollback; } );
69 __PACKAGE__->register_method(
70 method => 'begin_xaction',
71 api_name => 'open-ils.storage.transaction.begin',
75 __PACKAGE__->register_method(
76 method => 'begin_xaction',
77 api_name => 'open-ils.storage.transaction.begin.autocommit',
87 $client->session->session_data('dbh')->commit;
89 $client->session->session_data('dbh')->rollback;
92 __PACKAGE__->register_method(
93 method => 'commit_xaction',
94 api_name => 'open-ils.storage.transaction.commit',
98 sub rollback_xaction {
102 $client->session->session_data('dbh')->rollback;
104 __PACKAGE__->register_method(
105 method => 'rollback_xaction',
106 api_name => 'open-ils.storage.transaction.rollback',
113 return { map { ( $_ => $obj->$_ ) } ($obj->columns('All')) };
119 return [ map { $self->_cdbi2Hash($_) } @objs ];