1 package OpenILS::Application;
2 use OpenSRF::Application;
3 use UNIVERSAL::require;
4 use base qw/OpenSRF::Application/;
5 use OpenILS::Utils::Fieldmapper;
7 __PACKAGE__->register_method(
8 api_name => 'opensrf.open-ils.system.use_authoritative',
10 method => 'use_authoritative',
13 # Do authoritative methods do anything different or are they simply
14 # clones of their non-authoritative variant?
15 my $_use_authoritative;
16 sub use_authoritative {
17 if (!defined $_use_authoritative) {
18 my $ua = OpenSRF::Utils::SettingsClient
19 ->new->config_value('uses_pooled_read_replica_dbs') || '';
20 $_use_authoritative = lc($ua) eq 'true';
23 return $_use_authoritative;
27 # version format is "x-y-z", for example "2-0-0" for Evergreen 2.0.0
28 # For branches, format is "x-y"
32 __PACKAGE__->register_method(
33 api_name => 'opensrf.open-ils.system.ils_version',
35 method => 'ils_version',
38 __PACKAGE__->register_method(
39 api_name => 'opensrf.open-ils.fetch_idl.file',
41 method => 'get_idl_file',
44 use OpenSRF::Utils::SettingsClient;
45 return OpenSRF::Utils::SettingsClient->new->config_value('IDL');
48 sub publish_fieldmapper {
49 my ($self,$client,$class) = @_;
51 return $Fieldmapper::fieldmap unless (defined $class);
52 return undef unless (exists($$Fieldmapper::fieldmap{$class}));
53 return {$class => $$Fieldmapper::fieldmap{$class}};
55 __PACKAGE__->register_method(
56 api_name => 'opensrf.open-ils.system.fieldmapper',
58 method => 'publish_fieldmapper',
66 $class = ref($class) || $class;
68 $args{package} ||= $class;
69 __PACKAGE__->SUPER::register_method( %args );
71 if (exists($dup_args{authoritative}) and $dup_args{authoritative}) {
72 (my $name = $dup_args{api_name}) =~ s/$/.authoritative/o;
73 if ($name ne $dup_args{api_name}) {
74 $dup_args{real_api_name} = $dup_args{api_name};
75 $dup_args{method} = 'authoritative_wrapper';
76 $dup_args{api_name} = $name;
77 $dup_args{package} = __PACKAGE__;
78 __PACKAGE__->SUPER::register_method( %dup_args );
83 sub authoritative_wrapper {
85 if (!$OpenILS::Utils::CStoreEditor::_loaded) {
86 die "Couldn't load OpenILS::Utils::CStoreEditor!" unless 'OpenILS::Utils::CStoreEditor'->use;
93 my $method = $self->method_lookup($self->{real_api_name});
96 local $OpenILS::Utils::CStoreEditor::always_xact = use_authoritative();
98 $client->respond( $_ ) for ( $method->run(@args) );
100 OpenILS::Utils::CStoreEditor->flush_forced_xacts();