Changeset 6

Show
Ignore:
Timestamp:
05/03/06 23:59:06 (4 years ago)
Author:
sky
Message:

r9@crucially-3 (orig r926): btrott | 2005-06-23 14:32:15 -0700
Moved default init_db into DBI.pm.
Removed audit stuff from BaseObject.


Location:
trunk/lib/Data
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/Data/ObjectDriver.pm

    r5 r6  
    1010## refactoring the DBI.pm code 
    1111##      - ability to define column => database for each value 
    12 ##      - plugin interface for doing things like audit, filters 
     12##      - plugin interface for doing things like audit, filters, column_defs 
    1313## test suite 
    1414## dbh needs to stay around at least as long as sth in iterator 
  • trunk/lib/Data/ObjectDriver/BaseObject.pm

    r4 r6  
    8383 
    8484sub column_names { 
    85     my $obj = shift; 
    86     my $props = $obj->properties; 
    87     my @cols = @{ $props->{columns} }; 
    88     push @cols, qw( created_on modified_on ) 
    89         if $props->{audit}; 
    90     \@cols; 
     85    ## Reference to a copy. 
     86    [ @{ shift->properties->{columns} } ] 
    9187} 
    9288 
  • trunk/lib/Data/ObjectDriver/Driver/DBI.pm

    r5 r6  
    2222    ## Rebless the driver into the DSN-specific subclass (e.g. "mysql"). 
    2323    my($type) = lc($driver->dsn) =~ /^dbi:(\w*)/; 
    24     my $class = __PACKAGE__ . '::' . $type; 
     24    my $class = ref($driver) . '::' . $type; 
    2525    eval "use $class"; 
    2626    die $@ if $@; 
     
    4545# Override in DB Driver to pass correct attributes to bind_param call 
    4646sub bind_param_attributes { return undef } 
     47 
     48sub init_db { 
     49    my $driver = shift; 
     50    my $dbh; 
     51    eval { 
     52        local $SIG{ALRM} = sub { die "alarm\n" }; 
     53        $dbh = DBI->connect($driver->dsn, $driver->username, $driver->password, 
     54            { RaiseError => 1, PrintError => 0, AutoCommit => 1 }) 
     55            or Carp::croak("Connection error: " . $DBI::errstr); 
     56        alarm 0; 
     57    }; 
     58    if ($@) { 
     59        Carp::croak(@$ eq "alarm\n" ? "Connection timeout" : $@); 
     60    } 
     61    $dbh; 
     62} 
    4763 
    4864sub rw_handle { 
  • trunk/lib/Data/ObjectDriver/Driver/DBI/mysql.pm

    r4 r6  
    99sub fetch_id { $_[1]->{mysql_insertid} || $_[1]->{insertid} } 
    1010 
    11 sub init_db { 
    12     my $driver = shift; 
    13     my $dbh; 
    14     eval { 
    15         local $SIG{ALRM} = sub { die "alarm\n" }; 
    16         $dbh = DBI->connect($driver->dsn, $driver->username, $driver->password, 
    17             { RaiseError => 1, PrintError => 0, AutoCommit => 1 }) 
    18             or Carp::croak("Connection error: " . $DBI::errstr); 
    19         alarm 0; 
    20     }; 
    21     if ($@) { 
    22         Carp::croak(@$ eq "alarm\n" ? "Connection timeout" : $@); 
    23     } 
    24     $dbh; 
    25 } 
    26  
    2711sub commit   { 1 } 
    2812sub rollback { 1 }