SlideShare a Scribd company logo
JCR in Action

Content-based Applications with
      Apache Jackrabbit

      Carsten Ziegeler
      cziegeler@apache.org

      Apache Con US Presentation – November 2009 - Oakland
About
• Member of the ASF
  – Sling, Felix, Cocoon, Portals, Sanselan,
    Excalibur, Incubator
  – PMC: Felix, Portals, Sling, Incubator,
    Excalibur (Chair)
• RnD Team at Day Software
• Article/Book Author, Technical Reviewer
• JSR 286 Spec Group (Portlet API 2.0)

                                               2
Motivation
• Tried and trusted NOSQL solution
• Standard Java API
  – First spec released in May 2005
• Open Source Implementation
  – 1.0 Release in April 2006
• Think about your data storage use
  cases
  – JCR might help

                                      3
Agenda
•   JCR and Apache Jackrabbit
•   Basic Content Modeling
•   References and Search
•   Advanced Features
•   Demo: Sample Application
•   Summary and Questions



                                4
Content Repository




                     5
Content Storage
• Hierarchical content
  – Nodes and properties
• Structured
  – Nodetypes and typed properties
• And/or unstructured
• Fine and coarse-grained



                                     6
Sample Application
• Digital Asset Management
  – Hierarchical storage of pictures
  – Upload
  – Tagging                   Poor man's flickr...
  – Searching
  – Automatic thumbnail generation




                                                     7
Sample Content Structure


                 Travel              Family


            Europe                            Weddings


Amsterdam            Basel                         2008


2007                      City                 Photo      Photo


 Photo                           Photo


                                                                  8
Sample Application
• Java web application
• Uses Apache Sling as web framework
• Content repository managed by
  Apache Jackrabbit
• Interaction through the JCR API




                                       9
JSR 170: Content Repository
 for JavaTM technology API
• (Java) Standard – Version 1.0
  – Supported by many vendors
  – Used by many products and projects
  – Several open source solutions
• How do you connect to a CR?
• How do you interact with a CR?




                                         10
JSR 283 : JCR 2.0 is final
• New features
• Improved specification
  – Cleaned up API (deprecation)
  – Revised specification document
• Binary compatible
  – JSR 170 apps run without modification
• More later...


                                            11
CR : Combines Advantages




                           12
Content Repository Features
•   Query (XPath, SQL)
•   Export/Import (XML)
•   Referential Integrity
•   Authentication
•   Access Control
•   Versioning
•   Observation
•   Locking and Transactions (JTA)
                                     13
The Repository Model
•   Repository: one (or more) workspaces
•   Workspace contains a tree of items
•   Item: Node or property
•   Nodes provide the content structure
    – May have children
• Actual data is stored as values of
  properties
• Types and namespaces!

                Implementation of JCR   14
Nodes and Properties
                                   Root




                                                           W
= Node




                                                            or



                                                                       C
                                                              ks



                                                                        on
                                                                pa



                                                                          te
                                                                  ce



                                                                            nt
= Property




                                                                            R
                                                                  A



                                                                             ep
                                                                               os
                                                                                 it o
                       a




                                                                                     ry
                                                     c
                                       b




                                           g
         d    e                                            h


                                               „Once
                                               upon a           -25
                                               time..“
 i                j   k



             true          6.02x1023




                                   Implementation of JCR

                                                                                      15
Connecting to the Repository

                     JCR 1.0




                               16
Connecting to the Repository
• JCR 2.0 provides RepositoryFactory
• Uses Service Provider Mechanism
    • META-INF/services/javax.jcr.RepositoryFactory
• Just use
    • RepositoryFactory.getRepository(null)
• Or specify connection parameters
    • RepositoryFactory.getRepository(Map)




                                                17
Working with the Repository




                              18
Traverse the Hierarchy




                         19
Retrieve a Property




                      20
Interaction Summary
• Get the repository
• Login to a workspace
  – Provides a session
• Use the session to
  – Access nodes and their properties
  – Change and save them




                                        21
22


           Apache Jackrabbit
– JSR 170 and 283 reference
  implementation
– Apache TLP since 2006
– Releases
    • 1.6 (JSR 170 based)
    • 2.0 Beta 2 is out (nearly)
    • 2.0 Final (end of 2009)
    • announce-
      subscribe@jackrabbit.apache.org
