Thanks for the reply John - see inline:

> but then override the schema in the inventory class:
> 
> > package My::Inventory;
> > 
> > use base qw(Rose::DB::Object);
> > 
> > __PACKAGE__->meta->setup(
> >     table       => 'inventory',
> >     ...
> >     primary_key_columns  => [ qw(sku_code) ],
> >
> >     schema => 'b_custom',
> > );
> 
> That should do it.  

Indeed it did.  Thanks for that.  I sent you a stripped down test case -
my My::DB looks more like this:
Domain  Type            Schema
pts             main            b_main
pts             custom  b_custom
prod            main            prod_main
prod            custom  prod_custom

Because my schema name can change based upon domain and type (and I want
to keep everything in My::DB), I did the following in my Inventory
class:
    schema => My::DB->new_or_cached(type => 'custom')->schema,

It works, and seems to be okay - see any problems with that?

> Also, you may want to reconsider doing 
> this in every
> class:
> 
> > our $DB;
> > 
> > sub init_db {
> >   $DB ||= My::DB->new;
> > }
> 
> When this code appears in every class, it means that all 
> objects of a given
> class will share a single connection.  That's an odd 
> arrangement and perhaps
> not what you're aiming for :)
> 
> If you want to share a Rose::DB object among all your
> Rose::DB::Object-derived classes, consider using Rose::DB's 
> new_or_cached()
> method.

You were reading too much into my test case ;-).  In my "real" project I
have two base classes which all other RDBO's inherit from,
My::DefaultObject and My:DefaultCachedObject, and I define init_db in
those two base classes (DefaultCachedObject actually calls
DefaultObject's db_init).  When I initially set it up, I simply had
init_db call My::DB->new.  The overhead of creating all those new
connections slowed things down a lot.  I got the '$DB ||= My::DB->new;'
snippet from somewhere - maybe the mailing list?  Anyways, it improved
execution time on my test script by cutting it in half.  Plugging in
new_or_cached into my DefaultObject class works the same, and looks
cleaner, so I'll stick with it - but is there any difference here or is
it just semantics?

Justin

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to