[Bast-commits] r3835 - in DBIx-Class/0.09/trunk/lib/DBIx/Class: . Storage Storage/DBI

gphat at dev.catalyst.perl.org gphat at dev.catalyst.perl.org
Wed Oct 24 01:41:21 GMT 2007


Author: gphat
Date: 2007-10-24 01:41:21 +0100 (Wed, 24 Oct 2007)
New Revision: 3835

Modified:
   DBIx-Class/0.09/trunk/lib/DBIx/Class/Schema.pm
   DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage.pm
   DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/DBI.pm
   DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/DBI/Oracle.pm
   DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/DBI/Pg.pm
   DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/DBI/mysql.pm
   DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/Statistics.pm
Log:
First cut, tests to come.


Modified: DBIx-Class/0.09/trunk/lib/DBIx/Class/Schema.pm
===================================================================
--- DBIx-Class/0.09/trunk/lib/DBIx/Class/Schema.pm	2007-10-24 00:37:52 UTC (rev 3834)
+++ DBIx-Class/0.09/trunk/lib/DBIx/Class/Schema.pm	2007-10-24 00:41:21 UTC (rev 3835)
@@ -785,6 +785,57 @@
   $self->storage->txn_rollback;
 }
 
+=head2 svp_begin
+
+Creates a new savepoint (does nothing outside a transaction). 
+Equivalent to calling $schema->storage->svp_begin.  See
+L<DBIx::Class::Storage::DBI/"svp_begin"> for more information.
+
+=cut
+
+sub svp_begin {
+  my ($self, $name) = @_;
+
+  $self->storage or $self->throw_exception
+    ('svp_begin called on $schema without storage');
+
+  $self->storage->svp_begin($name);
+}
+
+=head2 svp_release
+
+Releases a savepoint (does nothing outside a transaction). 
+Equivalent to calling $schema->storage->svp_release.  See
+L<DBIx::Class::Storage::DBI/"svp_release"> for more information.
+
+=cut
+
+sub svp_release {
+  my ($self, $name) = @_;
+
+  $self->storage or $self->throw_exception
+    ('svp_release called on $schema without storage');
+
+  $self->storage->svp_release($name);
+}
+
+=head2 svp_rollback
+
+Rollback to a savepoint (does nothing outside a transaction). 
+Equivalent to calling $schema->storage->svp_rollback.  See
+L<DBIx::Class::Storage::DBI/"svp_rollback"> for more information.
+
+=cut
+
+sub svp_rollback {
+  my ($self, $name) = @_;
+
+  $self->storage or $self->throw_exception
+    ('svp_rollback called on $schema without storage');
+
+  $self->storage->svp_rollback($name);
+}
+
 =head2 clone
 
 =over 4

Modified: DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/DBI/Oracle.pm
===================================================================
--- DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/DBI/Oracle.pm	2007-10-24 00:37:52 UTC (rev 3834)
+++ DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/DBI/Oracle.pm	2007-10-24 00:41:21 UTC (rev 3835)
@@ -25,7 +25,20 @@
     }
 }
 
+sub _svp_begin {
+    my ($self, $dbh, $name) = @_;
 
+    $dbh->do("SAVEPOINT $name");
+}
+
+# Would've implemented _svp_release here, but Oracle doesn't support it.
+
+sub _svp_rollback {
+    my ($self, $dbh, $name) = @_;
+
+    $dbh->do("ROLLBACK TO SAVEPOINT $name")
+}
+
 1;
 
 =head1 NAME

Modified: DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/DBI/Pg.pm
===================================================================
--- DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/DBI/Pg.pm	2007-10-24 00:37:52 UTC (rev 3834)
+++ DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/DBI/Pg.pm	2007-10-24 00:41:21 UTC (rev 3835)
@@ -73,6 +73,24 @@
   }
 }
 
+sub _svp_begin {
+    my ($self, $dbh, $name) = @_;
+
+    $dbh->pg_savepoint($name);
+}
+
+sub _svp_release {
+    my ($self, $dbh, $name) = @_;
+
+    $dbh->pg_release($name;)
+}
+
+sub _svp_rollback {
+    my ($self, $dbh, $name) = @_;
+
+    $dbh->pg_rollback_to($name);
+}
+
 1;
 
 =head1 NAME

Modified: DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/DBI/mysql.pm
===================================================================
--- DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/DBI/mysql.pm	2007-10-24 00:37:52 UTC (rev 3834)
+++ DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/DBI/mysql.pm	2007-10-24 00:41:21 UTC (rev 3835)
@@ -16,6 +16,24 @@
   return 'MySQL';
 }
 
