Hibernate Filters Plugin - A Few Questions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Hibernate Filters Plugin - A Few Questions

g:silence
I'm working with the Hibernate Filters plugin and I've come across one issue and have a question.  

I'm working on a simple blog aggregator app as my first Grails app as a learning experience.  I have a Feed class which has many Entries.  I plan on letting users submit feeds to the app and I have setup a "isApproved" column on the Feed so that the app only displays those feeds which are approved by an administrator.  I figured this would be a nice use of hibernate filters to keep the unapproved feeds out of the general application without having to modify all of my service methods to check the flag.  

Here's my Feed with the filter:

https://github.com/compiledammit/warzone/blob/master/sharp/grails-agg/grails-app/domain/com/sharp/agg/feed/Feed.groovy

In general, things work as expected with this filter applied.  I do a list() and only get the approved feeds.  This makes me happy.  There is one instance that doesn't seem to work however.  The app has a scheduled job (via quartz plugin) that uses a dynamic finder to get feeds that haven't been updated (remote entries fetched) in the past hour.  You can see the "findNeedingUpdate" method in my service here:

https://github.com/compiledammit/warzone/blob/master/sharp/grails-agg/grails-app/services/com/sharp/agg/feed/FeedService.groovy

(I've changed it to find those not updated in the last minute for testing purposes).

The problem here is that when the job fires and calls the service method for some reason the "findAllByLastCheckedLessThan"  dynamic finder does not obey the hibernate filter (it returns even unapproved feeds).  Is this to be expected?  

The other question I have is this - is there a way to set a filter on the 'many' side of a one-to-many?  I'd love to be able to set up a filter on entries that limits them to only those that are associated with an approved feed.  Here is the Entry class:

https://github.com/compiledammit/warzone/blob/master/sharp/grails-agg/grails-app/domain/com/sharp/agg/feed/Entry.groovy

Thanks a lot - I'm really loving working with Grails so far!
Reply | Threaded
Open this post in threaded view
|

Re: Hibernate Filters Plugin - A Few Questions

gatherer
First I'd try enabling SQL logging to see what's really going on in there. Then I'd try activating the filter manually in the job before the problematic findAll with something like:

Foo.withHibernateFilter('filterName') {
    ..code to execute
}
Reply | Threaded
Open this post in threaded view
|

Re: Hibernate Filters Plugin - A Few Questions

g:silence
Good call - Looks like the dynamic finder does not obey the filter.  Per the SQL:


Hibernate: select this_.id as id1_0_, this_.version as version1_0_, this_.created_by_id as created3_1_0_, this_.date_created as date4_1_0_, this_.is_approved as is5_1_0_, this_.last_checked as last6_1_0_, this_.last_updated as last7_1_0_, this_.title as title1_0_, this_.url as url1_0_ from feed this_ where this_.last_checked<?


I'll give it a shot with the filter applied manually.  
Reply | Threaded
Open this post in threaded view
|

Re: Hibernate Filters Plugin - A Few Questions

g:silence
That worked - now I'm only getting the approved feeds.  

def stale
Feed.withHibernateFilter('approvedFilter'){
    stale = Feed.findAllByLastCheckedLessThan(hourAgo)
}
return stale

Thanks for that.  

Any idea on setting a filter on the 'many' side?
Reply | Threaded
Open this post in threaded view
|

Re: Hibernate Filters Plugin - A Few Questions

wwwclaes
Hi, here's some pretty vague answers but possibly better than none :-)

I think the Hibernate Filters plugin uses Grails filters for its default filters, that is probably why it isn't applied by default in your service (Grails filters don't apply to services).

For the 'many' side, maybe you can solve it using nested SQ, ie condition: 'id in (select e.id from feed f, entry e... insert join or similar here)'. The problem is you're setting up some very inefficient queries where a simple list query does the subselect for each entry in the list. Don't know if it can be optimized to just become the single join that is needed. I also don't know if this really makes sense since I'm in a bit of hurry, sorry for that :-)

/Claes

> Date: Wed, 5 Sep 2012 07:09:29 -0700

