| 1 | #!perl | ||
| 2 | |||
| 3 | # ########################################################################## # | ||
| 4 | # Title: Data stream sink | ||
| 5 | # Creation date: 2007-04-16 | ||
| 6 | # Author: Michael Zedeler | ||
| 7 | # Description: Receives data, binds to statement handle parameters and | ||
| 8 | # executes statement handle for each row. | ||
| 9 | # Data Stream class | ||
| 10 | # File: $Source: /data/cvs/lib/DSlib/lib/DS/Transformer/Sth.pm,v $ | ||
| 11 | # Repository: kronhjorten | ||
| 12 | # State: $State: Exp $ | ||
| 13 | # Documentation: inline | ||
| 14 | # Recepient: - | ||
| 15 | # ########################################################################## # | ||
| 16 | |||
| 17 | package DS::Transformer::Sth; | ||
| 18 | |||
| 19 | use base qw{ DS::Target }; | ||
| 20 | |||
| 21 | use strict; | ||
| 22 | |||
| 23 | our ($VERSION) = $DS::VERSION; | ||
| 24 | our ($REVISION) = '$Revision: 1.1 $' =~ /(\d+\.\d+)/; | ||
| 25 | our ($STATE) = '$State: Exp $' =~ /:\s+(.+\S)\s+\$$/; | ||
| 26 | |||
| 27 | sub new { | ||
| 28 | my( $class, $sth, $bind_map, $in_type, $out_type, $source, $target ) = @_; | ||
| 29 | |||
| 30 | my $self = $class->SUPER::new( $in_type, $out_type, $source, $target ); | ||
| 31 | |||
| 32 | #TODO Make sure that $bind_map and $in_type corresponds | ||
| 33 | |||
| 34 | should( ref( $sth ) => 'DBI::st' ); | ||
| 35 | should( ref( $bind_map ) => 'HASH' ); | ||
| 36 | |||
| 37 | $self->{sth} = $bind_map; | ||
| 38 | $self->{bind_map} = $bind_map; | ||
| 39 | |||
| 40 | return $self; | ||
| 41 | } | ||
| 42 | |||
| 43 | sub process { | ||
| 44 | my( $self, $row ) = @_; | ||
| 45 | |||
| 46 | foreach my $parnum ( keys %{$self->{bind_map}} ) { | ||
| 47 | my $field = $self->{bind_map}->{$parnum}; | ||
| 48 | $self->{sth}->bind_param( $parnum, $row->{ $field } ); | ||
| 49 | } | ||
| 50 | |||
| 51 | $self->{sth}->execute(); | ||
| 52 | |||
| 53 | return $row; | ||
| 54 | } | ||
| 55 | |||
| 56 | 1; |