Return-Path: Delivered-To: apmail-jackrabbit-users-archive@locus.apache.org Received: (qmail 89599 invoked from network); 7 Nov 2007 12:45:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Nov 2007 12:45:51 -0000 Received: (qmail 72851 invoked by uid 500); 7 Nov 2007 12:45:38 -0000 Delivered-To: apmail-jackrabbit-users-archive@jackrabbit.apache.org Received: (qmail 72833 invoked by uid 500); 7 Nov 2007 12:45:38 -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 72824 invoked by uid 99); 7 Nov 2007 12:45:38 -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 04:45:38 -0800 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [213.133.51.241] (HELO mail.hippo.nl) (213.133.51.241) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Nov 2007 12:45:38 +0000 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----_=_NextPart_001_01C8213C.0BDED838" Subject: RE: Jackrabbit Best Practices/Design Patterns (an attempt) Date: Wed, 7 Nov 2007 13:44:14 +0100 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Jackrabbit Best Practices/Design Patterns (an attempt) Thread-Index: AcghKnQ5ecq0RVd5SqmR1Ug9dq+/PwAEXKvO References: <13621138.post@talk.nabble.com> <13624765.post@talk.nabble.com> From: "Ard Schrijvers" To: X-Virus-Checked: Checked by ClamAV on apache.org ------_=_NextPart_001_01C8213C.0BDED838 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Not sure wether this is too abstract for you, but you might want to take = a look over here: http://wiki.apache.org/jackrabbit/DavidsModel Regards Ard 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 =3D session.getRootNode(); Node album =3D root.getNode("MyAlbum"); Node songs =3D album.getNode("songs"); Node song =3D 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(){ =09 Session session =3D null; =09 try{ session =3D Repository.login(); Node root =3D session.getRootNode(); =09 Album myAlbum =3D new Album(root.getNode("MyAlbum")); Song mySong =3D album.addSong("MySong"); mySong.setGenre("funky"); myAlbum.save(); } catch(Exception e){ System.err.println(e.getMessage()); } finally{ if(session !=3D null) session.logout(); } } } class Album{ private Node _album; =09 public Album(Node album){ _album =3D album; } =09 public String getName(){ Property name =3D _album.getProperty("name"); return name.getString(); } =09 public Song addSong(String name){ Node songs =3D _album.getNode("songs"); Node song =3D songs.addNode(name); return new Song(song); } =09 public void save(){ _album.save(); } } class Song{ private Node _song; =09 public Song(Node song){ _song =3D song; } =09 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.=20 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: >=20 > Hi, >=20 > 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! >=20 --=20 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. ------_=_NextPart_001_01C8213C.0BDED838--