I ran into the same issue when setting up Rose::DB on an already
established, very large DB.  I know this is not recommended, but since you
can do it, here it is.  Your base Rose::DB::Object module would resemble the
following:

package My::DB::Object;

use My::DB;
use Rose::DB::Object::Manager;

use base qw(Rose::DB::Object);

sub init_db {
    My::DB->new;
}


sub get_objects {
    my $self = shift;
    Rose::DB::Object::Manager->get_objects(object_class => "$self", @_);
}

sub get_objects_iterator {
    my $self = shift;
    Rose::DB::Object::Manager->get_objects_iterator(object_class => "$self",
@_);
  }

sub get_objects_count {
    my $self = shift;
    Rose::DB::Object::Manager->get_objects_count(object_class => "$self",
@_);
  }

sub delete_objects {
    my $self = shift;
    Rose::DB::Object::Manager->delete_objects(object_class => "$self", @_);
  }

sub update_objects {
    my $self = shift;
    Rose::DB::Object::Manager->update_objects(object_class => "$self", @_);
  }



Now all of your classes will have Thing->get_objects, Thing->update_objects,
etc...


I also added a paging option that returns an iterator and a Data::Page
object for all my tables, this is most likely not the best implementation
for this:

use Data::Page;

...

sub get_objects_pager {
    my $self = shift;
    my %data = @_;

    my $iter = $self->get_objects_iterator(@_);

    my $per_page = $data{per_page};
    my $current_page = $data{page};

    delete $data{per_page};
    delete $data{page};

    my $count = $self->get_objects_count(%data);

    my $page = Data::Page->new();
    $page->total_entries($count);
    $page->entries_per_page($per_page);
    $page->current_page($current_page);

    return ($iter, $page);

  }

....

So on the script side: my ($iter, $page) =
My::DB::Thing->get_objects_pager(per_page=>10);


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Michael
Reece
Sent: Wednesday, December 06, 2006 12:04 PM
To: Rose::DB::Object list
Subject: [RDBO] Manager classes?

do most users of RDBO tend to stick to the Thing and Thing::Manager pattern
from the docs and tutorial?

        my $thing = Thing->new(...)->load;
        my @things = Thing::Manager->get_things(...);

it seems like a lot of classes to juggle, when i'm looking at 100+ tables in
the schema ..

what headaches might one run into if the manager methods are created on the
Thing class instead?

        my $thing = Thing->new(...)->load;
        my @things = Thing->get_things(...);

alternatively, has anyone implemented a pattern using single manager class
that manages all tables?

        my @those = TheOneTrue::Manager->get_those();   # returns Those
objects
        my @these = TheOneTrue::Manager->get_these();   # returns These
objects

it seems like an intriguing idea, but what headaches might one run into with
this approach?


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to