jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jukka Zitting" <jukka.zitt...@gmail.com>
Subject Re: Jackrabbit Best Practices/Design Patterns (an attempt)
Date Wed, 07 Nov 2007 15:18:58 GMT

On Nov 7, 2007 12:38 PM, loproman <loproman@gmail.com> wrote:
> 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.

I wouldn't use your Album and Song classes as they are now, as their
methods are essentially just wrappers around equivalent JCR methods.
Such a data access layer is more useful for JDBC, where a method like
Album.getName() could become:

       public String getName() throws SQLException {
           PreparedStatement ps = connection.prepareStatement(
               "SELECT name FROM albums WHERE albumid=?");
           try {
               ps.setString(1, albumid);
               ResultSet rs = ps.executeQuery();
               try {
                   if (rs.next()) {
                       return rs.getString(1);
                   } else {
                       ... // handle error
               } finally {
           } finally {

No wonder why frameworks like Hibernate are popular...

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

It depends on your application. A standalone client is probably best
served with a single JCR session (just like a single JDBC connection
would be a good idea), but a webapp serving multiple independent and
concurrent requests should probably (unless it wants to leverage the
transient space for handling unsaved changes) use a session pool or
start separate sessions for each request.


Jukka Zitting

View raw message