SlideShare a Scribd company logo
1 of 60
Download to read offline
Apache Cayenne for WO Devs
by Andrus Adamchik, ObjectStyle LLC
• 2001 - inception
• 2002 - first “alpha” release and a large production deployment
• 2006 - Cayenne becomes “Apache Cayenne”
• still active and evolving...
History
• 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
Releases
• 3.0 - current stable
• 3.1 - Beta, recommended for all users
• 3.2 - in development; used for this presentation
Mapping Structure
Separate DB and Object Layers
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
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.
Connecting Obj to Db Layer
• ObjEntity references a single DbEntity
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
Connecting Obj to Db Layer
• (simple relationship) ObjRelationship references a
DbRelationship
• (flattened relationship) ObjRelationship references a “dbpath”
across 2 or more DbRelationships
CayenneModeler
Cross-platform natively-packaged tool
to work on Cayenne mapping projects
Tools > Reengineer Database Schema
Tools > Generate Database Schema
Tools > Migrate Schema
Tools > Generate Classes
Tools > Import EOModel
Modeling Workflow
Challenge - keeping these in sync:
Maven and Ant Tools
• cgen - generates classes from the ORM model
• cdbimport - generates model from DB
• cdbgen - generates DB from the model
Modeler Workflow
... on project start:
Modeler Workflow
... on each iteration:
Modeler-Free Workflow
... on project start:
Modeler-Free Workflow
... on each iteration:
Modeler-free Workflow - Maven
<plugin>
	 <groupId>org.apache.cayenne.plugins</groupId>
	 <artifactId>maven-cayenne-plugin</artifactId>
	 <configuration>
	 	 <map>${project.basedir}/src/main/resources/my.map.xml</map>
	 	 <destDir>${project.basedir}/src/main/java</destDir>
	 	 <defaultPackage>com.example.cayenne</defaultPackage>
	 	 <superPkg>com.example.cayenne.auto</superPkg>
	 	 <url>jdbc:mysql://127.0.0.1/mydb</url>
	 	 <username>user</username>
	 	 <password>secret</password>
	 	 <driver>com.mysql.jdbc.Driver</driver>
	 	 <excludeTables>migrations</excludeTables>
	 </configuration>
	 <executions>
	 	 <execution>
	 	 	 <id>default-cli</id>
	 	 	 <goals>
	 	 	 	 <goal>cdbimport</goal>
	 	 	 	 <goal>cgen</goal>
	 	 	 </goals>
	 	 </execution>
	 </executions>
</plugin>
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.)
Writing Apps with Cayenne
Starting Cayenne
// create reusable ‘runtime’ instance
ServerRuntime runtime = new ServerRuntime("cayenne-myproject.xml");
Stopping Cayenne
runtime.shutdown();
ObjectContext
Obtaining ObjectContext
// regular context
ObjectContext context = runtime.newContext();
// nested context
ObjectContext nestedContext = runtime.newContext(context);
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
Under the Hood ServerRuntime
is a DI container
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);
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
Queries
SelectQuery
• Most commonly used query
• Data rows option
• Fetch offset/limit
• Prefetching (separate strategies)
• Result caching, pagination
• Iterated result
SelectQuery
ObjectContext context = ...
SelectQuery<Artist> query = new SelectQuery<Artist>(Artist.class);
List<Artist> allArtists = context.select(query);
SelectQuery with qualifier
ObjectContext context = ...
SelectQuery<Artist> query = new SelectQuery<Artist>(Artist.class);
query.andQualifier(Artist.NAME.like("A%"));
query.andQualifier(Artist.DATE_OF_BIRTH.lt(new Date()));
List<Artist> someArtists = context.select(query);
INFO: SELECT t0.NAME, t0.DATE_OF_BIRTH, t0.ID FROM ARTIST t0 WHERE (t0.NAME LIKE ?) AND (t0.DATE_OF_BIRTH < ?)
[bind: 1->NAME:'A%', 2->DATE_OF_BIRTH:'2013-05-09 20:51:12.759']
INFO: === returned 1 row. - took 2 ms.
Other Queries
• EJBQLQuery
• SQLTemplate
• ProcedureQuery
• ObjectIdQuery, RelationshipQuery, QueryChain
• Custom queries...
Caching Query Results
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);
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.
Lifecycle Events
• Higher-level “workflows” are implemented by matching entities
with listeners using custom annotations and providing operation
context via DataChannelFilter
Remote Object Persistence
(ROP)
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
Other ORM Choices
• Hibernate
• JPA
Cayenne Difference - Object Design
Others
enhanced/proxied POJO	

