Chad Davis
●   Java Software Engineer
●   Colorado Springs Open Source Meetup
●   Blackdog Software, Inc.
●   Author
          –   Struts 2 in Action
          –   Sun Certified Mobile Application Developer Exam Guide
●   Corporate Trainer – Struts 2
●   Content Management System
●   Am I a DBA?
Development without Constraint
       ( or Integrity? )

 An Introduction to the Content Repository API for Java (JCR)

                              &

           “RDBMS v. Object Storage” Discussion
Our Itinerary
●   Introduction to the Content Repository API
    for Java ( JCR )
●   Development without Constraint ( or
    Integrity? )
●   “Is my project a match for the JCR?”
The Java Content Repository
              ( JCR )
●   Java Specification
●   JSR 170 ( 1.x )
●   JSR 268 ( 2.x )
●   How did this come to be a part of Java?
Jackrabbit
●   Open Source (Apache Project)
●   Reference Implementation
●   “A content repository is a hierarchical content
    store . . .”
●   For “content-oriented” applications
●   Anybody want to take a stab at defining “content-
    oriented”?
Content?
●   Blame the Web
●   Blame the Scope Creep of IT
●   Documents
●   Binaries / Digital Assets
●   Unpredictable Structure
●   Meta-data
Bells and Whistles
●   Version Control
●   Full Text Search
●   Observation (Event Handling)
●   Unstructured / Structured Content
●   Transactions
●   Workspaces
●   And more . . .
Data Model
●   Hierarchical
●   Unstructured
●   Or Structured
Hierarchical Data is Natural
●   File Systems
●   XML
●   DNS
●   DOM
●   Biology
●   Taxonomy
The Hierachy
         ●   Full Paths are ID's
         ●   Hiearchy is Semantic

         ●   Fast Navigation/Location

         ●   Human Readable
JCR Node Trees
             ●   Nodes
             ●   Properties
             ●   Values
             ●   Names
             ●   Structure
Property Types
STRING
●




URI
●




BOOLEAN
●




LONG
●




DOUBLE
●




DECIMAL
●




BINARY
●




DATE
●




NAME, PATH
●




WEAKREFERENCE, REFERENCE
●
More Property Stuff
●   Multi-Valued
●   Value Constraints
Structural Constraints: Nodes
●   Node Types
         –   Primary
         –   Mixin
●   Child Nodes
         –   Name and Type
●   Properties
         –   Name and Type
●   Inheritance
Compact Namespace & Node
   Type Definition (CND)
<cd = 'http://chaddavis.com'>
[cd:contact] > nt:unstructured
 ­cd:email ( string ) multiple
 ­cd:pic ( binary ) mandatory
 
Referential Integrity
●   Contained in Structure
●   Use Properties
●   REFERENCE
●   WEAKREFERENCE
●   paths/UUID
API Tour: Main Classes
API Tour: Reading
●   Direct Access
    bobNode=session.getNode(“/contacts/personal/Bob Smith” );

    bobEmail = session.getProperty(“/contacts/personal/Bob 
    Smith/email”);

●   Retrieve by ID
    bobNode = session.getNodeByIdentifier(bobUUID);

●   By Relative Path
    bobNode = personalNode.getNode(“Bob Smith”);

    emailProperty = bobNode.getProperty(“email”);

●   Reading Values
    emailValue = emailProperty.getValue(); 

    emailValue.getString();

    inputStream = picValue.getBinary().getStream();    
JCR Node Trees
             ●   Nodes
             ●   Properties
             ●   Values
             ●   Names
             ●   Structure
API Tour: Navigation
●   Iterator Over Child Nodes
    NodeIterator personalContactsItty = personal.getNodes();

●   Iterator Over Properties
    PropertyIterator propItty = bobNode.getProperties;
