[Bast-commits] r3950 -
DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class
edenc at dev.catalyst.perl.org
edenc at dev.catalyst.perl.org
Thu Jan 17 16:48:49 GMT 2008
Author: edenc
Date: 2008-01-17 16:48:49 +0000 (Thu, 17 Jan 2008)
New Revision: 3950
Modified:
DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/Partitioned.pm
Log:
deleting/inserting directly to storage
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-17 15:42:33 UTC (rev 3949)
+++ DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/Partitioned.pm 2008-01-17 16:48:49 UTC (rev 3950)
@@ -39,8 +39,7 @@
=cut
-__PACKAGE__->mk_group_accessors(
- 'simple' => qw/_current_partition is_partition_row/ );
+__PACKAGE__->mk_group_accessors( 'simple' => qw/_current_partition/ );
sub table {
my $class = shift;
@@ -54,37 +53,46 @@
shift->result_source_instance->partitions(@_);
}
+sub in_partition {
+ my ($self) = @_;
+ return unless $self->_current_partition;
+ my $partition = $self->result_source->partition( $self->_current_partition );
+ return $partition->resultset->find( $self->ident_condition ) ? 1 : 0;
+}
+
+sub insert_partitioned {
+ my ($self) = @_;
+ return if !$self->_current_partition or $self->in_partition;
+ my $partition =
+ $self->result_source->partition( $self->_current_partition );
+ $partition->storage->insert( $partition, { $self->get_columns } );
+}
+
+sub delete_partitioned {
+ my ($self) = @_;
+ return unless $self->in_partition;
+ my $partition = $self->result_source->partition( $self->_current_partition );
+ $partition->storage->delete( $partition, $self->ident_condition );
+}
+
sub new {
my $class = shift;
my $self = $class->next::method(@_);
- if ( my $partition_name = $self->_partition_name ) {
- $self->_current_partition($partition_name);
- }
+ $self->_current_partition( $self->_partition_name || '' );
return $self;
}
sub inflate_result {
my $class = shift;
my $self = $class->next::method(@_);
- if ( my $partition_name = $self->_partition_name ) {
- $self->_current_partition($partition_name);
- }
+ $self->_current_partition( $self->_partition_name || '' );
return $self;
}
sub insert {
my $self = shift;
- if ( !$self->in_storage
- && !$self->is_partition_row
- && ( my $part = $self->_partition_name ) )
- {
- my $partition = $self->result_source->partition($part)
- or confess("couldn't find partition '${part}'");
- my $row = $partition->resultset->new_result( { $self->get_columns } );
- $row->is_partition_row(1);
- $row->insert;
- $self->_current_partition($part);
- }
+ $self->_current_partition( $self->_partition_name || '' );
+ $self->insert_partitioned;
return $self->next::method(@_);
}
@@ -95,37 +103,21 @@
my $new_part = $self->_partition_name;
if ( $old_part && $new_part ) {
- my $part_row =
- $self->partition($old_part)
- ->resultset->find( { $self->get_columns } );
if ( $old_part ne $new_part ) {
- $part_row->delete;
- my $row =
- $self->result_source->partition($new_part)
- ->resultset->new_result( { $self->get_columns } );
- $row->is_partition_row(1);
- $row->insert;
+ $self->delete_partitioned;
$self->_current_partition($new_part);
+ $self->insert_partitioned;
}
else {
- $part_row->set_columns( { $self->get_columns } );
- $part_row->update;
+ $self->insert_partitioned;
}
}
elsif ( !$old_part && $new_part ) {
- my $row =
- $self->result_source->partition($new_part)
- ->resultset->new_result( { $self->get_columns } );
- $row->is_partition_row(1);
- $row->insert;
$self->_current_partition($new_part);
+ $self->insert_partitioned;
}
elsif ( $old_part && !$new_part ) {
- my $row =
- $self->result_source->partition($old_part)
- ->resultset->find( { $self->get_columns } );
- $row->is_partition_row(1);
- $row->delete;
+ $self->delete_partitioned;
$self->_current_partition('');
}
return $self;
@@ -134,9 +126,8 @@
sub delete {
my $self = shift;
$self->next::method(@_);
- if ( my $part = $self->_current_partition && !$self->is_partition_row ) {
- $self->result_source->partition($part)
- ->resultset->find( { $self->get_columns } )->delete;
+ if ( my $part = $self->_current_partition ) {
+ $self->delete_partitioned;
$self->_current_partition('');
}
return $self;
More information about the Bast-commits
mailing list