– Components
    • Commons, API
    • RMI, WebDAV, WebApp, JCA
    • OCM
    • And more...                       http://jackrabbit.apache.org/



                                                                        22
Words of Advice
• Read (or browse) the JCR specification
  – jcr-1.0.jar/jcr-2.0.jar included
• Getting started with Jackrabbit
  – jackrabbit-webapp: Drop-in deployment
  – First Hops: Embedded repository
  – Take your time
  – Think about your use cases
• Have a look at Apache Sling

                                            23
Agenda
•   JCR and Apache Jackrabbit
•   Basic Content Modeling
•   References and Search
•   Advanced Features
•   Demo: Sample Application
•   Summary and Questions



                                24
Starting point: Leverage the
     standard node types
• Type hierarchy             • Content hierarchy


nt:hierarchyNode

               nt:folder

                   nt:file

             nt:linkedFile

nt:unstructured




                                                   25
Bottom-up modeling:
                Content types

my:album > nt:folder                      my:tag
- description (string)                    - name (string)
- date (date)                             - description (string)


      my:photo > nt:file
      - description (string)
      - location (string)
      - tags (string[])

              my:resource > nt:resource
              - width, height (long)
              - format (string)


                                                                   26
Top-down modeling: Content
       hierarchies

                  Travel              Family


             Europe                            Weddings


 Amsterdam            Basel                         2008


 2007                      City                 Photo      Photo


  Photo                           Photo


                                                                   27
Content Modeling: Words of
         advice
• Namespaces
  – Use a single namespace per company or
    application
  – Use a reasonably unique namespace prefix
  – Prefixed names for structured content
  – Default namespace for unstructured
    content




                                         28
Content Modeling: Words of
         advice
• Use an application root node
  – /my:content
  – Good for searching, backup, and migration
• Avoid flat hierarchies
  – User interface complexity
• Content-driven design
  – Design your content before your application



                                           29
Content Modeling: Words of
         advice
• Checkout Apache Jackrabbit wiki and
  mailing lists
  – "Davids Model"
• Look at existing node types
• Mixin node types possible




                                        30
David‘s Model
• Rule #1: Data First, Structure Later.
  Maybe
• Rule #2: Drive the content hierarchy,
  don‘t let it happen
• Rule #6: Files are Files are Files
• Look at http://wiki.apache.org/jackrabbit/
  DavidsModel


                                         31
Agenda
•   JCR and Apache Jackrabbit
•   Basic Content Modeling
•   References and Search
•   Advanced Features
•   Demo: Sample Application
•   Summary and Questions



                                32
Alternative Views:
                        References


       Tags                      Album                       Favorites


Bird          Tree          Photo                       Top 10          Picks


                                    Photo           link         link           link


                     API:
                     Node.getReferences():PropertyIterator
                     Property.getNode():Node
                     Node.setProperty(String name, Node)

                                                                                33
Sample – Alternative Views
• Reference by name

  my:photo > nt:file       my:tag
  - description (string)   - name (string)
  - location (string)      - description (string)
  - tags (string[])




                                                    34
Sample - Alternative Views
• Reference by path
                                         /

  my:photo > nt:file
  - description (string)                Tags
  - location (string)
  - tags (string[])
                           /Tags/bird
                                         bird




                                                35
Alternative Views: Search
Looking     XPath                                SQL
for
Latest      /                                  SELECT * FROM my:photo
photos      jcr:root/my:albums//element(*,my:p WHERE
            hoto)
                                               jcr:path LIKE ‘/my:albums/%’
            [@data > xs:dateTime(‘…’)]
                                               AND date > DATE ‘…’

Favorites   /                                    SELECT * FROM my:favorites
with        jcr:root/my:albums//element(*,my:f   WHERE
keywords    avorite)
                                                 jcr:path LIKE ‘/my:albums/%’
            /jcr:content[jcr:contains(.,’…’)]
                                                 AND CONTAINS(*,‘…’)

            API:
            Session.getWorkspace().getQueryManager():QueryManager
            QueryManager.createQuery(String stmt, String
            language):Query;
            Query.execute():QueryResult
                                                                              36
Alternative Views: Words of
            advice
• Moderate use of references
  – Circular references only within a subtree
  – Plan for backup and content migration
• Best search performance when
  selecting a small subset of content
• References, path or name property




                                            37
Agenda
•   JCR and Apache Jackrabbit
•   Basic Content Modeling
•   References and Search
•   Advanced Features
•   Demo: Sample Application
•   Summary and Questions



                                38
