#!/usr/bin/perl
=head1 testdbf
Job testdbf, version 0.1, status .
Purpose:
=cut
use talend::runstat;
use routines::system::Date;
use routines::system::Misc;
use routines::system::Numeric;
use routines::system::String;
my $_licence = <<'END_OF_LICENCE';
Copyright (c) 2005-2008, Talend Inc.
=
/ JobDesigner (CodeGenerator version 3.2.1.r31371).
You can find more information about Talend products at http://www.talend.com.
You may distribute this code under the terms of the GNU LGPL license
(http://www.gnu.org/licenses/lgpl.html).
END_OF_LICENCE
# print $_licence;
use Getopt::Long;
use Time::HiRes qw/gettimeofday tv_interval time/;
my %opt = ();
GetOptions(
\%opt,
(
'context=s',
'stat_port=i',
'trace_port=i',
'client_host=s',
'watch',
'pid=s',
'father_pid=s',
'root_pid=s',
'context_param=s%',
'context_param_encoding=s',
)
);
$defaultClientHost = "127.0.0.1";
$clientHost = $opt{client_host} ? $opt{client_host} : $defaultClientHost;
our %_context;
our %_globals;
$_globals{pid} = defined $opt{pid}
? $opt{pid}
: getRandomString(6, ['a'..'z', 'A'..'Z', 0..9])
;
$_globals{father_pid} = defined $opt{father_pid}
? $opt{father_pid}
: $_globals{pid}
;
$_globals{root_pid} = defined $opt{root_pid}
? $opt{root_pid}
: $_globals{pid}
;
$_globals{job_name} = 'testdbf';
$_globals{job_repository_id} = '__10BsN4yEd6HpvTRZtNZmA';
$_globals{job_version} = '0.1';
$_globals{system_pid} = $$;
$_globals{project_name} = 'DBF_PERL';
$_globals{start} = [gettimeofday];
$_globals{job_execution_datetime} = getDate('CCYY-MM-DD hh:mm:ss');
if (defined $opt{context}) {
my $context_filename =
$_globals{project_name}
.'.job_'.$_globals{job_name}
.'_'.$_globals{job_version}
.'_'.$opt{context}
.'.pl'
;
use FindBin;
use lib $FindBin::Bin;
require $context_filename;
}
if (defined $opt{context_param}) {
my $cb = undef;
if (defined $opt{context_param_encoding}) {
require Convert::BaseN;
$cb = Convert::BaseN->new(base => $opt{context_param_encoding});
}
foreach my $key (keys %{ $opt{context_param} }) {
my $raw_value = $opt{context_param}{$key};
$_context{$key} = defined $cb ? $cb->decode($raw_value) : $raw_value;
}
}
use constant true => 1;
use constant false => 0;
use constant null => undef;
$SIG{__DIE__} = \&global_die_catcher;
$current_component = undef;
$current_component = undef;
sub global_die_catcher {
# go away if we are inside an eval
return if $^S;
our $_globals;
$_globals{job_failure} = 1;
if (defined $current_component) {
my $dying_component = $current_component;
my $exception = $_[0];
chomp($exception);
$_globals{$dying_component}{ERROR_MESSAGE} = $exception;
no strict 'refs';
&{$dying_component.'_error'}();
}
# if the error was catched, we say to the father job that everything is OK
if ($_globals{job_failure} == 0) {
exit(0);
}
}
# OnComponentError dedicated subs for all components of the job design
sub tFileInputXbase_1_error() {
# even if the error was "catched" in an OnComponentError, we call the
# corresponding OnSubjobError sub
tFileInputXbase_1_onSubjobError();
}
sub tLogRow_1_error() {
# even if the error was "catched" in an OnComponentError, we call the
# corresponding OnSubjobError sub
tFileInputXbase_1_onSubjobError();
}
# OnSubjobError dedicated subs for all components responsible (starting) a
# subjob
sub tFileInputXbase_1_onSubjobError() {
}
# +-------------------------------------------------------------------------+
# | [subprocess header] starts here |
# +-------------------------------------------------------------------------+
sub tFileInputXbase_1_subprocess {
# +-------------------------------------------------------------------------+
# | [subprocess header] stops here |
# +-------------------------------------------------------------------------+
# +-------------------------------------------------------------------------+
# | [tLogRow_1 begin ] start
# +-------------------------------------------------------------------------+
$current_component="tLogRow_1";
=head1 tLogRow tLogRow_1
=cut
$_globals{tLogRow_1}{OK} = false;
$_globals{tLogRow_1}{start} = [gettimeofday];
$count_row1 = 0;
$last_stat_update_of_row1 = time();
SendStat(
'row1'.(defined $exec_number ? '.'.$exec_number : ''),
$count_row1,
0,
'start'
);
my %desc_tLogRow_1 = (
schema => [
{
name => 'ord_num',
},
{
name => 'cust_num',
},
{
name => 'evtdate',
},
{
name => 'bookdate',
},
{
name => 'status',
},
{
name => 'partyname',
},
{
name => 'theme',
},
{
name => 'salesrep',
},
{
name => 'category',
},
{
name => 'plnguests',
},
{
name => 'subtotal',
},
{
name => 'tax',
},
{
name => 'servchg',
},
{
name => 'paid',
},
],
);
my @colnames_tLogRow_1 = map {$_->{name}} @{ $desc_tLogRow_1{schema} };
my @collengths_tLogRow_1 = map {$_->{printLength}} @{ $desc_tLogRow_1{schema} };
my $line_num_tLogRow_1 = 0;
# +-------------------------------------------------------------------------+
# | [tLogRow_1 begin ] stop
# +-------------------------------------------------------------------------+
# +-------------------------------------------------------------------------+
# | [tFileInputXbase_1 begin ] start
# +-------------------------------------------------------------------------+
$current_component="tFileInputXbase_1";
=head1 tFileInputXbase tFileInputXbase_1
=cut
$_globals{tFileInputXbase_1}{OK} = false;
$_globals{tFileInputXbase_1}{start} = [gettimeofday];
use FileHandle;
use List::Util qw/min/;
use Xbase;
use talend::filesOp;
my %desc_tFileInputXbase_1 = (
filename => 'C:/Documents and Settings/Administrador/Escritorio/Meson/EVENTS.DBF',
header => 0,
footer => 0,
limit => null,
schema => [
{
name => 'ord_num',
key => false,
type => '',
len => null,
null => true,
default => '',
comment => '',
},
{
name => 'cust_num',
key => false,
type => '',
len => null,
null => true,
default => '',
comment => '',
},
{
name => 'evtdate',
key => false,
type => '',
len => null,
null => true,
default => '',
comment => '',
},
{
name => 'bookdate',
key => false,
type => '',
len => null,
null => true,
default => '',
comment => '',
},
{
name => 'status',
key => false,
type => '',
len => null,
null => true,
default => '',
comment => '',
},
{
name => 'partyname',
key => false,
type => '',
len => null,
null => true,
default => '',
comment => '',
},
{
name => 'theme',
key => false,
type => '',
len => null,
null => true,
default => '',
comment => '',
},
{
name => 'salesrep',
key => false,
type => '',
len => null,
null => true,
default => '',
comment => '',
},
{
name => 'category',
key => false,
type => '',
len => null,
null => true,
default => '',
comment => '',
},
{
name => 'plnguests',
key => false,
type => '',
len => null,
null => true,
default => '',
comment => '',
},
{
name => 'subtotal',
key => false,
type => '',
len => null,
null => true,
default => '',
comment => '',
},
{
name => 'tax',
key => false,
type => '',
len => null,
null => true,
default => '',
comment => '',
},
{
name => 'servchg',
key => false,
type => '',
len => null,
null => true,
default => '',
comment => '',
},
{
name => 'paid',
key => false,
type => '',
len => null,
null => true,
default => '',
comment => '',
},
]
);
my $nb_fields_tFileInputXbase_1 = scalar @{ $desc_tFileInputXbase_1{schema} };
my $dbf_tFileInputXbase_1 = new Xbase;
$dbf_tFileInputXbase_1->open_dbf($desc_tFileInputXbase_1{filename});
$nb_line_tFileInputXbase_1 = 0;
my $total_line_tFileInputXbase_1 = $dbf_tFileInputXbase_1->lastrec;
my ($first_row_tFileInputXbase_1, $last_row_tFileInputXbase_1) = getFirstAndLastRowNumber(
header => $desc_tFileInputXbase_1{header},
footer => $desc_tFileInputXbase_1{footer},
limit => $desc_tFileInputXbase_1{limit},
total => $total_line_tFileInputXbase_1,
);
$first_row_tFileInputXbase_1 = $first_row_tFileInputXbase_1 - 1;
$last_row_tFileInputXbase_1 = $last_row_tFileInputXbase_1 -1;
$dbf_tFileInputXbase_1->go_top;
######loop
if ($first_row_tFileInputXbase_1 > 0) {
for (0 .. $first_row_tFileInputXbase_1-1) {
$dbf_tFileInputXbase_1->go_next;
}
}
for ($first_row_tFileInputXbase_1 .. $last_row_tFileInputXbase_1) {
@fields = $dbf_tFileInputXbase_1->get_record;
my @line_tFileInputXbase_1 = ();
$nb_line_tFileInputXbase_1++;
$dbf_tFileInputXbase_1->go_next;
my $tFileInputXbase_1 = [(@fields)[0 .. $nb_fields_tFileInputXbase_1 - 1]];
# +-------------------------------------------------------------------------+
# | [tFileInputXbase_1 begin ] stop
# +-------------------------------------------------------------------------+
# +-------------------------------------------------------------------------+
# | [tFileInputXbase_1 main ] start
# +-------------------------------------------------------------------------+
$current_component="tFileInputXbase_1";
my $row1 = $tFileInputXbase_1;
# +-------------------------------------------------------------------------+
# | [tFileInputXbase_1 main ] stop
# +-------------------------------------------------------------------------+
# +-------------------------------------------------------------------------+
# | [tLogRow_1 main ] start
# +-------------------------------------------------------------------------+
$current_component="tLogRow_1";
$now = time();
$count_row1++;
if ($now - $last_stat_update_of_row1 >= 2) {
$last_stat_update_of_row1 = $now;
my $duration = int(
1000 * tv_interval(
$_globals{tLogRow_1}{start},
[gettimeofday]
)
);
SendStat(
'row1'.(defined $exec_number ? '.'.$exec_number : ''),
$count_row1,
$duration
);
}
my $tLogRow_1 = $row1;
$line_num_tLogRow_1++;
$colnum1 = 0;
$colnum2 = 0;
print STDOUT (
join(
'|',
@$tLogRow_1
),
"\n"
)
or die "[tLogRow_1] can't print to STDOUT\n";
# +-------------------------------------------------------------------------+
# | [tLogRow_1 main ] stop
# +-------------------------------------------------------------------------+
# +-------------------------------------------------------------------------+
# | [ |
# +-------------------------------------------------------------------------+
# +-------------------------------------------------------------------------+
# | [tFileInputXbase_1 end ] start
# +-------------------------------------------------------------------------+
$current_component="tFileInputXbase_1";
}
$_globals{tFileInputXbase_1}{NB_LINE} = $nb_line_tFileInputXbase_1;
$_globals{tFileInputXbase_1}{OK} = true;
# +-------------------------------------------------------------------------+
# | [tFileInputXbase_1 end ] stop
# +-------------------------------------------------------------------------+
# +-------------------------------------------------------------------------+
# | [tLogRow_1 end ] start
# +-------------------------------------------------------------------------+
$current_component="tLogRow_1";
$duration = int(
1000 * tv_interval(
$_globals{tLogRow_1}{start},
[gettimeofday]
)
);
SendStat(
'row1'.(defined $exec_number ? '.'.$exec_number : ''),
$count_row1,
$duration,
'stop'
);
$_globals{tLogRow_1}{OK} = true;
# +-------------------------------------------------------------------------+
# | [tLogRow_1 end ] stop
# +-------------------------------------------------------------------------+
# +-------------------------------------------------------------------------+
# | [subprocess footer] starts here |
# +-------------------------------------------------------------------------+
}
# +-------------------------------------------------------------------------+
# | [subprocess footer] stops here |
# +-------------------------------------------------------------------------+
# +-------------------------------------------------------------------------+
# | [footer] starts here |
# +-------------------------------------------------------------------------+
StartStat($opt{stat_port}, $clientHost) if defined $opt{stat_port};
my $pid = undef;
tFileInputXbase_1_subprocess();
$_globals{stop} = [gettimeofday];
$_globals{duration} = int(
tv_interval(
$_globals{start},
$_globals{stop}
)
* 1000
);
if (defined $opt{watch}) {
printf(
"===\nexecution time: %u milliseconds\n===\n",
$_globals{duration}
);
}
sub wait_for_a_kid
{
my $pid = wait;
return 0 if $pid < 0;
1;
}
# +-------------------------------------------------------------------------+
# | [footer] stops here |
# +-------------------------------------------------------------------------+
# +-------------------------------------------------------------------------+
# 16.646 characters generated by Talend Open Studio
# on the 1 de diciembre de 2009 4:36:46 GMT
# +-------------------------------------------------------------------------+