org.hibernate.envers.reader
Class AuditReaderImpl

java.lang.Object
  extended by org.hibernate.envers.reader.AuditReaderImpl
All Implemented Interfaces:
AuditReader, AuditReaderImplementor, VersionsReader

public class AuditReaderImpl
extends Object
implements AuditReaderImplementor

Author:
Adam Warski (adam at warski dot org)

Constructor Summary
AuditReaderImpl(AuditConfiguration verCfg, org.hibernate.Session session, org.hibernate.engine.SessionImplementor sessionImplementor)
           
 
Method Summary
 VersionsQueryCreator createQuery()
           
<T> T
find(Class<T> cls, Object primaryKey, Number revision)
          Find an entity by primary key at the given revision.
<T> T
findRevision(Class<T> revisionEntityClass, Number revision)
          A helper method; should be used only if a custom revision entity is used.
 FirstLevelCache getFirstLevelCache()
           
 Date getRevisionDate(Number revision)
          Get the date, at which a revision was created.
 Number getRevisionNumberForDate(Date date)
          Gets the revision number, that corresponds to the given date.
 List<Number> getRevisions(Class<?> cls, Object primaryKey)
          Get a list of revision numbers, at which an entity was modified.
 org.hibernate.Session getSession()
           
 org.hibernate.engine.SessionImplementor getSessionImplementor()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AuditReaderImpl

public AuditReaderImpl(AuditConfiguration verCfg,
                       org.hibernate.Session session,
                       org.hibernate.engine.SessionImplementor sessionImplementor)
Method Detail

getSessionImplementor

public org.hibernate.engine.SessionImplementor getSessionImplementor()
Specified by:
getSessionImplementor in interface AuditReaderImplementor

getSession

public org.hibernate.Session getSession()
Specified by:
getSession in interface AuditReaderImplementor

getFirstLevelCache

public FirstLevelCache getFirstLevelCache()
Specified by:
getFirstLevelCache in interface AuditReaderImplementor

find

public <T> T find(Class<T> cls,
                  Object primaryKey,
                  Number revision)
       throws IllegalArgumentException,
              NotAuditedException,
              IllegalStateException
Description copied from interface: AuditReader
Find an entity by primary key at the given revision.

Specified by:
find in interface AuditReader
Specified by:
find in interface VersionsReader
Parameters:
cls - Class of the entity.
primaryKey - Primary key of the entity.
revision - Revision in which to get the entity.
Returns:
The found entity instance at the given revision (its properties may be partially filled if not all properties are audited) or null, if an entity with that id didn't exist at that revision.
Throws:
IllegalArgumentException - If cls or primaryKey is null or revision is less or equal to 0.
NotAuditedException - When entities of the given class are not audited.
IllegalStateException - If the associated entity manager is closed.

getRevisions

public List<Number> getRevisions(Class<?> cls,
                                 Object primaryKey)
                          throws IllegalArgumentException,
                                 NotAuditedException,
                                 IllegalStateException
Description copied from interface: AuditReader
Get a list of revision numbers, at which an entity was modified.

Specified by:
getRevisions in interface AuditReader
Specified by:
getRevisions in interface VersionsReader
Parameters:
cls - Class of the entity.
primaryKey - Primary key of the entity.
Returns:
A list of revision numbers, at which the entity was modified, sorted in ascending order (so older revisions come first).
Throws:
IllegalArgumentException - If cls or primaryKey is null.
NotAuditedException - When entities of the given class are not audited.
IllegalStateException - If the associated entity manager is closed.

getRevisionDate

public Date getRevisionDate(Number revision)
                     throws IllegalArgumentException,
                            RevisionDoesNotExistException,
                            IllegalStateException
Description copied from interface: AuditReader
Get the date, at which a revision was created.

Specified by:
getRevisionDate in interface AuditReader
Specified by:
getRevisionDate in interface VersionsReader
Parameters:
revision - Number of the revision for which to get the date.
Returns:
Date of commiting the given revision.
Throws:
IllegalArgumentException - If revision is less or equal to 0.
RevisionDoesNotExistException - If the revision does not exist.
IllegalStateException - If the associated entity manager is closed.

getRevisionNumberForDate

public Number getRevisionNumberForDate(Date date)
Description copied from interface: AuditReader
Gets the revision number, that corresponds to the given date. More precisely, returns the number of the highest revision, which was created on or before the given date. So: getRevisionDate(getRevisionNumberForDate(date)) <= date and getRevisionDate(getRevisionNumberForDate(date)+1) > date.

Specified by:
getRevisionNumberForDate in interface AuditReader
Specified by:
getRevisionNumberForDate in interface VersionsReader
Parameters:
date - Date for which to get the revision.
Returns:
Revision number corresponding to the given date.

findRevision

public <T> T findRevision(Class<T> revisionEntityClass,
                          Number revision)
               throws IllegalArgumentException,
                      RevisionDoesNotExistException,
                      IllegalStateException
Description copied from interface: AuditReader
A helper method; should be used only if a custom revision entity is used. See also RevisionEntity.

Specified by:
findRevision in interface AuditReader
Specified by:
findRevision in interface VersionsReader
Parameters:
revisionEntityClass - Class of the revision entity. Should be annotated with RevisionEntity.
revision - Number of the revision for which to get the data.
Returns:
Entity containing data for the given revision.
Throws:
IllegalArgumentException - If revision is less or equal to 0 or if the class of the revision entity is invalid.
RevisionDoesNotExistException - If the revision does not exist.
IllegalStateException - If the associated entity manager is closed.

createQuery

public VersionsQueryCreator createQuery()
Specified by:
createQuery in interface AuditReader
Specified by:
createQuery in interface VersionsReader
Returns:
A query creator, associated with this AuditReader instance, with which queries can be created and later executed. Shouldn't be used after the associated Session or EntityManager is closed.


Copyright © 2008 Hibernate.org. All Rights Reserved.