From: Chris W. <ch...@cw...> - 2004-03-12 15:08:26
|
On Mar 12, 2004, at 7:28 AM, Alexey Baldov wrote: > I need to work with a database which heavily use stored procedures. As > far as I can understand OpenInteract docs, I should write my own > SPOS-class (something like SPOPS::DBI) to use DB stored procedures to > restore/save objects. Am I right? Is there any better way to do that > (use of DB stored procedures)? Actually you don't need to do this. You don't *have* to use SPOPS to represent your own data, OI just makes it very easy to do so for the standard use cases. You'd be much better served by creating your own class/mini-framework to do this: package My::SP::Object; use OpenInteract::Request; sub new { return bless( $_[1], $_[0] ) } sub fetch { my ( $class, $id ) = @_; my $R = OpenInteract::Request->instance; # If you're not using the default connection, use # my $dbh = $R->db( 'myconnection' ); my $dbh = $R->db; my ( $sth ); eval { $sth = $dbh->prepare( 'exec fetch_my_object ?' ); $sth->execute( $id ); }; if ( $@ ) { ... } my $data = $sth->fetchrow_hashref; $sth->finish; return $class->new( $data ); } Create similar mappings for your other use cases ('create', 'query', 'update', 'remove', etc.) and then just reference the class from your handler: package My::Handler::Foo; use My::SP::Object; use OpenInteract::Request; sub show { my ( $class, $p ) = @_; my $R = OpenInteract::Request->instance; my $id = $R->apache->param( 'id' ); my $object = My::SP::Object->fetch( $id ); return $R->template->handler( {}, { object -> $object }, { name => 'mypkg::mytemplate' } ); } Hope this helps, Chris -- Chris Winters Creating enterprise-capable snack systems since 1988 |