ORM Annotations
Cayenne
framework superclass	

annotations used for other things
Advantage
faster startup times
“WYSIWYG” objects
generic persistent objects
less code clutter
Cayenne Difference - Runtime
Others explicit transactions
Cayenne on-demand implicit transactions
Advantage
less code, cleaner code
seamless relationship navigation
EOF Analogies
“All characters and events – even those based on real people
– are entirely fictional.”
Persistent Objects
• EOEnterpriseObject : Persistent, DataObject, CayenneDataObject
• EOGlobalID : ObjectId
• EOGenericRecord : CayenneDataObject
Mapping
• EOModel : DataMap
• EOModelGroup : EntityResolver
• EOEntity: DbEntity / ObjEntity
Query
• EOFetchSpecification : SelectQuery
• EOQualifier : Expression
• EOSortOrdering : Ordering
Runtime
• EOEditingContext : ObjectContext
• EOAdapter : DataNode
• JDBCPlugin : DbAdapter
Cayenne != EOF
WhatYou Might Miss from EOF
• QuirkyVertical Inheritance
• No Horizontal Inheritance
• No prototypes
• No Eclipse plugin
WhatYou Get in Return
• Multithreading
• IDE-independent Modeler
• Internal dependency injection
• Query abstraction beyond
SelectQuery
• EJBQL and aggregated queries
• Iterated query
• Transparent Query result cache
• Transparent Query result pagination
• Auto-increment PK
• Automated DB type detection
• Prefetch strategies
• Lifecycle events
A chance to influence things!
Q&A
Andrus Adamchik
andrus@objectstyle.com
twitter.com/andrus_a

More Related Content

What's hot

Getting started with ReactJS
Getting started with ReactJSGetting started with ReactJS
Getting started with ReactJSKrishna Sunuwar
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Oscar Merida
 
RESTful OSGi Web Applications Tutorial - Khawaja S Shams & Jeff Norris
RESTful OSGi Web Applications Tutorial - Khawaja S Shams & Jeff NorrisRESTful OSGi Web Applications Tutorial - Khawaja S Shams & Jeff Norris
RESTful OSGi Web Applications Tutorial - Khawaja S Shams & Jeff Norrismfrancis
 
Java EE revisits design patterns
Java EE revisits design patterns Java EE revisits design patterns
Java EE revisits design patterns Alex Theedom
 
Build Amazing Add-ons for Atlassian JIRA and Confluence
Build Amazing Add-ons for Atlassian JIRA and ConfluenceBuild Amazing Add-ons for Atlassian JIRA and Confluence
Build Amazing Add-ons for Atlassian JIRA and ConfluenceK15t
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
20151010 my sq-landjavav2a
20151010 my sq-landjavav2a20151010 my sq-landjavav2a
20151010 my sq-landjavav2aIvan Ma
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbtFabio Fumarola
 
Getting started with sbt
Getting started with sbtGetting started with sbt
Getting started with sbtikenna4u
 
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rulesSrijan Technologies
 
Connect 2016-Move Your XPages Applications to the Fast Lane
Connect 2016-Move Your XPages Applications to the Fast LaneConnect 2016-Move Your XPages Applications to the Fast Lane
Connect 2016-Move Your XPages Applications to the Fast LaneHoward Greenberg
 
In memory OLAP engine
In memory OLAP engineIn memory OLAP engine
In memory OLAP engineWO Community
 
