]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage.pm
fixed transaction support and tested with updates to biblio::record_node
[working/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
11 use OpenILS::Application::Storage::FTS;
12
13 # Suck in the method publishing modules
14 use OpenILS::Application::Storage::Publisher;
15
16 # the easy way to get to the logger...
17 my $log = "OpenSRF::Utils::Logger";
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         eval "use $driver;";
34         throw OpenILS::EX::PANIC ( "Can't load $driver!  :  $@" ) if ($@);
35
36         $log->debug("$driver loaded successfully", DEBUG);
37
38         @OpenILS::Application::Storage::CDBI::ISA = ( $driver );
39 }
40
41 sub child_init {
42
43         my $conf = OpenSRF::Utils::SettingsClient->new;
44
45         OpenSRF::Application->method_lookup('crappola');
46
47         $log->debug('Running child_init for ' . __PACKAGE__ . '...', DEBUG);
48
49         OpenILS::Application::Storage::CDBI->child_init(
50                 $conf->config_value( apps => 'open-ils.storage' => app_settings => databases => 'database')
51         );
52
53         if (OpenILS::Application::Storage::CDBI->db_Main()) {
54                 $log->debug("Success initializing driver!", DEBUG);
55                 return 1;
56         }
57         return 0;
58 }
59
60 sub begin_xaction {
61         my $self = shift;
62         my $client = shift;
63
64         $log->debug(" XACT --> 'BEGIN'ing transaction for session ".$client->session->session_id,DEBUG);
65         return OpenILS::Application::Storage::CDBI->db_Main->begin_work;
66 }
67 __PACKAGE__->register_method(
68         method          => 'begin_xaction',
69         api_name        => 'open-ils.storage.transaction.begin',
70         api_level       => 1,
71         argc            => 0,
72 );
73
74 sub commit_xaction {
75         my $self = shift;
76         my $client = shift;
77
78         $log->debug(" XACT --> 'COMMIT'ing transaction for session ".$client->session->session_id,DEBUG);
79         return OpenILS::Application::Storage::CDBI->db_Main->commit;
80 }
81 __PACKAGE__->register_method(
82         method          => 'commit_xaction',
83         api_name        => 'open-ils.storage.transaction.commit',
84         api_level       => 1,
85         argc            => 0,
86 );
87
88
89 sub rollback_xaction {
90         my $self = shift;
91         my $client = shift;
92
93         $log->debug(" XACT --> 'ROLLBACK'ing transaction for session ".$client->session->session_id,DEBUG);
94         return OpenILS::Application::Storage::CDBI->db_Main->rollback;
95 }
96 __PACKAGE__->register_method(
97         method          => 'rollback_xaction',
98         api_name        => 'open-ils.storage.transaction.rollback',
99         api_level       => 1,
100         argc            => 0,
101 );
102
103
104 sub _cdbi2Hash {
105         my $self = shift;
106         my $obj = shift;
107         return { map { ( $_ => $obj->$_ ) } ($obj->columns('All')) };
108 }
109
110 sub _cdbi_list2AoH {
111         my $self = shift;
112         my @objs = @_;
113         return [ map { $self->_cdbi2Hash($_) } @objs ];
114 }
115
116 1;