+sub _svp_begin {
+    my ($self, $dbh, $name) = @_;
+
+    $dbh->do("SAVEPOINT $name");
+}
+
+sub _svp_release {
+    my ($self, $dbh, $name) = @_;
+
+    $dbh->do("RELEASE SAVEPOINT $name");
+}
+
+sub _svp_rollback {
+    my ($self, $dbh, $name) = @_;
+
+    $dbh->do("ROLLBACK TO SAVEPOINT $name")
+}
+
 1;
 
 =head1 NAME

Modified: DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/DBI.pm	2007-10-24 00:37:52 UTC (rev 3834)
+++ DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/DBI.pm	2007-10-24 00:41:21 UTC (rev 3835)
@@ -861,7 +861,60 @@
   $dbh;
 }
 
+sub svp_begin {
+  my ($self, $name) = @_;
 
+  $self->throw_exception("You failed to provide a savepoint name!") if !$name;
+
+  if($self->{transaction_depth} == 0) {
+    warn("Can't use savepoints without a transaction.");
+    return 0;
+  }
+
+  if(!$self->can('_svp_begin')) {
+    warn("Your Storage implementation doesn't support savepoints!");
+    return 0;
+  }
+  $self->debugobj->svp_begin($name) if $self->debug;
+  $self->_svp_begin($self->dbh(), $name);
+}
+
+sub svp_release {
+  my ($self, $name) = @_;
+
+  $self->throw_exception("You failed to provide a savepoint name!") if !$name;
+
+  if($self->{transaction_depth} == 0) {
+    warn("Can't use savepoints without a transaction.");
+    return 0;
+  }
+
+  if(!$self->can('_svp_release')) {
+      warn("Your Storage implementation doesn't support savepoint releasing!");
+      return 0;
+  }
+  $self->debugobj->svp_release($name) if $self->debug;
+  $self->_svp_release($self->dbh(), $name);
+}
+
+sub svp_rollback {
+  my ($self, $name) = @_;
+
+  $self->throw_exception("You failed to provide a savepoint name!") if !$name;
+
+  if($self->{transaction_depth} == 0) {
+    warn("Can't use savepoints without a transaction.");
+    return 0;
+  }
+
+  if(!$self->can('_svp_rollback')) {
+      warn("Your Storage implementation doesn't support savepoints!");
+      return 0;
+  }
+  $self->debugobj->svp_rollback($name) if $self->debug;
+  $self->_svp_rollback($self->dbh(), $name);
+}
+
 sub txn_begin {
   my $self = shift;
   $self->ensure_connected();

Modified: DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/Statistics.pm
===================================================================
--- DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/Statistics.pm	2007-10-24 00:37:52 UTC (rev 3834)
+++ DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage/Statistics.pm	2007-10-24 00:41:21 UTC (rev 3835)
@@ -107,6 +107,39 @@
   $self->print("COMMIT\n");
 }
 
+=head2 svp_begin
+
+Called when a savepoint is created.
+
+=cut
+sub svp_begin {
+  my ($self, $name) = @_;
+
+  $self->print("SAVEPOINT $name\n");
+}
+
+=head2 svp_release
+
+Called when a savepoint is released.
+
+=cut
+sub svn_release {
+  my ($self, $name) = @_;
+
+ $self->print("RELEASE SAVEPOINT $name\n");
+}
+
+=head2 svp_rollback
+
+Called when rolling back to a savepoint.
+
+=cut
+sub svp_rollback {
+  my ($self, $name) = @_;
+
+ $self->print("ROLLBACK TO SAVEPOINT $name\n");
+}
+
 =head2 query_start
 
 Called before a query is executed.  The first argument is the SQL string being

Modified: DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage.pm
===================================================================
--- DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage.pm	2007-10-24 00:37:52 UTC (rev 3834)
+++ DBIx-Class/0.09/trunk/lib/DBIx/Class/Storage.pm	2007-10-24 00:41:21 UTC (rev 3835)
@@ -261,6 +261,38 @@
 
 sub txn_rollback { die "Virtual method!" }
 
+=head2 svp_begin
+
+Arguments: $savepoint_name
+
+Establishes a new savepoint of the specified name within the current
+transaction.
+
+=cut
+
+sub svp_begin { die "Virtual method!" }
+
+=head2 svp_release
+
+Arguments: $savepoint_name
+
+Destroy a savepoint, but keep the effects of the commands executed since
+it's creation.
+
+=cut
+
+sub svp_release { die "Virtual method!" }
+
+=head2 svp_rollback
+
+Arguments: $savepoint_name
+
+Rollback to the savepoint of the specified name.
+
+=cut
+
+sub svp_rollback { die "Virtual method!" }
+
 =head2 sql_maker
 
 Returns a C<sql_maker> object - normally an object of class




More information about the Bast-commits mailing list