2. Overview
• Intro
What is JCR?
What can you use JCR for?
• JCR Basic Structure
Repositories, Workspaces and Nodes Galore!
• JSR-170 Compliance Levels
Level 1 - Read Only Repository
Level 2 - Read and Write
Optional - Versioning, Transactions and More
• Demo!
3. What is JCR?
• JSR-170 defines the Java Content Repository (JCR) API
• First approved June 17, 2005, last updated March 1, 2006
• JCR is just an API, it is NOT a Content Repository
• Jackrabbit IS a Content Repository, that implements JSR-170
• JCR provides a universal way to access content within a repository
• Similar to what JDBC did for RDBMS, JCR does for content repositories
4. What can you use JCR for?
• Common access multiple Content Repositories from different Providers
• Other things...
5. JCR Basic
Structure
• A Repository has Workspaces
• A Workspace is a tree of Items
• An Item is a Node or Property
• A Property can only be a leaf
• Property Values hold the data
• A Session is used to access a
Workspace in the Repository
• Nodes can have Types
6. Level 1 Compliance - Read Only Repository
• Access the Repository
• Read Repository Content
• Export Repository Content
• Search the Repository (via XPath)
• Discover configured Node Types
• Remap Namespaces within Session
7. Level 2 Compliance - Level 1 + Edits
• Add, Remove or Modify Nodes and Properties
• Import Repository Content
• Assign Node Types to Nodes
• Add, Remove or Modify Namespaces
8. Optional Features
• Can be part of Level 1 or Level 2 compliant implementation
• Transactions: Adhere to JTA Spec, support container & user managed
• Versioning: Allow checkin and checkout of Nodes
• Observation: Applications can “register interest in events that describe
changes to a workspace, and then monitor and respond” to them
• Locking: Allow temporary locking of Nodes to prevent changes
• Search via SQL: Use SQL to query in addition to XPath
10. Demo - Jackrabbit Hops
• FirstHop.java
Access the Repository
Find and display features of this implementation
• SecondHop.java
Add Nodes
Add a Property
Get a Node and Property
Navigate over the Repository
11. JCR Demo - Versioning
• VersionDemo.java
Try to find a Node
If not found, add it
Once have Node, modify a Property
• Execute this with the following arguments to see the Node change
1: default versioning versionThis quot;this is my first valuequot;
2: default versioning versionThis quot;I have been changed!quot;
• Look at final line of ouput, should see
1: versionThis = this is my first value
2: versionThis = I have been changed!
12. JCR Demo - Fun with Queries
• QueryDemo.java
Run an XPath query on a Workspace
Display the results
• After executing the VersionDemo, the workspace has Nodes to query
• Run this with the following arguments
1: default quot;//versioningquot;
• This will display 2 results: A table like below, & all properties of the Node
| jcr:primaryType || jcr:path || jcr:score |
________________________________________________________________________
| nt:unstructured || /versioning || 1000 |
13. Other Cool Stuff
• Apache Sling: JCR + REST = something that quot;is almost painfully hip, in
a way only a dedicated nerd could appreciatequot;
Home: http://incubator.apache.org/sling/
Overview: http://www.unc.edu/home/adamc/sling-overview.html
• JCROM/Jackrabbit OCM: Object-content mapping, like JPA for the JCR
http://jackrabbit.apache.org/jackrabbit-ocm.html
http://code.google.com/p/jcrom/
• JSR-283: JCR 2.0 - adding enhancements like federation, remoting,
more standard node types, and better access control.
Spec: http://jcp.org/en/jsr/detail?id=283
14. Resources
• JSR-170 Specification: Defines JCR 1.0
Spec: http://jcp.org/en/jsr/detail?id=170
API: http://www.day.com/maven/jsr170/javadocs/jcr-1.0/
• Apache Jackrabbit: Reference Implementation for JSR-170
Home: http://jackrabbit.apache.org/
API: http://jackrabbit.apache.org/api/1.5/ (as of last night, Dec 8)
• Introducing the Java Content Repository API
http://www.ibm.com/developerworks/java/library/j-jcr/
• Catch Jackrabbit and the Java Content Repository API
http://www.artima.com/lejava/articles/contentrepository.html
15. More Resources
• What is Java Content Repository?
http://www.onjava.com/pub/a/onjava/2006/10/04/what-is-java-content-
repository.html
• Advanced Java Content Repository API
http://www.onjava.com/pub/a/onjava/2006/11/08/advanced-java-
content-repository.html
• Day Dev Blog: Lead contributors to Jackrabbit, Sling and all things JCR
http://dev.day.com/
• Post: http://paul.heaberlin.net/2008/12/ojug-presentation-on-jcr.html
Slides: http://www.slideshare.net/lobsterboy1980
Demo Code: http://cid-61cb9c642b07d62e.skydrive.live.com/
browse.aspx/OJUG