On 12/4/06, Peter Leonard <[EMAIL PROTECTED]> wrote:
> A second RDBO question - Does RDBO play nicely with Storable?  Can I
> freeze/thaw RDBO objects among various processes and get clean results?
>     (In a serial fashion, of course - I would not try to make updates to
> the same object in several different places at once.)

Freeze/thawing an unmodified RDBO-derived object will probably not do
what you want because each object has a back-pointer to the metadata
object for that class (which, in turn, has code references inside it).
 When you thaw it, you may have already loaded that class, and will
therefore end up with two metadata objects for the same class, one of
which is "dangling" (i.e., not connected to the metadata "registry"
that knows how to look up the metadata object for each class).

I've tried to implement Storable hooks for "db" (Rose::DB) objects,
mostly just to discard the DBI $dbh (which won't survive freeze/thaw
anyway), and that experience has shown me that Storable's hooks are
pretty limited.  (Or maybe I'm just doing it wrong...)  If anyone
wants to take a crack at making Storable hooks for RDBO that enable
safe, coherent freeze/thaw, by all means, take a crack at it :)

In the meantime, I suggest looking at the various
serialization-related Helper methods like, column_values_as_json() and
column_values_as_yaml(), and their reverse methods, init_with_json()
and init_with_yaml()

http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/Helpers.pm

Even if you don't use them, you can look at the implementation and
then make your own, similar methods that use Storable for
serialization instead.  It should be quite simple.

The basic idea is not to serialize the entire object, but instead just
serialize the column values.  Deserialization then becomes simple
instantiation and init()ialization with the thawed column values (+/-
the futzing with column/method name mapping--again, check the code for
examples).

(Serializing a "tree" of nested RDBO-derived objects could be done
using a similar approach for each object in the tree, plus a bit of
extra info detailing how to hook things back up later, but it'd be
considerably more complex than doing single objects.  It's on my
long-term list...)

-John

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