org.davesag.generica.persistence.jdo
Class JdoArchivist

java.lang.Object
  extended byorg.davesag.generica.persistence.jdo.JdoArchivist
All Implemented Interfaces:
Archivist, Manager

public class JdoArchivist
extends Object
implements Archivist, Manager

The JdoArchivist manages persistance for objects by delegating to a JDO PersistenceManager.

Since:
Generica 1.0
Version:
CVS Revision $Id: JdoArchivist.java,v 1.5 2004/04/06 15:40:41 davesag Exp $
Author:
Dave Sag http://www.davesag.com

Field Summary
protected  javax.jdo.PersistenceManager thePersistenceManager
          the hibernate session
 
Constructor Summary
JdoArchivist()
          null constructor
 
Method Summary
 void close()
          Closes the PersistanceManager so it an no longer be used.
 void delete(Object o)
          Delete the supplied object.
 boolean exists(Map fields, String classname)
          A fast test to determine if there is an object with values matching field names according to the supplied map.
 boolean exists(String namefield, String name, String classname)
          A test to determine if there is an object with the given name, using the supplied namefield and classname as qualifiers of the search.
 void flush()
          Does nothing.
 Object getDelegate()
          Get the hibernate session to delegate to.
 Transaction getTransaction()
          Return a Transaction that can be used to wrap atomic operations.
 Object load(Map fields, String classname)
          Load an object whose field values match the values keyed against those field names in the supplied Map.
 Object load(Object target, Class clazz)
          Load an object according to the target parameter supplied.
 Object load(String namefield, String name, String classname)
          Convenience method to load an object with the given name, using the supplied namefield and classname as qualifiers of the search.
protected  javax.jdo.Query loadByUniqueStringQuery(String namefield, String classname)
          Build a Query from the named field and class for loading an object or objects of that class where the namefield equals some value.
 Object save(Object o)
          Save the supplied object.
 void setDelegate(Object delegate)
          Set the hibernate session to delegate to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

thePersistenceManager

protected javax.jdo.PersistenceManager thePersistenceManager
the hibernate session

Constructor Detail

JdoArchivist

public JdoArchivist()
null constructor

Method Detail

setDelegate

public void setDelegate(Object delegate)
                 throws ClassCastException
Set the hibernate session to delegate to.

Specified by:
setDelegate in interface Manager
Parameters:
delegate - The hibernate session to delegate to.
Throws:
ClassCastException - if the deletaged object was not a valid class hibernate session.

getDelegate

public Object getDelegate()
Get the hibernate session to delegate to.

Specified by:
getDelegate in interface Manager
Returns:
The hibernate session being delegated to.

load

public Object load(String namefield,
                   String name,
                   String classname)
            throws ArchiveException
Convenience method to load an 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.

Specified by:
load in interface Archivist
Parameters:
namefield - The name of the property that holds the name to against.
name - The name The actual name we are looking for.
classname - The fully qualified class of the object to load.
Returns:
the object.
Throws:
ArchiveException - if anything went wrong.
See Also:
loadByUniqueStringQuery(java.lang.String, java.lang.String)

load

public Object load(Map fields,
                   String classname)
            throws ArchiveException
Load an object whose field values match the values keyed against those field names in the supplied Map.

Specified by:
load in interface Archivist
Parameters:
fields - The map of field valeus keyed against the field names they corrospond with.
classname - The fully qualified class of the object to load.
Returns:
the object.
Throws:
ArchiveException - if anything went wrong.

load

public Object load(Object target,
                   Class clazz)
            throws ArchiveException
Load an object according to the target parameter supplied.

Specified by:
load in interface Archivist
Parameters:
target - The target that informs the archivist as to which object to load.
clazz - the class to load
Returns:
the object.
Throws:
ArchiveException - if anything went wrong.

save

public Object save(Object o)
            throws ArchiveException
Save the supplied object.

Specified by:
save in interface Archivist
Parameters:
o - the object to save.
Returns:
The saved object.
Throws:
ArchiveException - if anything went wrong.

delete

public void delete(Object o)
            throws ArchiveException
Delete the supplied object.

Specified by:
delete in interface Archivist
Parameters:
o - the object to delete.
Throws:
ArchiveException - if anything went wrong.

exists

public boolean exists(String namefield,
                      String name,
                      String classname)
               throws ArchiveException
A test to determine if there is an 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.

Specified by:
exists in interface Archivist
Parameters:
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:
ArchiveException - if anything went wrong.

exists

public boolean exists(Map fields,
                      String classname)
               throws ArchiveException
A fast test to determine if there is an object with values matching field names according to the supplied map. Use this test if your application wishes to enforce uniqueness of various fields and thus enable the load method to make sense. Load an object whose field values match the values keyed against those field names in the supplied Map.

Specified by:
exists in interface Archivist
Parameters:
fields - The map of field valeus keyed against the field names they corrospond with.
classname - The fully qualified class of the object to load.
Returns:
the object.
Throws:
ArchiveException - if anything went wrong.

getTransaction

public Transaction getTransaction()
                           throws ArchiveException
Return a Transaction that can be used to wrap atomic operations.

Specified by:
getTransaction in interface Archivist
Returns:
a Transaction.
Throws:
ArchiveException - if anything went wrong.

flush

public void flush()
           throws ArchiveException
Does nothing.

Specified by:
flush in interface Archivist
Throws:
ArchiveException - never.

close

public void close()
           throws ArchiveException
Closes the PersistanceManager so it an no longer be used.

Specified by:
close in interface Archivist
Throws:
ArchiveException - if anything went wrong.

loadByUniqueStringQuery

protected javax.jdo.Query loadByUniqueStringQuery(String namefield,
                                                  String classname)
Build a Query from the named field and class for loading an object or objects of that class where the namefield equals some value.

Parameters:
namefield - The name of the field to be matched against a string value.
classname - The name of the class to search for. Will search for subclasses too.
Returns:
A query which can be executed thusly:
     Query q = loadByUniqueStringQuery("username", "org.davesag.generica.core.User");
     (Collection) result = (Collection) q.execute("davesag");


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