问题
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