ETLp

 view release on metacpan or  search on metacpan

lib/ETLp/Loader/OracleSQLLoader.pm  view on Meta::CPAN

package ETLp::Loader::OracleSQLLoader;

use MooseX::Declare;

=head1 NAME

ETLp::Loader::OracleSQLLoader - Load data using SQL*Loader

=head1 SYNOPSIS

This module will load data using Oracle's SQL*Loader utility. It is designed
to be used when:

    * The backend database is Oracle
    * The functionality is not provided by ETLp::Loader::CSV
    * Speed is of the essence, and features such as direct path or
      parallel loading are required.

For Example

    use ETLp::Loader::OracleSQLLoader;

    my $sqlldr = ETLp::Loader::OracleSQLLoader->new(
        userid           => 'scott/tiger',
        table            => 'scores',
        filename         => "$data_directory/$filename",
        specification    => $specification,
        mode             => 'truncate',
        controlfile      => "$outfile_directory/$filename.ctl",
        logfile          => "$outfile_directory/$filename.log",
        discardfile      => "$outfile_directory/$filename.dsc",
        badfile          => "$outfile_directory/$filename.bad",
    );
    
    my $recode = $sqlldr->load;
    
    if ($retcode) {
        print $sqlldr->error;
    }
    
=cut

class ETLp::Loader::OracleSQLLoader with ETLp::Role::Config {
    use ETLp::Exception;
    use ETLp::Types;
    
    has 'userid'           => (is => 'ro', isa => 'Str',  required => 1);
    has 'controlfile'      => (is => 'ro', isa => 'Str',  required => 1);
    has 'table'            => (is => 'ro', isa => 'Str',  required => 1);
    has 'filename'         => (is => 'ro', isa => 'Str',  required => 1);
    has 'specification'    => (is => 'ro', isa => 'Str',  required => 1);
    has 'logfile'          => (is => 'ro', isa => 'Maybe[Str]');
    has 'badfile'          => (is => 'ro', isa => 'Maybe[Str]');
    has 'discardfile'      => (is => 'ro', isa => 'Maybe[Str]');
    has 'keep_controlfile' => (is => 'ro', isa => 'Bool', default  => 0);
    has 'keep_logfile'     => (is => 'ro', isa => 'Bool', default  => 1);
    has 'keep_badfile'     => (is => 'ro', isa => 'Bool', default  => 1);
    has 'keep_discardfile' => (is => 'ro', isa => 'Bool', default  => 1);
    has 'parameters'       => (is => 'ro', isa => 'Maybe[HashRef]');
    has 'localize'         => (is => 'ro', isa => 'Bool', default  => 0);
    has 'mode' => (is => 'ro', isa => 'SQLLoaderMode', default => 'append');
    
    our @keywords = qw/
        discardmax
        skip
        load
        errors
        rows
        bindsize
        silent
        direct
        parfile
        parallel
        file
        skip_unusable_indexes
        skip_index_maintenance
        readsize
        external_table
        columnarrayrows
        streamsize
        multithreading
        resumable
        resumable_name
        resumable_timeout
    /;
    
=head1 METHODS

=head2 new

Creates a new ETLp::Loader::OracleSQLLoader object. Accespts the
following attributes:

    * userid. Required. The username and password of the user connecting
      to the database, in the form:
          o <user>/<password> or
          o <user>/<password>@<tns alias>
    * controlfile. Required. The name of the control file. The content
      will be generated by this module.
    * table. Required. The name of the table that the data will be loaded
      into
    * filename. Required. The file to be loaded.
    * mode. Optional. The type of load - append, truncate, insert or
      replace. Defaults to append
    * specification. Required. The specification of the incoming file and
      the processing. E.g.
      
            fields terminated by "," 
            (id, name, score, file_id constant 4)
            
    * logfile. Optional. The name of the log file
    * badfile. Optional. The name of the bad file.
    * discardfile . Optional. The name of the discardfile.
    * keep_controlfile. Optional. Whether to keep the control file
      following processing. Defaults to no (0).
    * keep_logfile. Optional. Whether to keep the log file
      following processing. Defaults to yes (1).
    * keep_badfile. Optional. Whether to keep the bad file
      following processing. Defaults to yes (1).



( run in 1.749 second using v1.01-cache-2.11-cpan-39bf76dae61 )