> From: [hidden email]
> To: [hidden email]
> Subject: [grails-user] Re: Hibernate Filters Plugin - A Few Questions
>
> That worked - now I'm only getting the approved feeds.
>
> def stale
> Feed.withHibernateFilter('approvedFilter'){
> stale = Feed.findAllByLastCheckedLessThan(hourAgo)
> }
> return stale
>
> Thanks for that.
>
> Any idea on setting a filter on the 'many' side?
>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Hibernate-Filters-Plugin-A-Few-Questions-tp4634330p4634336.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Hibernate Filters Plugin - A Few Questions

bdrhoa
It seems that you have to apply the hibernate filter on every request.
I do that in a grails filter.

I use hibernate filters to implement my own multi-tenant solution.
Here's where I set a filter to the customer of the currently logged on
user:

https://trac.maflt.org/web/ibidem/browser/trunk/src/ibidem/grails-app/conf/CustomerFilters.groovy

---------------------------
www.maf.org/rhoads
www.ontherhoads.org


On Wed, Sep 5, 2012 at 10:32 AM, Claes Svensson <[hidden email]> wrote:

> Hi, here's some pretty vague answers but possibly better than none :-)
>
> I think the Hibernate Filters plugin uses Grails filters for its default
> filters, that is probably why it isn't applied by default in your service
> (Grails filters don't apply to services).
>
> For the 'many' side, maybe you can solve it using nested SQ, ie condition:
> 'id in (select e.id from feed f, entry e... insert join or similar here)'.
> The problem is you're setting up some very inefficient queries where a
> simple list query does the subselect for each entry in the list. Don't know
> if it can be optimized to just become the single join that is needed. I also
> don't know if this really makes sense since I'm in a bit of hurry, sorry for
> that :-)
>
> /Claes
>
>> Date: Wed, 5 Sep 2012 07:09:29 -0700
>> From: [hidden email]
>> To: [hidden email]
>> Subject: [grails-user] Re: Hibernate Filters Plugin - A Few Questions
>
>>
>> That worked - now I'm only getting the approved feeds.
>>
>> def stale
>> Feed.withHibernateFilter('approvedFilter'){
>> stale = Feed.findAllByLastCheckedLessThan(hourAgo)
>> }
>> return stale
>>
>> Thanks for that.
>>
>> Any idea on setting a filter on the 'many' side?
>>
>>
>>
>> --
>> View this message in context:
>> http://grails.1312388.n4.nabble.com/Hibernate-Filters-Plugin-A-Few-Questions-tp4634330p4634336.html
>> Sent from the Grails - user mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Hibernate Filters Plugin - A Few Questions

wwwclaes
In reply to this post by wwwclaes
Oh, sorry. When I said "Grails filters don't apply to services" I really meant "Grails filters don't apply to jobs" (which I believe your service was called from). Here's a thread about it:

http://grails.1312388.n4.nabble.com/hibernate-filter-plugin-Improved-default-filter-activation-td4435607.html

/Claes


From: [hidden email]
To: [hidden email]
Date: Wed, 5 Sep 2012 18:32:16 +0200
Subject: RE: [grails-user] Re: Hibernate Filters Plugin - A Few Questions

Hi, here's some pretty vague answers but possibly better than none :-)

I think the Hibernate Filters plugin uses Grails filters for its default filters, that is probably why it isn't applied by default in your service (Grails filters don't apply to services).

For the 'many' side, maybe you can solve it using nested SQ, ie condition: 'id in (select e.id from feed f, entry e... insert join or similar here)'. The problem is you're setting up some very inefficient queries where a simple list query does the subselect for each entry in the list. Don't know if it can be optimized to just become the single join that is needed. I also don't know if this really makes sense since I'm in a bit of hurry, sorry for that :-)

/Claes

> Date: Wed, 5 Sep 2012 07:09:29 -0700

> From: [hidden email]
> To: [hidden email]
> Subject: [grails-user] Re: Hibernate Filters Plugin - A Few Questions
>
> That worked - now I'm only getting the approved feeds.
>
> def stale
> Feed.withHibernateFilter('approvedFilter'){
> stale = Feed.findAllByLastCheckedLessThan(hourAgo)
> }
> return stale
>
> Thanks for that.
>
> Any idea on setting a filter on the 'many' side?
>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Hibernate-Filters-Plugin-A-Few-Questions-tp4634330p4634336.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>