JDBI like layer for cassandra

569 views Asked by At

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

There are 1 answers

1
Aaron On BEST ANSWER

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", "[email protected]", address);
mapper.save(account);
Account whose = mapper.get("[email protected]");
System.out.println("Account name: " + whose.getName());
mapper.delete(account);

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