1

有谁知道是否有可能使用 GridGain 实现对存储在内存数据网格中的对象的模板搜索?让我们考虑以下内容。你有这些课程:

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 子句之后总是使用不同数量的参数......我无法解决这个问题。

我将感谢任何帮助/提示。

彼得

4

1 回答 1

1

你可以使用这样的东西:

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");
于 2014-04-10T12:50:00.287 回答