cvs commit: p5ee/App-Repository/lib/App/SessionObject RepositoryObjectSet.pm

[email protected] (Stephen Adkins)
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
cvsuser     05/11/07 12:08:51

  Modified:    App-Repository/lib/App/SessionObject RepositoryObjectSet.pm
  Log:
  auto_params, auto_columns
  
  Revision  Changes    Path
  1.7       +138 -1    p5ee/App-Repository/lib/App/SessionObject/RepositoryObjectSet.pm
  
  Index: RepositoryObjectSet.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/lib/App/SessionObject/RepositoryObjectSet.pm,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- RepositoryObjectSet.pm	13 Sep 2005 15:10:38 -0000	1.6
  +++ RepositoryObjectSet.pm	7 Nov 2005 20:08:51 -0000	1.7
  @@ -46,6 +46,22 @@
   # Support Routines
   ###########################################################################
   
  +sub _init {
  +    &App::sub_entry if ($App::trace);
  +    my ($self, $args) = @_;
  +    $self->_clear_cache_if_auto_params_changed() if ($self->{auto_params});   # sets params from auto_params
  +    $self->_clear_cache_if_auto_columns_changed() if ($self->{auto_columns}); # sets columns from auto_columns
  +    if (!$self->{columns}) {
  +        my $context = $self->{context};
  +        my $repname = $self->{repository};
  +        my $rep     = $context->repository($repname);
  +        my $table   = $self->{table} || die "table not defined";
  +        $self->{columns} = $rep->_get_default_columns($table);
  +    }
  +    $self->SUPER::_init();
  +    &App::sub_exit() if ($App::trace);
  +}
  +
   sub _clear_cache {
       &App::sub_entry if ($App::trace);
       my ($self) = @_;
  @@ -71,6 +87,52 @@
       &App::sub_exit() if ($App::trace);
   }
   
  +sub _clear_cache_if_auto_params_changed {
  +    &App::sub_entry if ($App::trace);
  +    my ($self, $options) = @_;
  +    if (defined $self->{auto_params}) {
  +        my $newparams = $self->substitute($self->{auto_params});
  +        if (!$self->{params}) {
  +            $self->{params} = $newparams;
  +        }
  +        else {
  +            my $changed = 0;
  +            my $params = $self->{params};
  +            foreach my $var (keys %$newparams) {
  +                if ($params->{$var} ne $newparams->{$var}) {
  +                    $changed = 1;
  +                    last;
  +                }
  +            }
  +            if ($changed) {
  +                $self->{params} = $newparams;
  +                $self->_clear_cache();
  +            }
  +        }
  +    }
  +    &App::sub_exit() if ($App::trace);
  +}
  +
  +sub _clear_cache_if_auto_columns_changed {
  +    &App::sub_entry if ($App::trace);
  +    my ($self, $options) = @_;
  +    if (defined $self->{auto_columns}) {
  +        my (@auto_columns, %column, $new_columns);
  +        my $context = $self->{context};
  +        foreach my $wname (split(/,/, $self->{auto_columns})) {
  +            $new_columns = $context->so_get($wname);
  +            if ($new_columns) {
  +                push(@auto_columns, split(/,/, $new_columns));
  +            }
  +        }
  +        if (!$self->{columns}) {
  +            $self->{columns} = \@auto_columns;
  +            $self->_clear_cache();
  +        }
  +    }
  +    &App::sub_exit() if ($App::trace);
  +}
  +
   sub set_table {
       &App::sub_entry if ($App::trace);
       my ($self, $table, $repository) = @_;
  @@ -128,6 +190,76 @@
   }
   
   ###########################################################################
  +# Column Control
  +###########################################################################
  +
  +sub set_columns {
  +    my ($self, $new_columns) = @_;
  +    $self->{columns} = $new_columns;
  +    $self->_clear_cache();
  +}
  +
  +sub include_columns {
  +    my ($self, $new_columns) = @_;
  +    my $columns = $self->{columns};
  +    if (!$columns) {
  +        my $repname = $self->{repository};
  +        my $context = $self->{context};
  +        my $rep = $context->repository($repname);
  +        my $table = $self->{table} || die "table not defined on object_set [$self->{name}]";
  +        $columns = $rep->_get_default_columns($table);
  +        $self->{columns} = $columns;
  +    }
  +    my (%colidx, $column_added, $column);
  +    for (my $i = 0; $i <= $#$columns; $i++) {
  +        $colidx{$columns->[$i]} = $i;
  +    }
  +    for (my $i = 0; $i <= $#$new_columns; $i++) {
  +        $column = $new_columns->[$i];
  +        if (! defined $colidx{$column}) {
  +            push(@$columns, $column);
  +            $colidx{$column} = $#$columns;
  +            $column_added = 1;
  +        }
  +    }
  +    if ($column_added) {
  +        $self->_clear_cache();
  +    }
  +}
  +
  +sub get_key_columns {
  +    my ($self) = @_;
  +    my $repname = $self->{repository};
  +    my $context = $self->{context};
  +    my $rep     = $context->repository($repname);
  +    my $table   = $self->{table} || die "table not defined";
  +    my $column_defs = $rep->{table}{$table}{column};
  +    my $columns = $self->{columns};
  +    if (!$columns) {
  +        $columns = $rep->_get_default_columns($table);
  +        $self->{columns} = $columns;
  +    }
  +    my (@key_columns, $column);
  +    for (my $i = 0; $i <= $#$columns; $i++) {
  +        $column = $columns->[$i];
  +        if ($column_defs->{$column}{is_key}) {
  +            push(@key_columns, $column);
  +        }
  +    }
  +    return(\@key_columns);
  +}
  +
  +sub get_column_defs {
  +    my ($self) = @_;
  +    my $context     = $self->{context};
  +    my $repname     = $self->{repository};
  +    my $rep         = $context->repository($repname);
  +    my $table       = $self->{table} || die "table not defined";
  +    my $column_defs = $rep->{table}{$table}{column};
  +    return($column_defs);
  +}
  +
  +###########################################################################
   # Accessing individual objects
   ###########################################################################
   
  @@ -139,6 +271,7 @@
       $key_name ||= "ie1";
       my $key_columns = shift;
   
  +    $self->_clear_cache_if_auto_params_changed($options) if (defined $self->{auto_params});
       $self->_clear_cache_if_objects_expired($options) if (defined $options->{max_age} && $self->{objects});
   
       my $index = $self->{index}{$key_name};
  @@ -176,6 +309,7 @@
       $key_name ||= "ak1";
       my $key_columns = shift;
   
  +    $self->_clear_cache_if_auto_params_changed($options) if (defined $self->{auto_params});
       $self->_clear_cache_if_objects_expired($options) if (defined $options->{max_age} && $self->{objects});
   
       my $unique_index = $self->{unique_index}{$key_name};
  @@ -201,6 +335,7 @@
       &App::sub_entry if ($App::trace);
       my ($self, $column, $options) = @_;
   
  +    $self->_clear_cache_if_auto_params_changed($options) if (defined $self->{auto_params});
       $self->_clear_cache_if_objects_expired($options) if (defined $options->{max_age} && $self->{objects});
   
       my $values = $self->{column_values}{$column};
  @@ -236,6 +371,7 @@
       my $key_name = ref($_[0]) ? "ak1" : shift;
       my $key_columns = shift;
   
  +    $self->_clear_cache_if_auto_params_changed($options) if (defined $self->{auto_params});
       $self->_clear_cache_if_objects_expired($options) if (defined $options->{max_age} && $self->{objects});
   
       my $unique_index = $self->get_unique_index($key_name, $key_columns);
  @@ -257,6 +393,7 @@
       my $key_name = ref($_[0]) ? "ie1" : shift;
       my $key_columns = shift;
   
  +    $self->_clear_cache_if_auto_params_changed($options) if (defined $self->{auto_params});
       $self->_clear_cache_if_objects_expired($options) if (defined $options->{max_age} && $self->{objects});
   
       my ($objects);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.