On Jan 29, 2008 9:52 PM, Sam Tregar <[EMAIL PROTECTED]> wrote:
> Hey all.  I'm getting started with Rose::DB::Object.  My problem is I need
> to inter-operate with a large pre-existing Class::DBI code-base.  I'd like
> to setup Rose to be able to share the same DBI connection that Class::DBI
> uses - otherwise I'll instantly double the number of connections from our
> web cluster when I roll out Rose::DB::Object.
>
> I know of one problem - Class::DBI requires its DBI handles to inherit from
> DBIx::ContextualFetch while Rose wants its handle to inherit from
> Rose::DB::MySQL.  Anybody know how to solve this?  Alternately, do you know
> of other reasons why it won't work?

The "db" atribute of an RDBO-derived object "isa" Rose::DB, but each
Rose::DB-derived object "has a" DBI $dbh.  IOW, plain old DBI database
handles are used via delegation in RDBO.  There's no subclassing of
DBI classes at all.

As for sharing, if you already have a DBI $dbh from elsewhere, you can
simply stuff it into an appropriate Rose::DB object and use that as
the "db" value in RDBO objects and calls.  Just make sure that the
Rose::DB object has the same driver as the DBI $dbh.

Example:

  $dbh = ...; # get from elsewhere
  $db = Rose::DB->new(driver => 'mysql', dbh => $dbh);

Overriding init_db() in a common base class is the usual way to do
this "everywhere."  There are many possible policies for init_db().
You can find a few old threads on the topic in the list archives:

http://www.mail-archive.com/rose-db-object@lists.sourceforge.net/maillist.html

but keep in mind the new new_or_cached() Rose::DB method that makes a
lot of the caching discussion in some older threads less relevant
these days.

http://search.cpan.org/dist/Rose-DB/lib/Rose/DB.pm#new_or_cached

Also keep in mind the funky (but useful! :) mod_perl-aware default
behavior of new_or_cached()'s default cache backend:

http://search.cpan.org/dist/Rose-DB/lib/Rose/DB/Cache.pm#prepare_db

-John

-------------------------------------------------------------------------
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

Reply via email to