Cool, that is helpful. 

Jeremy

On Aug 27, 2013, at 10:14 AM, GESCONSULTOR - Óscar Bou wrote:

> Hi Jeremy,
> 
> If you want to execute queries by means of JDO, you can inject the 
> IsisJdoSupport service, as of:
> 
> 
>    // {{ injected: IsisJdoSupport
>    protected IsisJdoSupport isisJdoSupport;
> 
>    public void injectIsisJdoSupport(final IsisJdoSupport isisJdoSupport) {
>        this.isisJdoSupport = isisJdoSupport;
>    }
> 
>    // }}
> 
> 
> After that, you can use the service to execute queries against the database. 
> As an example, one "generic" finder method is this one:
> 
>  @SuppressWarnings("unchecked")
>    @Programmatic
>    private <S extends AbstractXMSDomainObject> List<S> doFindByProp(final 
> Class<S> clazz, final String whereClause, final Integer firstResult, final 
> Integer maxResults, final String orderClause) {
> 
>        // Ensure any newly persisted objects are saved to the object store
>        // before executing the query.
>        this.getContainer().flush();
> 
>        // See this for examples:
>        // 
> http://www.datanucleus.org/products/accessplatform_2_1/jdo/query_api.html
>        final Query query = 
> this.isisJdoSupport.getJdoPersistenceManager().newQuery(clazz);
> 
>        // Always add the Tenant filter.
>        String filter = String.format("tenantId == '%s'", 
> this.userAccount.authenticatedUserTenantId());
>        if ((whereClause != null) && (whereClause.trim().length() != 0)) {
>            filter = filter.concat(" && ").concat(whereClause);
>        }
>        query.setFilter(filter);
> 
>        query.setRange(this.firstResultToLong(firstResult), 
> this.maxResultsToLong(maxResults));
>        final List<S> result = (List<S>) query.execute();
>        return result;
>    }
> 
> 
> HTH,
> 
> Oscar

Reply via email to