JDO查询帮助(按成分查找菜谱)

发布于 2024-11-09 16:06:52 字数 1322 浏览 0 评论 0原文

我需要一些有关 JDO 查询的帮助。

我有以下实体:

recipe:

@PersistenceCapable
class Recipe{

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long key;

    ...

    @Persistent(mappedBy = "recipe")
    private List<RecipeIngredient> ingredients
}

recipeIngredient:

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
class RecipeIngredient implements Serializable {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    Integer amount

    @Persistent
    Key unit

    @Persistent
    Key ingredient

    @Persistent
    Recipe recipe

成分:

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
class Ingredient implements Serializable {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    String name

一个Recipe可以有多个recipeIngredients,其中包含实际成分、成分的数量和单位。

我想按成分获取所有食谱,这些成分仅含有给定的成分,而不是更多。

目前我这样做:

  • 按成分名称获取所有成分对象
  • 按成分键获取所有配方成分对象
  • 按配方成分获取所有配方
  • 检查配方中的所有配方成分是否都在之前的配方成分列表中
  • 如果是的话 将配方添加到输出列表

我可以这样做吗一个查询?也许类似于拥有的东西?

I need some help with a JDO query.

I have the following Entities:

recipe:

@PersistenceCapable
class Recipe{

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long key;

    ...

    @Persistent(mappedBy = "recipe")
    private List<RecipeIngredient> ingredients
}

recipeIngredient:

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
class RecipeIngredient implements Serializable {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    Integer amount

    @Persistent
    Key unit

    @Persistent
    Key ingredient

    @Persistent
    Recipe recipe

ingredient:

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
class Ingredient implements Serializable {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    String name

A Recipe can have several recipeIngredients which holds the actual ingredient, the amount of the ingredient and the unit.

I would like to get all recipes by ingredients which only hold the given ingredients and not more.

At the moment I do this:

  • get all ingredient objects by ingredient name
  • get all recipeIngredient objects by ingredient key
  • get all recipes by recipeIngredient
  • check if all recipeIngredients from recipe are in recipeIngredient list from before
  • if so add recipe to output list

Can I do this with a query? maybe something similar to having ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放飞的风筝 2024-11-16 16:06:52

尝试类似...

select r from Recipe r
        where ingredients.contains(ri) && (ri.ingredient.name.matches(:searchTxt))

另请参阅: http://www.datanucleus .org/servlet/forum/listthreads?forum=9

我不使用 Google App Engine,但我确实大量使用 DataNucleus,并且我相信 DataNucleus 是 App Engine 使用的 JDO 的实现。

让我知道这在 App Engine 上是如何工作的,因为我一直在我的应用程序中做同样的事情。

Try something like...

select r from Recipe r
        where ingredients.contains(ri) && (ri.ingredient.name.matches(:searchTxt))

Also take a look at: http://www.datanucleus.org/servlet/forum/listthreads?forum=9

I don't use Google App Engine but I do use DataNucleus heavily and I believe that DataNucleus is the implementation of JDO that the App Engine uses.

Let me know how this works on App Engine as I do this same kind of thing all the time in my apps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文