【问题标题】:JDBI like layer for cassandra用于 cassandra 的 JDBI 类层
【发布时间】:2014-11-27 09:04:12
【问题描述】:

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

【问题讨论】:

    标签: orm cassandra jdbi


    【解决方案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(附代码)。

    【讨论】:

    • 哦.. 超级。太感谢了。我浏览了第 25 页。将完全休息。
    猜你喜欢
    • 2020-10-18
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-08
    • 1970-01-01
    相关资源
    最近更新 更多