On 1/25/08 4:54 PM, maxim wrote: > How it may work if I am using Rose::DB::Object::Loader and creating my Manager > subclasses in the runtime ?
You can pre-create the common base class for all your classes created by the Loader, then tell the Loader to use your base class using the base_class parameter: http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/Loader.pm#base _class > I ran into the same problem with looping over thousand of > My::Manager->get_someTable() calls Manager classes will call init_db() on their object_class if you do not pass in a Rose::DB -derived object using the "db" parameter. http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/Manager.pm#obj ect_class http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/Manager.pm#db So either make sure your init_db() methods are set up correctly (e.g., by defining your common base class up-front, as described above) or just pass in a "db" parameter to every Manager call. -John >> -----Original Message----- >> From: [EMAIL PROTECTED] >> [mailto:[EMAIL PROTECTED] On >> Behalf Of John Siracusa >> Sent: Thursday, January 10, 2008 7:25 PM >> To: Rose-DB-Object >> Subject: Re: [RDBO] Too Many connections >> >> On 1/10/08 5:30 PM, James Masters wrote: >>> Looking into this, I seem to simply be doing the following >> in a "for" >>> loop more than 100 times: >>> >>> my $shipobj = MGORD::Shipment->new(shipid => $shipid)->load(with >>> =>['items', 'costs', 'problems', 'predictedcosts', 'toaddress', >>> 'fromaddress']); >>> >>> So the implication is that each one of these is opening a >> new client >>> connection and not closing it. >>> >>> I know I can just increase the default connections limit >> from 100 to >>> say 200 to fix the problem. But is Rose really supposed to be >>> creating all these client connections or have I written >> something wrongly? >> >> When an RDBO-derived object needs a database connection, it >> calls its db() >> method: >> >> >> http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object.pm#db >> >> If a db object does not yet exist, the init_db() method is >> called to create >> one: >> >> >> http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object. > pm#init_db >> >> The default implementation of init_db() returns a new >> Rose::DB object, which in turn will create its own DBI >> database connection. >> >> If you'd like one or more objects to share a single >> Rose::DB-derived object (and therefore a single database >> connection), a straightforward way to do it is to explicitly >> code the sharing: >> >> my $db = My::DB->new; # share this among all objects created below >> >> for(...) >> { >> my $shipobj = >> MGORD::Shipment->new(db => $db, ...)->load(...); >> } >> >> If you'd rather not do this explicitly, or if you simply want >> another default policy, then you should override the >> init_db() method, either in your common base class or in each >> individual RDBO-derived class, depending on the policy you want. >> >> For example, if you want all objects of or derived from a >> given class to share a single database connection by default, >> you could use the >> new_or_cached() Rose::DB method: >> >> http://search.cpan.org/dist/Rose-DB/lib/Rose/DB.pm#new_or_cached >> >> writing an init_db() method like this: >> >> sub init_db { My::DB->new_or_cached } >> >> Remember that no matter what policy you implement in >> init_db(), you can always explicitly create and pass a >> Rose::DB-derived object as that value of a "db" parameter to >> any individual object or Manager call. >> >> -John >> >> >> >> >> -------------------------------------------------------------- >> ----------- >> Check out the new SourceForge.net Marketplace. >> It's the best place to buy or sell services for just about >> anything Open Source. >> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.n > et/marketplace >> _______________________________________________ >> Rose-db-object mailing list >> Rose-db-object@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/rose-db-object >> > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > 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 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. 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