JDBI喜欢cassandra的图层

时间:2014-11-27 09:04:12

标签: orm cassandra jdbi

我正在开发一个以cassandra作为后端的模块。为cassandra搜索JDBI类库。 Cassandra java驱动程序是我的主要选择。想知道在cassandra java驱动程序之上是否存在用于更高级抽象的库。

1 个答案:

答案 0 :(得分:1)

最新的Java驱动程序附带了一个对象映射API。

基本上,您可以注释Java类:

@Table(keyspace = "complex", name = "accounts")
public class Account {
    @PartitionKey
    private String email;
    private String name;
    @Column (name = "addr")
    @Frozen
    private Address address;

然后你可以执行这样的典型CRUD操作:

Mapper<Account> mapper = new MappingManager(getSession()).mapper(Account.class);
Phone phone = new Phone("home", "707-555-3537");
List<Phone> phones = new ArrayList<Phone>();
phones.add(phone);
Address address = new Address("25800 Arnold Drive", "Sonoma", 95476, phones);
Account account = new Account("John Doe", "jd@example.com", address);
mapper.save(account);
Account whose = mapper.get("jd@example.com");
System.out.println("Account name: " + whose.getName());
mapper.delete(account);

查看此DataStax doc for a complete explanation(带代码)。