Introduction to JCR and Apache Jackrabbi
-
Upload
jukka-zitting -
Category
Technology
-
view
7.524 -
download
1
Transcript of Introduction to JCR and Apache Jackrabbi
Slide 1
Introduction to JCR and
Apache Jackrabbit
Jukka Zitting
ApacheCon US 2008
JCR Crash Course!
import javax.jcr.*;import org.apache.jackrabbit.core.TransientRepository;
repository = new TransientRepository();println repository.getDescriptor(Repository.REP_NAME_DESC);
Jackrabbit
Sessions and Workspaces
credentials = new SimpleCredentials(
username, password.toCharArray());session =
repository.login(credentials)workspace = session.getWorkspace()
println workspace.getName()
default
println workspace.getAccessibleWorkspaceNames()
{ default }
Node Hierarchy
root = session.getRootNode();foo = root.addNode("foo");bar = root.addNode("bar");baz = bar.addNode("baz");
println baz.getPath();
/bar/baz
Properties
a = foo.setProperty("A", "abc");b = foo.setProperty("B", "123");
println b.getPath();
/foo/B
println b.getLong() + 321;
444
Transient State
other = repository.login();println other.itemExists("/foo");
false
session.save();println other.itemExists("/foo");
true
XPath Query
qm = workspace.getQueryManager();query = qm.createQuery(
"//*[A = 'abc']", "xpath");nodes =
query.execute().getNodes();println nodes.nextNode().getPath();
/foo
SQL Query
query = qm.createQuery( "SELECT * FROM nt:base + WHERE A =
'abc'", "sql");rows = query.execute().getRows();println
rows.nextRow()
.getValue("jcr:path").getString()
/foo
And Remember!
session.logout()other.logout()
Content Modeling
nt:hierarchyNode
nt:foldernt:filent:linkedFilent:resource
Bottom-Up Modeling
my:resource > nt:resource codec (string)
bitrate (long)
my:tune > nt:file artist (string)
release date (date)
my:album > nt:folder artist (string)
release date (date)
my:review > nt:file author (string)
star rating (long)
Top-Down Modeling
AlbumImagesTune
BandLabelLabelTuneAlbumReviewsLabelBand
Reviews
Tune
Images
Finding Content by Reference
RocktagstunesTune
Tune
Classic
Top 10playlists
Picks
link
linklink
Finding Content by Search
Looking forXPathSQL
Latest releases/jcr:root/my:tunes//element(*,my:tune)[@released > xs:dateTime()]SELECT * FROM my:tuneWHEREjcr:path LIKE /my:tunes/%AND released > DATE
Reviews with keywords/jcr:root/my:tunes//element(*,my:review)/jcr:content[jcr:contains(.,)]SELECT * FROM my:reviewWHEREjcr:path LIKE /my:tunes/%AND CONTAINS(*,)
Versioning and Publishing
Version store
Live
Staging
http://jackrabbit.apache.org/