From: miker Date: Thu, 13 Jul 2006 04:53:51 +0000 (+0000) Subject: abstracting batch.create X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=c81202eed1c098424c21bfbf3d173ba16436512e;p=Evergreen.git abstracting batch.create git-svn-id: svn://svn.open-ils.org/ILS/trunk@4966 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm index 0cf0046c50..86d1cef55d 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm @@ -443,14 +443,6 @@ metabib::metarecord->table( 'metabib.metarecord' ); metabib::metarecord->sequence( 'metabib.metarecord_id_seq' ); - OpenILS::Application::Storage->register_method( - api_name => 'open-ils.storage.direct.metabib.metarecord.batch.create', - method => 'copy_create', - api_level => 1, - 'package' => 'OpenILS::Application::Storage', - cdbi => 'metabib::metarecord', - ); - #------------------------------------------------------------------------------- @@ -468,14 +460,6 @@ # before_update => \&OpenILS::Application::Storage::Driver::Pg::tsearch2_trigger # ); - OpenILS::Application::Storage->register_method( - api_name => 'open-ils.storage.direct.metabib.title_field_entry.batch.create', - method => 'copy_create', - api_level => 1, - 'package' => 'OpenILS::Application::Storage', - cdbi => 'metabib::title_field_entry', - ); - #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- @@ -485,14 +469,6 @@ metabib::author_field_entry->sequence( 'metabib.author_field_entry_id_seq' ); metabib::author_field_entry->columns( 'FTS' => 'index_vector' ); - OpenILS::Application::Storage->register_method( - api_name => 'open-ils.storage.direct.metabib.author_field_entry.batch.create', - method => 'copy_create', - api_level => 1, - 'package' => 'OpenILS::Application::Storage', - cdbi => 'metabib::author_field_entry', - ); - #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- @@ -502,14 +478,6 @@ metabib::subject_field_entry->sequence( 'metabib.subject_field_entry_id_seq' ); metabib::subject_field_entry->columns( 'FTS' => 'index_vector' ); - OpenILS::Application::Storage->register_method( - api_name => 'open-ils.storage.direct.metabib.subject_field_entry.batch.create', - method => 'copy_create', - api_level => 1, - 'package' => 'OpenILS::Application::Storage', - cdbi => 'metabib::subject_field_entry', - ); - #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- @@ -519,14 +487,6 @@ metabib::keyword_field_entry->sequence( 'metabib.keyword_field_entry_id_seq' ); metabib::keyword_field_entry->columns( 'FTS' => 'index_vector' ); - OpenILS::Application::Storage->register_method( - api_name => 'open-ils.storage.direct.metabib.keyword_field_entry.batch.create', - method => 'copy_create', - api_level => 1, - 'package' => 'OpenILS::Application::Storage', - cdbi => 'metabib::keyword_field_entry', - ); - #------------------------------------------------------------------------------- package metabib::series_field_entry; @@ -534,14 +494,6 @@ metabib::series_field_entry->sequence( 'metabib.series_field_entry_id_seq' ); metabib::series_field_entry->columns( 'FTS' => 'index_vector' ); - OpenILS::Application::Storage->register_method( - api_name => 'open-ils.storage.direct.metabib.series_field_entry.batch.create', - method => 'copy_create', - api_level => 1, - 'package' => 'OpenILS::Application::Storage', - cdbi => 'metabib::series_field_entry', - ); - #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- @@ -577,14 +529,6 @@ metabib::metarecord_source_map->table( 'metabib.metarecord_source_map' ); metabib::metarecord_source_map->sequence( 'metabib.metarecord_source_map_id_seq' ); - OpenILS::Application::Storage->register_method( - api_name => 'open-ils.storage.direct.metabib.metarecord_source_map.batch.create', - method => 'copy_create', - api_level => 1, - 'package' => 'OpenILS::Application::Storage', - cdbi => 'metabib::metarecord_source_map', - ); - #------------------------------------------------------------------------------- package authority::record_descriptor; @@ -592,28 +536,12 @@ authority::record_descriptor->table( 'authority.rec_descriptor' ); authority::record_descriptor->sequence( 'authority.rec_descriptor_id_seq' ); - OpenILS::Application::Storage->register_method( - api_name => 'open-ils.storage.direct.authority.record_descriptor.batch.create', - method => 'copy_create', - api_level => 1, - 'package' => 'OpenILS::Application::Storage', - cdbi => 'authority::record_descriptor', - ); - #------------------------------------------------------------------------------- package metabib::record_descriptor; metabib::record_descriptor->table( 'metabib.rec_descriptor' ); metabib::record_descriptor->sequence( 'metabib.rec_descriptor_id_seq' ); - OpenILS::Application::Storage->register_method( - api_name => 'open-ils.storage.direct.metabib.record_descriptor.batch.create', - method => 'copy_create', - api_level => 1, - 'package' => 'OpenILS::Application::Storage', - cdbi => 'metabib::record_descriptor', - ); - #------------------------------------------------------------------------------- @@ -624,15 +552,6 @@ authority::full_rec->sequence( 'authority.full_rec_id_seq' ); authority::full_rec->columns( 'FTS' => 'index_vector' ); - OpenILS::Application::Storage->register_method( - api_name => 'open-ils.storage.direct.authority.full_rec.batch.create', - method => 'copy_create', - api_level => 1, - 'package' => 'OpenILS::Application::Storage', - cdbi => 'authority::full_rec', - ); - - #------------------------------------------------------------------------------- package metabib::full_rec; @@ -640,15 +559,6 @@ metabib::full_rec->sequence( 'metabib.full_rec_id_seq' ); metabib::full_rec->columns( 'FTS' => 'index_vector' ); - OpenILS::Application::Storage->register_method( - api_name => 'open-ils.storage.direct.metabib.full_rec.batch.create', - method => 'copy_create', - api_level => 1, - 'package' => 'OpenILS::Application::Storage', - cdbi => 'metabib::full_rec', - ); - - #------------------------------------------------------------------------------- package permission::perm_list; @@ -755,4 +665,38 @@ } +for my $class ( qw/ + biblio::record_entry + metabib::metarecord + metabib::title_field_entry + metabib::author_field_entry + metabib::subject_field_entry + metabib::keyword_field_entry + metabib::series_field_entry + metabib::metarecord_source_map + metabib::record_descriptor + metabib::full_rec + authority::record_descriptor + authority::full_rec + / ) { + + (my $method_class = $class) =~ s/::/./go; + + for my $type ( qw/create create_start create_push create_finish/ ) { + my ($name,$part) = split('_', $type); + + my $apiname = "open-ils.storage.direct.$method_class.batch.$name"; + $apiname .= ".$part" if ($part); + + OpenILS::Application::Storage->register_method( + api_name => $apiname, + method => "copy_$type", + api_level => 1, + 'package' => 'OpenILS::Application::Storage', + cdbi => $class, + ); + } +} + + 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/storage.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/storage.pm index 2ec7e7ab81..ada1ce4858 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/storage.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/storage.pm @@ -1,6 +1,8 @@ + { package OpenILS::Application::Storage; use OpenSRF::Utils::Logger; + our $NOPRIMARY = 0; my $log = 'OpenSRF::Utils::Logger'; my $pg = 'OpenILS::Application::Storage::Driver::Pg'; @@ -218,27 +220,44 @@ ); - sub copy_create { + sub copy_create_start { my $self = shift; my $client = shift; - my @fm_nodes = @_; local $OpenILS::Application::Storage::WRITE = 1; #return undef unless ($pg->current_xact_session); - my $cdbi = $self->{cdbi}; + my @cols = $self->{cdbi}->columns('Essential'); + if ($NOPRIMARY) { + my ($p) = $self->{cdbi}->columns('Primary'); + @cols = grep { $_ ne $p } @cols; + } - my $pri = $cdbi->columns('Primary'); + my $col_list = join ',', @cols; - my @cols = grep {$_ ne $pri} $cdbi->columns('Essential'); + $log->debug('Starting COPY import for '.$self->{cdbi}->table." ($col_list)", DEBUG); + $self->{cdbi}->sql_copy_start($self->{cdbi}->table, $col_list)->execute; - my $col_list = join ',', @cols; + return 1; + } - $log->debug('Starting COPY import for '.$cdbi->table." ($col_list)", DEBUG); - $cdbi->sql_copy_start($cdbi->table, $col_list)->execute; + sub copy_create_push { + my $self = shift; + my $client = shift; + my @fm_nodes = @_; - my $dbh = $cdbi->db_Main; + local $OpenILS::Application::Storage::WRITE = 1; + + #return undef unless ($pg->current_xact_session); + + my @cols = $self->{cdbi}->columns('Essential'); + if ($NOPRIMARY) { + my ($p) = $self->{cdbi}->columns('Primary'); + @cols = grep { $_ ne $p } @cols; + } + + my $dbh = $self->{cdbi}->db_Main; for my $node ( @fm_nodes ) { next unless ($node); my $line = join("\t", map { defined($node->$_()) ? $node->$_() : '\N' } @cols); @@ -246,13 +265,48 @@ $dbh->pg_putline($line."\n"); } + return scalar(@fm_nodes); + } + + sub copy_create_finish { + my $self = shift; + my $client = shift; + my @fm_nodes = @_; + + local $OpenILS::Application::Storage::WRITE = 1; + + #return undef unless ($pg->current_xact_session); + + my $dbh = $self->{cdbi}->db_Main; + $dbh->pg_endcopy || $log->debug("Could not end COPY with pg_endcopy", WARN); - $log->debug('COPY import for '.$cdbi->table." ($col_list) complete", DEBUG); + $log->debug('COPY import for '.$self->{cdbi}->table." ($col_list) complete", DEBUG); + + return 1; + } + + sub copy_create { + my $self = shift; + my $client = shift; + my @fm_nodes = @_; + + local $NOPRIMARY = 1; + + copy_create_start( $self => $client ); + copy_create_push( $self => $client => @fm_nodes ); + copy_create_finish( $self => $client ); return scalar(@fm_nodes); } + sub autoprimary { + my $class = shift; + my $val = shift; + $NOPRIMARY = $val if (defined $val); + return $NOPRIMARY; + } + } 1;