[Bast-commits] r4091 - in
DBIx-Class/0.08/branches/cdbicompat_integration: . lib/DBIx
lib/DBIx/Class lib/DBIx/Class/Manual
lib/DBIx/Class/ResultClass lib/DBIx/Class/Storage
lib/DBIx/Class/Storage/DBI/ODBC t
schwern at dev.catalyst.perl.org
schwern at dev.catalyst.perl.org
Thu Feb 21 08:03:48 GMT 2008
Author: schwern
Date: 2008-02-21 08:03:47 +0000 (Thu, 21 Feb 2008)
New Revision: 4091
Added:
DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Storage/TxnScopeGuard.pm
Modified:
DBIx-Class/0.08/branches/cdbicompat_integration/
DBIx-Class/0.08/branches/cdbicompat_integration/Changes
DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class.pm
DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Manual/Joining.pod
DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/ResultClass/HashRefInflator.pm
DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/ResultSet.pm
DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Row.pm
DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Schema.pm
DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Storage.pm
DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm
DBIx-Class/0.08/branches/cdbicompat_integration/t/76joins.t
Log:
r54378 at windhund (orig r3954): matthewt | 2008-01-18 05:03:08 -0800
added strict and warnings to HashRefInflator, fixed inflation for empty has_many rels
r54379 at windhund (orig r3955): matthewt | 2008-01-20 04:28:55 -0800
made search_rs smarter about when to preserve the cache to fix mm prefetch usage
r54389 at windhund (orig r3965): semifor | 2008-01-22 07:13:11 -0800
Added build_datetime_parser method for MSSQL over ODBC.
r54394 at windhund (orig r3970): castaway | 2008-01-24 05:19:52 -0800
Oops, fix joining manual to be correct
r54395 at windhund (orig r3971): castaway | 2008-01-24 15:22:49 -0800
Version 0.08009
r54396 at windhund (orig r3972): castaway | 2008-01-24 15:36:59 -0800
0.08009 released
r54399 at windhund (orig r3975): tomboh | 2008-01-25 09:20:38 -0800
Fix a typo and a couple of links.
r54448 at windhund (orig r4024): oyse | 2008-02-05 00:42:32 -0800
Added ?\195?\152ystein Torget to the list of contributers
r54474 at windhund (orig r4050): ash | 2008-02-10 09:31:27 -0800
Add txn_scope_guard method/object
Property changes on: DBIx-Class/0.08/branches/cdbicompat_integration
___________________________________________________________________
Name: svk:merge
- 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class:32260
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class-CDBICompat:54535
9c88509d-e914-0410-b01c-b9530614cbfe:/vendor/DBIx-Class:31122
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/on_disconnect_do:3694
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/trunk:3943
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-current:2222
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class:3606
fe160bb6-dc1c-0410-9f2b-d64a711b54a5:/local/DBIC-trunk-0.08:10510
+ 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class:32260
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class-CDBICompat:54535
9c88509d-e914-0410-b01c-b9530614cbfe:/vendor/DBIx-Class:31122
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/on_disconnect_do:3694
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/trunk:4050
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-current:2222
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class:3606
fe160bb6-dc1c-0410-9f2b-d64a711b54a5:/local/DBIC-trunk-0.08:10510
Modified: DBIx-Class/0.08/branches/cdbicompat_integration/Changes
===================================================================
--- DBIx-Class/0.08/branches/cdbicompat_integration/Changes 2008-02-20 12:15:42 UTC (rev 4090)
+++ DBIx-Class/0.08/branches/cdbicompat_integration/Changes 2008-02-21 08:03:47 UTC (rev 4091)
@@ -1,5 +1,11 @@
Revision history for DBIx::Class
+ - Created Storage::TxnScopeGuard object and txn_scope_guard methods
+ on Schema and Storage as an alternative way of doing transactions
+
+0.08009 2008-01-20 13:30
+ - Made search_rs smarter about when to preserve the cache to fix
+ mm prefetch usage
- Added Storage::DBI subclass for MSSQL over ODBC.
- Added freeze, thaw and dclone methods to Schema so that thawed
objects will get re-attached to the schema.
Modified: DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Manual/Joining.pod
===================================================================
--- DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Manual/Joining.pod 2008-02-20 12:15:42 UTC (rev 4090)
+++ DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Manual/Joining.pod 2008-02-21 08:03:47 UTC (rev 4091)
@@ -165,7 +165,7 @@
join => [ 'room', 'room' ]
-The aliases are: C<room_1> and C<room_2>.
+The aliases are: C<room> and C<room_2>.
=cut
Modified: DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/ResultClass/HashRefInflator.pm
===================================================================
--- DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/ResultClass/HashRefInflator.pm 2008-02-20 12:15:42 UTC (rev 4090)
+++ DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/ResultClass/HashRefInflator.pm 2008-02-21 08:03:47 UTC (rev 4091)
@@ -1,5 +1,8 @@
package DBIx::Class::ResultClass::HashRefInflator;
+use strict;
+use warnings;
+
=head1 NAME
DBIx::Class::ResultClass::HashRefInflator
@@ -61,7 +64,7 @@
# related sources.
# to avoid emtpy has_many rels contain one empty hashref
- return if (not keys %$me);
+ return undef if (not keys %$me);
my $def;
@@ -71,13 +74,14 @@
last;
}
}
- return unless $def;
+ return undef unless $def;
return { %$me,
map {
( $_ =>
- ref($rest->{$_}[0]) eq 'ARRAY' ? [ map { mk_hash(@$_) } @{$rest->{$_}} ]
- : mk_hash( @{$rest->{$_}} )
+ ref($rest->{$_}[0]) eq 'ARRAY'
+ ? [ grep defined, map mk_hash(@$_), @{$rest->{$_}} ]
+ : mk_hash( @{$rest->{$_}} )
)
} keys %$rest
};
Modified: DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/ResultSet.pm 2008-02-20 12:15:42 UTC (rev 4090)
+++ DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/ResultSet.pm 2008-02-21 08:03:47 UTC (rev 4091)
@@ -11,6 +11,7 @@
use Storable;
use DBIx::Class::ResultSetColumn;
use DBIx::Class::ResultSourceHandle;
+use List::Util ();
use base qw/DBIx::Class/;
__PACKAGE__->mk_group_accessors('simple' => qw/result_class _source_handle/);
@@ -172,18 +173,26 @@
sub search_rs {
my $self = shift;
- my $rows;
-
- unless (@_) { # no search, effectively just a clone
- $rows = $self->get_cache;
- }
-
my $attrs = {};
$attrs = pop(@_) if @_ > 1 and ref $_[$#_] eq 'HASH';
my $our_attrs = { %{$self->{attrs}} };
my $having = delete $our_attrs->{having};
my $where = delete $our_attrs->{where};
+ my $rows;
+
+ my %safe = (alias => 1, cache => 1);
+
+ unless (
+ (@_ && defined($_[0])) # @_ == () or (undef)
+ ||
+ (keys %$attrs # empty attrs or only 'safe' attrs
+ && List::Util::first { !$safe{$_} } keys %$attrs)
+ ) {
+ # no search, effectively just a clone
+ $rows = $self->get_cache;
+ }
+
my $new_attrs = { %{$our_attrs}, %{$attrs} };
# merge new attrs into inherited
Modified: DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Row.pm
===================================================================
--- DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Row.pm 2008-02-20 12:15:42 UTC (rev 4090)
+++ DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Row.pm 2008-02-21 08:03:47 UTC (rev 4091)
@@ -161,12 +161,10 @@
%{$self->{_inflated_column} || {}});
if(!$self->{_rel_in_storage}) {
- $source->storage->txn_begin;
# The guard will save us if we blow out of this scope via die
+ $rollback_guard = $source->storage->txn_scope_guard;
- $rollback_guard = Scope::Guard->new(sub { $source->storage->txn_rollback });
-
## Should all be in relationship_data, but we need to get rid of the
## 'filter' reltype..
## These are the FK rels, need their IDs for the insert.
@@ -248,8 +246,7 @@
}
}
}
- $source->storage->txn_commit;
- $rollback_guard->dismiss;
+ $rollback_guard->commit;
}
$self->in_storage(1);
@@ -283,7 +280,7 @@
required.
Also takes an options hashref of C<< column_name => value> pairs >> to update
-first. But be awawre that the hashref will be passed to
+first. But be aware that the hashref will be passed to
C<set_inflated_columns>, which might edit it in place, so dont rely on it being
the same after a call to C<update>. If you need to preserve the hashref, it is
sufficient to pass a shallow copy to C<update>, e.g. ( { %{ $href } } )
@@ -773,7 +770,7 @@
=head2 id
Returns the primary key(s) for a row. Can't be called as a class method.
-Actually implemented in L<DBIx::Class::Pk>
+Actually implemented in L<DBIx::Class::PK>
=head2 discard_changes
@@ -782,7 +779,7 @@
This method can also be used to refresh from storage, retrieving any
changes made since the row was last read from storage. Actually
-implemented in L<DBIx::Class::Pk>
+implemented in L<DBIx::Class::PK>
=cut
Modified: DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Schema.pm
===================================================================
--- DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Schema.pm 2008-02-20 12:15:42 UTC (rev 4090)
+++ DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Schema.pm 2008-02-21 08:03:47 UTC (rev 4091)
@@ -734,6 +734,15 @@
$self->storage->txn_do(@_);
}
+sub txn_scope_guard {
+ my $self = shift;
+
+ $self->storage or $self->throw_exception
+ ('txn_scope_guard called on $schema without storage');
+
+ $self->storage->txn_scope_guard(@_);
+}
+
=head2 txn_begin
Begins a transaction (does nothing if AutoCommit is off). Equivalent to
Modified: DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm
===================================================================
--- DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm 2008-02-20 12:15:42 UTC (rev 4090)
+++ DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm 2008-02-21 08:03:47 UTC (rev 4091)
@@ -38,6 +38,14 @@
return { limit_dialect => 'Top', %{$self->{_sql_maker_opts}||{}} };
}
+sub build_datetime_parser {
+ my $self = shift;
+ my $type = "DateTime::Format::Strptime";
+ eval "use ${type}";
+ $self->throw_exception("Couldn't load ${type}: $@") if $@;
+ return $type->new( pattern => '%F %T' );
+}
+
1;
__END__
@@ -72,6 +80,11 @@
=head2 sqlt_type
+=head2 build_datetime_parser
+
+The resulting parser handles the MSSQL C<DATETIME> type, but is almost
+certainly not sufficient for the other MSSQL 2008 date/time types.
+
=head1 AUTHORS
Marc Mims C<< <marc at questright.com> >>
Added: DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Storage/TxnScopeGuard.pm
===================================================================
--- DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Storage/TxnScopeGuard.pm (rev 0)
+++ DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Storage/TxnScopeGuard.pm 2008-02-21 08:03:47 UTC (rev 4091)
@@ -0,0 +1,79 @@
+package DBIx::Class::Storage::TxnScopeGuard;
+
+use strict;
+use warnings;
+
+sub new {
+ my ($class, $storage) = @_;
+
+ $storage->txn_begin;
+ bless [ 0, $storage ], ref $class || $class;
+}
+
+sub commit {
+ my $self = shift;
+
+ $self->[1]->txn_commit;
+ $self->[0] = 1;
+}
+
+sub DESTROY {
+ my ($dismiss, $storage) = @{$_[0]};
+
+ $storage->txn_rollback unless $dismiss;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+DBIx::Class::Storage::TxnScopeGuard
+
+=head1 SYNOPSIS
+
+ sub foo {
+ my ($self, $schema) = @_;
+
+ my $guard = $schema->txn_scope_guard;
+
+ # Multiple database operations here
+
+ $guard->commit;
+ }
+
+=head1 DESCRIPTION
+
+An object that behaves much like L<Scope::Guard>, but hardcoded to do the
+right thing with transactions in DBIx::Class.
+
+=head1 METHODS
+
+=head2 new
+
+Creating an instance of this class will start a new transaction. Expects a
+L<DBIx::Class::Storage> object as its only argument.
+
+=head2 commit
+
+Commit the transaction, and stop guarding the scope. If this method is not
+called (i.e. an exception is thrown) and this object goes out of scope then
+the transaction is rolled back.
+
+=cut
+
+=head1 SEE ALSO
+
+L<DBIx::Class::Schema/txn_scope_guard>.
+
+=head1 AUTHOR
+
+Ash Berlin, 2008.
+
+Insipred by L<Scope::Guard> by chocolateboy.
+
+This module is free software. It may be used, redistributed and/or modified
+under the same terms as Perl itself.
+
+=cut
Modified: DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Storage.pm
===================================================================
--- DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Storage.pm 2008-02-20 12:15:42 UTC (rev 4090)
+++ DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/Storage.pm 2008-02-21 08:03:47 UTC (rev 4091)
@@ -8,6 +8,7 @@
use Scalar::Util qw/weaken/;
use Carp::Clan qw/^DBIx::Class/;
use IO::File;
+use DBIx::Class::Storage::TxnScopeGuard;
__PACKAGE__->mk_group_accessors('simple' => qw/debug debugobj schema/);
__PACKAGE__->mk_group_accessors('inherited' => 'cursor_class');
@@ -261,6 +262,16 @@
sub txn_rollback { die "Virtual method!" }
+=head2 txn_scope_guard
+
+Return an object that does stuff.
+
+=cut
+
+sub txn_scope_guard {
+ return DBIx::Class::Storage::TxnScopeGuard->new($_[0]);
+}
+
=head2 sql_maker
Returns a C<sql_maker> object - normally an object of class
Modified: DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class.pm
===================================================================
--- DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class.pm 2008-02-20 12:15:42 UTC (rev 4090)
+++ DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class.pm 2008-02-21 08:03:47 UTC (rev 4091)
@@ -24,7 +24,7 @@
# i.e. first release of 0.XX *must* be 0.XX000. This avoids fBSD ports
# brain damage and presumably various other packaging systems too
-$VERSION = '0.08008';
+$VERSION = '0.08009';
sub MODIFY_CODE_ATTRIBUTES {
my ($class,$code, at attrs) = @_;
@@ -254,6 +254,8 @@
Numa: Dan Sully <daniel at cpan.org>
+oyse: Øystein Torget <oystein.torget at dnv.com>
+
paulm: Paul Makepeace
penguin: K J Cheetham
Modified: DBIx-Class/0.08/branches/cdbicompat_integration/t/76joins.t
===================================================================
--- DBIx-Class/0.08/branches/cdbicompat_integration/t/76joins.t 2008-02-20 12:15:42 UTC (rev 4090)
+++ DBIx-Class/0.08/branches/cdbicompat_integration/t/76joins.t 2008-02-21 08:03:47 UTC (rev 4091)
@@ -247,12 +247,8 @@
is($cd->producers->first->name, 'Matt S Trout', 'many_to_many accessor ok');
-TODO: {
- local $TODO = 'use prefetched values for many_to_many accessor';
+is($queries, 1, 'many_to_many accessor with nested prefetch ran exactly 1 query');
- is($queries, 1, 'many_to_many accessor with nested prefetch ran exactly 1 query');
-}
-
$queries = 0;
my $producers = $cd->search_related('cd_to_producer')->search_related('producer');
More information about the Bast-commits
mailing list