[Bast-commits] r5125 - in DBIx-Class-OptimisticLocking/1.000/trunk:
. lib/DBIx/Class t t/lib t/lib/OLTest t/lib/OLTest/Schema t/var
bpphillips at dev.catalyst.perl.org
bpphillips at dev.catalyst.perl.org
Thu Nov 13 22:01:34 GMT 2008
Author: bpphillips
Date: 2008-11-13 22:01:34 +0000 (Thu, 13 Nov 2008)
New Revision: 5125
Added:
DBIx-Class-OptimisticLocking/1.000/trunk/t/01-dirty.t
DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/
DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/.OLTest.pm.swo
DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest.pm
DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/
DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema.pm
DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/
DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestAll.pm
DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestDirty.pm
DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestDirtyInsignificant.pm
DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestVersion.pm
DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestVersionAlt.pm
DBIx-Class-OptimisticLocking/1.000/trunk/t/var/
DBIx-Class-OptimisticLocking/1.000/trunk/t/var/oltest.sql
Modified:
DBIx-Class-OptimisticLocking/1.000/trunk/Changes
DBIx-Class-OptimisticLocking/1.000/trunk/Makefile.PL
DBIx-Class-OptimisticLocking/1.000/trunk/README
DBIx-Class-OptimisticLocking/1.000/trunk/lib/DBIx/Class/OptimisticLocking.pm
DBIx-Class-OptimisticLocking/1.000/trunk/t/boilerplate.t
Log:
first round of unit tests (it works!)
Modified: DBIx-Class-OptimisticLocking/1.000/trunk/Changes
===================================================================
--- DBIx-Class-OptimisticLocking/1.000/trunk/Changes 2008-11-13 22:01:10 UTC (rev 5124)
+++ DBIx-Class-OptimisticLocking/1.000/trunk/Changes 2008-11-13 22:01:34 UTC (rev 5125)
@@ -1,5 +1,5 @@
Revision history for DBIx-Class-OptimisticLocking
-0.01 Date/time
+0.01 2008-11-13
First version, released on an unsuspecting world.
Modified: DBIx-Class-OptimisticLocking/1.000/trunk/Makefile.PL
===================================================================
--- DBIx-Class-OptimisticLocking/1.000/trunk/Makefile.PL 2008-11-13 22:01:10 UTC (rev 5124)
+++ DBIx-Class-OptimisticLocking/1.000/trunk/Makefile.PL 2008-11-13 22:01:34 UTC (rev 5125)
@@ -13,6 +13,7 @@
PL_FILES => {},
PREREQ_PM => {
'Test::More' => 0,
+ 'DBIx::Class' => 0,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'DBIx-Class-OptimisticLocking-*' },
Modified: DBIx-Class-OptimisticLocking/1.000/trunk/README
===================================================================
--- DBIx-Class-OptimisticLocking/1.000/trunk/README 2008-11-13 22:01:10 UTC (rev 5124)
+++ DBIx-Class-OptimisticLocking/1.000/trunk/README 2008-11-13 22:01:34 UTC (rev 5125)
@@ -1,17 +1,7 @@
DBIx-Class-OptimisticLocking
-The README is used to introduce the module and provide instructions on
-how to install the module, any machine dependencies it may have (for
-example C compilers and installed libraries) and any other information
-that should be provided before the module is installed.
+This module provides optimistic locking support to DBIx::Class.
-A README file is required for CPAN modules since CPAN extracts the README
-file from a module distribution so that people browsing the archive
-can use it to get an idea of the module's uses. It is usually a good idea
-to provide version information here so that people can decide whether
-fixes for the module are worth downloading.
-
-
INSTALLATION
To install this module, run the following commands:
Modified: DBIx-Class-OptimisticLocking/1.000/trunk/lib/DBIx/Class/OptimisticLocking.pm
===================================================================
--- DBIx-Class-OptimisticLocking/1.000/trunk/lib/DBIx/Class/OptimisticLocking.pm 2008-11-13 22:01:10 UTC (rev 5124)
+++ DBIx-Class-OptimisticLocking/1.000/trunk/lib/DBIx/Class/OptimisticLocking.pm 2008-11-13 22:01:34 UTC (rev 5125)
@@ -118,6 +118,20 @@
return exists $columns{$column} ? $columns{$column} : ();
}
+=head1 EXTENDED METHODS
+
+=head2 set_column
+
+See L<DBIx::Class::Row::set_column> for basic usage.
+
+In addition to the basic functionality, this method will track the
+original value of the column if the optimistic locking mode is set
+to C<dirty> or C<all> and this is the first time this column has been
+updated. So it can be used as a C<WHERE> condition when the C<UPDATE>
+is issued.
+
+=cut
+
sub set_column {
my $self = shift;
my ($column) = @_;
@@ -138,7 +152,17 @@
return $self->next::method(@_);
}
+=head2 update
+See L<DBIx::Class::Row::update> for basic usage.
+
+Before issuing the actual update, this component injects additional
+criteria that will be used in the C<WHERE> clause in the C<UPDATE>. The
+criteria that is used depends on the L<CONFIGURATION> defined in the
+model class.
+
+=cut
+
sub update {
my $self = shift;
my $upd = shift;
@@ -161,7 +185,7 @@
# here to make sure it has all the elements we need (kind of a hack)
$self->{_orig_ident} = $self->_optimistic_locking_ident_condition;
- my $return = $self->next::method(@_);
+ my $return = $self->next::method();
# flush the original values cache
undef $self->{_opt_locking_orig_values};
Added: DBIx-Class-OptimisticLocking/1.000/trunk/t/01-dirty.t
===================================================================
--- DBIx-Class-OptimisticLocking/1.000/trunk/t/01-dirty.t (rev 0)
+++ DBIx-Class-OptimisticLocking/1.000/trunk/t/01-dirty.t 2008-11-13 22:01:34 UTC (rev 5125)
@@ -0,0 +1,47 @@
+use strict;
+use warnings;
+use Test::More;
+
+
+BEGIN {
+ eval "use DBD::SQLite";
+ plan $@
+ ? ( skip_all => 'needs DBD::SQLite for testing' )
+ : ( tests => 7 );
+}
+
+use lib 't/lib';
+
+use_ok('DBIx::Class::OptimisticLocking');
+
+use_ok( 'OLTest' );
+
+use_ok( 'OLTest::Schema' );
+
+my $s = OLTest->init_schema();
+
+my $r1 = $s->resultset('TestDirty')->new({
+ col1 => 'a',
+ col2 => 'a',
+ col3 => 'a',
+});
+$r1->insert;
+
+my $r2 = $s->resultset('TestDirty')->find($r1->id);
+is($r1->id, $r2->id, 'retrieved identical object');
+$r1->col1('b');
+$r2->col1('c');
+$r1->update;
+
+# this will fail because $r2->col1 doesn't match the database anymore
+eval { $r2->update };
+ok($@,'error expected');
+
+$r2 = $s->resultset('TestDirty')->find($r1->id);
+$r2->col1('c');
+$r2->update;
+is($r2->col1,'c', 'update succeeded');
+
+$r1->col2('b');
+$r1->update;
+is($r1->col2, 'b', "different column updates don't clash");
Modified: DBIx-Class-OptimisticLocking/1.000/trunk/t/boilerplate.t
===================================================================
--- DBIx-Class-OptimisticLocking/1.000/trunk/t/boilerplate.t 2008-11-13 22:01:10 UTC (rev 5124)
+++ DBIx-Class-OptimisticLocking/1.000/trunk/t/boilerplate.t 2008-11-13 22:01:34 UTC (rev 5125)
@@ -36,9 +36,6 @@
);
}
-TODO: {
- local $TODO = "Need to replace the boilerplate text";
-
not_in_file_ok(README =>
"The README is used..." => qr/The README is used/,
"'version information here'" => qr/to provide version information/,
@@ -49,7 +46,3 @@
);
module_boilerplate_ok('lib/DBIx/Class/OptimisticLocking.pm');
-
-
-}
-
Added: DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/.OLTest.pm.swo
===================================================================
--- DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/.OLTest.pm.swo (rev 0)
+++ DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/.OLTest.pm.swo 2008-11-13 22:01:34 UTC (rev 5125)
@@ -0,0 +1,2 @@
+b0VIM 7.1 ¡IÀÁ Ñ8 bphillips bphillips-vbox-ubuntu ~bphillips/git/DBIx-Class-OptimisticLocking/t/lib/OLTest.pm
3210#"! U tp ÿ 2 ad X
+ 4 2 æ Ý Ü Ð Â Á b P : ' & î Ü ¤ [ U J å
Ó
z
1
+
Ü Ö Â À ¿ « { z R 0 * ú é ¾ ¬ d @ : 8 7 4 3 1; } } for split( /;\n/, $sql ); ( $schema->storage->dbh->do($_) || print "Error on SQL: $_\n" ) close IN; { local $/ = undef; $sql = <IN>; } my $sql; open IN, "t/var/oltest.sql"; else { } return $schema->deploy(); if ( $ENV{"OLTEST_SQLT_DEPLOY"} ) { my $schema = shift; my $self = shift; sub deploy_schema { } return $schema; } __PACKAGE__->deploy_schema($schema); unless ( $args{no_deploy} ) { } $schema->storage->on_connect_do( ['PRAGMA synchronous = OFF'] ); $schema->connect( "dbi:SQLite:t/var/oltest.db", "", "", { AutoCommit => 1 } ); $schema = if ( !$args{no_connect} ) { } $schema = OLTest::Schema->compose_namespace('OLTest'); else { } "dbi:SQLite:t/var/oltest.db", "", "", { AutoCommit => 1 } ); OLTest::Schema->compose_connection( 'OLTest', $schema = if ( $args{compose_connection} ) { my $schema; my %args = @_; my $self = shift; sub init_schema { # much of this is ripped directly from DBIx::Class::VirtualColumns (thanks for the jumpstart!) use warnings; use strict; OLTest; package # hide from PAUSE
\ No newline at end of file
Added: DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestAll.pm
===================================================================
--- DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestAll.pm (rev 0)
+++ DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestAll.pm 2008-11-13 22:01:34 UTC (rev 5125)
@@ -0,0 +1,14 @@
+package OLTest::Schema::TestAll;
+
+use strict;
+use warnings;
+use base qw/DBIx::Class/;
+__PACKAGE__->load_components(qw/ OptimisticLocking PK::Auto Core /);
+__PACKAGE__->table('test_all');
+__PACKAGE__->add_columns(
+ qw/ id col1 col2 col3 /
+);
+
+__PACKAGE__->optimistic_locking_mode('all');
+
+1;
Added: DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestDirty.pm
===================================================================
--- DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestDirty.pm (rev 0)
+++ DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestDirty.pm 2008-11-13 22:01:34 UTC (rev 5125)
@@ -0,0 +1,13 @@
+package OLTest::Schema::TestDirty;
+
+use strict;
+use warnings;
+use base qw/DBIx::Class/;
+__PACKAGE__->load_components(qw/ OptimisticLocking PK::Auto Core /);
+__PACKAGE__->table('test_dirty');
+__PACKAGE__->add_columns(
+ qw/ id col1 col2 col3 /
+);
+__PACKAGE__->set_primary_key(qw/id/);
+
+1;
Added: DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestDirtyInsignificant.pm
===================================================================
--- DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestDirtyInsignificant.pm (rev 0)
+++ DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestDirtyInsignificant.pm 2008-11-13 22:01:34 UTC (rev 5125)
@@ -0,0 +1,14 @@
+package OLTest::Schema::TestDirtyInsignificant;
+
+use strict;
+use warnings;
+use base qw/DBIx::Class/;
+__PACKAGE__->load_components(qw/ OptimisticLocking PK::Auto Core /);
+__PACKAGE__->table('test_dirty_insignificant');
+__PACKAGE__->add_columns(
+ qw/ id col1 col2 col3 /
+);
+
+__PACKAGE__->optimistic_locking_insignificant_dirty_columns([qw(col3)]);
+
+1;
Added: DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestVersion.pm
===================================================================
--- DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestVersion.pm (rev 0)
+++ DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestVersion.pm 2008-11-13 22:01:34 UTC (rev 5125)
@@ -0,0 +1,12 @@
+package OLTest::Schema::TestVersion;
+
+use strict;
+use warnings;
+use base qw/DBIx::Class/;
+__PACKAGE__->load_components(qw/ OptimisticLocking PK::Auto Core /);
+__PACKAGE__->table('test_version');
+__PACKAGE__->add_columns( qw/ id col1 version / );
+
+__PACKAGE__->optimistic_locking_mode('version');
+
+1;
Added: DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestVersionAlt.pm
===================================================================
--- DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestVersionAlt.pm (rev 0)
+++ DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema/TestVersionAlt.pm 2008-11-13 22:01:34 UTC (rev 5125)
@@ -0,0 +1,13 @@
+package OLTest::Schema::TestVersionAlt;
+
+use strict;
+use warnings;
+use base qw/DBIx::Class/;
+__PACKAGE__->load_components(qw/ OptimisticLocking PK::Auto Core /);
+__PACKAGE__->table('test_version_alt');
+__PACKAGE__->add_columns( qw/ id col1 myversion / );
+
+__PACKAGE__->optimistic_locking_mode('version');
+__PACKAGE__->optimistic_locking_version_column('myversion');
+
+1;
Added: DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema.pm
===================================================================
--- DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema.pm (rev 0)
+++ DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest/Schema.pm 2008-11-13 22:01:34 UTC (rev 5125)
@@ -0,0 +1,8 @@
+package # hide from PAUSE
+ OLTest::Schema;
+
+use base qw/DBIx::Class::Schema/;
+
+__PACKAGE__->load_classes(qw/TestDirty TestDirtyInsignificant TestAll TestVersion TestVersionAlt/);
+
+1;
Added: DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest.pm
===================================================================
--- DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest.pm (rev 0)
+++ DBIx-Class-OptimisticLocking/1.000/trunk/t/lib/OLTest.pm 2008-11-13 22:01:34 UTC (rev 5125)
@@ -0,0 +1,50 @@
+package # hide from PAUSE
+ OLTest;
+
+use strict;
+use warnings;
+
+# much of this is ripped directly from DBIx::Class::VirtualColumns (thanks for the jumpstart!)
+sub init_schema {
+ my $self = shift;
+ my %args = @_;
+
+ my $schema;
+
+ if ( $args{compose_connection} ) {
+ $schema =
+ OLTest::Schema->compose_connection( 'OLTest',
+ "dbi:SQLite:t/var/oltest.db", "", "", { AutoCommit => 1 } );
+ }
+ else {
+ $schema = OLTest::Schema->compose_namespace('OLTest');
+ }
+ if ( !$args{no_connect} ) {
+ $schema =
+ $schema->connect( "dbi:SQLite:t/var/oltest.db", "", "", { AutoCommit => 1 } );
+ $schema->storage->on_connect_do( ['PRAGMA synchronous = OFF'] );
+ }
+ unless ( $args{no_deploy} ) {
+ __PACKAGE__->deploy_schema($schema);
+ }
+ return $schema;
+}
+
+sub deploy_schema {
+ my $self = shift;
+ my $schema = shift;
+
+ if ( $ENV{"OLTEST_SQLT_DEPLOY"} ) {
+ return $schema->deploy();
+ }
+ else {
+ open IN, "t/var/oltest.sql";
+ my $sql;
+ { local $/ = undef; $sql = <IN>; }
+ close IN;
+ ( $schema->storage->dbh->do($_) || print "Error on SQL: $_\n" )
+ for split( /;\n/, $sql );
+ }
+}
+
+1;
Added: DBIx-Class-OptimisticLocking/1.000/trunk/t/var/oltest.sql
===================================================================
--- DBIx-Class-OptimisticLocking/1.000/trunk/t/var/oltest.sql (rev 0)
+++ DBIx-Class-OptimisticLocking/1.000/trunk/t/var/oltest.sql 2008-11-13 22:01:34 UTC (rev 5125)
@@ -0,0 +1,35 @@
+BEGIN TRANSACTION;
+DROP TABLE IF EXISTS test_dirty;
+DROP TABLE IF EXISTS test_dirty_insignificant;
+DROP TABLE IF EXISTS test_all;
+DROP TABLE IF EXISTS test_version;
+DROP TABLE IF EXISTS test_version_alt;
+CREATE TABLE test_dirty (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ col1 TEXT NOT NULL,
+ col2 TEXT NOT NULL,
+ col3 TEXT NOT NULL
+);
+CREATE TABLE test_dirty_insignificant (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ col1 TEXT NOT NULL,
+ col2 TEXT NOT NULL,
+ col3 TEXT NOT NULL
+);
+CREATE TABLE test_all (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ col1 TEXT NOT NULL,
+ col2 TEXT NOT NULL,
+ col3 TEXT NOT NULL
+);
+CREATE TABLE test_version (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ col1 TEXT NOT NULL,
+ version INTEGER NOT NULL
+);
+CREATE TABLE test_version_alt (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ col1 TEXT NOT NULL,
+ myversion INTEGER NOT NULL
+);
+COMMIT;
More information about the Bast-commits
mailing list