JPA and Hibernate Performance Tips
JPA and Hibernate Performance TipsJPA and Hibernate Performance Tips
JPA and Hibernate Performance TipsVlad Mihalcea
 
Java build tool_comparison
Java build tool_comparisonJava build tool_comparison
Java build tool_comparisonManav Prasad
 
My "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsMy "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsGR8Conf
 

What's hot (20)

Getting started with ReactJS
Getting started with ReactJSGetting started with ReactJS
Getting started with ReactJS
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)
 
RESTful OSGi Web Applications Tutorial - Khawaja S Shams & Jeff Norris
RESTful OSGi Web Applications Tutorial - Khawaja S Shams & Jeff NorrisRESTful OSGi Web Applications Tutorial - Khawaja S Shams & Jeff Norris
RESTful OSGi Web Applications Tutorial - Khawaja S Shams & Jeff Norris
 
Mule 2.2.1-users-guide
Mule 2.2.1-users-guideMule 2.2.1-users-guide
Mule 2.2.1-users-guide
 
Java EE revisits design patterns
Java EE revisits design patterns Java EE revisits design patterns
Java EE revisits design patterns
 
Build Amazing Add-ons for Atlassian JIRA and Confluence
Build Amazing Add-ons for Atlassian JIRA and ConfluenceBuild Amazing Add-ons for Atlassian JIRA and Confluence
Build Amazing Add-ons for Atlassian JIRA and Confluence
 
Play framework
Play frameworkPlay framework
Play framework
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Real World MVC
Real World MVCReal World MVC
Real World MVC
 
20151010 my sq-landjavav2a
20151010 my sq-landjavav2a20151010 my sq-landjavav2a
20151010 my sq-landjavav2a
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbt
 
SBT Crash Course
SBT Crash CourseSBT Crash Course
SBT Crash Course
 
Getting started with sbt
Getting started with sbtGetting started with sbt
Getting started with sbt
 
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
 
Connect 2016-Move Your XPages Applications to the Fast Lane
Connect 2016-Move Your XPages Applications to the Fast LaneConnect 2016-Move Your XPages Applications to the Fast Lane
Connect 2016-Move Your XPages Applications to the Fast Lane
 
In memory OLAP engine
In memory OLAP engineIn memory OLAP engine
In memory OLAP engine
 
JPA and Hibernate Performance Tips
JPA and Hibernate Performance TipsJPA and Hibernate Performance Tips
JPA and Hibernate Performance Tips
 
Geotalk presentation
Geotalk presentationGeotalk presentation
Geotalk presentation
 
Java build tool_comparison
Java build tool_comparisonJava build tool_comparison
Java build tool_comparison
 
My "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsMy "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails Projects
 

Viewers also liked

Reenabling SOAP using ERJaxWS
Reenabling SOAP using ERJaxWSReenabling SOAP using ERJaxWS
Reenabling SOAP using ERJaxWSWO Community
 
Using Nagios to monitor your WO systems
Using Nagios to monitor your WO systemsUsing Nagios to monitor your WO systems
Using Nagios to monitor your WO systemsWO Community
 
Build and deployment
Build and deploymentBuild and deployment
Build and deploymentWO Community
 
Migrating existing Projects to Wonder
Migrating existing Projects to WonderMigrating existing Projects to Wonder
Migrating existing Projects to WonderWO Community
 
Filtering data with D2W
Filtering data with D2W Filtering data with D2W
Filtering data with D2W WO Community
 
Advanced Apache Cayenne
Advanced Apache CayenneAdvanced Apache Cayenne
Advanced Apache CayenneWO Community
 
Chaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real WorldChaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real WorldWO Community
 
Unit Testing with WOUnit
Unit Testing with WOUnitUnit Testing with WOUnit
Unit Testing with WOUnitWO Community
 
iOS for ERREST - alternative version
iOS for ERREST - alternative versioniOS for ERREST - alternative version
iOS for ERREST - alternative versionWO Community
 
