cvsuser     02/07/30 09:32:03

  Modified:    P5EEx/Blue/P5EEx/Blue Repository.pm
  Added:       P5EEx/Blue/P5EEx/Blue RepositoryObject.pm
  Log:
  added repository objects
  
  Revision  Changes    Path
  1.18      +49 -2     p5ee/P5EEx/Blue/P5EEx/Blue/Repository.pm
  
  Index: Repository.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/P5EEx/Blue/P5EEx/Blue/Repository.pm,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -w -r1.17 -r1.18
  --- Repository.pm     12 Jul 2002 21:06:58 -0000      1.17
  +++ Repository.pm     30 Jul 2002 16:32:03 -0000      1.18
  @@ -1,6 +1,6 @@
   
   #############################################################################
  -## $Id: Repository.pm,v 1.17 2002/07/12 21:06:58 spadkins Exp $
  +## $Id: Repository.pm,v 1.18 2002/07/30 16:32:03 spadkins Exp $
   #############################################################################
   
   package P5EEx::Blue::Repository;
  @@ -115,6 +115,9 @@
       $rep->commit();
       $rep->rollback();
   
  +    # OBJECT FACTORY
  +    $obj = $rep->object($table, $key);
  +
   =cut
   
   =head1 DESCRIPTION
  @@ -2173,6 +2176,50 @@
   # PUBLIC METHODS
   #############################################################################
   
  +=head1 Public Methods: Repository Objects
  +
  +=cut
  +
  +#############################################################################
  +# object()
  +#############################################################################
  +
  +=head2 object()
  +
  +    * Signature: $obj = $rep->object($table, $key);
  +    * Param:     $table            $string
  +    * Param:     $key              $string
  +    * Return:    $obj              P5EEx::Blue::RepositoryObject
  +    * Throws:    P5EEx::Blue::Exception::Repository
  +    * Since:     0.01
  +
  +    Sample Usage: 
  +
  +    $obj = $rep->object($table, $key);
  +
  +=cut
  +
  +sub object {
  +    my ($self, $table, $key) = @_;
  +    my $class = $self->{table}{$table}{objectClass} || 
"P5EEx::Blue::RepositoryObject";
  +    if (! $self->{used}{$class}) {
  +        P5EEx::Blue::P5EE->use($class);
  +        $self->{used}{$class} = 1;
  +    }
  +    my $object = {
  +        repository => $self,
  +        context => $self->{context},
  +        table => $table,
  +        key => $key,
  +    };
  +    bless $object, $class;
  +    return $object;
  +}
  +
  +#############################################################################
  +# PUBLIC METHODS
  +#############################################################################
  +
   =head1 Public Methods: Miscellaneous
   
   =cut
  
  
  
  1.1                  p5ee/P5EEx/Blue/P5EEx/Blue/RepositoryObject.pm
  
  Index: RepositoryObject.pm
  ===================================================================
  
  #############################################################################
  ## $Id: RepositoryObject.pm,v 1.1 2002/07/30 16:32:03 spadkins Exp $
  #############################################################################
  
  package P5EEx::Blue::RepositoryObject;
  
  use P5EEx::Blue::P5EE;
  use P5EEx::Blue::Service;
  @ISA = ( "P5EEx::Blue::Service" );
  
  use strict;
  
  =head1 NAME
  
  P5EEx::Blue::RepositoryObject - Interface for data persistence
  
  =head1 SYNOPSIS
  
      use P5EEx::Blue::RepositoryObject;
  
      $context = P5EEx::Blue::P5EE->context();
  
      $rep = $context->service("Repository");  # or ...
      $rep = $context->repository();
  
      $obj = $rep->object($table, $key);
  
      $value  = $rep->get($attrib);
      $rep->set($attrib, $value);
  
  =cut
  
  =head1 DESCRIPTION
  
  A RepositoryObject is an object whose state is stored in a repository.
  It is a base class for many business classes.
  
  All RepositoryObjects are created using the $rep->object() method,
  and they all have the following attributes.
  
      $self->{repository} - the Repository which the object came from
      $self->{context}    - the Context the object is running in
      $self->{table}      - the table name associated with the object
      $self->{key}        - the unique identifier of the object in the
                            table in the repository
  
  =cut
  
  #############################################################################
  # PUBLIC METHODS
  #############################################################################
  
  =head1 Public Methods
  
  =cut
  
  #############################################################################
  # get()
  #############################################################################
  
  =head2 get()
  
      * Signature: $value = $obj->get($attrib);
      * Param:     $attrib      string
      * Return:    $value       any
      * Throws:    P5EEx::Blue::Exception
      * Since:     0.01
  
      Sample Usage: 
  
      $value = $obj->get($attrib);
  
  Gets the value of an attribute of an object.
  
  =cut
  
  sub get {
      my ($self, $attrib) = @_;
      return $self->{repository}->get_value($self->{table}, $self->{key}, $attrib);
  }
  
  #############################################################################
  # set()
  #############################################################################
  
  =head2 set()
  
      * Signature: $obj->set($attrib, $value);
      * Param:     $attrib      string
      * Param:     $value       any
      * Return:    void
      * Throws:    P5EEx::Blue::Exception
      * Since:     0.01
  
      Sample Usage: 
  
      $obj->set($attrib, $value);
  
  Sets the value of an attribute of an object.
  
  =cut
  
  sub set {
      my ($self, $attrib, $value) = @_;
      $self->{repository}->set_value($self->{table}, $self->{key}, $attrib, $value);
  }
  
  =head1 ACKNOWLEDGEMENTS
  
   * Author:  Stephen Adkins <[EMAIL PROTECTED]>
   * License: This is free software. It is licensed under the same terms as Perl 
itself.
  
  =head1 SEE ALSO
  
  L<C<P5EEx::Blue::Context>|P5EEx::Blue::Context>,
  L<C<P5EEx::Blue::Repository>|P5EEx::Blue::Repository>
  
  =cut
  
  1;
  
  
  
  


Reply via email to