Observation
• Optional feature of the JCR specification
• Enables applications to register interest
  in events
• Monitor events
• Respond to events
          API:
          ObservationManager:
          addEventListener(EventListener listener,
            int eventTypes,
            java.lang.String absPath, boolean isDeep,
            java.lang.String[] uuid,
            java.lang.String[] nodeTypeName, boolean noLocal)

               Advanced JCR Features                     39
Event Types
• Events can be of 5 different types
  – Node added
  – Node removed
  – Property added
  – Property removed
  – Property changed




              Advanced JCR Features    40
Observation Events
• Describe changes to a workspace
• Dispatched on persistent change
• Provide the path of the item
• Provide the user ID
• Only provided to sessions with
  sufficient access privileges
• Events may not be complete!
    – Example: removal of a tree of nodes

                Advanced JCR Features       41
Event Listeners
• Registered with a workspace
• Registration with optional filters
  – Like node types, paths
• Receive events for every change


      API:
      public void onEvent(EventIterator events);




                   Advanced JCR Features           42
Events Advice
• Events occur after a save
  – Modification based on events is a new
    operation
  – Such events can be filtered
• Events may not tell the complete story
  – Tree removal, copy, move
• Most common pattern
  – Node added, removed, changed


              Advanced JCR Features         43
Staged Publishing:
    Versioning
          Version store




Staging                   Live




                                 44
Jackrabbit Configuration
• Workspace configuration
  – XML configuration
  – Persistence Managers
  – Query index configuration (Lucene)
  – File system configuration
• Check out the documentation




                                         45
Agenda
•   JCR and Apache Jackrabbit
•   Basic Content Modeling
•   References and Search
•   Advanced Features
•   Demo: Sample Application
•   Summary and Questions



                                46
Getting Content
• Get the repository
• Login to a workspace
  – Returns a session
• Starting with the session
  – Navigate to the desired content
  – Get the query manager and search




                                       47
Writing Content
• Get the repository
• Login to a workspace
  – Returns a session
• Navigate to the correct node
  – To change it
  – To add new nodes/properties
  – To remove nodes/properties
• Persist changes

                                  48
Advanced Development
• Apache Sling
  – REST based web framework
  – Powered by OSGi
  – Scripting Inside
• Apache Jackrabbit OCM
  – Map content to Java objects and vice
    versa
  – Similar to database ORMs


                                           49
JCR 2.0 Features
• Abstract Query Model
    – Java Query Object Model / SQL
• ACL and Access Control Policies
    – Plus Retention Policies and Hold
•   Nodetype Registry
•   New Property Types and Nodetypes
•   Shareable Nodes (Graph)
•   Journalling Observation

                                         50
Agenda
•   JCR and Apache Jackrabbit
•   Basic Content Modeling
•   References and Search
•   Advanced Features
•   Demo: Sample Application
•   Summary and Questions



                                51
(Nearly) Everthing is Content
• Application Domain Specific Content
• Presentation Support (HTML, CSS,
  JavaScript, Images)
• Documentation, Translations
• ...




                                        52
Conclusion
• Content Repositories
  – Combine advantages from FS and DB
  – Add important features
  – Structure/Access your data the way your
    domain requires it
• JCR – The Java API
• Apache Jackrabbit – The Implementation



                                              53
Famous Last Words
• Read the specification
• JCR in your application?
• Join the Jackrabbit community!
• Seriously consider Apache Sling for
  web applications
• Check for additional stuff like OCM



                                        54
Q&A




      55

More Related Content

PPT
SAP Demo
PPTX
Sap Business Objects solutioning Framework architecture
PDF
Technical Overview of CDS View – SAP HANA Part I
PDF
Exclusive SAP Basis Training Book | www.sapdocs.info
PDF
Authorisations in SAP: best practices
PDF
Discover SAP BusinessObjects BI 4.3
PPTX
SAP BPC Embedded for S/4 HANA
PDF
Sap co profit center accounting
SAP Demo
Sap Business Objects solutioning Framework architecture
Technical Overview of CDS View – SAP HANA Part I
Exclusive SAP Basis Training Book | www.sapdocs.info
Authorisations in SAP: best practices
Discover SAP BusinessObjects BI 4.3
SAP BPC Embedded for S/4 HANA
Sap co profit center accounting

What's hot (7)

