fr.umlv.javaodb
Interface PersistenceContext


public interface PersistenceContext

Memory data structure attached to a thread that manages objects that are persistent. A persistence context can be nested in another one, in that case any commit() or rollback() of an enclosing context will automatically commit() or rollback() all nested context. Because a persistence context is attached to a thread, all methods are not required to be thread safe.

Author:
Remi Forax
See Also:
PersistenceManager

Nested Class Summary
static class PersistenceContext.Kind
          The kind of peristence context.
 
Method Summary
 void commit()
          Commits all persistent object states.
<T> T
create(Class<T> persistenceType)
          Create a persistent object belong to the current context.
 void delete(Object o)
          Deletes an object from the context.
<T> Set<? extends T>
findAll(Class<T> persistenceType)
          Returns a view of all persistent objects of a specific persistent class.
<T> T
findById(long id, Class<T> persistenceType)
          Returns a persistent object from its id.
 PersistenceContext.Kind getKind()
          Returns the current context kind.
 void rollback()
          Discards all modificatiions on all objects states of the current context.
 

Method Detail

getKind

PersistenceContext.Kind getKind()
Returns the current context kind. This kind can be different from the one specified by the user in the context creation (see PersistenceManager.newContext(fr.umlv.javaodb.PersistenceContext.Kind)) because it can be downgraded/upgraded due to the fact that contexts of other kinds may exist.

Returns:
the current context kind.

findById

<T> T findById(long id,
               Class<T> persistenceType)
           throws PersistenceException
Returns a persistent object from its id. The returned object is bound to this context.

Type Parameters:
T - the type of the persistent class.
Parameters:
id - the id of the object, must be non null.
persistenceType - the persistent type.
Returns:
a persistent object.
Throws:
PersistenceException - if the type is not persistent type, if the current manager is closed, if the current context is already commited or if id is not a valid id.

findAll

<T> Set<? extends T> findAll(Class<T> persistenceType)
                         throws PersistenceException
Returns a view of all persistent objects of a specific persistent class.

Type Parameters:
T - the type of the persistent class.
Parameters:
persistenceType - the persistent type
Returns:
a set containing all persistent objects of a specific persistent class.
Throws:
PersistenceException - if the type is not persistent type, if the current manager is closed or if the current context was already commited.

create

<T> T create(Class<T> persistenceType)
         throws PersistenceException
Create a persistent object belong to the current context. All the objects persistent in the context will be saved or deleted when the context is commited. The value of the properties of the newly created object are initialized to the default value of their type.

Type Parameters:
T - the type of the persistent interface.
Parameters:
persistenceType - the persistent type.
Returns:
a new object that implements the persistence type
Throws:
PersistenceException - if the type is not persistent type, in the context or if the current context is already commited.
See Also:
delete(Object)

delete

void delete(Object o)
            throws PersistenceException,
                   RollbackException
Deletes an object from the context. The object is marked as deleted and will be removed from the database after a commit.

Parameters:
o - the object to delete.
Throws:
PersistenceException - if the object don't depends on the current context or if the current context is already commited.
RollbackException - if the transaction is rollbacked.
See Also:
create(Class)

commit

void commit()
            throws PersistenceException,
                   RollbackException
Commits all persistent object states. This method will save all persistent object states and delete all objects was need to be deleted. A persistent object is an object returned by findAll(Class) or findById(long, Class) or explicitely made persistent using create(Class).

Throws:
PersistenceException - if the manager that creates this context is closed, if the current context is already commited.
RollbackException - if the transaction is rollbacked.

rollback

void rollback()
              throws PersistenceException,
                     RollbackException
Discards all modificatiions on all objects states of the current context. This method always raises a RollbackException.

Throws:
PersistenceException - if the manager that creates this context is closed
RollbackException - is the context can be rollbacked.


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