domain default sort order

View: New views
6 Messages — Rating Filter:   Alert me  

domain default sort order

by Steve Krenek :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Would anyone happen to know how I can determine a domain class's default sort (specified in the mapipng, added in Grails 1.1) at runtime by interrogating the classes?  I've been searching the Grails API and source code all evening, and haven't been able to find to find any reference to it.  I did find a reference in Mapping.groovy, but haven't been able to find a way to obtain the mapping in GrailsDomainClass or the like.

Cheers,
Steve

Re: domain default sort order

by Daniel Rinser-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Steve,

I guess GrailsDomainBinder is what you are looking for. Try:

import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder
import org.codehaus.groovy.grails.orm.hibernate.cfg.Mapping

Mapping mapping = GrailsDomainBinder.getMapping(clazz)
def defaultSort = mapping.sort
def defaultOrder = mapping.order


(not tested though)

Cheers,
Daniel


On 09.11.2009, at 07:10, Steve Krenek wrote:

> Would anyone happen to know how I can determine a domain class's  
> default sort (specified in the mapipng, added in Grails 1.1) at  
> runtime by interrogating the classes?  I've been searching the  
> Grails API and source code all evening, and haven't been able to  
> find to find any reference to it.  I did find a reference in  
> Mapping.groovy, but haven't been able to find a way to obtain the  
> mapping in GrailsDomainClass or the like.
>
> Cheers,
> Steve


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

    http://xircles.codehaus.org/manage_email



Re: domain default sort order

by Robert Fischer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

There's no particularly good way to get information out of the mapping closure.  That's something
that could probably go into GORM Labs.

~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

Grails Expert Retainer Services
http://smokejumperit.com/grails-retainer/


Steve Krenek wrote:

> Would anyone happen to know how I can determine a domain class's default
> sort (specified in the mapipng, added in Grails 1.1) at runtime by
> interrogating the classes?  I've been searching the Grails API and
> source code all evening, and haven't been able to find to find any
> reference to it.  I did find a reference in Mapping.groovy, but haven't
> been able to find a way to obtain the mapping in GrailsDomainClass or
> the like.
>
> Cheers,
> Steve

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

    http://xircles.codehaus.org/manage_email



Re: domain default sort order

by Robert Fischer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I did not know that beast existed.  Learn something new every day!

~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

Grails Expert Retainer Services
http://smokejumperit.com/grails-retainer/


Daniel Rinser wrote:

> Hi Steve,
>
> I guess GrailsDomainBinder is what you are looking for. Try:
>
> import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder
> import org.codehaus.groovy.grails.orm.hibernate.cfg.Mapping
>
> Mapping mapping = GrailsDomainBinder.getMapping(clazz)
> def defaultSort = mapping.sort
> def defaultOrder = mapping.order
>
>
> (not tested though)
>
> Cheers,
> Daniel
>
>
> On 09.11.2009, at 07:10, Steve Krenek wrote:
>
>> Would anyone happen to know how I can determine a domain class's
>> default sort (specified in the mapipng, added in Grails 1.1) at
>> runtime by interrogating the classes?  I've been searching the Grails
>> API and source code all evening, and haven't been able to find to find
>> any reference to it.  I did find a reference in Mapping.groovy, but
>> haven't been able to find a way to obtain the mapping in
>> GrailsDomainClass or the like.
>>
>> Cheers,
>> Steve
>
>
> ---------------------------------------------------------------------
> 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



Re: domain default sort order

by Steve Krenek-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Daniel,
  Your reply got buried in my inbox, so a belated thanks.

To anyone:
Given Robert Fischer's replies (that there's currently no good way to pull info out of the mapping), am I safe enough using the Hibernate specific code below in a plugin?  I know Grails is moving core modules into plugins (including Hibernate), so I don't want to import something that may not be there by default two releases from now.

- Steve

On Mon, Nov 9, 2009 at 7:29 AM, Daniel Rinser <lists@...> wrote:
Hi Steve,

I guess GrailsDomainBinder is what you are looking for. Try:

import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder
import org.codehaus.groovy.grails.orm.hibernate.cfg.Mapping

Mapping mapping = GrailsDomainBinder.getMapping(clazz)
def defaultSort = mapping.sort
def defaultOrder = mapping.order


(not tested though)

Cheers,
Daniel



On 09.11.2009, at 07:10, Steve Krenek wrote:

Would anyone happen to know how I can determine a domain class's default sort (specified in the mapipng, added in Grails 1.1) at runtime by interrogating the classes?  I've been searching the Grails API and source code all evening, and haven't been able to find to find any reference to it.  I did find a reference in Mapping.groovy, but haven't been able to find a way to obtain the mapping in GrailsDomainClass or the like.

Cheers,
Steve


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

  http://xircles.codehaus.org/manage_email




Re: domain default sort order

by David Jacobs-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've yet to run into a case where elements of a GORM closure are not accessible at runtime from a domain class or instance. Using the Grails console seems to be the best way to inspect these runtime properties.

This works:

SomeDomainClass.mapping.mapping.sort
SomeDomainClass.mapping.mapping.order

or:

domainClassInstance.mapping.mapping.sort
domainClassInstance.mapping.mapping.order

Caveat: use techniques like this at your own risk, since they are coupled to current implementations instead of a stable API. I'd love to see a full API reference with best practices for inspecting Grails artifacts.


David Jacobs



On Sun, Nov 22, 2009 at 10:48 PM, Steve Krenek <zeddmaxim@...> wrote:
Daniel,
  Your reply got buried in my inbox, so a belated thanks.

To anyone:
Given Robert Fischer's replies (that there's currently no good way to pull info out of the mapping), am I safe enough using the Hibernate specific code below in a plugin?  I know Grails is moving core modules into plugins (including Hibernate), so I don't want to import something that may not be there by default two releases from now.

- Steve


On Mon, Nov 9, 2009 at 7:29 AM, Daniel Rinser <lists@...> wrote:
Hi Steve,

I guess GrailsDomainBinder is what you are looking for. Try:

import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder
import org.codehaus.groovy.grails.orm.hibernate.cfg.Mapping

Mapping mapping = GrailsDomainBinder.getMapping(clazz)
def defaultSort = mapping.sort
def defaultOrder = mapping.order


(not tested though)

Cheers,
Daniel



On 09.11.2009, at 07:10, Steve Krenek wrote:

Would anyone happen to know how I can determine a domain class's default sort (specified in the mapipng, added in Grails 1.1) at runtime by interrogating the classes?  I've been searching the Grails API and source code all evening, and haven't been able to find to find any reference to it.  I did find a reference in Mapping.groovy, but haven't been able to find a way to obtain the mapping in GrailsDomainClass or the like.

Cheers,
Steve


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

  http://xircles.codehaus.org/manage_email