PPT
Geração Própria de Energia em PCH`s e PCT`s, por Eric Cerqueira Carozzi, SABESP
PPTX
PDF
SAP HANA SPS10- Multitenant Database Containers
PDF
SAP FICO overview
PPT
SAP Document Management System Integration with Content Servers
PDF
Transaction launcher
PDF
SAP Treasury PPT.pdf
Geração Própria de Energia em PCH`s e PCT`s, por Eric Cerqueira Carozzi, SABESP
SAP HANA SPS10- Multitenant Database Containers
SAP FICO overview
SAP Document Management System Integration with Content Servers
Transaction launcher
SAP Treasury PPT.pdf
Ad

Viewers also liked (20)

ODP
JCR and ModeShape
PPTX
Hippo CMS at OpenCo Amsterdam 2014
PPT
Hippo Presentation Jboye Study tour
PDF
Hippo get together workshop automatic export
PPTX
Web Applications Development
PDF
What's new in JSR-283?
PDF
2008-12 OJUG JCR Demo
KEY
Introducing Apricot, The Eclipse Content Management Platform
PDF
The Java Content Repository
PPTX
App and web with Hippo CMS and AngularJS
PDF
Cms integration of apache solr how we did it.
PDF
Introducing Hippo CMS 10.2
PDF
JCR - Java Content Repositories
PPT
Build Your Own CMS with Apache Sling
PDF
Hippo gettogether april 2012 faceted navigation a tale of daemons
PDF
The Zero Bullshit Architecture
PDF
Hippo get together presentation solr integration
PDF
Hippo CMS Integration Patterns
PPT
Hippo CMS - A first look
PDF
Introduction to JCR
JCR and ModeShape
Hippo CMS at OpenCo Amsterdam 2014
Hippo Presentation Jboye Study tour
Hippo get together workshop automatic export
Web Applications Development
What's new in JSR-283?
2008-12 OJUG JCR Demo
Introducing Apricot, The Eclipse Content Management Platform
The Java Content Repository
App and web with Hippo CMS and AngularJS
Cms integration of apache solr how we did it.
Introducing Hippo CMS 10.2
JCR - Java Content Repositories
Build Your Own CMS with Apache Sling
Hippo gettogether april 2012 faceted navigation a tale of daemons
The Zero Bullshit Architecture
Hippo get together presentation solr integration
Hippo CMS Integration Patterns
Hippo CMS - A first look
Introduction to JCR
Ad

Similar to JCR In Action (ApacheCon US 2009) (20)

PDF
Apache Con Us2007 Jcr In Action
 
PDF
Apache Sling : JCR, OSGi, Scripting and REST
PDF
Jazoon 2009
PDF
Taming Jcr With Sling
ZIP
Rapid JCR applications development with Sling
PDF
µjax in 30 minutes
PDF
JCR In 10 Minutes
PDF
µjax in 30 minutes (for Stockholm)
PDF
µjax in 30 minutes (for Stockholm)
PDF
Sean coates fifty things and tricks, confoo 2011
PDF
XML-Free Programming : Java Server and Client Development without <>
PDF
Building Content Applications with JCR and OSGi
PDF
CQ5 and Sling overview
PDF
OSGi, Scripting and REST, Building Webapps With Apache Sling
PDF
IJTC%202009%20JRuby
PDF
IJTC%202009%20JRuby
PDF
Eclipse Virgo presentation at OSGi Users' Forum UK (27 Apr 2010)
PDF
Martin Odersky: What's next for Scala
KEY
Groovy overview, DSLs and ecosystem - Mars JUG - 2010
PDF
Crx 2.2 Deep-Dive
Apache Con Us2007 Jcr In Action
 
Apache Sling : JCR, OSGi, Scripting and REST
Jazoon 2009
Taming Jcr With Sling
Rapid JCR applications development with Sling
µjax in 30 minutes
JCR In 10 Minutes
µjax in 30 minutes (for Stockholm)
µjax in 30 minutes (for Stockholm)
Sean coates fifty things and tricks, confoo 2011
XML-Free Programming : Java Server and Client Development without <>
Building Content Applications with JCR and OSGi
CQ5 and Sling overview
OSGi, Scripting and REST, Building Webapps With Apache Sling
IJTC%202009%20JRuby
IJTC%202009%20JRuby
Eclipse Virgo presentation at OSGi Users' Forum UK (27 Apr 2010)
Martin Odersky: What's next for Scala
Groovy overview, DSLs and ecosystem - Mars JUG - 2010
Crx 2.2 Deep-Dive

