The document discusses Achilles, an open source Java library that provides an object mapping layer for Apache Cassandra. It allows for rapid prototyping with Cassandra by providing a concise API for CRUD operations, queries, validation, batch processing and more. The document outlines Achilles' main features and capabilities, provides code examples, and invites the reader to learn more and download Achilles from their website.
6. Main API
•manager.insert(entity)
!
•manager.update(managedEntity)
!
•manager.remove(entity)
!
•manager.find(Entity.class, primaryKey)
www.achilles.io 6
@doanduyhai
7. Thread safety for persistence manager
No JOINS means
www.achilles.io 7
@doanduyhai
8. Thread safety for persistence manager
No JOINS means
!
!
No complex object graph
www.achilles.io 8
@doanduyhai
9. Thread safety for persistence manager
No JOINS means
!
!
No complex object graph
!
!
No state to keep
www.achilles.io 9
@doanduyhai
10. What’s about proxy ?
proxifiedEntity = manager.find(Entity.class, primaryKey)
Dirty check
www.achilles.io 10
@doanduyhai
ProxifiedEntity
Real
Entity
State
Setters interception
11. Why proxies ?
emc² Albert EINSTEIN GERMANY
User einstein = manager.find(User.class,”emc²”);
!
einstein.setCountry(“USA”);
!
manager.insert(einstein);
emc² Albert EINSTEIN GERMANY emc² Albert EINSTEIN USA
www.achilles.io 11
@doanduyhai
Waste of space !!
12. Why proxies ?
emc² Albert EINSTEIN GERMANY
User einstein = manager.find(User.class,”emc²”);
!
einstein.setCountry(“USA”);
!
manager.update(einstein);
emc² Albert EINSTEIN GERMANY USA
www.achilles.io 12
@doanduyhai
13. Slice query
List<Message> entities = manager.sliceQuery(Message.class)
.forSelect()
.withPartitionComponents(10L)
.fromClusterings(“forums”).toClusterings(“forums”, uuid1)
.limit(10).fromInclusiveToExclusiveBounds()
.get();
SELECT * FROM Message
WHERE user_id = 10
AND (message_folder) ≥ (‘forums’)
AND (message_folder, date) < (‘forums’, uuid1)
ORDER BY message_folder ASC LIMIT 10;
www.achilles.io 13
@doanduyhai
15. Native query
RegularStatement nativeQuery = new SimpleStatement(“SELECT * FROM Message
WHERE … LIMIT 20”);
!
List<TypedMap> messages = manager.nativeQuery(nativeQuery).get();
!
TypedMap firstMessage = messages.get(0);
!
// with normal Map<String, Object>
// String interlocutor = (String) map.get(“interlocutor”);
!
String interlocutor = firstMessage.getTyped(“interlocutor”);
String interlocutor = firstMessage.<String>getTyped(“interlocutor”);
www.achilles.io 15
@doanduyhai
16. Counter API
Special proxy type
www.achilles.io 16
@doanduyhai
public Long get();
!
public void incr();
!
public void incr(Long increment);
!
public void decr();
!
public void decr(Long decrement);
17. Options
•Setting C* special options
•Apply to main API insert(), update(), remove() …
www.achilles.io 17
@doanduyhai
manager.insert(user,
OptionsBuilder
.withConsistency(QUORUM)
.ttl(10)
.timestamp(1357949499999L)
.ifNotExists()
);
18. Lifecycle interceptors
Hooks into persistence lifecycle
www.achilles.io 18
@doanduyhai
public interface Interceptor<T> {
public void onEvent(T entity);
public List<Event> events();
}
!
public enum Event {
PRE_PERSIST, POST_PERSIST, PRE_UPDATE, POST_UPDATE, PRE_REMOVE,
POST_REMOVE, POST_LOAD;
}
19. Bean Validation (JSR-303)
Just a built-in interceptor, PRE_PERSIST, PRE_UPDATE
@Entity(table = “entity”)
public class Entity {
@Id
private Long id;
!
@Column
@NotEmpty
private String name;
}
www.achilles.io 19
@doanduyhai