fr.umlv.javaodb
Interface PersistenceManager


public interface PersistenceManager

This class is used to store and retrieve objects by their type in the database. A persistence instance can be obtains using the method PersistenceManagerFactory.getPersistenceManager(). To be persistent, an object must have its interface tagged by the annotation Persistent. In order to track the relation between a location on the disk and a persistent object, the persistent manager use a special getter of the persistent class to store an uniq id. Its up to the developer to declare it in a persistent type using the annotation Id). Only one getter can be tagged by Id in the persistent type and the persitent type must not own a corresponding setter. By default, a persistent type only support getter and setter typed with a primitive type (not even String) but implementors can provide an implementation without these restrictions. However, a persistent type can't own a method that is not a setter or a getter. All operations on persistent objects rely on a thread-local context. This context is created using newContext(fr.umlv.javaodb.PersistenceContext.Kind). The context kind taken as argument is a user's on that which kind of context is requested, but depending on the implementation of the manager andd on the runtime environment the kind of created context can be downgraded/upgraded to another kind to ensure coherence (see context.getKind() for more info). All the methods of the persistence manager are thread safe.

Author:
Remi Forax
See Also:
PersistenceManagerFactory, PersistenceContext

Method Summary
 void close()
          Shutdown the database.
 void commit()
          Convenient method for PersistenceContext.commit() on the inner most thread-local context.
 void drop(Class<?> persistenceType)
          Drops all objects of the specfic persistence type.
 Set<? extends Class<?>> getPersistentTypes()
          Returns the types of all persistent objects stored in the database.
 boolean isClosed()
          Returns whenever the current manager is close or not.
 PersistenceContext newContext(PersistenceContext.Kind kind)
          Creates a thread local context or a nested context if a context already exists on the current thread.
 void rollback()
          Convenient method for PersistenceContext.rollback() on the inner most thread-local context.
 

Method Detail

drop

void drop(Class<?> persistenceType)
          throws PersistenceException
Drops all objects of the specfic persistence type. This method silently returns if no object of that type is persistent.

Parameters:
persistenceType - an interface tagged by Persistent.
Throws:
PersistenceException - if the type is not persistent or if the current manager is closed or if an IO error occurs.

getPersistentTypes

Set<? extends Class<?>> getPersistentTypes()
                                           throws PersistenceException
Returns the types of all persistent objects stored in the database. This returned set is a snapshot of all available types in the database when this method is called.

Returns:
an unmodifiable set containing all persistent type of the database.
Throws:
PersistenceException - if the current manager is closed or if if an IO error occurs.

newContext

PersistenceContext newContext(PersistenceContext.Kind kind)
                              throws PersistenceException
Creates a thread local context or a nested context if a context already exists on the current thread. The kind of the resulting context can be another kind that the one specified by the user:
  1. If a context of another thread already have an imcompatible kind.
  2. If the context is a nested one and the outer context has a different kind.
  3. If the current manager doesn't support the requested kind.

Parameters:
kind - a hint of the context kind.
Returns:
a new context attached to the current thread.
Throws:
PersistenceException - if contexts can't be nested or if the current manager is closed.
See Also:
PersistenceContext.getKind()

commit

void commit()
            throws PersistenceException
Convenient method for PersistenceContext.commit() on the inner most thread-local context.

Throws:
PersistenceException - if no thread-local context is defined or if the current manager is closed.
See Also:
PersistenceContext.commit()

rollback

void rollback()
              throws PersistenceException
Convenient method for PersistenceContext.rollback() on the inner most thread-local context.

Throws:
PersistenceException - if no thread-local context is defined or if the current manager is closed.
See Also:
PersistenceContext.rollback()

isClosed

boolean isClosed()
Returns whenever the current manager is close or not.

Returns:
true if the current manager is closed.

close

void close()
           throws PersistenceException
Shutdown the database. All pending transactions are not stored and can not be stored after that call.

Throws:
PersistenceException - if current manager can't be closed or is already closed.


2006 - Université de Marne-la-Vallée