Return-Path: Delivered-To: apmail-jackrabbit-users-archive@locus.apache.org Received: (qmail 50593 invoked from network); 7 Nov 2007 10:39:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Nov 2007 10:39:18 -0000 Received: (qmail 53115 invoked by uid 500); 7 Nov 2007 10:39:04 -0000 Delivered-To: apmail-jackrabbit-users-archive@jackrabbit.apache.org Received: (qmail 53091 invoked by uid 500); 7 Nov 2007 10:39:04 -0000 Mailing-List: contact users-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@jackrabbit.apache.org Delivered-To: mailing list users@jackrabbit.apache.org Received: (qmail 53082 invoked by uid 99); 7 Nov 2007 10:39:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Nov 2007 02:39:04 -0800 X-ASF-Spam-Status: No, hits=2.6 required=10.0 tests=DNS_FROM_OPENWHOIS,SPF_HELO_PASS,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Nov 2007 10:39:05 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1IpiJ2-0001kH-G4 for users@jackrabbit.apache.org; Wed, 07 Nov 2007 02:38:44 -0800 Message-ID: <13624765.post@talk.nabble.com> Date: Wed, 7 Nov 2007 02:38:44 -0800 (PST) From: loproman To: users@jackrabbit.apache.org Subject: Re: Jackrabbit Best Practices/Design Patterns (an attempt) In-Reply-To: <13621138.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: loproman@gmail.com References: <13621138.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org 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"); session.save(); I've expanded this into a richer object model: public class Album{ public static void main(){ Session session = null; try{ session = Repository.login(); Node root = session.getRootNode(); Album myAlbum = new Album(root.getNode("MyAlbum")); Song mySong = album.addSong("MySong"); mySong.setGenre("funky"); myAlbum.save(); } catch(Exception e){ System.err.println(e.getMessage()); } finally{ if(session != null) session.logout(); } } } 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(){ _album.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.