Deploying WO on Windows
Deploying WO on WindowsDeploying WO on Windows
Deploying WO on WindowsWO Community
 
"Framework Principal" pattern
"Framework Principal" pattern"Framework Principal" pattern
"Framework Principal" patternWO Community
 

Viewers also liked (16)

iOS for ERREST
iOS for ERRESTiOS for ERREST
iOS for ERREST
 
Reenabling SOAP using ERJaxWS
Reenabling SOAP using ERJaxWSReenabling SOAP using ERJaxWS
Reenabling SOAP using ERJaxWS
 
Using Nagios to monitor your WO systems
Using Nagios to monitor your WO systemsUsing Nagios to monitor your WO systems
Using Nagios to monitor your WO systems
 
Build and deployment
Build and deploymentBuild and deployment
Build and deployment
 
Migrating existing Projects to Wonder
Migrating existing Projects to WonderMigrating existing Projects to Wonder
Migrating existing Projects to Wonder
 
Filtering data with D2W
Filtering data with D2W Filtering data with D2W
Filtering data with D2W
 
WOver
WOverWOver
WOver
 
Advanced Apache Cayenne
Advanced Apache CayenneAdvanced Apache Cayenne
Advanced Apache Cayenne
 
Chaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real WorldChaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real World
 
Life outside WO
Life outside WOLife outside WO
Life outside WO
 
Unit Testing with WOUnit
Unit Testing with WOUnitUnit Testing with WOUnit
Unit Testing with WOUnit
 
iOS for ERREST - alternative version
iOS for ERREST - alternative versioniOS for ERREST - alternative version
iOS for ERREST - alternative version
 
KAAccessControl
KAAccessControlKAAccessControl
KAAccessControl
 
Deploying WO on Windows
Deploying WO on WindowsDeploying WO on Windows
Deploying WO on Windows
 
High availability
High availabilityHigh availability
High availability
 
"Framework Principal" pattern
"Framework Principal" pattern"Framework Principal" pattern
"Framework Principal" pattern
 

Similar to Apache Cayenne for WO Devs

Apache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM AlternativeApache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM AlternativeAndrus Adamchik
 
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
ZZ BC#7 asp.net mvc practice and guideline by NineMvpZZ BC#7 asp.net mvc practice and guideline by NineMvp
ZZ BC#7 asp.net mvc practice and guideline by NineMvpChalermpon Areepong
 
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...HostedbyConfluent
 
04 integrate entityframework
04 integrate entityframework04 integrate entityframework
04 integrate entityframeworkErhwen Kuo
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
ZZ BC#7.5 asp.net mvc practice  and guideline refresh! ZZ BC#7.5 asp.net mvc practice  and guideline refresh!
ZZ BC#7.5 asp.net mvc practice and guideline refresh! Chalermpon Areepong
 
JavaScript and jQuery for SharePoint Developers
JavaScript and jQuery for SharePoint DevelopersJavaScript and jQuery for SharePoint Developers
JavaScript and jQuery for SharePoint DevelopersRob Windsor
 
Elements for an iOS Backend
Elements for an iOS BackendElements for an iOS Backend
Elements for an iOS BackendLaurent Cerveau
 
Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)Robert Scholte
 
The Meteor Framework
The Meteor FrameworkThe Meteor Framework
The Meteor FrameworkDamien Magoni
 
Developing Liferay Plugins with Maven
Developing Liferay Plugins with MavenDeveloping Liferay Plugins with Maven
Developing Liferay Plugins with MavenMika Koivisto
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015Hossein Zahed
 
2011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 52011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 5Daniel Fisher
 

Similar to Apache Cayenne for WO Devs (20)

Apache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM AlternativeApache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM Alternative
 
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
ZZ BC#7 asp.net mvc practice and guideline by NineMvpZZ BC#7 asp.net mvc practice and guideline by NineMvp
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
 
JS Essence
JS EssenceJS Essence
JS Essence
 
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
 
