X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBM%2FDeep%2FEngine%2FDBI.pm;h=10f5b17aa5011f350257dd22858bc9b6cded808c;hb=bd6b4f3cc1bf5f5448dc37a362d324118bbc82c5;hp=b00b98ae103a9b717a3d2aae412131e79aac793a;hpb=7c92743701bf50496060f64e671d80965654a219;p=dbsrgits%2FDBM-Deep.git diff --git a/lib/DBM/Deep/Engine/DBI.pm b/lib/DBM/Deep/Engine/DBI.pm index b00b98a..10f5b17 100644 --- a/lib/DBM/Deep/Engine/DBI.pm +++ b/lib/DBM/Deep/Engine/DBI.pm @@ -311,15 +311,68 @@ sub write_value { return 1; } -sub begin_work { die "Transactions are not supported by this engine" } -sub rollback { die "Transactions are not supported by this engine" } -sub commit { die "Transactions are not supported by this engine" } +sub begin_work { + my $self = shift; + die "Transactions are not supported by this engine" + unless $self->supports('transactions'); + + if ( $self->in_txn ) { + DBM::Deep->_throw_error( "Cannot begin_work within an active transaction" ); + } + + $self->storage->begin_work; + + $self->in_txn( 1 ); + + return 1; +} + +sub rollback { + my $self = shift; + die "Transactions are not supported by this engine" + unless $self->supports('transactions'); + + if ( !$self->in_txn ) { + DBM::Deep->_throw_error( "Cannot rollback without an active transaction" ); + } + + $self->storage->rollback; + + $self->in_txn( 0 ); + + return 1; +} + +sub commit { + my $self = shift; + die "Transactions are not supported by this engine" + unless $self->supports('transactions'); + + if ( !$self->in_txn ) { + DBM::Deep->_throw_error( "Cannot commit without an active transaction" ); + } + + $self->storage->commit; + + $self->in_txn( 0 ); + + return 1; +} + +sub in_txn { + my $self = shift; + $self->{in_txn} = shift if @_; + $self->{in_txn}; +} sub supports { - shift; + my $self = shift; my ($feature) = @_; - return if $feature eq 'transactions'; + if ( $feature eq 'transactions' ) { +# return 1 if $self->storage->driver eq 'sqlite'; + return; + } return; }