]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage.pm
more more more... see diffs
[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 use OpenILS::Application::Storage::FTS;
11
12
13 # the easy way to get to the logger...
14 my $log = "OpenSRF::Utils::Logger";
15
16 sub DESTROY {};
17
18 sub initialize {
19
20         my $conf = OpenSRF::Utils::SettingsClient->new;
21
22         $log->debug('Initializing ' . __PACKAGE__ . '...', DEBUG);
23
24         my $driver = "OpenILS::Application::Storage::Driver::".
25                 $conf->config_value( apps => 'open-ils.storage' => app_settings => databases => 'driver');
26
27
28         $log->debug("Attempting to load $driver ...", DEBUG);
29
30         eval "use $driver;";
31         if ($@) {
32                 $log->debug( "Can't load $driver!  :  $@", ERROR );
33                 $log->error( "Can't load $driver!  :  $@");
34                 throw OpenILS::EX::PANIC ( "Can't load $driver!  :  $@" );
35         }
36
37         $log->debug("$driver loaded successfully", DEBUG);
38
39         # Suck in the method publishing modules
40         @OpenILS::Application::Storage::CDBI::ISA = ( $driver );
41
42         eval 'use OpenILS::Application::Storage::Publisher;';
43         eval 'use OpenILS::Application::Storage::WORM;';
44 }
45
46 sub child_init {
47
48         $log->debug('Running child_init for ' . __PACKAGE__ . '...', DEBUG);
49
50         my $conf = OpenSRF::Utils::SettingsClient->new;
51
52         $log->debug('Calling the Driver child_init', DEBUG);
53         OpenILS::Application::Storage::CDBI->child_init(
54                 $conf->config_value( apps => 'open-ils.storage' => app_settings => databases => 'database')
55         );
56
57         if (OpenILS::Application::Storage::CDBI->db_Main()) {
58                 OpenILS::Application::Storage::WORM->child_init();
59                 $log->debug("Success initializing driver!", DEBUG);
60                 return 1;
61         }
62         return 0;
63 }
64
65 sub begin_xaction {
66         my $self = shift;
67         my $client = shift;
68
69         $log->debug(" XACT --> 'BEGIN'ing transaction for session ".$client->session->session_id,DEBUG);
70         try {
71                 OpenILS::Application::Storage::CDBI->db_Main->begin_work;
72                 $client->session->session_data( xact_id => $client->session->session_id );
73         } catch Error with {
74                 throw OpenSRF::DomainObject::oilsException->new(
75                         statusCode => 500,
76                         status => "Could not BEGIN transaction!",
77                 );
78         };
79         return 1;
80
81 }
82 __PACKAGE__->register_method(
83         method          => 'begin_xaction',
84         api_name        => 'open-ils.storage.transaction.begin',
85         api_level       => 1,
86         argc            => 0,
87 );
88
89 sub commit_xaction {
90         my $self = shift;
91         my $client = shift;
92
93         try {
94                 OpenILS::Application::Storage::CDBI->db_Main->commit;
95                 $client->session->session_data( xact_id => '' );
96         } catch Error with {
97                 throw OpenSRF::DomainObject::oilsException->new(
98                         statusCode => 500,
99                         status => "Could not COMMIT  transaction!",
100                 );
101         };
102         return 1;
103 }
104 __PACKAGE__->register_method(
105         method          => 'commit_xaction',
106         api_name        => 'open-ils.storage.transaction.commit',
107         api_level       => 1,
108         argc            => 0,
109 );
110
111
112 sub current_xact {
113         my $self = shift;
114         my $client = shift;
115
116         return $client->session->session_data( 'xact_id' );
117 }
118 __PACKAGE__->register_method(
119         method          => 'current_xact',
120         api_name        => 'open-ils.storage.transaction.current',
121         api_level       => 1,
122         argc            => 0,
123 );
124
125 sub rollback_xaction {
126         my $self = shift;
127         my $client = shift;
128
129         $log->debug(" XACT --> 'ROLLBACK'ing transaction for session ".$client->session->session_id,DEBUG);
130         $client->session->session_data( xact_id => '' );
131         return OpenILS::Application::Storage::CDBI->db_Main->rollback;
132 }
133 __PACKAGE__->register_method(
134         method          => 'rollback_xaction',
135         api_name        => 'open-ils.storage.transaction.rollback',
136         api_level       => 1,
137         argc            => 0,
138 );
139
140
141 sub _cdbi2Hash {
142         my $self = shift;
143         my $obj = shift;
144         return { map { ( $_ => $obj->$_ ) } ($obj->columns('All')) };
145 }
146
147 sub _cdbi_list2AoH {
148         my $self = shift;
149         my @objs = @_;
150         return [ map { $self->_cdbi2Hash($_) } @objs ];
151 }
152
153 1;