More from Carsten Ziegeler (16)

PDF
Service oriented web development with OSGi
PDF
Use Case: Building OSGi Enterprise Applications (QCon 14)
PDF
What's cool in the new and updated OSGi Specs
PDF
What's cool in the new and updated OSGi specs
PDF
Monitoring OSGi Applications with the Web Console
PDF
Distributed Eventing in OSGi
PDF
Apache Sling - Distributed Eventing, Discovery, and Jobs (adaptTo 2013)
PDF
Adobe AEM - From Eventing to Job Processing
PDF
Embrace Change - Embrace OSGi
PDF
Embrace OSGi
PDF
Apache Sanselan (ApacheCon US 2007 FFT)
PDF
Apache iBatis (ApacheCon US 2007)
PDF
JCR In Action (ApacheCon US 2007)
PDF
Apache Portals Panel (ApacheCon US 2007)
PDF
JCR In Action (ApacheCon EU 2008)
PDF
Maven SCR Plugin (ApacheCon EU 2008 - FFT)
Service oriented web development with OSGi
Use Case: Building OSGi Enterprise Applications (QCon 14)
What's cool in the new and updated OSGi Specs
What's cool in the new and updated OSGi specs
Monitoring OSGi Applications with the Web Console
Distributed Eventing in OSGi
Apache Sling - Distributed Eventing, Discovery, and Jobs (adaptTo 2013)
Adobe AEM - From Eventing to Job Processing
Embrace Change - Embrace OSGi
Embrace OSGi
Apache Sanselan (ApacheCon US 2007 FFT)
Apache iBatis (ApacheCon US 2007)
JCR In Action (ApacheCon US 2007)
Apache Portals Panel (ApacheCon US 2007)
JCR In Action (ApacheCon EU 2008)
Maven SCR Plugin (ApacheCon EU 2008 - FFT)

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Modernizing your data center with Dell and AMD
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
Approach and Philosophy of On baking technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Building Integrated photovoltaic BIPV_UPV.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Unlocking AI with Model Context Protocol (MCP)
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Chapter 3 Spatial Domain Image Processing.pdf
Network Security Unit 5.pdf for BCA BBA.
Review of recent advances in non-invasive hemoglobin estimation
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Digital-Transformation-Roadmap-for-Companies.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Empathic Computing: Creating Shared Understanding
Understanding_Digital_Forensics_Presentation.pptx
Modernizing your data center with Dell and AMD
Mobile App Security Testing_ A Comprehensive Guide.pdf

