org.davesag.generica.peer
Class PersistablePeer

java.lang.Object
  extended byorg.davesag.generica.peer.PersistablePeer

public class PersistablePeer
extends Object

This peer manipulates Persistable s using hibernate.

Since:
Generica 1.0
Version:
CVS Revision $Id: PersistablePeer.java,v 1.14 2004/03/30 10:12:57 norm Exp $
Author:
Dave Sag http://www.davesag.com

Constructor Summary
PersistablePeer()
           
 
Method Summary
static void delete(Session sess, Persistable bean)
          Delete this bean.
static boolean exists(Session sess, String namefield, String name, String classname)
          A quick tests to determine if there is a persistable object with the given name, using the supplied namefield and classname as qualifiers of the search.
static Persistable load(Session sess, String namefield, String name, String classname)
          Load a persistable object with the given name, using the supplied namefield and classname as qualifiers of the search.
static Long save(Session sess, Persistable bean)
          Save this persistable object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistablePeer

public PersistablePeer()
Method Detail

save

public static Long save(Session sess,
                        Persistable bean)
Save this persistable object.

Parameters:
sess - The Session to use to save the object. The session will be flushed but not closed.
bean - The persistable bean.
Returns:
The ID of the saved bean, or null if there was an error.
Throws:
RuntimeException - if the params were invalid.

delete

public static void delete(Session sess,
                          Persistable bean)
Delete this bean.

Parameters:
sess - The Session to use to delete the bean. The session will be flushed but not closed.
bean - The persistable object.
Throws:
RuntimeException - if the params were invalid, or if an internal exception was encountered.

exists

public static boolean exists(Session sess,
                             String namefield,
                             String name,
                             String classname)
A quick tests to determine if there is a persistable object with the given name, using the supplied namefield and classname as qualifiers of the search. Use this test if your application wishes to enforce uniqueness of name and thus enable the load method to make sense.

Parameters:
sess - The Session to use to query for the persistable object.
namefield - The name of the bean property that holds the name to test.
name - The name The actual name we are looking for.
classname - The fully qualified class of the persistable bean to test for.
Returns:
true if the name supplied corresponds to a known persistable object.
Throws:
RuntimeException - if the params were invalid, or if there was a HibernateException.

load

public static Persistable load(Session sess,
                               String namefield,
                               String name,
                               String classname)
Load a persistable object with the given name, using the supplied namefield and classname as qualifiers of the search. This assumes that the namefield:name pair are unique to this class.

Parameters:
sess - The Session to use to query for the persistable object.
namefield - The name of the bean property that holds the name to test.
name - The name The actual name we are looking for.
classname - The fully qualified class of the persistable bean to test for.
Returns:
the persistable object, or null if there was not exactly one object matching the params.
Throws:
RuntimeException - if the params were invalid, or if HibernateException.


Dave Sag Generica API version 0.5.9 - (prerelease) Copyright 2003 - 2004 Dave Sag.