public class AuditReaderImpl extends Object implements AuditReaderImplementor
Constructor and Description |
---|
AuditReaderImpl(EnversService enversService,
Session session,
SessionImplementor sessionImplementor) |
Modifier and Type | Method and Description |
---|---|
AuditQueryCreator |
createQuery()
Creates an audit query
|
<T> T |
find(Class<T> cls,
Object primaryKey,
Date date)
Find an entity by primary key on the given date.
|
<T> T |
find(Class<T> cls,
Object primaryKey,
Number revision)
Find an entity by primary key at the given revision.
|
<T> T |
find(Class<T> cls,
String entityName,
Object primaryKey,
Number revision)
Find an entity by primary key at the given revision with the specified entityName.
|
<T> T |
find(Class<T> cls,
String entityName,
Object primaryKey,
Number revision,
boolean includeDeletions)
Find an entity by primary key at the given revision with the specified entityName,
possibly including deleted entities in the search.
|
<T> T |
findRevision(Class<T> revisionEntityClass,
Number revision)
A helper method; should be used only if a custom revision entity is used.
|
<T> Map<Number,T> |
findRevisions(Class<T> revisionEntityClass,
Set<Number> revisions)
Find a map of revisions using the revision numbers specified.
|
CrossTypeRevisionChangesReader |
getCrossTypeRevisionChangesReader() |
<T> T |
getCurrentRevision(Class<T> revisionEntityClass,
boolean persist)
Gets an instance of the current revision entity, to which any entries in the audit tables will be bound.
|
String |
getEntityName(Object primaryKey,
Number revision,
Object entity)
Get the entity name of an instance of an entity returned by this AuditReader.
|
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.
|
List<Number> |
getRevisions(Class<?> cls,
String entityName,
Object primaryKey)
Get a list of revision numbers, at which an entity was modified, looking by entityName.
|
Session |
getSession() |
SessionImplementor |
getSessionImplementor() |
boolean |
isEntityClassAudited(Class<?> entityClass)
Checks if the entityClass was configured to be audited.
|
boolean |
isEntityNameAudited(String entityName)
Checks if the entityName was configured to be audited.
|
public AuditReaderImpl(EnversService enversService, Session session, SessionImplementor sessionImplementor)
public SessionImplementor getSessionImplementor()
getSessionImplementor
in interface AuditReaderImplementor
public Session getSession()
getSession
in interface AuditReaderImplementor
public FirstLevelCache getFirstLevelCache()
getFirstLevelCache
in interface AuditReaderImplementor
public <T> T find(Class<T> cls, Object primaryKey, Number revision) throws IllegalArgumentException, NotAuditedException, IllegalStateException
AuditReader
find
in interface AuditReader
T
- The type of the entity to findcls
- Class of the entity.primaryKey
- Primary key of the entity.revision
- Revision in which to get the entity.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.public <T> T find(Class<T> cls, String entityName, Object primaryKey, Number revision) throws IllegalArgumentException, NotAuditedException, IllegalStateException
AuditReader
find
in interface AuditReader
T
- The type of the entity to findcls
- Class of the entity.entityName
- Name of the entity (if can't be guessed basing on the cls
).primaryKey
- Primary key of the entity.revision
- Revision in which to get the entity.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.public <T> T find(Class<T> cls, String entityName, Object primaryKey, Number revision, boolean includeDeletions) throws IllegalArgumentException, NotAuditedException, IllegalStateException
AuditReader
find
in interface AuditReader
T
- The type of the entity to findcls
- Class of the entity.entityName
- Name of the entity (if can't be guessed basing on the cls
).primaryKey
- Primary key of the entity.revision
- Revision in which to get the entity.includeDeletions
- Whether to include deleted entities in the search.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.public List<Number> getRevisions(Class<?> cls, Object primaryKey) throws IllegalArgumentException, NotAuditedException, IllegalStateException
AuditReader
getRevisions
in interface AuditReader
cls
- Class of the entity.primaryKey
- Primary key of the entity.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.public <T> T find(Class<T> cls, Object primaryKey, Date date) throws IllegalArgumentException, NotAuditedException, RevisionDoesNotExistException, IllegalStateException
AuditReader
find
in interface AuditReader
cls
- Class of the entity.primaryKey
- Primary key of the entity.date
- Date for which to get entity revision.IllegalArgumentException
- if cls, primaryKey, or date is null.NotAuditedException
- When entities of the given class are not audited.RevisionDoesNotExistException
- If the given date is before the first revision.IllegalStateException
- If the associated entity manager is closed.public List<Number> getRevisions(Class<?> cls, String entityName, Object primaryKey) throws IllegalArgumentException, NotAuditedException, IllegalStateException
AuditReader
getRevisions
in interface AuditReader
cls
- Class of the entity.entityName
- Name of the entity (if can't be guessed basing on the cls
).primaryKey
- Primary key of the entity.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.public Date getRevisionDate(Number revision) throws IllegalArgumentException, RevisionDoesNotExistException, IllegalStateException
AuditReader
getRevisionDate
in interface AuditReader
revision
- Number of the revision for which to get the date.IllegalArgumentException
- If revision is less or equal to 0.RevisionDoesNotExistException
- If the revision does not exist.IllegalStateException
- If the associated entity manager is closed.public Number getRevisionNumberForDate(Date date)
AuditReader
getRevisionDate(getRevisionNumberForDate(date)) <= date
and
getRevisionDate(getRevisionNumberForDate(date)+1) > date
.getRevisionNumberForDate
in interface AuditReader
date
- Date for which to get the revision.public <T> T findRevision(Class<T> revisionEntityClass, Number revision) throws IllegalArgumentException, RevisionDoesNotExistException, IllegalStateException
AuditReader
RevisionEntity
.findRevision
in interface AuditReader
T
- The type of the revision entity to findrevisionEntityClass
- Class of the revision entity. Should be annotated with RevisionEntity
.revision
- Number of the revision for which to get the data.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.public <T> Map<Number,T> findRevisions(Class<T> revisionEntityClass, Set<Number> revisions) throws IllegalArgumentException, IllegalStateException
AuditReader
findRevisions
in interface AuditReader
T
- The type of the revision entity to findrevisionEntityClass
- Class of the revision entity. Should be annotated with
RevisionEntity
.revisions
- Revision numbers of the revision for which to get the data.IllegalArgumentException
- If a revision number is less or equal to 0 or if the class of
the revision entity is invalid.IllegalStateException
- If the associated entity manager is closed.public CrossTypeRevisionChangesReader getCrossTypeRevisionChangesReader() throws AuditException
getCrossTypeRevisionChangesReader
in interface AuditReader
CrossTypeRevisionChangesReader
interface. Raises an exception if the default
mechanism of tracking entity names modified during revisions has not been enabled.AuditException
- If none of the following conditions is satisfied:
org.hibernate.envers.track_entities_changed_in_revision
parameter is set to true
.RevisionEntity
)
extends DefaultTrackingModifiedEntitiesRevisionEntity
base class.RevisionEntity
) encapsulates a field
marked with ModifiedEntityNames
interface.public <T> T getCurrentRevision(Class<T> revisionEntityClass, boolean persist)
AuditReader
persist
is false
, and no audited entities are modified in this session,
then the obtained revision entity instance won't be persisted. If persist
is true
, the revision
entity instance will always be persisted, regardless of whether audited entities are changed or not.getCurrentRevision
in interface AuditReader
T
- The type of the revision entity to findrevisionEntityClass
- Class of the revision entity. Should be annotated with RevisionEntity
.persist
- If the revision entity is not yet persisted, should it become persisted. This way, the primary
identifier (id) will be filled (if it's assigned by the DB) and available, but the revision entity will be
persisted even if there are no changes to audited entities. Otherwise, the revision number (id) can be
null
.public AuditQueryCreator createQuery()
AuditReader
createQuery
in interface AuditReader
public boolean isEntityClassAudited(Class<?> entityClass)
AuditReader
isEntityClassAudited
in interface AuditReader
entityClass
- Class of the entity asking for audit supportpublic boolean isEntityNameAudited(String entityName)
AuditReader
isEntityNameAudited
in interface AuditReader
entityName
- EntityName of the entity asking for audit support.public String getEntityName(Object primaryKey, Number revision, Object entity) throws HibernateException
AuditReader
Session
maintains a first-level cache. It is this specific cache which this
call uses to find and return the entity-name. This means if the supplied three values do not correlate
to an existing entry in the AuditReader's first-level cache, this method will result in throwing a
HibernateException
since that entity has not yet been loaded.getEntityName
in interface AuditReader
primaryKey
- the primary key of the associated entity instance.revision
- the revision of the associated entity of interest.entity
- the entity instance that was obtained previously from the same AuditReader.HibernateException
- if one of the following conditions are satisfied:
Copyright © 2019 JBoss by Red Hat. All rights reserved.