API Tour: Creating
●   Create Node and Properties
    chadNode = personalContactsNode.addNode(“Chad Davis”);

    chadNode.setProperty ( “email”, “chad@mail.com”);

    //binaries

    Binary picBinary = valueFactory.createBinary(picInputStream);

    Value fileValue = valueFactory.createValue(picBinary);

    contentNode.setProperty("jcr:data", fileValue);
API Tour: Query
●   SQL, XPath, JQOM
●   Full Text Search
    xpathExp = “/contacts/personal/element(*,nt:unstructured[jcr:contains(.,'hotmail')]";

    queryMng = session.getWorkspace().getQueryManager();

    query = QueryMng.createQuery(xpathExp, Query.XPATH);

    results = query.execute();

●   All Properties and Node Names Included in Full Text Search
●   Binaries Too!
API Tour: Query
●   Saving Queries to Repo

    query.storeAsNode(“/queries/chad/query1”);
API Tour: Version Control
●   Labels
●   Merge
●   Check In New Version
    versionMngr = session.getWorkspace().getVersionManager();

    newVersion = versionManager.checkin( nodeToCommit.getPath() );

    versionHist = versionMngr.getVersionHistory( nodeToCommit.getPath() );

    versionHistory.addVersionLabel( newVersion.getName(), label, false );
API Tour: Version Control
●   Restore to Other Version
    versionMngr = session.getWorkspace().getVersionManager();

    VersionHistory = versionMngr.getVersionHistory( targetNode.getPath());

    targetVersion = versionHistory.getVersionByLabel(versionLabel);

    versionManager.restore(targetVersion, false);
End of JCR Tour
●   Jackrabbit
●   Content Management Systems
●   Artifact Management
●   Operations Management
RDBMS v. Object Storage

“Schema-less databases and document-oriented databases are a
paradigm shift, and it provides bigger programmer challenges than
something like picking up a new language. I would liken it to the
transition from procedural to object oriented programming.”

                                --Scott Swigart, “How Software is Built”
Paradigm Shift?
The Relational Model
●   Hegemonic Concept
●   Mathematical
●   Taught in Every DB Course
●   1970's
Edgar Frank "Ted" Codd
           ●
               IBM
           ●
               Invented the Relational 
               Model
           ●
               "A Relational Model of Data 
               for Large Shared Data Banks"
           ●
               1970
           ●
               “Is Your DBMS Really 
               Relational?"
           ●
               “Does Your DBMS Run By the 
               Rules?”
Goals of Relational Model
●   Mathematical
       –   Efficiency
       –   Resource Friendly
       –   Powerful Operations
●   Program-Data Independence
       –   More than one app can access data
       –   Consider file based data persistence
Goals of Relational Model
●   Data Integrity
●   Column Constraints
●   Referential Integrity
●   Normalization
        –   Insert, Update and Delete Anomalies
        –   Data redundancy
        –   3NF
Structure Driven Development
●   Database Design
●   Upfront Concretization of Data Model
●   DDL
●   Tables
●   Structure Comes Before Data
●   Heavy Weight
●   Formal
Does Your DBMS Run By the Rules?
Impedance Mismatch
●   Object-Relational
           –   Hibernate
●   Data Types
           –   1970 – No Web
           –   2010 – Content, Documents, Tweets
           –   JSON As Storage Format?
●   Structure First
           –   Data First
           –   Agile Development
●   Program-Data independence
           –   This architectural imperitive has also shifted, but I can't quite
                 express it . . .
New Stuff
●   NoSQL
●   Schemaless DB
●   Object DB
●   Content Repository
●   Document-Oriented DB
Some Offerings
●   CouchDB
●   MongoDB
●   Hadoop
●   SimpleDB ( Amazon )
The Case for Jackrabbit
●   Coy Data
        –   Data Driven Development
        –   Agile
●   Naturally Hierarchical Data
●   “Content” Oriented Data
●   Navigation / Query
●   Integrity?
The Case for RDBMS
●   Interrelated Data
●   Lots of Joins
●   Flat Data
●   Operations
R U Relaxed?
References
●   Database:Principles, Programming, Performance. Patrick O'Neil and
    Elizabeth O'Neil.
●   JCR or RDBMS: Why, When, How? Bertil Chapuis
●   Interview with CouchDB's Damien Katz
●   CouchDB Rap

Development without Constraint

  • 2.
    Chad Davis ● Java Software Engineer ● Colorado Springs Open Source Meetup ● Blackdog Software, Inc. ● Author – Struts 2 in Action – Sun Certified Mobile Application Developer Exam Guide ● Corporate Trainer – Struts 2 ● Content Management System ● Am I a DBA?
  • 3.
    Development without Constraint ( or Integrity? ) An Introduction to the Content Repository API for Java (JCR) & “RDBMS v. Object Storage” Discussion
  • 4.
    Our Itinerary ● Introduction to the Content Repository API for Java ( JCR ) ● Development without Constraint ( or Integrity? ) ● “Is my project a match for the JCR?”
  • 5.
    The Java ContentRepository ( JCR ) ● Java Specification ● JSR 170 ( 1.x ) ● JSR 268 ( 2.x ) ● How did this come to be a part of Java?
  • 6.
    Jackrabbit ● Open Source (Apache Project) ● Reference Implementation ● “A content repository is a hierarchical content store . . .” ● For “content-oriented” applications ● Anybody want to take a stab at defining “content- oriented”?
  • 7.
    Content? ● Blame the Web ● Blame the Scope Creep of IT ● Documents ● Binaries / Digital Assets ● Unpredictable Structure ● Meta-data
  • 8.
    Bells and Whistles ● Version Control ● Full Text Search ● Observation (Event Handling) ● Unstructured / Structured Content ● Transactions ● Workspaces ● And more . . .
  • 9.
    Data Model ● Hierarchical ● Unstructured ● Or Structured
  • 10.
    Hierarchical Data isNatural ● File Systems ● XML ● DNS ● DOM ● Biology ● Taxonomy
  • 13.
    The Hierachy ● Full Paths are ID's ● Hiearchy is Semantic ● Fast Navigation/Location ● Human Readable
  • 14.
    JCR Node Trees ● Nodes ● Properties ● Values ● Names ● Structure
  • 15.
  • 16.
    More Property Stuff ● Multi-Valued ● Value Constraints
  • 17.
    Structural Constraints: Nodes ● Node Types – Primary – Mixin ● Child Nodes – Name and Type ● Properties – Name and Type ● Inheritance
  • 18.
    Compact Namespace &Node Type Definition (CND) <cd = 'http://chaddavis.com'> [cd:contact] > nt:unstructured  ­cd:email ( string ) multiple  ­cd:pic ( binary ) mandatory  
  • 19.
    Referential Integrity ● Contained in Structure ● Use Properties ● REFERENCE ● WEAKREFERENCE ● paths/UUID
  • 20.
  • 21.
    API Tour: Reading ● Direct Access bobNode=session.getNode(“/contacts/personal/Bob Smith” ); bobEmail = session.getProperty(“/contacts/personal/Bob  Smith/email”); ● Retrieve by ID bobNode = session.getNodeByIdentifier(bobUUID); ● By Relative Path bobNode = personalNode.getNode(“Bob Smith”); emailProperty = bobNode.getProperty(“email”); ● Reading Values emailValue = emailProperty.getValue();  emailValue.getString(); inputStream = picValue.getBinary().getStream();    
  • 22.
    JCR Node Trees ● Nodes ● Properties ● Values ● Names ● Structure
  • 23.
    API Tour: Navigation ● Iterator Over Child Nodes NodeIterator personalContactsItty = personal.getNodes(); ● Iterator Over Properties PropertyIterator propItty = bobNode.getProperties;
  • 24.
    API Tour: Creating ● Create Node and Properties chadNode = personalContactsNode.addNode(“Chad Davis”); chadNode.setProperty ( “email”, “chad@mail.com”); //binaries Binary picBinary = valueFactory.createBinary(picInputStream); Value fileValue = valueFactory.createValue(picBinary); contentNode.setProperty("jcr:data", fileValue);
  • 25.
    API Tour: Query ● SQL, XPath, JQOM ● Full Text Search xpathExp = “/contacts/personal/element(*,nt:unstructured[jcr:contains(.,'hotmail')]"; queryMng = session.getWorkspace().getQueryManager(); query = QueryMng.createQuery(xpathExp, Query.XPATH); results = query.execute(); ● All Properties and Node Names Included in Full Text Search ● Binaries Too!
  • 26.
    API Tour: Query ● Saving Queries to Repo query.storeAsNode(“/queries/chad/query1”);
  • 27.
    API Tour: VersionControl ● Labels ● Merge ● Check In New Version versionMngr = session.getWorkspace().getVersionManager(); newVersion = versionManager.checkin( nodeToCommit.getPath() ); versionHist = versionMngr.getVersionHistory( nodeToCommit.getPath() ); versionHistory.addVersionLabel( newVersion.getName(), label, false );
  • 28.
    API Tour: VersionControl ● Restore to Other Version versionMngr = session.getWorkspace().getVersionManager(); VersionHistory = versionMngr.getVersionHistory( targetNode.getPath()); targetVersion = versionHistory.getVersionByLabel(versionLabel); versionManager.restore(targetVersion, false);
  • 29.
    End of JCRTour ● Jackrabbit ● Content Management Systems ● Artifact Management ● Operations Management
  • 30.
    RDBMS v. ObjectStorage “Schema-less databases and document-oriented databases are a paradigm shift, and it provides bigger programmer challenges than something like picking up a new language. I would liken it to the transition from procedural to object oriented programming.” --Scott Swigart, “How Software is Built”
  • 31.
  • 32.
    The Relational Model ● Hegemonic Concept ● Mathematical ● Taught in Every DB Course ● 1970's
  • 33.
    Edgar Frank "Ted"Codd ● IBM ● Invented the Relational  Model ● "A Relational Model of Data  for Large Shared Data Banks" ● 1970 ● “Is Your DBMS Really  Relational?" ● “Does Your DBMS Run By the  Rules?”
  • 34.
    Goals of RelationalModel ● Mathematical – Efficiency – Resource Friendly – Powerful Operations ● Program-Data Independence – More than one app can access data – Consider file based data persistence
  • 35.
    Goals of RelationalModel ● Data Integrity ● Column Constraints ● Referential Integrity ● Normalization – Insert, Update and Delete Anomalies – Data redundancy – 3NF
  • 36.
    Structure Driven Development ● Database Design ● Upfront Concretization of Data Model ● DDL ● Tables ● Structure Comes Before Data ● Heavy Weight ● Formal
  • 38.
  • 39.
    Impedance Mismatch ● Object-Relational – Hibernate ● Data Types – 1970 – No Web – 2010 – Content, Documents, Tweets – JSON As Storage Format? ● Structure First – Data First – Agile Development ● Program-Data independence – This architectural imperitive has also shifted, but I can't quite express it . . .
  • 40.
    New Stuff ● NoSQL ● Schemaless DB ● Object DB ● Content Repository ● Document-Oriented DB
  • 41.
    Some Offerings ● CouchDB ● MongoDB ● Hadoop ● SimpleDB ( Amazon )
  • 42.
    The Case forJackrabbit ● Coy Data – Data Driven Development – Agile ● Naturally Hierarchical Data ● “Content” Oriented Data ● Navigation / Query ● Integrity?
  • 43.
    The Case forRDBMS ● Interrelated Data ● Lots of Joins ● Flat Data ● Operations
  • 44.
  • 45.
    References ● Database:Principles, Programming, Performance. Patrick O'Neil and Elizabeth O'Neil. ● JCR or RDBMS: Why, When, How? Bertil Chapuis ● Interview with CouchDB's Damien Katz ● CouchDB Rap