我使用GridGain作为我的数据对象(pojos)的本地内存存储,我需要查询这些对象并选择具有特定值的正确对象。让我们考虑以下情况:
class Person {
public Long id;
public String name;
public Organization organization;
}
class Organization{
public Long id;
public String name;
}
您能否建议如何进行查询以便检索,例如特定组织的所有人? 我试过以下:
final GridCacheProjection<GridCacheAffinityKey<Long>, Person> appCache = cache.projection(GridCacheAffinityKey.class, Person.class);
final GridCacheQuery<Map.Entry<GridCacheAffinityKey<Long>, Person>> query = appCache.queries().createSqlQuery(Person.class, "from Person, Organization " + "where Person.organization.id = " + "Organization.id = ?");
但没有运气。我发现很多使用Person.id = Organization.id =的例子?但是我将Organization作为Person类中的对象,那么如何以这种方式编写查询或检索数据?
提前感谢任何提示。
答案 0 :(得分:0)
您的代码看起来不正确。
查看GitHub上提供的CacheQueryExample(也随GridGain一起提供)
特别是在进行连接的部分:
// Create query which joins on 2 types to select people for a specific organization.
GridCacheQuery<Map.Entry<GridCacheAffinityKey<UUID>, Person>> qry = cache.queries().
createSqlQuery(Person.class,
"from Person, Organization " + "where Person.orgId = Organization.id and " +
"lower(Organization.name) = lower(?)");
// Execute queries for find employees for different organizations.
print("Following people are 'GridGain' employees: ", qry.execute("GridGain").get());
print("Following people are 'Other' employees: ", qry.execute("Other").get());