jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From loproman <lopro...@gmail.com>
Subject Re: Jackrabbit Best Practices/Design Patterns (an attempt)
Date Wed, 07 Nov 2007 10:38:44 GMT

I thought I would augment my question with a (simplified) example of what I'm
trying to do. Starting with a very basic approach:

Node root = session.getRootNode();
Node album = root.getNode("MyAlbum");
Node songs = album.getNode("songs");
Node song = songs.addNode("MySong");
song.setProperty("genre", "funky");

I've expanded this into a richer object model:

public class Album{

	public static void main(){
		Session session = null;
			session = Repository.login();
			Node root = session.getRootNode();
			Album myAlbum = new Album(root.getNode("MyAlbum"));
			Song mySong = album.addSong("MySong");
		catch(Exception e){
			if(session != null)

class Album{

	private Node _album;
	public Album(Node album){
		_album = album;
	public String getName(){
		Property name = _album.getProperty("name");
		return name.getString();
	public Song addSong(String name){
		Node songs = _album.getNode("songs");
		Node song = songs.addNode(name);
		return new Song(song);
	public void save(){

class Song{
	private Node _song;
	public Song(Node song){
		_song = song;
	public void setGenre(String genre){
		_song.setProperty("genre", genre);

What are your thoughts? Am I doing anything that might cause issues as
things get more complex? I'm new to the concept of JCR, so I'm very
interested in learning how I can use it in my code as naturally as possible. 

Personally, I feel the "addSong" method is a little awkward, but I don't
really see another way to do it. Also, how long should sessions live? With
relational databases, best practice is to open and close the connection as
quickly as possible. However, it seems like JCR sessions can/should stay
open much longer. Any thoughts/tips/examples are very much appreciated!

loproman wrote:
> Hi,
> Does anyone know if there has been any research or documentation developed
> on best practices working with repositories?  Specifically, I'm wondering
> if there are any ideal patterns out there for working with the JCR API.
> I've seen lots of primitive examples where nodes are accessed directly via
> "getNode" and "addNode" etc. However, I think a more scalable solution
> would need to wrap nodes with domain logic (similar to how DTO objects are
> used with a relational database I suspect). Thanks!

View this message in context: http://www.nabble.com/Jackrabbit-Best-Practices-Design-Patterns-tf4762615.html#a13624765
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

View raw message