Bio::DB::DBI Transaction
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvs
Summary
Bio::DB::DBI::Transaction - DESCRIPTION of Object
Package variables
Privates (from "my" definitions)
%transactions = ()
Included modules
Bio::Root::Root
Carp qw ( confess )
Inherit
Bio::Root::Root
Synopsis
Give standard usage here
Description
Describe the object here
Methods
newDescriptionCode
_newDescriptionCode
dbhDescriptionCode
commitDescriptionCode
rollbackDescriptionCode
get_TransactionListenersDescriptionCode
add_TransactionListenerDescriptionCode
remove_TransactionListenersDescriptionCode
remove_TransactionListenerDescriptionCode
get_TransactionDescriptionCode
Methods description
newcode    nextTop
 Title   : new
Usage :
Function: This method throws an exception. Use get_Transaction()
to get a Transaction object.
Returns :
Args :
_newcodeprevnextTop
 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 :
dbhcodeprevnextTop
 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
commitcodeprevnextTop
 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
rollbackcodeprevnextTop
 Title   : rollback
Usage :
Function: Rollback this transaction.
Read the DBI perldoc for $dbh->rollback about possible return values and behaviour. Rolling back the transaction will also notify all listeners before and after the actual rollback. Listeners cannot veto a transaction rollback. Example : Returns : The return value from $dbh->rollback() Args : none
get_TransactionListenerscodeprevnextTop
 Title   : get_TransactionListeners
Usage : @arr = get_TransactionListeners()
Function: Get the list of TransactionListener(s) for this object.
We currently do not enforce the listener objects to literally be Bio::DB::DBI::TransactionListener implementing objects. This object can handle this; use $obj->can() for every listener-specific call you invoke yourself on the returned objects. Example : Returns : An array of Bio::DB::DBI::TransactionListener objects Args :
add_TransactionListenercodeprevnextTop
 Title   : add_TransactionListener
Usage :
Function: Add one or more TransactionListener(s) to this object.
We currently do not enforce the listener objects to literally be Bio::DB::DBI::TransactionListener implementing objects. Example : Returns : Args : One or more Bio::DB::DBI::TransactionListener objects.
remove_TransactionListenerscodeprevnextTop
 Title   : remove_TransactionListeners
Usage :
Function: Remove all TransactionListeners for this class.
We currently do not enforce the listener objects to literally be Bio::DB::DBI::TransactionListener implementing objects. This object can handle this; use $obj->can() for every listener-specific call you invoke yourself on the returned objects. Example : Returns : The list of previous TransactionListeners as an array of Bio::DB::DBI::TransactionListener objects. Args :
remove_TransactionListenercodeprevnextTop
 Title   : remove_TransactionListener
Usage :
Function: Remove one TransactionListener for this class.
We currently do not enforce the listener objects to literally be Bio::DB::DBI::TransactionListener implementing objects. This object can handle this; use $obj->can() for every listener-specific call you invoke yourself on the returned objects. Example : Returns : void Args : A Bio::DB::DBI::TransactionListener object
get_TransactioncodeprevnextTop
 Title   : get_Transaction
Usage :
Function: Get the Transaction for a particular connection.
This is a class method. Example : Returns : an instance of this class Args : a DBI database connection handle for which to obtain the transaction All other arguments are passed on to new() if a new Transaction needs to be created.
Methods code
newdescriptionprevnextTop
sub new {
    my($class,@args) = @_;
    
    confess "You cannot instantiate this class from outside. ".
	"Use get_Transaction() to get an object.";
}
_newdescriptionprevnextTop
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;
}
dbhdescriptionprevnextTop
sub dbh {
    my $self = shift;

    return $self->{'dbh'} = shift if @_;
    return $self->{'dbh'};
}
commitdescriptionprevnextTop
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;
}
rollbackdescriptionprevnextTop
sub rollback {
    my $self = shift;

    foreach my $listener ($self->get_TransactionListeners()) {
	eval {
	    $listener->before_rollback() if $listener->can("before_rollback");
	};
	if($@) {
	    $self->warn(ref($listener).
			"::before_rollback threw an exception, but rollback ".
			"cannot be vetoed (message was: ".$@.")");
	}
    }
    my $rv = $self->dbh->rollback();
    foreach my $listener ($self->get_TransactionListeners()) {
	$listener->after_rollback() if $listener->can("after_rollback");
    }
    return $rv;
}
get_TransactionListenersdescriptionprevnextTop
sub get_TransactionListeners {
    my $self = shift;

    return @{$self->{'_listeners'}} if exists($self->{'_listeners'});
    return ();
}
add_TransactionListenerdescriptionprevnextTop
sub add_TransactionListener {
    my $self = shift;

    $self->{'_listeners'} = [] unless exists($self->{'_listeners'});
    push(@{$self->{'_listeners'}}, @_);
}
remove_TransactionListenersdescriptionprevnextTop
sub remove_TransactionListeners {
    my $self = shift;

    my @arr = $self->get_TransactionListeners();
    $self->{'_listeners'} = [];
    return @arr;
}
remove_TransactionListenerdescriptionprevnextTop
sub remove_TransactionListener {
    my $self = shift;
    my $obj = shift;

    my @arr = grep { $_ != $obj } $self->remove_TransactionListeners();
    $self->{'_listeners'} = [@arr];
}
get_TransactiondescriptionprevnextTop
sub get_Transaction {
    my $class = shift;
    my $dbh = shift;
    my $tx;

    if(exists($transactions{$dbh})) {
	$tx = $transactions{$dbh};
    } else {
	$tx = $class->_new("Bummer",@_);
	$tx->dbh($dbh);
	$transactions{$dbh} = $tx;
    }
    return $tx;
}

1;
}
General documentation
FEEDBACKTop
Mailing ListsTop
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to
the Bioperl mailing list. Your participation is much appreciated.
  bioperl-l@bioperl.org                  - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
Support Top
 
Please direct usage questions or support issues to the mailing list:

bioperl-l@bioperl.org

rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
Reporting BugsTop
Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via
the web:
  http://bugzilla.open-bio.org/
AUTHOR - Hilmar LappTop
Email hlapp at gmx.net
Describe contact details here
CONTRIBUTORSTop
Additional contributors names and emails here
APPENDIXTop
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _