Hi Paul,

FWIW, Here is a slightly edited version of my JDO query by id.
Perhaps it can help you get over this bump.

@SuppressWarnings("unchecked")
public Account lookupAccountById( PersistenceManager pm, Long accountId) {
    logger.fine("looking up account id=" + accountId );
    // look up
    Query q1 = pm.newQuery(Account.class, "id == accountId");
    q1.declareParameters("Long accountId");
    List<Account> accounts = (List<Account>) q1.execute(accountId);
    if (accounts == null || accounts.isEmpty()) {
        logger.warning("Account Id = " + accountId + " not found.");
        return null;
    }
    return (accounts.get(0));
}





On Fri, Oct 1, 2010 at 4:13 PM, Paul <[email protected]> wrote:

> Hi,
>
> I must admit that my db knowledge is very lacking, thus I need some
> help with making a simple query. I know I am just missing smth obvious
> and easy.
>
> Anyway, what I need is just a boolean method to check if enity
> exists.
>
> I am using Guice too, for binding all stuff.
>
> I know that the query syntax is SELECT * FROM entity WHERE __key__ =
> KEY('entity', 'key name')
>
> My class for DB queries looks like that [yeah, from gae-wicket
> template]:
>
> public abstract class JdoQueries<T>
> {
>    private final Class<T> clazz;
>    private final Provider<PersistenceManager> pmProvider;
>
>    protected JdoQueries(Class<T> clazz, Provider<PersistenceManager>
> pmProvider)
>    {
>        this.clazz = clazz;
>        this.pmProvider = pmProvider;
>    }
>
>    protected Query newQuery()
>    {
>        return pmProvider.get().newQuery(clazz);
>    }
>
>    @SuppressWarnings("unchecked")
>    protected Collection<T> toCollection(Object queryResult)
>    {
>        return (Collection<T>) queryResult;
>    }
>
>    protected List<T> toList(Object queryResult)
>    {
>        return new ArrayList<T>(toCollection(queryResult));
>    }
> }
>
>
> I know I should create public interface for query I need, then create
> a class extending JdoQueries and implementing my interface, but it's
> just theory and I cannot write that final part :)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to