有谁知道是否有可能使用GridGain实现内存数据网格中存储的对象的模板搜索?让我们考虑以下几点。您有这些类(class):
class Employee{
private Long id;
private String name;
private Address address;
private Account account;
}
class Account{
private Long id;
private String accountNr;
}
class Address{
private String street;
private String postcode;
private String city;
private Country country;
}
然后你就有了一个像这样的搜索模板:
Address address = new Address(null, null, "New York", null);
Employee template = new Employee(null, null,address, null);
grid.read(template);
- 这将找到居住在纽约的所有员工。是否有可能在 GridGain 中实现这一点?如果是这样,你能建议一下如何做吗? 我正在考虑使用 sql 连接来执行此操作,但是我需要在运行时创建这样的查询,并且在 Where 子句之后始终使用不同数量的参数...并且我无法解决此问题。
我将感谢任何帮助/提示。
彼得
最佳答案
你可以使用这样的东西:
public class Address {
@GridCacheQuerySqlField(unique = true)
private long id;
@GridCacheQuerySqlField
private String street;
@GridCacheQuerySqlField
private String postcode;
@GridCacheQuerySqlField
private String city;
@GridCacheQuerySqlField
private Country country;
}
public class Employee {
@GridCacheQuerySqlField(unique=true)
private long id;
@GridCacheQuerySqlField
private long addressId; // Address ID.
// Not indexed.
private String name;
}
然后进行查询:
GridCacheQuery<Map.Entry<Long, Employee>> qry = cache.queries().createSqlQuery(Employee.class,
"from Employee, Address where Employee.addressId = Address.id " +
"and Address.name = ?");
// Query all nodes to find all cached CompanyZ employees in New York
qry.execute("CompanyZ","New York");
关于java - GridGain 模板搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22987403/