Backbonejs
BackbonejsBackbonejs
Backbonejs
 
04 integrate entityframework
04 integrate entityframework04 integrate entityframework
04 integrate entityframework
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Liferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for DevelopersLiferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for Developers
 
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
ZZ BC#7.5 asp.net mvc practice  and guideline refresh! ZZ BC#7.5 asp.net mvc practice  and guideline refresh!
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
 
JavaScript and jQuery for SharePoint Developers
JavaScript and jQuery for SharePoint DevelopersJavaScript and jQuery for SharePoint Developers
JavaScript and jQuery for SharePoint Developers
 
Elements for an iOS Backend
Elements for an iOS BackendElements for an iOS Backend
Elements for an iOS Backend
 
Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)
 
The Meteor Framework
The Meteor FrameworkThe Meteor Framework
The Meteor Framework
 
70487.pdf
70487.pdf70487.pdf
70487.pdf
 
AngularJS
AngularJSAngularJS
AngularJS
 
Maven
MavenMaven
Maven
 
Developing Liferay Plugins with Maven
Developing Liferay Plugins with MavenDeveloping Liferay Plugins with Maven
Developing Liferay Plugins with Maven
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
 
2011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 52011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 5
 

More from WO Community

Localizing your apps for multibyte languages
Localizing your apps for multibyte languagesLocalizing your apps for multibyte languages
Localizing your apps for multibyte languagesWO Community
 
CMS / BLOG and SnoWOman
CMS / BLOG and SnoWOmanCMS / BLOG and SnoWOman
CMS / BLOG and SnoWOmanWO Community
 
Persistent Session Storage
Persistent Session StoragePersistent Session Storage
Persistent Session StorageWO Community
 
WebObjects Optimization
WebObjects OptimizationWebObjects Optimization
WebObjects OptimizationWO Community
 
ERRest: the Basics
ERRest: the BasicsERRest: the Basics
ERRest: the BasicsWO Community
 

More from WO Community (10)

Localizing your apps for multibyte languages
Localizing your apps for multibyte languagesLocalizing your apps for multibyte languages
Localizing your apps for multibyte languages
 
WOdka
WOdkaWOdka
WOdka
 
ERGroupware
ERGroupwareERGroupware
ERGroupware
 
CMS / BLOG and SnoWOman
CMS / BLOG and SnoWOmanCMS / BLOG and SnoWOman
CMS / BLOG and SnoWOman
 
Using GIT
Using GITUsing GIT
Using GIT
 
Persistent Session Storage
Persistent Session StoragePersistent Session Storage
Persistent Session Storage
 
Back2 future
Back2 futureBack2 future
Back2 future
 
WebObjects Optimization
WebObjects OptimizationWebObjects Optimization
WebObjects Optimization
 
Dynamic Elements
Dynamic ElementsDynamic Elements
Dynamic Elements
 
ERRest: the Basics
ERRest: the BasicsERRest: the Basics
ERRest: the Basics
 

