JDBI like layer for cassandra

被刻印的时光 ゝ 提交于 2019-12-11 09:33:56

问题


I am developing a module having cassandra as backend. Searching for JDBI sort of library for cassandra. Cassandra java driver is my primary option. Would like to know if there is exists library for higher level abstraction on top of cassandra java driver.


回答1:


The latest Java Driver comes with an object mapping API.

Basically, you can annotate your Java class:

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

Then you can perform typical CRUD operations like this:

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);

Check out this DataStax doc for a complete explanation (with code).



来源:https://stackoverflow.com/questions/27166695/jdbi-like-layer-for-cassandra

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!