[Bast-commits] r3931 - in DBIx-Class-Partitioned/1.000/trunk:
lib/DBIx/Class lib/DBIx/Class/ResultSet t t/lib t/lib/My
t/lib/My/Schema
edenc at dev.catalyst.perl.org
edenc at dev.catalyst.perl.org
Sat Jan 12 17:06:09 GMT 2008
Author: edenc
Date: 2008-01-12 17:06:08 +0000 (Sat, 12 Jan 2008)
New Revision: 3931
Added:
DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/Partition.pm
DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/ResultSet/
DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/ResultSet/Partitioned.pm
DBIx-Class-Partitioned/1.000/trunk/t/01-basic.t
DBIx-Class-Partitioned/1.000/trunk/t/lib/
DBIx-Class-Partitioned/1.000/trunk/t/lib/My/
DBIx-Class-Partitioned/1.000/trunk/t/lib/My/Schema.pm
DBIx-Class-Partitioned/1.000/trunk/t/lib/My/Schema/
DBIx-Class-Partitioned/1.000/trunk/t/lib/My/Schema/Foo.pm
DBIx-Class-Partitioned/1.000/trunk/t/lib/My/Schema/Foo1.pm
DBIx-Class-Partitioned/1.000/trunk/t/lib/My/Schema/Foo2.pm
DBIx-Class-Partitioned/1.000/trunk/t/test.db
Removed:
DBIx-Class-Partitioned/1.000/trunk/t/pod-coverage.t
Modified:
DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/Partitioned.pm
Log:
basic partioned selects
Added: DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/Partition.pm
===================================================================
--- DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/Partition.pm (rev 0)
+++ DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/Partition.pm 2008-01-12 17:06:08 UTC (rev 3931)
@@ -0,0 +1,9 @@
+package DBIx::Class::Partition;
+
+use warnings;
+use strict;
+use base qw/DBIx::Class/;
+
+#__PACKAGE__->mk_accessors(qw/partition/);
+
+1;
Modified: DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/Partitioned.pm
===================================================================
--- DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/Partitioned.pm 2008-01-11 23:45:03 UTC (rev 3930)
+++ DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/Partitioned.pm 2008-01-12 17:06:08 UTC (rev 3931)
@@ -2,6 +2,7 @@
use warnings;
use strict;
+use base qw/DBIx::Class/;
=head1 NAME
@@ -22,8 +23,7 @@
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/Partitioned Core/);
- __PACKAGE__->partitions(qw/Foo1 Foo2/);
- __PACKAGE__->default_partition('Foo1');
+ __PACKAGE__->partitions([qw/foo1 foo2/]);
package My::Schema::Foo1;
use base qw/DBIx::Class/;
@@ -47,8 +47,24 @@
my @rows = $foo_rs->all; # selects rows from foo1 and foo2
$foo_rs->new({ ... })->insert; # inserts to foo1
+=for discussion with matt
+
+__PACKAGE__->table(\'...'); # requires patch to DBIC::ResultSourceProxy::Table and DBIC::Schema::deploy
+
+how am I supposed to know what table the object selected from a union belongs to?
+
=cut
+__PACKAGE__->mk_classdata('_partitions');
+
+sub partitions {
+ my ( $class, @parts ) = @_;
+ return $class->_partitions unless @parts;
+ $class->resultset_class('DBIx::Class::ResultSet::Partitioned')
+ unless $class->resultset_class->isa('DBIx::Class::ResultSet::Partitioned');
+ $class->_partitions( \@parts );
+}
+
=head1 AUTHOR
Eden Cardim, C<< <edenc at shadowcatsystems.co.uk> >>
Added: DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/ResultSet/Partitioned.pm
===================================================================
--- DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/ResultSet/Partitioned.pm (rev 0)
+++ DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/ResultSet/Partitioned.pm 2008-01-12 17:06:08 UTC (rev 3931)
@@ -0,0 +1,33 @@
+package DBIx::Class::ResultSet::Partitioned;
+
+use warnings;
+use strict;
+
+use base qw/DBIx::Class::ResultSet/;
+
+__PACKAGE__->mk_group_accessors( 'simple' => '__current_partition' );
+
+sub new {
+ my $self = shift->next::method(@_);
+ $self->__current_partition( $self->result_class->partitions->[0] );
+ return $self;
+}
+
+sub _current_partition {
+ my $self = shift;
+ if (@_) {
+ foreach ( @{ $self->result_class->partitions } ) {
+ $self->__current_partition( $_[0] ), last if $_ eq $_[0];
+ }
+ }
+ return $self->_source_handle->schema->source( $self->__current_partition );
+}
+
+sub new_result {
+ my $self = shift;
+ my $result = $self->next::method(@_);
+ $result->result_source( $self->_current_partition );
+ return $result;
+}
+
+1;
Added: DBIx-Class-Partitioned/1.000/trunk/t/01-basic.t
===================================================================
--- DBIx-Class-Partitioned/1.000/trunk/t/01-basic.t (rev 0)
+++ DBIx-Class-Partitioned/1.000/trunk/t/01-basic.t 2008-01-12 17:06:08 UTC (rev 3931)
@@ -0,0 +1,27 @@
+use warnings;
+use strict;
+
+use lib 't/lib';
+use Test::More qw/no_plan/;
+use My::Schema;
+my $schema = My::Schema->connect('dbi:SQLite:dbname=t/test.db');
+my $test = sub {
+ my $foo_rs = $schema->resultset('Foo');
+ my $data = { bar => 'bar 11', baz => 'baz 11' };
+ isa_ok( $foo_rs->create($data), 'My::Schema::Foo' );
+ ok( my $row = $foo_rs->search($data)->single );
+ ok( my $foo1_row = $schema->resultset('Foo1')->search($data)->single );
+ is( $row->id, $foo1_row->id );
+ is_deeply( { $row->get_columns }, { $foo1_row->get_columns } );
+
+ $foo_rs->_current_partition('Foo2');
+ $data = { bar => 'bar 12', baz => 'baz 12' };
+ isa_ok( $foo_rs->create($data), 'My::Schema::Foo' );
+ ok( $row = $foo_rs->search($data)->single );
+ ok( my $foo2_row = $schema->resultset('Foo2')->search($data)->single );
+ is( $row->id, $foo2_row->id );
+ is_deeply( { $row->get_columns }, { $foo2_row->get_columns } );
+ die 'rollback';
+};
+eval { $schema->txn_do($test) };
+die $@ if $@ !~ 'rollback';
Added: DBIx-Class-Partitioned/1.000/trunk/t/lib/My/Schema/Foo.pm
===================================================================
--- DBIx-Class-Partitioned/1.000/trunk/t/lib/My/Schema/Foo.pm (rev 0)
+++ DBIx-Class-Partitioned/1.000/trunk/t/lib/My/Schema/Foo.pm 2008-01-12 17:06:08 UTC (rev 3931)
@@ -0,0 +1,16 @@
+package My::Schema::Foo;
+
+use warnings;
+use strict;
+
+use base qw/DBIx::Class/;
+
+__PACKAGE__->load_components(qw/Partitioned Core/);
+__PACKAGE__->table('(SELECT * FROM foo1 UNION ALL SELECT * FROM foo2)');
+__PACKAGE__->add_column(
+ id => { is_auto_increment => 1, data_type => 'integer' } );
+__PACKAGE__->add_columns(qw/bar baz/);
+__PACKAGE__->set_primary_key('id');
+__PACKAGE__->partitions(qw/Foo1 Foo2/);
+
+1;
Added: DBIx-Class-Partitioned/1.000/trunk/t/lib/My/Schema/Foo1.pm
===================================================================
--- DBIx-Class-Partitioned/1.000/trunk/t/lib/My/Schema/Foo1.pm (rev 0)
+++ DBIx-Class-Partitioned/1.000/trunk/t/lib/My/Schema/Foo1.pm 2008-01-12 17:06:08 UTC (rev 3931)
@@ -0,0 +1,15 @@
+package My::Schema::Foo1;
+
+use warnings;
+use strict;
+
+use base qw/DBIx::Class/;
+
+__PACKAGE__->load_components(qw/Partition Core/);
+__PACKAGE__->table('foo1');
+__PACKAGE__->add_column(
+ id => { is_auto_increment => 1, data_type => 'integer' } );
+__PACKAGE__->add_columns(qw/bar baz/);
+__PACKAGE__->set_primary_key('id');
+
+1;
Added: DBIx-Class-Partitioned/1.000/trunk/t/lib/My/Schema/Foo2.pm
===================================================================
--- DBIx-Class-Partitioned/1.000/trunk/t/lib/My/Schema/Foo2.pm (rev 0)
+++ DBIx-Class-Partitioned/1.000/trunk/t/lib/My/Schema/Foo2.pm 2008-01-12 17:06:08 UTC (rev 3931)
@@ -0,0 +1,15 @@
+package My::Schema::Foo2;
+
+use warnings;
+use strict;
+
+use base qw/DBIx::Class/;
+
+__PACKAGE__->load_components(qw/Partition Core/);
+__PACKAGE__->table('foo2');
+__PACKAGE__->add_column(
+ id => { is_auto_increment => 1, data_type => 'integer' } );
+__PACKAGE__->add_columns(qw/bar baz/);
+__PACKAGE__->set_primary_key('id');
+
+1;
Added: DBIx-Class-Partitioned/1.000/trunk/t/lib/My/Schema.pm
===================================================================
--- DBIx-Class-Partitioned/1.000/trunk/t/lib/My/Schema.pm (rev 0)
+++ DBIx-Class-Partitioned/1.000/trunk/t/lib/My/Schema.pm 2008-01-12 17:06:08 UTC (rev 3931)
@@ -0,0 +1,19 @@
+package My::Schema;
+
+use warnings;
+use strict;
+
+use base qw/DBIx::Class::Schema/;
+
+__PACKAGE__->load_classes();
+#__PACKAGE__->load_classes(qw/Foo1 Foo2/);
+
+sub setup_test_data {
+ my ($self) = @_;
+ $self->populate( 'Foo1',
+ [ [qw/id bar baz/], map { [ "bar $_", "baz $_" ] } 1 .. 5 ] );
+ $self->populate( 'Foo2',
+ [ [qw/id bar baz/], map { [ "bar $_", "baz $_" ] } 6 .. 10 ] );
+}
+
+1;
Deleted: DBIx-Class-Partitioned/1.000/trunk/t/pod-coverage.t
===================================================================
--- DBIx-Class-Partitioned/1.000/trunk/t/pod-coverage.t 2008-01-11 23:45:03 UTC (rev 3930)
+++ DBIx-Class-Partitioned/1.000/trunk/t/pod-coverage.t 2008-01-12 17:06:08 UTC (rev 3931)
@@ -1,18 +0,0 @@
-use strict;
-use warnings;
-use Test::More;
-
-# Ensure a recent version of Test::Pod::Coverage
-my $min_tpc = 1.08;
-eval "use Test::Pod::Coverage $min_tpc";
-plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage"
- if $@;
-
-# Test::Pod::Coverage doesn't require a minimum Pod::Coverage version,
-# but older versions don't recognize some common documentation styles
-my $min_pc = 0.18;
-eval "use Pod::Coverage $min_pc";
-plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage"
- if $@;
-
-all_pod_coverage_ok();
Added: DBIx-Class-Partitioned/1.000/trunk/t/test.db
===================================================================
(Binary files differ)
Property changes on: DBIx-Class-Partitioned/1.000/trunk/t/test.db
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
More information about the Bast-commits
mailing list