BioPerl-DB

 view release on metacpan or  search on metacpan

lib/Bio/DB/DBI/Transaction.pm  view on Meta::CPAN

use Bio::Root::Root;

@ISA = qw(Bio::Root::Root );

my %transactions = ();

=head2 new

 Title   : new
 Usage   : 
 Function: This method throws an exception. Use get_Transaction() 
           to get a Transaction object.
 Returns : 
 Args    :


=cut

sub new {
    my($class,@args) = @_;
    
    confess "You cannot instantiate this class from outside. ".
	"Use get_Transaction() to get an object.";
}

=head2 _new

 Title   : _new
 Usage   : my $obj = Bio::DB::DBI::Transaction->_new();
 Function: Builds a new Bio::DB::DBI::Transaction object 

           This is a private method. If you call this method from
           outside you are on your own. Call get_Transaction() to
           obtain an instance of this class.

 Returns : an instance of Bio::DB::DBI::Transaction
 Args    :


=cut

sub _new {
    my($class,@args) = @_;

    # silly trick but maybe catches some silly people who don't believe
    my $bummer = pop(@args);
    return $class->new($bummer, @args) unless $bummer && ($bummer eq "Bummer");

    my $self = $class->SUPER::new(@args);
    return $self;
}

=head2 dbh

 Title   : dbh
 Usage   :
 Function: Get/set the database connection handle for this transaction.
           Transactions are connection-specific.

           You should not need to call this method from outside. If
           you do, call yourself bold, but you're on your own ...

 Example :
 Returns : A DBI database connection handle 
 Args    : on set, the new DBI database connection handle


=cut

sub dbh{
    my $self = shift;

    return $self->{'dbh'} = shift if @_;
    return $self->{'dbh'};
}

=head2 commit

 Title   : commit
 Usage   :
 Function: Commit this transaction.

           Read the DBI perldoc for $dbh->commit about possible
           return values and behaviour.

           Committing the transaction will also notify all listeners
           before and after the actual commit. Listeners have the
           opportunity to veto a transaction commit by returning
           false from their before_commit() method.

 Example :
 Returns : The return value from $dbh->commit()
 Args    : none


=cut

sub commit{
    my $self = shift;

    foreach my $listener ($self->get_TransactionListeners()) {
	if($listener->can("before_commit")) {
	    $listener->before_commit() || return;
	}
    }
    my $rv = $self->dbh->commit();
    foreach my $listener ($self->get_TransactionListeners()) {
	$listener->after_commit() if $listener->can("after_commit");
    }
    return $rv;
}

=head2 rollback

 Title   : rollback
 Usage   :
 Function: Rollback this transaction.

           Read the DBI perldoc for $dbh->rollback about possible
           return values and behaviour.



( run in 0.752 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )