Sunday, September 13, 2009

AppEngine datastore query: WHERE statement

When writing AppEngine queries here is the simplest of examples:

    public List<RecipeStep> fetch(Long recipeId)
    { 
checkPersistenceManager();

String query = "SELECT FROM " + RecipeStep.class.getName() + " WHERE recipeId == " + recipeId.longValue();
List<RecipeStep> steps = null;

try
{
    steps = (List<RecipeStep>) pm.newQuery(query).execute()
} finally
{
    pm.close();
}


List<RecipeStep> returnList = new ArrayList<RecipeStep>();
for(RecipeStep step: steps)
{
    returnList.add(step);
}
return returnList;
    }