libdbix-class-optimisticlocking-perl-0.02/000077500000000000000000000000001277154727600206665ustar00rootroot00000000000000libdbix-class-optimisticlocking-perl-0.02/Changes000066400000000000000000000004101277154727600221540ustar00rootroot00000000000000Revision history for DBIx-Class-OptimisticLocking 0.02 2011-08-22 Fixed to work with newer versions of DBIC that no longer use the $self->{_orig_ident} internal attribute. 0.01 2008-11-13 First version, released on an unsuspecting world. libdbix-class-optimisticlocking-perl-0.02/LICENSE000066400000000000000000000435221277154727600217010ustar00rootroot00000000000000This software is copyright (c) 2011 by Brian Phillips. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2011 by Brian Phillips. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2011 by Brian Phillips. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End libdbix-class-optimisticlocking-perl-0.02/MANIFEST000066400000000000000000000012541277154727600220210ustar00rootroot00000000000000Changes LICENSE MANIFEST META.yml Makefile.PL README dist.ini lib/DBIx/Class/OptimisticLocking.pm t/00-compile.t t/01-dirty.t t/02-dirty-ignored.t t/03-all.t t/04-all-ignored.t t/05-version.t t/06-version-custom-column.t t/07-version-with-ignored.t t/08-none.t t/lib/OLTest.pm t/lib/OLTest/Schema.pm t/lib/OLTest/Schema/TestAll.pm t/lib/OLTest/Schema/TestAllIgnored.pm t/lib/OLTest/Schema/TestDirty.pm t/lib/OLTest/Schema/TestDirtyIgnored.pm t/lib/OLTest/Schema/TestDirtyInsignificant.pm t/lib/OLTest/Schema/TestVersion.pm t/lib/OLTest/Schema/TestVersionAlt.pm t/lib/OLTest/Schema/TestVersionIgnored.pm t/release-pod-coverage.t t/release-pod-syntax.t t/var/oltest.db t/var/oltest.sql libdbix-class-optimisticlocking-perl-0.02/META.yml000066400000000000000000000012371277154727600221420ustar00rootroot00000000000000--- abstract: 'Optimistic locking support for DBIx::Class' author: - 'Brian Phillips ' build_requires: Cwd: 0 DBIx::Class::Schema: 0 File::Find: 0 File::Spec: 0 File::Temp: 0 Test::More: 0 configure_requires: ExtUtils::MakeMaker: 6.30 dynamic_config: 0 generated_by: 'Dist::Zilla version 4.200012, CPAN::Meta::Converter version 2.101610' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: DBIx-Class-OptimisticLocking requires: Carp: 0 DBIx::Class: 0.08195 List::Util: 0 resources: repository: http://github.com/brianphillips/dbix-class-optimisticlocking version: 0.02 libdbix-class-optimisticlocking-perl-0.02/Makefile.PL000066400000000000000000000023261277154727600226430ustar00rootroot00000000000000 use strict; use warnings; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( 'ABSTRACT' => 'Optimistic locking support for DBIx::Class', 'AUTHOR' => 'Brian Phillips ', 'BUILD_REQUIRES' => { 'Cwd' => '0', 'DBIx::Class::Schema' => '0', 'File::Find' => '0', 'File::Spec' => '0', 'File::Temp' => '0', 'Test::More' => '0' }, 'CONFIGURE_REQUIRES' => { 'ExtUtils::MakeMaker' => '6.30' }, 'DISTNAME' => 'DBIx-Class-OptimisticLocking', 'EXE_FILES' => [], 'LICENSE' => 'perl', 'NAME' => 'DBIx::Class::OptimisticLocking', 'PREREQ_PM' => { 'Carp' => '0', 'DBIx::Class' => '0.08195', 'List::Util' => '0' }, 'VERSION' => '0.02', 'test' => { 'TESTS' => 't/*.t' } ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; my $pp = $WriteMakefileArgs{PREREQ_PM}; for my $mod ( keys %$br ) { if ( exists $pp->{$mod} ) { $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; } else { $pp->{$mod} = $br->{$mod}; } } } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); libdbix-class-optimisticlocking-perl-0.02/README000066400000000000000000000136131277154727600215520ustar00rootroot00000000000000NAME DBIx::Class::OptimisticLocking - Optimistic locking support for DBIx::Class VERSION version 0.02 SYNOPSIS This module allows the user to utilize optimistic locking when updating a row. Example usage: package DB::Main::Orders; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/OptimisticLocking Core/); __PACKAGE__->optimistic_locking_strategy('dirty'); # this is the default behavior PURPOSE Optimistic locking is an alternative to using exclusive locks when you have the possibility of concurrent, conflicting updates in your database. The basic principle is you allow any and all clients to issue updates and rather than preemptively synchronizing all data modifications (which is what happens with exclusive locks) you are "optimistic" that updates won't interfere with one another and the updates will only fail when they do in fact interfere with one another. Consider the following scenario (in timeline order, not in the same block of code): my $order = $schema->resultset('Orders')->find(1); # some other different, concurrent process loads the same object my $other_order = $schema->resultset('Orders')->find(1); $order->status('fraud review'); $other_order->status('processed'); $order->update; # this succeeds $other_order->update; # this fails when using optimistic locking Without locking (optimistic or exclusive ), the example order would have two sequential updates issued with the second essentially erasing the results of the first. With optimistic locking, the second update (on $other_order) would fail. This optimistic locking is typically done by adding additional restrictions to the "WHERE" clause of the "UPDATE" statement. These additional restrictions ensure the data is still in the expected state before applying the update. This DBIx::Class::OptimisticLocking component provides a few different strategies for providing this functionality. CONFIGURATION optimistic_locking_strategy This configuration controls the main functionality of this component. The current recognized optimistic locking modes supported are: * dirty When issuing an update, the "WHERE" clause of the update will include all of the original values of the columns that are being updated. Any columns that are not being updated will be ignored. * version When issuing an update, the "WHERE" clause of the update will include a check of the "version" column (or otherwise configured column using optimistic_locking_version_column). The "version" column will also be incremented on each update as well. The exception is if all of the updated columns are in the optimistic_locking_ignore_columns configuration. * all When issuing an update, the "WHERE" clause of the update will include a check on each column in the object regardless of whether they were updated or not. * none (or any other value) This turns off the functionality of this component. But why would you load it if you don't need it? :-) optimistic_locking_ignore_columns Occassionally you may elect to ignore certain columns that are not significant enough to detect colisions and cause the update to fail. For instance, if you have a timestamp column, you may want to add that to this list so that it is ignored when generating the "UPDATE" where clause for the update. optimistic_locking_version_column If you are using 'version' as your optimistic_locking_strategy, you can optionally specify a different name for the column used for version tracking. If an alternate name is not passed, the component will look for a column named "version" in your model. EXTENDED METHODS update See DBIx::Class::Row::update for basic usage. Before issuing the actual update, this component injects additional criteria that will be used in the "WHERE" clause in the "UPDATE". The criteria that is used depends on the CONFIGURATION defined in the model class. _track_storage_value This is a method internal to DBIx::Class::Row that basically serves as a predicate method that indicates whether or not the orginal value of the row (as loaded from storage) should be recorded when it is updated. Typically, only primary key values are persisted but for DBIx::Class::OptimisticLocking, this list is augmented to include other columns based on the optimistic locking strategy that is configured for this DBIx::Class::ResultSource. For instance, if the chosen strategy is '"dirty"' (the default), every column's original value will be tracked in order to generate the appropriate "WHERE" clause in any subsequent "UPDATE" operations. _storage_ident_condition This is an internal method to DBIx::Class::PK that generates the "WHERE" clause for update and delete operations. BUGS Please report any bugs or feature requests to "bug-dbix-class-optimisticlocking at rt.cpan.org", or through the web interface at . I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. SUPPORT You can find documentation for this module with the perldoc command. perldoc DBIx::Class::OptimisticLocking ACKNOWLEDGEMENTS Credit goes to the Java ORM package for inspiring me to write this for DBIx::Class. AUTHOR Brian Phillips COPYRIGHT AND LICENSE This software is copyright (c) 2011 by Brian Phillips. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. libdbix-class-optimisticlocking-perl-0.02/dist.ini000066400000000000000000000006741277154727600223410ustar00rootroot00000000000000name = DBIx-Class-OptimisticLocking abstract = Optimistic locking support for DBIx::Class version = 0.02 author = Brian Phillips license = Perl_5 copyright_holder = Brian Phillips [@Basic] [MetaResources] repository = http://github.com/brianphillips/dbix-class-optimisticlocking [AutoPrereqs] [CompileTests] [PodWeaver] [PodSyntaxTests] [PodCoverageTests] [PkgVersion] [ReadmeFromPod] [@Git] [Git::CommitBuild] libdbix-class-optimisticlocking-perl-0.02/lib/000077500000000000000000000000001277154727600214345ustar00rootroot00000000000000libdbix-class-optimisticlocking-perl-0.02/lib/DBIx/000077500000000000000000000000001277154727600222225ustar00rootroot00000000000000libdbix-class-optimisticlocking-perl-0.02/lib/DBIx/Class/000077500000000000000000000000001277154727600232675ustar00rootroot00000000000000libdbix-class-optimisticlocking-perl-0.02/lib/DBIx/Class/OptimisticLocking.pm000066400000000000000000000216351277154727600272670ustar00rootroot00000000000000package DBIx::Class::OptimisticLocking; BEGIN { $DBIx::Class::OptimisticLocking::VERSION = '0.02'; } # ABSTRACT: Optimistic locking support for DBIx::Class use strict; use warnings; use DBIx::Class 0.08195; use base 'DBIx::Class'; use Carp qw(croak); use List::Util qw(first); __PACKAGE__->mk_classdata( optimistic_locking_strategy => 'dirty' ); __PACKAGE__->mk_classdata('optimistic_locking_ignore_columns'); __PACKAGE__->mk_classdata( optimistic_locking_version_column => 'version' ); my %valid_strategies = map { $_ => undef } qw(dirty all none version); sub optimistic_locking_strategy { my @args = @_; my $class = shift(@args); my ($strategy) = $args[0]; croak "invalid optimistic_locking_strategy $strategy" unless exists $valid_strategies{$strategy}; return $class->_opt_locking_strategy_accessor(@args); } sub update { my $self = shift; my $upd = shift; # we have to do this ahead of time to make sure our WHERE # clause is computed correctly $self->set_inflated_columns($upd) if($upd); # short-circuit if we're not changed return $self if !$self->is_changed; if ( $self->optimistic_locking_strategy eq 'version' ) { # increment the version number but only if there are dirty # columns that are not being ignored by the optimistic # locking my %dirty_columns = $self->get_dirty_columns; delete(@dirty_columns{ @{ $self->optimistic_locking_ignore_columns || [] } }); if(%dirty_columns){ my $v_col = $self->optimistic_locking_version_column; my $current_version = $self->{_column_data_in_storage}{$v_col}; $current_version = $self->get_column($v_col) || 0 if ! defined $current_version; # increment the version $self->set_column( $v_col, $current_version + 1); } } my $return = $self->next::method(); return $return; } sub _track_storage_value { my ( $self, $col ) = @_; return 1 if $self->next::method($col); my $mode = $self->optimistic_locking_strategy; my $ignore_columns = $self->optimistic_locking_ignore_columns || []; if ( $mode eq 'dirty' || $mode eq 'all' ) { return !first { $col eq $_ } @$ignore_columns; # implicit return from do block } elsif ( $mode eq 'version' ) { return $col eq $self->optimistic_locking_version_column; # implicit return from do block } return 0; } sub _storage_ident_condition { my $self = shift; my $ident_condition = $self->next::method(@_); # YUCK YUCK YUCK my(undef,undef,undef,$caller) = caller(1); return $ident_condition if $caller eq 'DBIx::Class::Row::get_from_storage'; my $mode = $self->optimistic_locking_strategy; my $ignore_columns = $self->optimistic_locking_ignore_columns || []; if ( $mode eq 'dirty' ) { my %orig = %{$self->{_column_data_in_storage} || {}}; delete @orig{@$ignore_columns}; $ident_condition = {%orig, %$ident_condition }; } elsif ( $mode eq 'version' ) { my $v_col = $self->optimistic_locking_version_column; $ident_condition->{ $v_col } = defined $self->{_column_data_in_storage}{$v_col} ? $self->{_column_data_in_storage}{$v_col} : $self->get_column($v_col); } elsif ( $mode eq 'all' ) { my %orig = ($self->get_columns, %{$self->{_column_data_in_storage} || {}}); delete @orig{@$ignore_columns}; $ident_condition = { %orig, %$ident_condition }; } return $ident_condition; } 1; # End of DBIx::Class::OptimisticLocking __END__ =pod =head1 NAME DBIx::Class::OptimisticLocking - Optimistic locking support for DBIx::Class =head1 VERSION version 0.02 =head1 SYNOPSIS This module allows the user to utilize optimistic locking when updating a row. Example usage: package DB::Main::Orders; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/OptimisticLocking Core/); __PACKAGE__->optimistic_locking_strategy('dirty'); # this is the default behavior =head1 PURPOSE Optimistic locking is an alternative to using exclusive locks when you have the possibility of concurrent, conflicting updates in your database. The basic principle is you allow any and all clients to issue updates and rather than preemptively synchronizing all data modifications (which is what happens with exclusive locks) you are "optimistic" that updates won't interfere with one another and the updates will only fail when they do in fact interfere with one another. Consider the following scenario (in timeline order, not in the same block of code): my $order = $schema->resultset('Orders')->find(1); # some other different, concurrent process loads the same object my $other_order = $schema->resultset('Orders')->find(1); $order->status('fraud review'); $other_order->status('processed'); $order->update; # this succeeds $other_order->update; # this fails when using optimistic locking Without locking (optimistic or exclusive ), the example order would have two sequential updates issued with the second essentially erasing the results of the first. With optimistic locking, the second update (on C<$other_order>) would fail. This optimistic locking is typically done by adding additional restrictions to the C clause of the C statement. These additional restrictions ensure the data is still in the expected state before applying the update. This DBIx::Class::OptimisticLocking component provides a few different strategies for providing this functionality. =head1 CONFIGURATION =head2 optimistic_locking_strategy This configuration controls the main functionality of this component. The current recognized optimistic locking modes supported are: =over 4 =item * dirty When issuing an update, the C clause of the update will include all of the original values of the columns that are being updated. Any columns that are not being updated will be ignored. =item * version When issuing an update, the C clause of the update will include a check of the C column (or otherwise configured column using L). The C column will also be incremented on each update as well. The exception is if all of the updated columns are in the L configuration. =item * all When issuing an update, the C clause of the update will include a check on each column in the object regardless of whether they were updated or not. =item * none (or any other value) This turns off the functionality of this component. But why would you load it if you don't need it? :-) =back =head2 optimistic_locking_ignore_columns Occassionally you may elect to ignore certain columns that are not significant enough to detect colisions and cause the update to fail. For instance, if you have a timestamp column, you may want to add that to this list so that it is ignored when generating the C where clause for the update. =head2 optimistic_locking_version_column If you are using 'version' as your L, you can optionally specify a different name for the column used for version tracking. If an alternate name is not passed, the component will look for a column named C in your model. =head1 EXTENDED METHODS =head2 update See L for basic usage. Before issuing the actual update, this component injects additional criteria that will be used in the C clause in the C. The criteria that is used depends on the L defined in the model class. =head2 _track_storage_value This is a method internal to L that basically serves as a predicate method that indicates whether or not the orginal value of the row (as loaded from storage) should be recorded when it is updated. Typically, only primary key values are persisted but for L, this list is augmented to include other columns based on the optimistic locking strategy that is configured for this L. For instance, if the chosen strategy is 'C' (the default), every column's original value will be tracked in order to generate the appropriate C clause in any subsequent C operations. =head2 _storage_ident_condition This is an internal method to L that generates the C clause for update and delete operations. =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc DBIx::Class::OptimisticLocking =head1 ACKNOWLEDGEMENTS Credit goes to the Java ORM package L for inspiring me to write this for L. =head1 AUTHOR Brian Phillips =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2011 by Brian Phillips. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut libdbix-class-optimisticlocking-perl-0.02/t/000077500000000000000000000000001277154727600211315ustar00rootroot00000000000000libdbix-class-optimisticlocking-perl-0.02/t/00-compile.t000066400000000000000000000017141277154727600231660ustar00rootroot00000000000000#!perl use strict; use warnings; use Test::More; use File::Find; use File::Temp qw{ tempdir }; my @modules; find( sub { return if $File::Find::name !~ /\.pm\z/; my $found = $File::Find::name; $found =~ s{^lib/}{}; $found =~ s{[/\\]}{::}g; $found =~ s/\.pm$//; # nothing to skip push @modules, $found; }, 'lib', ); my @scripts = glob "bin/*"; plan tests => scalar(@modules) + scalar(@scripts); { # fake home for cpan-testers # no fake requested ## local $ENV{HOME} = tempdir( CLEANUP => 1 ); is( qx{ $^X -Ilib -e "use $_; print '$_ ok'" }, "$_ ok", "$_ loaded ok" ) for sort @modules; SKIP: { eval "use Test::Script; 1;"; skip "Test::Script needed to test script compilation", scalar(@scripts) if $@; foreach my $file ( @scripts ) { my $script = $file; $script =~ s!.*/!!; script_compiles_ok( $file, "$script script compiles" ); } } } libdbix-class-optimisticlocking-perl-0.02/t/01-dirty.t000066400000000000000000000021731277154727600226720ustar00rootroot00000000000000use strict; use warnings; use Test::More; BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) : ( tests => 9 ); $DBD::SQLite::sqlite_version; # get rid of warnings } 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"); $r1->discard_changes; $r1->col1('d'); $r1->col1('e'); eval { $r1->update }; ok(!$@, 'no error expected on multiple sets before an update'); is($r1->col1, 'e', 'second value stored appropriately'); libdbix-class-optimisticlocking-perl-0.02/t/02-dirty-ignored.t000066400000000000000000000016761277154727600243270ustar00rootroot00000000000000use strict; use warnings; use Test::More; BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) : ( tests => 7 ); $DBD::SQLite::sqlite_version; # get rid of warnings } 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('TestDirtyIgnored')->new({ col1 => 'a', col2 => 'a', col3 => 'a', }); $r1->insert; my $r2 = $s->resultset('TestDirtyIgnored')->find($r1->id); is($r1->id, $r2->id, 'retrieved identical object'); $r1->col3('b'); $r2->col3('c'); $r1->update; # won't fail because col3 is marked "ignored" eval {$r2->update}; ok(!$@,'no error expected'); $r2 = $s->resultset('TestDirtyIgnored')->find($r1->id); $r2->col1('c'); $r2->update; is($r2->col1,'c', 'update succeeded'); $r1->col1('d'); eval { $r1->update; }; ok($@, 'error expected on critical dirty column update'); libdbix-class-optimisticlocking-perl-0.02/t/03-all.t000066400000000000000000000016421277154727600223110ustar00rootroot00000000000000use strict; use warnings; use Test::More; BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) : ( tests => 7 ); $DBD::SQLite::sqlite_version; # get rid of warnings } 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('TestAll')->new({ col1 => 'a', col2 => 'a', col3 => 'a', }); $r1->insert; my $r2 = $s->resultset('TestAll')->find($r1->id); is($r1->id, $r2->id, 'retrieved identical object'); $r1->col2('b'); $r2->col3('c'); $r1->update; # fails because $r2 doesn't have $r1's new col2 value eval {$r2->update}; ok($@,'error expected'); $r2 = $s->resultset('TestAll')->find($r1->id); $r2->col2('d'); $r2->update; is($r2->col2,'d', 'update succeeded'); $r1->col2('d'); eval { $r1->update; }; ok($@, 'error expected even on identical update '); libdbix-class-optimisticlocking-perl-0.02/t/04-all-ignored.t000066400000000000000000000017541277154727600237430ustar00rootroot00000000000000use strict; use warnings; use Test::More; BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) : ( tests => 7 ); $DBD::SQLite::sqlite_version; # get rid of warnings } 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('TestAllIgnored')->new({ col1 => 'a', col2 => 'a', col3 => 'a', }); $r1->insert; my $r2 = $s->resultset('TestAllIgnored')->find($r1->id); is($r1->id, $r2->id, 'retrieved identical object'); $r1->col3('b'); $r2->col2('c'); $r1->update; # passes because $r2's col3 is an ignored column when it comes to optimistic locking eval {$r2->update}; ok(!$@,'error expected'); $r2 = $s->resultset('TestAllIgnored')->find($r1->id); $r2->col2('d'); $r2->update; is($r2->col2,'d', 'update succeeded'); $r1->col2('d'); eval { $r1->update; }; ok($@, 'error expected even on identical update of non-ignored column'); libdbix-class-optimisticlocking-perl-0.02/t/05-version.t000066400000000000000000000025261277154727600232320ustar00rootroot00000000000000use strict; use warnings; use Test::More; BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) : ( tests => 12 ); $DBD::SQLite::sqlite_version; # get rid of warnings } 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('TestVersion')->new({ col1 => 'a', col2 => 'a', }); $r1->insert; $r1->discard_changes; is($r1->version, 0, 'version at 0'); my $r2 = $s->resultset('TestVersion')->find($r1->id); is($r1->id, $r2->id, 'retrieved identical object'); $r1->col1('b'); $r2->col2('c'); $r1->update; $r1->discard_changes; is($r1->version, 1, 'version incremented'); $r1->update; $r1->discard_changes; is($r1->version, 1, 'version not incremented when update is not executed'); # fails because $r2's version is behind $r1's version eval {$r2->update}; ok($@,'error expected, version mismatch'); $r2 = $s->resultset('TestVersion')->find($r1->id); $r2->col2('d'); $r2->update; $r2->discard_changes; is($r2->version, 2, 'version incremented'); is($r2->col2,'d', 'update succeeded after refresh'); $r1->col2('d'); eval { $r1->update; }; ok($@, 'error expected even on identical update because version did not match'); $r1->discard_changes; is($r1->version, 2, 'version remains on error'); libdbix-class-optimisticlocking-perl-0.02/t/06-version-custom-column.t000066400000000000000000000011671277154727600260360ustar00rootroot00000000000000use strict; use warnings; use Test::More; BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) : ( tests => 5 ); $DBD::SQLite::sqlite_version; # get rid of warnings } 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('TestVersionAlt')->new({ col1 => 'a', col2 => 'a', }); $r1->insert; $r1->discard_changes; is($r1->myversion, 0, 'myversion at 0'); $r1->col1('b'); $r1->update; $r1->discard_changes; is($r1->myversion, 1, 'myversion incremented'); libdbix-class-optimisticlocking-perl-0.02/t/07-version-with-ignored.t000066400000000000000000000016471277154727600256350ustar00rootroot00000000000000use strict; use warnings; use Test::More; BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) : ( tests => 7 ); $DBD::SQLite::sqlite_version; # get rid of warnings } 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('TestVersionIgnored')->new({ col1 => 'a', col2 => 'a', }); $r1->insert; $r1->discard_changes; is($r1->version, 0, 'myversion at 0'); $r1->col1('b'); $r1->update; $r1->discard_changes; is($r1->version, 1, 'version incremented'); $r1->col2('c'); $r1->update; $r1->discard_changes; is($r1->version, 1, 'version not incremented when only ignored column is updated'); $r1->update({col1=>'d', col2=>'e'}); $r1->discard_changes; is($r1->version, 2, 'version incremented when columns updated are mixed between ignored and non-ignored'); libdbix-class-optimisticlocking-perl-0.02/t/08-none.t000066400000000000000000000016271277154727600225100ustar00rootroot00000000000000use strict; use warnings; use Test::More; BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) : ( tests => 6 ); $DBD::SQLite::sqlite_version; # get rid of warnings } use lib 't/lib'; use_ok('DBIx::Class::OptimisticLocking'); use_ok( 'OLTest' ); use_ok( 'OLTest::Schema' ); my $s = OLTest->init_schema(); OLTest::Schema::TestDirty->optimistic_locking_strategy('none'); is(OLTest::Schema::TestDirty->optimistic_locking_strategy, 'none', 'strategy set to "none"'); my $r1 = $s->resultset('TestDirty')->new({ col1 => 'a', col2 => 'a', col3 => 'a' }); $r1->insert; $r1->discard_changes; my $r2 = $s->resultset('TestDirty')->find($r1->id); $r1->col1('b'); $r2->col1('c'); $r1->update; eval {$r2->update}; ok(!$@, 'no error thrown on conflicting update when mode set to "none"'); $r1->discard_changes; is($r1->col1, 'c', 'second update succeeded'); libdbix-class-optimisticlocking-perl-0.02/t/lib/000077500000000000000000000000001277154727600216775ustar00rootroot00000000000000libdbix-class-optimisticlocking-perl-0.02/t/lib/OLTest.pm000066400000000000000000000025121277154727600234070ustar00rootroot00000000000000package # hide from PAUSE OLTest; use strict; use warnings; use File::Spec; use Cwd qw(abs_path); my ($vol, $dir, $file) = File::Spec->splitpath(abs_path(__FILE__)); # 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:$dir/../var/oltest.db", "", "", { AutoCommit => 1 } ); } else { $schema = OLTest::Schema->compose_namespace('OLTest'); } if ( !$args{no_connect} ) { $schema = $schema->connect( "dbi:SQLite:$dir/../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, "$dir/../var/oltest.sql"; my $sql; { local $/ = undef; $sql = ; } close IN; ( $schema->storage->dbh->do($_) || print "Error on SQL: $_\n" ) for split( /;\n/, $sql ); } } 1; libdbix-class-optimisticlocking-perl-0.02/t/lib/OLTest/000077500000000000000000000000001277154727600230515ustar00rootroot00000000000000libdbix-class-optimisticlocking-perl-0.02/t/lib/OLTest/Schema.pm000066400000000000000000000003271277154727600246110ustar00rootroot00000000000000package # hide from PAUSE OLTest::Schema; use base qw/DBIx::Class::Schema/; __PACKAGE__->load_classes(qw/TestDirty TestDirtyIgnored TestAll TestAllIgnored TestVersion TestVersionAlt TestVersionIgnored/); 1; libdbix-class-optimisticlocking-perl-0.02/t/lib/OLTest/Schema/000077500000000000000000000000001277154727600242515ustar00rootroot00000000000000libdbix-class-optimisticlocking-perl-0.02/t/lib/OLTest/Schema/TestAll.pm000066400000000000000000000005151277154727600261600ustar00rootroot00000000000000package 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__->set_primary_key(qw/id/); __PACKAGE__->optimistic_locking_strategy('all'); 1; libdbix-class-optimisticlocking-perl-0.02/t/lib/OLTest/Schema/TestAllIgnored.pm000066400000000000000000000006261277154727600274730ustar00rootroot00000000000000package OLTest::Schema::TestAllIgnored; use strict; use warnings; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/ OptimisticLocking PK::Auto Core /); __PACKAGE__->table('test_all_ignored'); __PACKAGE__->add_columns( qw/ id col1 col2 col3 / ); __PACKAGE__->set_primary_key(qw/id/); __PACKAGE__->optimistic_locking_strategy('all'); __PACKAGE__->optimistic_locking_ignore_columns(['col3']); 1; libdbix-class-optimisticlocking-perl-0.02/t/lib/OLTest/Schema/TestDirty.pm000066400000000000000000000004371277154727600265460ustar00rootroot00000000000000package 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; libdbix-class-optimisticlocking-perl-0.02/t/lib/OLTest/Schema/TestDirtyIgnored.pm000066400000000000000000000005531277154727600300550ustar00rootroot00000000000000package OLTest::Schema::TestDirtyIgnored; use strict; use warnings; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/ OptimisticLocking PK::Auto Core /); __PACKAGE__->table('test_dirty_ignored'); __PACKAGE__->add_columns( qw/ id col1 col2 col3 / ); __PACKAGE__->set_primary_key(qw/id/); __PACKAGE__->optimistic_locking_ignore_columns([qw(col3)]); 1; libdbix-class-optimisticlocking-perl-0.02/t/lib/OLTest/Schema/TestDirtyInsignificant.pm000066400000000000000000000005361277154727600312540ustar00rootroot00000000000000package 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; libdbix-class-optimisticlocking-perl-0.02/t/lib/OLTest/Schema/TestVersion.pm000066400000000000000000000005311277154727600270730ustar00rootroot00000000000000package 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 col2 version / ); __PACKAGE__->set_primary_key('id'); __PACKAGE__->optimistic_locking_strategy('version'); 1; libdbix-class-optimisticlocking-perl-0.02/t/lib/OLTest/Schema/TestVersionAlt.pm000066400000000000000000000006371277154727600275430ustar00rootroot00000000000000package 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 col2 myversion / ); __PACKAGE__->set_primary_key('id'); __PACKAGE__->optimistic_locking_strategy('version'); __PACKAGE__->optimistic_locking_version_column('myversion'); 1; libdbix-class-optimisticlocking-perl-0.02/t/lib/OLTest/Schema/TestVersionIgnored.pm000066400000000000000000000006421277154727600304060ustar00rootroot00000000000000package OLTest::Schema::TestVersionIgnored; use strict; use warnings; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/ OptimisticLocking PK::Auto Core /); __PACKAGE__->table('test_version_ignored'); __PACKAGE__->add_columns( qw/ id col1 col2 version / ); __PACKAGE__->set_primary_key('id'); __PACKAGE__->optimistic_locking_strategy('version'); __PACKAGE__->optimistic_locking_ignore_columns(['col2']); 1; libdbix-class-optimisticlocking-perl-0.02/t/release-pod-coverage.t000066400000000000000000000007651277154727600253170ustar00rootroot00000000000000#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::Pod::Coverage 1.08"; plan skip_all => "Test::Pod::Coverage 1.08 required for testing POD coverage" if $@; eval "use Pod::Coverage::TrustPod"; plan skip_all => "Pod::Coverage::TrustPod required for testing POD coverage" if $@; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); libdbix-class-optimisticlocking-perl-0.02/t/release-pod-syntax.t000066400000000000000000000004501277154727600250410ustar00rootroot00000000000000#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok(); libdbix-class-optimisticlocking-perl-0.02/t/var/000077500000000000000000000000001277154727600217215ustar00rootroot00000000000000libdbix-class-optimisticlocking-perl-0.02/t/var/oltest.db000066400000000000000000000260001277154727600235400ustar00rootroot00000000000000SQLite format 3@ V ?--1tabletest_all_ignoredtest_all_ignoredCREATE TABLE test_all_ignored ( id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT NOT NULL, col2 TEXT NOT NULL, col3 TEXT NOT NULL )'!tabletest_alltest_allCREATE TABLE test_all ( id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT NOT NULL, col2 TEXT NOT NULL, col3 TEXT NOT NULL )E115tabletest_dirty_ignoredtest_dirty_ignoredCREATE TABLE test_dirty_ignored ( id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT NOT NULL, col2 TEXT NOT NULL, col3 TEXT NOT NULL )-!!%tabletest_dirtytest_dirtyCREATE TABLE test_dirty ( id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT NOT NULL, col2 TEXT NOT NULL, col3 TEXT NOT NULL )P++Ytablesqlite_sequencesqlite_sequenceCREATE TABLE sqlite_sequence(name    caa test_!test_dirty   ba cac ada adb N,?--1tablet?--1tabletest_all_ignoredtest_all_ignoredCREATE TABLE test_all_ignored ( id INTEGER PRIMARY KEY AP++Ytablesqlite_sequencesqlite_sequenceCREATE TABLE sqlite_sequence(name,seq)C%%Itabletest_versiontest_versionCREATE TABLE test_version ( id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT NOT NULL, col2 TEXT NOT NULL, version INTEGER NOT NULL default 0 )[55Ytabletest_version_ignoredtest_version_ignored CREATE TABLE test_version_ignored ( id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT NOT NULL, col2 TEXT NOT NULL, version INTEGER NOT NULL default 0 )Q--Utabletest_version_alttest_version_alt CREATE TABLE test_version_alt ( id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT NOT NULL, col2 TEXT NOT NULL, myversion INTEGER NOT NULL dbd V?--1tabletQ?--1tabletest_all_ignoredtest_all_ignoredCREATE TABLE test_all_ignored ( id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT NOT NULL, col2 TEXT NOT NULL, col3 TEXT NOT NULL )P++Ytablesqlite_sequencesqlite_sequenceCREATE TABLE sqlite_sequence(name,seq)-!!%tabletest_dirtytest_dirtyCREATE TABLE test_dirty ( id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT NOT NULL, col2 TEXT NOT NULL, col3 TEXT NOT NULL )E115tabletest_dirty_ignoredtest_dirty_ignoredCREATE TABLE test_dirty_ignored ( id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT NOT NULL, col2 TEXT NOT NULL, col3 TEXT NOT NULL )'!tabletest_alltest_allCREATE TABLE test_all ( id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT NOT NULL, col2 TEXT NOT NULL, col3 TEXT NOT NULL ) x:Q --Utabletest_version_alttest_version_altCREATE TABLE test_version_alt ( id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT NOT NULL, col2 TEXT NOT NULL, myversion INTEGER NOT NULL default 0 )[55Ytabletest_version_ignoredtest_version_ignored CREATE TABLE test_version_ignored ( id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT NOT NULL, col2 TEXT NOT NULL, version INTEGER NOT NULL default 0 )?--1tabletest_all_ignoredtest_all_ignoredCREATE TABLE test_all_ignored ( id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT NOT NULL, col2 TEXT NOT NULL, col3 TEXT NOT NULL )C%%Itabletest_versiontest_versionCREATE TABLE test_version ( id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT NOT NULL, col2 TEXT NOT NULL, version INTEGER NOT NULL default 0 ) delibdbix-class-optimisticlocking-perl-0.02/t/var/oltest.sql000066400000000000000000000025221277154727600237550ustar00rootroot00000000000000BEGIN TRANSACTION; DROP TABLE IF EXISTS test_dirty; DROP TABLE IF EXISTS test_dirty_ignored; DROP TABLE IF EXISTS test_all; DROP TABLE IF EXISTS test_all_ignored; DROP TABLE IF EXISTS test_version; DROP TABLE IF EXISTS test_version_ignored; 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_ignored ( 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_all_ignored ( 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, col2 TEXT NOT NULL, version INTEGER NOT NULL default 0 ); CREATE TABLE test_version_ignored ( id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT NOT NULL, col2 TEXT NOT NULL, version INTEGER NOT NULL default 0 ); CREATE TABLE test_version_alt ( id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT NOT NULL, col2 TEXT NOT NULL, myversion INTEGER NOT NULL default 0 ); COMMIT;