]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage.pm
beginings of the new transaction infrastructure
[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;
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         $log->debug('Running child_init for ' . __PACKAGE__ . '...', DEBUG);
46
47         OpenILS::Application::Storage::CDBI->child_init(
48                 $conf->config_value( apps => 'open-ils.storage' => app_settings => databases => 'database')
49         );
50         
51
52         if (OpenILS::Application::Storage::CDBI->db_Main()) {
53                 $log->debug("Success initializing driver!", DEBUG);
54                 return 1;
55         }
56         return 0;
57 }
58
59 sub begin_xaction {
60         my $self = shift;
61         my $client = shift;
62
63         return OpenILS::Application::Storage::CDBI->db_Main->begin_work;
64 }
65 __PACKAGE__->register_method(
66         method          => 'begin_xaction',
67         api_name        => 'open-ils.storage.transaction.begin',
68         api_level       => 1,
69         argc            => 0,
70 );
71
72 sub commit_xaction {
73         my $self = shift;
74         my $client = shift;
75
76         return OpenILS::Application::Storage::CDBI->db_Main->commit;
77 }
78 __PACKAGE__->register_method(
79         method          => 'commit_xaction',
80         api_name        => 'open-ils.storage.transaction.commit',
81 );
82
83
84 sub rollback_xaction {
85         my $self = shift;
86         my $client = shift;
87
88         return OpenILS::Application::Storage::CDBI->db_Main->rollback;
89 }
90 __PACKAGE__->register_method(
91         method          => 'rollback_xaction',
92         api_name        => 'open-ils.storage.transaction.rollback',
93 );
94
95
96 sub _cdbi2Hash {
97         my $self = shift;
98         my $obj = shift;
99         return { map { ( $_ => $obj->$_ ) } ($obj->columns('All')) };
100 }
101
102 sub _cdbi_list2AoH {
103         my $self = shift;
104         my @objs = @_;
105         return [ map { $self->_cdbi2Hash($_) } @objs ];
106 }
107
108 1;