On 12/27/05 8:44 PM, Daniel Pittman wrote: > In playing around with Rose::DB::Object, I have a question about the > Rose::DB derived object: > > The examples for Rose::DB::Object all implement init_db like this: > > sub init_db { return My::DB->new(); } > > Now, so far as I can see that will create multiple My::DB (which isa > Rose::DB) instances, and each of those instances will have a unique DBI > database handle.
Yep...unless you're running under mod_perl using Apache::DBI, in which case they will all actually get the same DBI $dbh under the covers. > Assuming that I haven't missed something there, doesn't this plethora of > database handles make transaction support difficult, since the > transaction state is typically per handle? Not really, since each relationship and foreign key has a share_db attribute that defaults to true and causes the parent object's db to be shared with all sub-objects. When doing transactions across multiple "top-level/parent" objects, however, you would have to explicitly share a single Rose::DB-derived object by passing it into each top-level object. There's an example of this in the RDBO tutorial: http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/Tutorial.pod#A _brief_digression%3A_database_objects > Given that, is there any good reason not to return the same My::DB > instance from every call to init_db? That's certainly an option as well. As noted above, this is essentially what happens when running under Apache::DBI (only it's just the DBI $dbh that's shared; there are still separate Rose::DB-derived objects wrapping them). In the end, it's a question of what you want to do. If you really want every object of a particular class to use the same db handle, then go ahead and have init_db for that class always return a single db object (making the db object effectively "class data" instead of "object data"). Similarly, if you want all objects of all classes to share the same db handle, then make your common base RDBO-derived class always return the same db object. In all cases, you can always override this behavior by explicitly setting the db attribute of an individual RDBO object. -John ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click _______________________________________________ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object