Recently uploaded

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Recently uploaded (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

Apache Cayenne for WO Devs

  • 1. Apache Cayenne for WO Devs by Andrus Adamchik, ObjectStyle LLC
  • 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
  • 6. Separate DB and Object Layers
  • 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.
  • 9. Connecting Obj to Db Layer • ObjEntity references a single DbEntity
  • 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
  • 13. Cross-platform natively-packaged tool to work on Cayenne mapping projects
  • 14. Tools > Reengineer Database Schema
  • 15. Tools > Generate Database Schema
  • 16. Tools > Migrate Schema
  • 17. Tools > Generate Classes
  • 18. Tools > Import EOModel
  • 20. Challenge - keeping these in sync:
  • 21. Maven and Ant Tools • cgen - generates classes from the ORM model • cdbimport - generates model from DB • cdbgen - generates DB from the model
  • 22. Modeler Workflow ... on project start:
  • 23. Modeler Workflow ... on each iteration:
  • 25. Modeler-Free Workflow ... on each iteration:
  • 26. Modeler-free Workflow - Maven <plugin> <groupId>org.apache.cayenne.plugins</groupId> <artifactId>maven-cayenne-plugin</artifactId> <configuration> <map>${project.basedir}/src/main/resources/my.map.xml</map> <destDir>${project.basedir}/src/main/java</destDir> <defaultPackage>com.example.cayenne</defaultPackage> <superPkg>com.example.cayenne.auto</superPkg> <url>jdbc:mysql://127.0.0.1/mydb</url> <username>user</username> <password>secret</password> <driver>com.mysql.jdbc.Driver</driver> <excludeTables>migrations</excludeTables> </configuration> <executions> <execution> <id>default-cli</id> <goals> <goal>cdbimport</goal> <goal>cgen</goal> </goals> </execution> </executions> </plugin>
  • 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.)
  • 28. Writing Apps with Cayenne
  • 29. Starting Cayenne // create reusable ‘runtime’ instance ServerRuntime runtime = new ServerRuntime("cayenne-myproject.xml");
  • 32. Obtaining ObjectContext // regular context ObjectContext context = runtime.newContext(); // nested context ObjectContext nestedContext = runtime.newContext(context);
  • 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
  • 34. Under the Hood ServerRuntime is a DI container
  • 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
  • 39. SelectQuery ObjectContext context = ... SelectQuery<Artist> query = new SelectQuery<Artist>(Artist.class); List<Artist> allArtists = context.select(query);
  • 40. SelectQuery with qualifier ObjectContext context = ... SelectQuery<Artist> query = new SelectQuery<Artist>(Artist.class); query.andQualifier(Artist.NAME.like("A%")); query.andQualifier(Artist.DATE_OF_BIRTH.lt(new Date())); List<Artist> someArtists = context.select(query); INFO: SELECT t0.NAME, t0.DATE_OF_BIRTH, t0.ID FROM ARTIST t0 WHERE (t0.NAME LIKE ?) AND (t0.DATE_OF_BIRTH < ?) [bind: 1->NAME:'A%', 2->DATE_OF_BIRTH:'2013-05-09 20:51:12.759'] INFO: === returned 1 row. - took 2 ms.
  • 41. Other Queries • EJBQLQuery • SQLTemplate • ProcedureQuery • ObjectIdQuery, RelationshipQuery, QueryChain • Custom queries...
  • 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
  • 48. Other ORM Choices • Hibernate • JPA
  • 49. Cayenne Difference - Object Design Others enhanced/proxied POJO ORM Annotations Cayenne framework superclass annotations used for other things Advantage faster startup times “WYSIWYG” objects generic persistent objects less code clutter
  • 50. Cayenne Difference - Runtime Others explicit transactions Cayenne on-demand implicit transactions Advantage less code, cleaner code seamless relationship navigation
  • 51. EOF Analogies “All characters and events – even those based on real people – are entirely fictional.”
  • 52. Persistent Objects • EOEnterpriseObject : Persistent, DataObject, CayenneDataObject • EOGlobalID : ObjectId • EOGenericRecord : CayenneDataObject
  • 53. Mapping • EOModel : DataMap • EOModelGroup : EntityResolver • EOEntity: DbEntity / ObjEntity
  • 54. Query • EOFetchSpecification : SelectQuery • EOQualifier : Expression • EOSortOrdering : Ordering
  • 55. Runtime • EOEditingContext : ObjectContext • EOAdapter : DataNode • JDBCPlugin : DbAdapter
  • 57. WhatYou Might Miss from EOF • QuirkyVertical Inheritance • No Horizontal Inheritance • No prototypes • No Eclipse plugin
  • 58. WhatYou Get in Return • Multithreading • IDE-independent Modeler • Internal dependency injection • Query abstraction beyond SelectQuery • EJBQL and aggregated queries • Iterated query • Transparent Query result cache • Transparent Query result pagination • Auto-increment PK • Automated DB type detection • Prefetch strategies • Lifecycle events
  • 59. A chance to influence things!