class ChangeBroker.SessionInterceptor
extends org.hibernate.EmptyInterceptor
Interceptor
which listens
for session flush events and clears the enclosing instance's pending
flush status whenever a flush occurs.Modifier and Type | Field and Description |
---|---|
private BufferManager |
bufferManager
Buffer manager for the current context
|
private int |
dirtyChecks
Number of dirty checks performed by Hibernate since last flush
|
private java.util.Map<RecordIdentifier,RecordChangeEvent> |
dirtyDMOs
Map of dirty DMOs which require a Hibernate session flush to record change events
|
private boolean |
empty
Flag to track presence of any DMO entities which need flushing
|
private int[] |
NOT_DIRTY
Indicates an entity is not dirty
|
private java.util.Set<Persistable> |
pendingEvictions
Set of records detecting during flush as not being in active use
|
private java.util.Set<java.lang.String> |
pendingFlushTypes
Set of DMO entity types which require a Hibernate session flush
|
private Persistence |
persistence
Persistence service object associated with this interceptor
|
private boolean |
trace
Flag indicating trace-level debug logging
|
Modifier | Constructor and Description |
---|---|
private |
SessionInterceptor(Persistence persistence)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
afterTransactionCompletion(org.hibernate.Transaction tx)
Called after a transaction is committed or rolled back.
|
private void |
cleanup(java.util.Set<RecordIdentifier> flushed)
Clean up the interceptor's state after a flush or transaction.
|
int[] |
findDirty(java.lang.Object entity,
java.io.Serializable id,
java.lang.Object[] currentState,
java.lang.Object[] previousState,
java.lang.String[] propertyNames,
org.hibernate.type.Type[] types)
Indicates whether a data model object entity either:
might be dirty, possibly requiring a flush to the database; or
definitely is not dirty.
|
(package private) RecordChangeEvent |
getLastDirtyEvent(RecordIdentifier ident)
Get the last record change event for the DMO the given ID, if that DMO currently is
dirty.
|
(package private) boolean |
isFlushPending(java.lang.String entityName)
Indicate whether a Hibernate session flush is pending for the given
DMO implementation class.
|
(package private) void |
markDirty(RecordIdentifier ident,
RecordChangeEvent event)
Mark a record as dirty.
|
void |
postFlush(java.util.Iterator entities)
Invoked by Hibernate after the current session has been flushed so
as to execute the SQL statements required to synchronize in-memory
session state with the database.
|
(package private) void |
resetDirty(RecordIdentifier ident)
Stop tracking the DMO with the given ID as dirty; called after the changes have been
flushed.
|
(package private) void |
setFlushPending(java.lang.String entityName)
Set a Hibernate session flush pending for the given DMO
implementation class.
|
private final Persistence persistence
private final int[] NOT_DIRTY
private final java.util.Set<java.lang.String> pendingFlushTypes
private final java.util.Map<RecordIdentifier,RecordChangeEvent> dirtyDMOs
private final boolean trace
private final BufferManager bufferManager
private int dirtyChecks
private java.util.Set<Persistable> pendingEvictions
private boolean empty
private SessionInterceptor(Persistence persistence)
persistence
- Persistence service object associated with this interceptor.public int[] findDirty(java.lang.Object entity, java.io.Serializable id, java.lang.Object[] currentState, java.lang.Object[] previousState, java.lang.String[] propertyNames, org.hibernate.type.Type[] types)
We do not definitively indicate that a record is dirty, since
Hibernate does not honor this indication when it comes to composite
elements within first class entities. Therefore, when we can detect
that an entity might be dirty (i.e., its DMO class has been added to
the set of pending flush types), we return null
to
indicate to Hibernate that it should use its default dirty checking
strategy to make this determination for sure.
We can, however, definitively detect when an entity cannot be dirty (i.e., its DMO class is not present in the set of pending flush types). In this case, we short-circuit Hibernate's default checking as an optimization.
findDirty
in interface org.hibernate.Interceptor
findDirty
in class org.hibernate.EmptyInterceptor
entity
- The DMO to be tested for modifications.id
- The DMO's primary key ID.currentState
- Array of all of the DMO's properties in their current state.previousState
- Array of all of the DMO's properties in their previous
state, presumably before they were updated.propertyNames
- Property names corresponding with the previous two arrays
parameters.types
- Hibernate types corresponding with the previous three
array parameters.int
s to indicate that the
entity is not dirty, or null
to indicate the
entity may be dirty. Always return null
if
not in legacy mode, because we won't have enough information
to second-guess Hibernate in that case.public void postFlush(java.util.Iterator entities)
postFlush
in interface org.hibernate.Interceptor
postFlush
in class org.hibernate.EmptyInterceptor
entities
- An iterator on the DMO instances whose updates were flushed
to the database.public void afterTransactionCompletion(org.hibernate.Transaction tx)
afterTransactionCompletion
in interface org.hibernate.Interceptor
afterTransactionCompletion
in class org.hibernate.EmptyInterceptor
void markDirty(RecordIdentifier ident, RecordChangeEvent event)
ident
- Primary key.event
- Record change event.RecordChangeEvent getLastDirtyEvent(RecordIdentifier ident)
ident
- Unique record identifier.null
if there is none.void resetDirty(RecordIdentifier ident)
ident
- Unique record identifier.boolean isFlushPending(java.lang.String entityName)
entityName
- DMO implementation class as stored by the DMO's record
buffer. Do not use getClass()
on a DMO to
retrieve this argument, as Hibernate may have proxied the
DMO and an unexpected class will be returned.true
if a flush is pending for the DMO type
indicated by dmoClass
. If the argument is
null
, this method conservatively returns
true
if any DMO class has a session
flush pending.void setFlushPending(java.lang.String entityName)
entityName
- DMO implementation class as stored by the DMO's record
buffer. Do not use getClass()
on a DMO to
retrieve this argument, as Hibernate may have proxied the
DMO and an unexpected class will be returned.private void cleanup(java.util.Set<RecordIdentifier> flushed)
A partial flush may result in some entity types being flushed, while others are not. This can happen, for example, if a query only needs to synchronize certain query spaces.
flushed
- Set of record identifiers for those records that were flushed during the most
recent session flush, or null
if none. When called at the end of a
transaction, this parameter should be null
.