[RDBO] cascading Manager queries

2007-05-17 Thread Michael Reece
in Collection.pm, i have

 sub count_assets {
 my $self = shift;
 return CollectionAsset::Manager-get_collection_assets_count(
 require_objects = ['asset'],
 query   = [ collection_id = $self- 
 collection_id, @_ ],
 );
 }

 sub count_assets_published {
 my $self = shift;
 return $self-count_assets('asset.pubstatus' = 'published',  
@_);
 }

and later:

 my $count = $collection-count_assets_published(
 [ \'t2.pubdate = NOW() - INTERVAL ? DAY' = $num_days ] #  
t2 ~ asset
 );


i can't refer to 'asset.pubdate' in this query param, because RDBOM  
insists i use a scalar-ref here, and wisely avoids doing  
substitutions when handed a scalar-ref, and mysql won't let me refer  
to the table by its real name once it has been aliased.. since the  
generated query aliases asset as t2, i have to use t2 here, though  
not elsewhere.  needless to day, it's a little confusing, especially  
to future-maintenance-programmer.

any advice?


another thing i am struggling with a bit is allowing such helper  
methods to modify both the query and manager_args.  in the above  
example, require_objects=['asset'] isn't required in the basic case  
where it exists, but is there because methods like  
count_assets_published need to refer to the assets..  seems common  
enough, so maybe there is already a convenient way to merge manager  
args in this case?

here is a bit of ugliness that hints at what i am after:

 sub count_assets {
 my $self = shift;
 my ($manager_args, $query_args) =  
_separate_manager_query_args(@_);
 return Plex::RDBO::CollectionAsset::Manager- 
 get_collection_assets_count(
 @$manager_args,
 query = [ collection_id = $self-collection_id, @ 
$query_args ],
 );
 }

 sub count_assets_published {
 my $self = shift;
 my ($manager_args, $query_args) =  
_separate_manager_query_args(@_);
 return $self-count_assets(
 require_objects = ['asset'], @$manager_args,
 query   = [ 'asset.pubstatus' = 'published', @ 
$query_args ]
 );
 }

 sub _separate_manager_query_args {
 my @manager_args = @_;
 my @query_args;
 foreach my $i (0..$#manager_args) {
 if ($manager_args[$i] eq 'query') {
 @query_args = @{ (splice @manager_args, $i, 2)[1] };
 last;
 }
 }
 return ([EMAIL PROTECTED], [EMAIL PROTECTED]);
 }

any advice? ;)



-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


Re: [RDBO] cascading Manager queries

2007-05-17 Thread Jonathan Vanasco

On May 17, 2007, at 3:12 PM, Michael Reece wrote:

 here is a bit of ugliness that hints at what i am after:


I think i do some similar stuff, so I'll give my advice -- which you  
may be better off to not take ;)

I never use 'make manager methods'. i started it as a memory saver  
because i use RDBO in 2 systems with 300+ sql tables/classes in each  
- it was too too much overhead.  instead i use dummy manager classes  
and call get_objects directly.

that being said, since I only call get_objects directly , I found  
that i could improve some memory use if i didn't use the default RDBO  
manager class...  instead I inherit off of my own class which wraps  
the manager calls

if this makes any sense:

| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -

package MyApp::RDBO::Object::Item;
# setup here
1;

package MyApp::RDBO::Object::Item::Manager;
use MyApp::RDBO::Object::_ManagerCustom();
use base qw( MyApp::RDBO::Object::_ManagerCustom );
use MyApp::RDBO::Object::Item ();
sub object_class { 'MyApp::RDBO::Object::Item' }
# often no calls
1;

| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -

then in MyApp::RDBO::Object::_ManagerCustom I do some wonky things:

a) I have a bunch of standardized calls to get_objects, which just  
subs in this to the query builder: object_class= $class-object_class
b) i rewrite get_objects , often in this form:

sub get_objects {
my  ( $self , %kw_args )= @_;

# mess with kw_args ( often bless into class that provides indexing  
etc )

my  $results= Rose::DB::Object::Manager::get_objects ( $self , % 
kw_args );

# mess with results ( often bless into class that provides indexing  
etc )

return $results;
}

the point of this is as follows:

instead of using helper methods to modify the manger args, just  
inherit from a different class and you can stuff anything you want  
into the manager args,
then just hijack manager calls via your own subclass, which will call  
the real rose manager and return results from it.

this method is slightly slower to run-- there are way more class  
lookups , but it cuts down on enough memory that lets me run more  
processes ( which gets me an overall better server load, as my  
performance  blocking is on the DB , not in perl )


-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object