Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Introduction to JCR and Apache Jackrabbit Jukka Zitting ApacheCon US 2008
JCR Crash Course! <ul>import  javax.jcr.*; import  org.apache.jackrabbit.core.TransientRepository; repository =  new   Tra...
Sessions and Workspaces <ul>credentials =  new  SimpleCredentials(   “username”, “password”. toCharArray ()); session = re...
Node Hierarchy <ul>root = session. getRootNode (); foo = root. addNode (&quot;foo&quot;); bar = root. addNode (&quot;bar&q...
Properties <ul>a = foo. setProperty (&quot;A&quot;, &quot;abc&quot;); b = foo. setProperty (&quot;B&quot;, &quot;123&quot;...
Transient State <ul>other = repository. login (); println  other. itemExists (&quot;/foo&quot;); </ul><ul><ul><li>false </...
XPath Query <ul>qm = workspace. getQueryManager (); query = qm. createQuery (   &quot;//*[A = 'abc']&quot;, &quot;xpath&qu...
SQL Query <ul>query = qm. createQuery ( &quot;SELECT * FROM nt:base” + “ WHERE A = 'abc'&quot;, &quot;sql&quot;); rows = q...
And Remember! <ul>session. logout () other. logout () </ul>
Content Modeling nt:hierarchyNode nt:folder nt:file nt:linkedFile nt:resource
Bottom-Up Modeling my:resource > nt:resource <ul><li>codec (string)
bitrate (long) </li></ul>my:tune > nt:file <ul><li>artist (string)
release date (date) </li></ul>my:album > nt:folder <ul><li>artist (string)
release date (date) </li></ul>my:review > nt:file <ul><li>author (string)
star rating (long) </li></ul>
Top-Down Modeling Album Images Tune Band Label Label Tune Album Reviews Label Band Reviews Tune Images
Upcoming SlideShare
Loading in …5
×

Introduction to JCR and Apache Jackrabbi

7,999 views

Published on

Introduction to JCR and Apache Jackrabbi

  1. 1. Introduction to JCR and Apache Jackrabbit Jukka Zitting ApacheCon US 2008
  2. 2. JCR Crash Course! <ul>import javax.jcr.*; import org.apache.jackrabbit.core.TransientRepository; repository = new TransientRepository (); println repository. getDescriptor (Repository.REP_NAME_DESC); </ul><ul><ul><li>Jackrabbit </li></ul></ul>
  3. 3. Sessions and Workspaces <ul>credentials = new SimpleCredentials( “username”, “password”. toCharArray ()); session = repository. login (credentials) workspace = session. getWorkspace () println workspace. getName () </ul><ul><ul><li>default </li></ul></ul><ul>println workspace. getAccessibleWorkspaceNames () </ul><ul><ul><li>{ “default” } </li></ul></ul>
  4. 4. Node Hierarchy <ul>root = session. getRootNode (); foo = root. addNode (&quot;foo&quot;); bar = root. addNode (&quot;bar&quot;); baz = bar. addNode (&quot;baz&quot;); println baz. getPath (); </ul><ul><ul><li>/bar/baz </li></ul></ul>
  5. 5. Properties <ul>a = foo. setProperty (&quot;A&quot;, &quot;abc&quot;); b = foo. setProperty (&quot;B&quot;, &quot;123&quot;); println b. getPath (); </ul><ul><ul><li>/foo/B </li></ul></ul><ul>println b. getLong () + 321; </ul><ul><ul><li>444 </li></ul></ul>
  6. 6. Transient State <ul>other = repository. login (); println other. itemExists (&quot;/foo&quot;); </ul><ul><ul><li>false </li></ul></ul><ul>session. save (); println other. itemExists (&quot;/foo&quot;); </ul><ul><ul><li>true </li></ul></ul>
  7. 7. XPath Query <ul>qm = workspace. getQueryManager (); query = qm. createQuery ( &quot;//*[A = 'abc']&quot;, &quot;xpath&quot;); nodes = query. execute (). getNodes (); println nodes. nextNode (). getPath (); </ul><ul><ul><li>/foo </li></ul></ul>
  8. 8. SQL Query <ul>query = qm. createQuery ( &quot;SELECT * FROM nt:base” + “ WHERE A = 'abc'&quot;, &quot;sql&quot;); rows = query. execute (). getRows (); println rows. nextRow () . getValue (&quot;jcr:path&quot;). getString () </ul><ul><ul><li>/foo </li></ul></ul>
  9. 9. And Remember! <ul>session. logout () other. logout () </ul>
  10. 10. Content Modeling nt:hierarchyNode nt:folder nt:file nt:linkedFile nt:resource
  11. 11. Bottom-Up Modeling my:resource > nt:resource <ul><li>codec (string)
  12. 12. bitrate (long) </li></ul>my:tune > nt:file <ul><li>artist (string)
  13. 13. release date (date) </li></ul>my:album > nt:folder <ul><li>artist (string)
  14. 14. release date (date) </li></ul>my:review > nt:file <ul><li>author (string)
  15. 15. star rating (long) </li></ul>
  16. 16. Top-Down Modeling Album Images Tune Band Label Label Tune Album Reviews Label Band Reviews Tune Images
  17. 17. Finding Content by Reference Rock tags tunes Tune Tune Classic Top 10 playlists Picks link link link
  18. 18. Finding Content by Search Looking for XPath SQL Latest releases /jcr:root/my:tunes//element(*,my:tune) [@released > xs:dateTime(‘…’)] SELECT * FROM my:tune WHERE jcr:path LIKE ‘/my:tunes/%’ AND released > DATE ‘…’ Reviews with keywords /jcr:root/my:tunes//element(*,my:review) /jcr:content[jcr:contains(.,’…’)] SELECT * FROM my:review WHERE jcr:path LIKE ‘/my:tunes/%’ AND CONTAINS(*,‘…’)
  19. 19. Versioning and Publishing Version store Live Staging
  20. 20. http://jackrabbit.apache.org/

×