Shooting rabbits with sling

Introduction to Apache Jackrabbit & JCR

• Content Repository API for • JSR-170 & JSR-283 • javax.jcr • Object database • Hierarchical data model • Apache Jackrabbit – reference implementation Mantra: everything is content

• Content is content – Blogs, articles, posts, etc. • Structured data – List of addresses in e-mail database • Unstructured data – Word document • ACLs • Code Content hierarchy

• JCR has tree-like data model • Repository consists of items • Item can be node or property • Node children are properties or other nodes • Properties are leaves Node

• Nodes form content hierarchy • Nodes are named • Each node has primary type specifying it’s structure (allowed and required children and properties) – Something like class – Eg. myapp:Contact requires properties myapp:givenName and myapp:familyName • Nodes can also have mixin types – Something like interface – Eg. mix:versionable, mix:lockable or myapp:Emailable • Popular types: – nt:base, nt:unstructured, nt:folder Property

• Property contains data • Types: – string, binary, long, double, date, boolean, name, path, reference • Can be multivalued Searching

• Node names and properties are indexed • Jackrabbit uses • Supported query languages: – XPath – JCR-SQL – JCR-SQL2 (recommended) SQL2

SELECT * FROM [cq:PageContent] AS s WHERE ISDESCENDANTNODE([/content]) AND s.[jcr:title] = ’Moja strona’ • Main purpose: find node by property contents • Avoid queries with parent path (as it’s not indexed) – It’s better to create a mixin or marker property • We don’t JOIN • SQL and XPath are isomorphic Versioning

• Any subtree can be versioned • Add mixin mix:versionable • node.checkin() – Creates new version – Makes the node read-only • node.checkout() – Allows to modify the node • Usage examples: – Page versions at many levels Observation

• Event listener • We can filter events with: – Event type – Path – Node types – An explicit list of nodes • Usage examples: – Automatic workflows – Generating thumbnails – “Last modified” date – Indexing in internal and external search engine