development without constraint

45

Upload: chad-davis

Post on 22-May-2015

1.283 views

Category:

Documents


2 download

DESCRIPTION

Introduction to Development with the Content Repository API for Java ( JCR ) and Discussion of the RDBMS Versus NoSQL Decision Space

TRANSCRIPT

Page 1: Development without Constraint
Page 2: Development without Constraint

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?

Page 3: Development without Constraint

Development without Constraint( or Integrity? )

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

&

“RDBMS v. Object Storage” Discussion

Page 4: Development without Constraint

Our Itinerary

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

● Development without Constraint ( or Integrity? )

● “Is my project a match for the JCR?”

Page 5: Development without Constraint

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?

Page 6: Development without Constraint

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”?

Page 7: Development without Constraint

Content?

● Blame the Web● Blame the Scope Creep of IT● Documents● Binaries / Digital Assets● Unpredictable Structure● Meta-data

Page 8: Development without Constraint

Bells and Whistles● Version Control● Full Text Search● Observation (Event Handling)● Unstructured / Structured Content● Transactions● Workspaces● And more . . .

Page 9: Development without Constraint

Data Model

● Hierarchical● Unstructured● Or Structured

Page 10: Development without Constraint

Hierarchical Data is Natural

● File Systems● XML● DNS● DOM● Biology● Taxonomy

Page 11: Development without Constraint
Page 12: Development without Constraint
Page 13: Development without Constraint

The Hierachy●Full Paths are ID's

●Hiearchy is Semantic

●Fast Navigation/Location

●Human Readable

Page 14: Development without Constraint

JCR Node Trees● Nodes

● Properties

● Values

● Names

● Structure

Page 15: Development without Constraint

Property Types●STRING

●URI

●BOOLEAN

●LONG

●DOUBLE

●DECIMAL

●BINARY

●DATE

●NAME, PATH

●WEAKREFERENCE, REFERENCE

Page 16: Development without Constraint

More Property Stuff

● Multi-Valued● Value Constraints

Page 17: Development without Constraint

Structural Constraints: Nodes● Node Types

– Primary

– Mixin● Child Nodes

– Name and Type● Properties

– Name and Type● Inheritance

Page 18: Development without Constraint

Compact Namespace & Node Type Definition (CND)

<cd = 'http://chaddavis.com'>

[cd:contact] > nt:unstructured

 ­cd:email ( string ) multiple

 ­cd:pic ( binary ) mandatory

 

Page 19: Development without Constraint

Referential Integrity● Contained in Structure

● Use Properties

● REFERENCE

● WEAKREFERENCE

● paths/UUID

Page 20: Development without Constraint

API Tour: Main Classes

Page 21: Development without Constraint

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();    

Page 22: Development without Constraint

JCR Node Trees● Nodes

● Properties

● Values

● Names

● Structure

Page 23: Development without Constraint

API Tour: Navigation● Iterator Over Child Nodes

NodeIterator personalContactsItty = personal.getNodes();

● Iterator Over Properties

PropertyIterator propItty = bobNode.getProperties;

Page 24: Development without Constraint

API Tour: Creating● Create Node and Properties

chadNode = personalContactsNode.addNode(“Chad Davis”);

chadNode.setProperty ( “email”, “[email protected]”);

//binaries

Binary picBinary = valueFactory.createBinary(picInputStream);

Value fileValue = valueFactory.createValue(picBinary);

contentNode.setProperty("jcr:data", fileValue);

Page 25: Development without Constraint

API Tour: Query● SQL, XPath, JQOM

● Full Text SearchxpathExp = “/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!

Page 26: Development without Constraint

API Tour: Query

● Saving Queries to Repo

query.storeAsNode(“/queries/chad/query1”);

Page 27: Development without Constraint

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 );

Page 28: Development without Constraint

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);

Page 29: Development without Constraint

End of JCR Tour● Jackrabbit● Content Management Systems● Artifact Management● Operations Management

Page 30: Development without Constraint

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”

Page 31: Development without Constraint

Paradigm Shift?

Page 32: Development without Constraint

The Relational Model

● Hegemonic Concept● Mathematical● Taught in Every DB Course● 1970's

Page 33: Development without Constraint

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?”

Page 34: Development without Constraint

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

Page 35: Development without Constraint

Goals of Relational Model

● Data Integrity● Column Constraints● Referential Integrity● Normalization

– Insert, Update and Delete Anomalies

– Data redundancy

– 3NF

Page 36: Development without Constraint

Structure Driven Development● Database Design● Upfront Concretization of Data Model● DDL● Tables● Structure Comes Before Data● Heavy Weight● Formal

Page 37: Development without Constraint
Page 38: Development without Constraint

Does Your DBMS Run By the Rules?

Page 39: Development without Constraint

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 . . .

Page 40: Development without Constraint

New Stuff● NoSQL● Schemaless DB● Object DB● Content Repository● Document-Oriented DB

Page 41: Development without Constraint

Some Offerings

● CouchDB● MongoDB● Hadoop● SimpleDB ( Amazon )

Page 42: Development without Constraint

The Case for Jackrabbit

● Coy Data– Data Driven Development

– Agile

● Naturally Hierarchical Data● “Content” Oriented Data● Navigation / Query● Integrity?

Page 43: Development without Constraint

The Case for RDBMS

● Interrelated Data● Lots of Joins● Flat Data● Operations

Page 44: Development without Constraint

R U Relaxed?

Page 45: Development without Constraint

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