JCR In Action (ApacheCon US 2009)

  • 1. JCR in Action Content-based Applications with Apache Jackrabbit Carsten Ziegeler cziegeler@apache.org Apache Con US Presentation – November 2009 - Oakland
  • 2. About • Member of the ASF – Sling, Felix, Cocoon, Portals, Sanselan, Excalibur, Incubator – PMC: Felix, Portals, Sling, Incubator, Excalibur (Chair) • RnD Team at Day Software • Article/Book Author, Technical Reviewer • JSR 286 Spec Group (Portlet API 2.0) 2
  • 3. Motivation • Tried and trusted NOSQL solution • Standard Java API – First spec released in May 2005 • Open Source Implementation – 1.0 Release in April 2006 • Think about your data storage use cases – JCR might help 3
  • 4. Agenda • JCR and Apache Jackrabbit • Basic Content Modeling • References and Search • Advanced Features • Demo: Sample Application • Summary and Questions 4
  • 6. Content Storage • Hierarchical content – Nodes and properties • Structured – Nodetypes and typed properties • And/or unstructured • Fine and coarse-grained 6
  • 7. Sample Application • Digital Asset Management – Hierarchical storage of pictures – Upload – Tagging Poor man's flickr... – Searching – Automatic thumbnail generation 7
  • 8. Sample Content Structure Travel Family Europe Weddings Amsterdam Basel 2008 2007 City Photo Photo Photo Photo 8
  • 9. Sample Application • Java web application • Uses Apache Sling as web framework • Content repository managed by Apache Jackrabbit • Interaction through the JCR API 9
  • 10. JSR 170: Content Repository for JavaTM technology API • (Java) Standard – Version 1.0 – Supported by many vendors – Used by many products and projects – Several open source solutions • How do you connect to a CR? • How do you interact with a CR? 10
  • 11. JSR 283 : JCR 2.0 is final • New features • Improved specification – Cleaned up API (deprecation) – Revised specification document • Binary compatible – JSR 170 apps run without modification • More later... 11
  • 12. CR : Combines Advantages 12
  • 13. Content Repository Features • Query (XPath, SQL) • Export/Import (XML) • Referential Integrity • Authentication • Access Control • Versioning • Observation • Locking and Transactions (JTA) 13
  • 14. The Repository Model • Repository: one (or more) workspaces • Workspace contains a tree of items • Item: Node or property • Nodes provide the content structure – May have children • Actual data is stored as values of properties • Types and namespaces! Implementation of JCR 14
  • 15. Nodes and Properties Root W = Node or C ks on pa te ce nt = Property R A ep os it o a ry c b g d e h „Once upon a -25 time..“ i j k true 6.02x1023 Implementation of JCR 15
  • 16. Connecting to the Repository JCR 1.0 16
  • 17. Connecting to the Repository • JCR 2.0 provides RepositoryFactory • Uses Service Provider Mechanism • META-INF/services/javax.jcr.RepositoryFactory • Just use • RepositoryFactory.getRepository(null) • Or specify connection parameters • RepositoryFactory.getRepository(Map) 17
  • 18. Working with the Repository 18
  • 21. Interaction Summary • Get the repository • Login to a workspace – Provides a session • Use the session to – Access nodes and their properties – Change and save them 21
  • 22. 22 Apache Jackrabbit – JSR 170 and 283 reference implementation – Apache TLP since 2006 – Releases • 1.6 (JSR 170 based) • 2.0 Beta 2 is out (nearly) • 2.0 Final (end of 2009) • announce- subscribe@jackrabbit.apache.org – Components • Commons, API • RMI, WebDAV, WebApp, JCA • OCM • And more... http://jackrabbit.apache.org/ 22
  • 23. Words of Advice • Read (or browse) the JCR specification – jcr-1.0.jar/jcr-2.0.jar included • Getting started with Jackrabbit – jackrabbit-webapp: Drop-in deployment – First Hops: Embedded repository – Take your time – Think about your use cases • Have a look at Apache Sling 23
  • 24. Agenda • JCR and Apache Jackrabbit • Basic Content Modeling • References and Search • Advanced Features • Demo: Sample Application • Summary and Questions 24
  • 25. Starting point: Leverage the standard node types • Type hierarchy • Content hierarchy nt:hierarchyNode nt:folder nt:file nt:linkedFile nt:unstructured 25
  • 26. Bottom-up modeling: Content types my:album > nt:folder my:tag - description (string) - name (string) - date (date) - description (string) my:photo > nt:file - description (string) - location (string) - tags (string[]) my:resource > nt:resource - width, height (long) - format (string) 26
  • 27. Top-down modeling: Content hierarchies Travel Family Europe Weddings Amsterdam Basel 2008 2007 City Photo Photo Photo Photo 27
  • 28. Content Modeling: Words of advice • Namespaces – Use a single namespace per company or application – Use a reasonably unique namespace prefix – Prefixed names for structured content – Default namespace for unstructured content 28
  • 29. Content Modeling: Words of advice • Use an application root node – /my:content – Good for searching, backup, and migration • Avoid flat hierarchies – User interface complexity • Content-driven design – Design your content before your application 29
  • 30. Content Modeling: Words of advice • Checkout Apache Jackrabbit wiki and mailing lists – "Davids Model" • Look at existing node types • Mixin node types possible 30
  • 31. David‘s Model • Rule #1: Data First, Structure Later. Maybe • Rule #2: Drive the content hierarchy, don‘t let it happen • Rule #6: Files are Files are Files • Look at http://wiki.apache.org/jackrabbit/ DavidsModel 31
  • 32. Agenda • JCR and Apache Jackrabbit • Basic Content Modeling • References and Search • Advanced Features • Demo: Sample Application • Summary and Questions 32
  • 33. Alternative Views: References Tags Album Favorites Bird Tree Photo Top 10 Picks Photo link link link API: Node.getReferences():PropertyIterator Property.getNode():Node Node.setProperty(String name, Node) 33
  • 34. Sample – Alternative Views • Reference by name my:photo > nt:file my:tag - description (string) - name (string) - location (string) - description (string) - tags (string[]) 34
  • 35. Sample - Alternative Views • Reference by path / my:photo > nt:file - description (string) Tags - location (string) - tags (string[]) /Tags/bird bird 35
  • 36. Alternative Views: Search Looking XPath SQL for Latest / SELECT * FROM my:photo photos jcr:root/my:albums//element(*,my:p WHERE hoto) jcr:path LIKE ‘/my:albums/%’ [@data > xs:dateTime(‘…’)] AND date > DATE ‘…’ Favorites / SELECT * FROM my:favorites with jcr:root/my:albums//element(*,my:f WHERE keywords avorite) jcr:path LIKE ‘/my:albums/%’ /jcr:content[jcr:contains(.,’…’)] AND CONTAINS(*,‘…’) API: Session.getWorkspace().getQueryManager():QueryManager QueryManager.createQuery(String stmt, String language):Query; Query.execute():QueryResult 36
  • 37. Alternative Views: Words of advice • Moderate use of references – Circular references only within a subtree – Plan for backup and content migration • Best search performance when selecting a small subset of content • References, path or name property 37
  • 38. Agenda • JCR and Apache Jackrabbit • Basic Content Modeling • References and Search • Advanced Features • Demo: Sample Application • Summary and Questions 38
  • 39. Observation • Optional feature of the JCR specification • Enables applications to register interest in events • Monitor events • Respond to events API: ObservationManager: addEventListener(EventListener listener, int eventTypes, java.lang.String absPath, boolean isDeep, java.lang.String[] uuid, java.lang.String[] nodeTypeName, boolean noLocal) Advanced JCR Features 39
  • 40. Event Types • Events can be of 5 different types – Node added – Node removed – Property added – Property removed – Property changed Advanced JCR Features 40
  • 41. Observation Events • Describe changes to a workspace • Dispatched on persistent change • Provide the path of the item • Provide the user ID • Only provided to sessions with sufficient access privileges • Events may not be complete! – Example: removal of a tree of nodes Advanced JCR Features 41
  • 42. Event Listeners • Registered with a workspace • Registration with optional filters – Like node types, paths • Receive events for every change API: public void onEvent(EventIterator events); Advanced JCR Features 42
  • 43. Events Advice • Events occur after a save – Modification based on events is a new operation – Such events can be filtered • Events may not tell the complete story – Tree removal, copy, move • Most common pattern – Node added, removed, changed Advanced JCR Features 43
  • 44. Staged Publishing: Versioning Version store Staging Live 44
  • 45. Jackrabbit Configuration • Workspace configuration – XML configuration – Persistence Managers – Query index configuration (Lucene) – File system configuration • Check out the documentation 45
  • 46. Agenda • JCR and Apache Jackrabbit • Basic Content Modeling • References and Search • Advanced Features • Demo: Sample Application • Summary and Questions 46
  • 47. Getting Content • Get the repository • Login to a workspace – Returns a session • Starting with the session – Navigate to the desired content – Get the query manager and search 47
  • 48. Writing Content • Get the repository • Login to a workspace – Returns a session • Navigate to the correct node – To change it – To add new nodes/properties – To remove nodes/properties • Persist changes 48
  • 49. Advanced Development • Apache Sling – REST based web framework – Powered by OSGi – Scripting Inside • Apache Jackrabbit OCM – Map content to Java objects and vice versa – Similar to database ORMs 49
  • 50. JCR 2.0 Features • Abstract Query Model – Java Query Object Model / SQL • ACL and Access Control Policies – Plus Retention Policies and Hold • Nodetype Registry • New Property Types and Nodetypes • Shareable Nodes (Graph) • Journalling Observation 50
  • 51. Agenda • JCR and Apache Jackrabbit • Basic Content Modeling • References and Search • Advanced Features • Demo: Sample Application • Summary and Questions 51
  • 52. (Nearly) Everthing is Content • Application Domain Specific Content • Presentation Support (HTML, CSS, JavaScript, Images) • Documentation, Translations • ... 52
  • 53. Conclusion • Content Repositories – Combine advantages from FS and DB – Add important features – Structure/Access your data the way your domain requires it • JCR – The Java API • Apache Jackrabbit – The Implementation 53
  • 54. Famous Last Words • Read the specification • JCR in your application? • Join the Jackrabbit community! • Seriously consider Apache Sling for web applications • Check for additional stuff like OCM 54
  • 55. Q&A 55