2. • 2001 - inception
• 2002 - first “alpha” release and a large production deployment
• 2006 - Cayenne becomes “Apache Cayenne”
• still active and evolving...
History
3. • A top-level project at Apache Software Foundation
• 17 committers
• 9 PMC members
• Majority of PMC have WO/EOF background
• ... not all are active ...
Project Structure and
Governance
4. Releases
• 3.0 - current stable
• 3.1 - Beta, recommended for all users
• 3.2 - in development; used for this presentation
7. DB layer: DbEntities containing DbAttributes and
connected with DbRlationships
• DbEntity - models a table or a view
• DbAttribute - models a column
• DbRelationship - models PK/FK relationship going in one
direction
8. Object layer: ObjEntities containing ObjAttributes
and connected with ObjRlationships
• ObjEntity - models a persistent Java class
• ObjAttribute - models a “simple” property of a Java class
• ObjRelationship - models a “relationship” property, i.e. a
property of type that is another ObjEntity (can be to-one or to-
many). Going in one direction only.
10. Connecting Obj to Db Layer
• (simple attribute) ObjAttribute references a DbAttribute
• (flattened attribute) ObjAttribute references a “dbpath” across
one or more DbRelationships ending with an attribute
11. Connecting Obj to Db Layer
• (simple relationship) ObjRelationship references a
DbRelationship
• (flattened relationship) ObjRelationship references a “dbpath”
across 2 or more DbRelationships
27. When to use Modeler-free
workflow?
• when DB objects have sane naming
• when DB has FK constraints defined
• when no per-entity model tweaking is needed (optimistic
locking, PK generation, exclusion of attributes, etc.)
33. ObjectContext
• An isolated “session” to access Cayenne
• Has its own copy of each object
• Doesn’t require explicit shutdown (can be simply thrown away
when no longer in use)
• Can be serialized
• Can be scoped differently based on app requirements
35. Overriding a DI service to create custom
ObjectContexts
public class MyContextFactory implements ObjectContextFactory {
@Inject
private EventManager eventManager;
@Override
public ObjectContext createContext() {
return new MyContext(eventManager);
}
@Override
public ObjectContext createContext(DataChannel parent) {
return new MyContext(parent, eventManager);
}
}
Module myModule = new Module() {
@Override
public void configure(Binder binder) {
binder.bind(ObjectContextFactory.class).to(MyContextFactory.class);
}
};
// override built-in services via a custom module
ServerRuntime runtime = new ServerRuntime("cayenne-myproject.xml", myModule);
36. DI Container Highlights
• Very small - 40K
• Intended to make Cayenne runtime modular and customizable
• Does not interfere with or care about application DI
• Can be used outside Cayenne, but this was not the goal
38. SelectQuery
• Most commonly used query
• Data rows option
• Fetch offset/limit
• Prefetching (separate strategies)
• Result caching, pagination
• Iterated result
43. Can be used with any Query and is fairly transparent
SelectQuery<Artist> query = new SelectQuery<Artist>(Artist.class);
query.andQualifier(Artist.ARTIST_NAME.like("A%"));
// This is all it takes to cache the result.
// There’s no need to calculate a cache key.
// Cayenne will do that for you
query.useLocalCache();
List<Artist> someArtists = context.select(query);
44. Lifecycle Events
• PostAdd, PrePersist, PreUpdate, PreRemove, PostPersist,
PostUpdate, PostRemove, PostLoad
• Persistent objects can declare callback methods to be notified
about own events
• Any non-persistent object can be a listener for various entity
events.
45. Lifecycle Events
• Higher-level “workflows” are implemented by matching entities
with listeners using custom annotations and providing operation
context via DataChannelFilter
47. ROP Highlights
• Same as nested ObjectContext, only child context lives in a
remote JVM
• Full ORM API and behavior available on the client:
• Queries, lazy relationships, caching, pagination, etc.
• Client objects based on the same model as server
• Client objects are using a different superclass