private static class TemporaryBuffer.Context extends java.lang.Object implements SessionListener, Commitable
This object also tracks tables which have been created during the current database session, and drops them when the session is being closed. This is done as an optimization to prevent potential thrashing in the event a class which creates a temporary buffer and then allows it to go out of scope is invoked repeatedly in a loop.
SessionListener.Event, SessionListener.Scope
Modifier and Type | Field and Description |
---|---|
private java.util.Set<java.lang.String> |
activeTables
Names of active temp tables in the order they were created
|
private java.util.Map<TemporaryBuffer,java.util.Map<TemporaryBuffer,java.lang.Object>> |
domains
Map of master buffers to weak hash maps with slave buffer keys
|
private java.util.Map<java.lang.Integer,java.lang.Boolean> |
emptyTableFlags
Map of flags indicating whether each virtual table is empty
|
private java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.Integer,java.lang.Integer>> |
inUseMPIDs
Map of DMO interfaces to counts of multiplex IDs currently in use
|
private int |
nextMPID
Next value to try when assigning a multiplex ID
|
private java.util.Map<java.lang.Class<?>,java.lang.Long> |
openTables
Map of open tables to most recent primary key ID generated
|
private Persistence.Context |
pctx
Persistence context for transaction management
|
private java.util.Set<java.lang.Class<?>> |
pendingDrop
Set of DMO interfaces whose corresponding tables will be dropped at the next commit
|
private java.util.Map<java.lang.Class<?>,java.util.List<java.io.Serializable>> |
pendingReclaimedKeys
Primary keys which will be recycled after the next commit
|
private Persistence |
persistence
Persistence service object for temp tables
|
private java.util.Map<java.lang.Class<?>,java.util.SortedSet<java.io.Serializable>> |
reclaimedKeys
Recycled primary keys available for re-use (lowest first)
|
private java.util.Map<java.lang.String,java.lang.String> |
sweepMap
Singleton map of a unique key to session ID string
|
Constructor and Description |
---|
Context()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
commit(boolean transaction)
On a full transaction commit, reclaim all of the primary keys which
have been surrendered by record deletes and clear the set of pending,
reclaimable keys.
|
(package private) void |
createTable(java.lang.Class<?> dmoIface,
java.lang.String table)
Create a temp table in the database for the given DMO interface, if
it does not already exist.
|
void |
deregisteredSessionListener()
Invoked when this session listener is removed from the list of
registered session listeners.
|
private void |
doCreateTable(java.lang.Class<?> dmoIface)
Issue the SQL statement(s) against the backing database necessary to
create the backing temp table needed for the given DMO interface, as
well as all indexes defined for that table.
|
private void |
doDropTable(java.lang.Class<?> dmoIface)
Issue the SQL statement(s) against the backing database necessary to
drop the backing temp table for the given DMO interface.
|
(package private) void |
dropTable(TempTable tt,
java.lang.String table,
java.lang.Class<?> dmoIface,
int scope)
Remove the given table from the active temp tables in use within the current context,
and add it to the pending drop tables.
|
private void |
dropUnusedTables(boolean sessionClosing)
Drop all temporary tables which have been created during the current database session,
but which are no longer in use.
|
(package private) java.lang.Integer |
getNextMPID(java.util.Map<java.lang.Integer,java.lang.Integer> inUse)
Returns a context-local multiplex ID value.
|
(package private) int |
getTableCount()
Report the number of temp tables which currently are in use in the
current context for the database associated with this buffer.
|
private java.lang.String |
getTableName(java.lang.Class<?> dmoIface)
Get the backing temp table name associated with the given DMO
interface, primarily for debugging and error reporting purposes.
|
(package private) void |
init()
Initialize this object by storing the persistence service object and
registering as a session listener.
|
(package private) java.io.Serializable |
nextPrimaryKey(java.lang.Class<?> dmoIface)
Returns the next available primary key for the temp table associated
with the given DMO interface.
|
(package private) void |
reclaimKey(java.lang.Class<?> dmoIface,
java.io.Serializable id)
Prepare a single, primary key for reclamation.
|
void |
rollback(boolean transaction)
On a full transaction rollback,clear the set of pending, reclaimable
keys.
|
void |
rollbackPending()
No-op.
|
boolean |
sessionEvent(SessionListener.Event event)
This method is invoked by the persistence context when a Hibernate session has just
ended a transaction or is about to close.
|
void |
validate(boolean transaction)
No-op
|
private final java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.Integer,java.lang.Integer>> inUseMPIDs
private final java.util.Map<java.lang.Class<?>,java.lang.Long> openTables
private final java.util.Set<java.lang.Class<?>> pendingDrop
private final java.util.Map<java.lang.Class<?>,java.util.List<java.io.Serializable>> pendingReclaimedKeys
private final java.util.Map<java.lang.Class<?>,java.util.SortedSet<java.io.Serializable>> reclaimedKeys
private final java.util.Set<java.lang.String> activeTables
private final java.util.Map<java.lang.Integer,java.lang.Boolean> emptyTableFlags
private final java.util.Map<java.lang.String,java.lang.String> sweepMap
private Persistence persistence
private Persistence.Context pctx
private java.util.Map<TemporaryBuffer,java.util.Map<TemporaryBuffer,java.lang.Object>> domains
private int nextMPID
public boolean sessionEvent(SessionListener.Event event) throws PersistenceException
sessionEvent
in interface SessionListener
event
- Session event type.false
, indicating that this session listener should remain registered
after this method returns.PersistenceException
- if any error occurs dropping temp tables from the closing session.public void deregisteredSessionListener()
This implementation does nothing.
deregisteredSessionListener
in interface SessionListener
public void commit(boolean transaction)
commit
in interface Commitable
transaction
- true
if called on a full transaction boundary;
false
if called on a subtransaction boundary.public void rollback(boolean transaction)
rollback
in interface Commitable
transaction
- true
if called on a full transaction boundary;
false
if called on a subtransaction boundary.public void rollbackPending()
rollbackPending
in interface Commitable
Commitable.rollbackPending()
public void validate(boolean transaction)
validate
in interface Commitable
transaction
- true
if this is a full transaction and
false
if this is only a sub-transaction (a
nested scope with transaction support).Commitable.validate(boolean)
void init()
Context
instance.int getTableCount()
persistence
.java.lang.Integer getNextMPID(java.util.Map<java.lang.Integer,java.lang.Integer> inUse)
inUse
- Map of multiplex IDs currently in use in this context, to
reference count of buffers using them.void createTable(java.lang.Class<?> dmoIface, java.lang.String table)
dmoIface
- DMO interface for which a backing temp table is needed.table
- Name of temp table to be created.void dropTable(TempTable tt, java.lang.String table, java.lang.Class<?> dmoIface, int scope)
tt
- The temp-table resource.table
- Name of temp table to be dropped.dmoIface
- DMO interface.scope
- Current block depth.java.io.Serializable nextPrimaryKey(java.lang.Class<?> dmoIface) throws PersistenceException
dmoIface
- Data model object interface.PersistenceException
- if dmoIface
is unknown.void reclaimKey(java.lang.Class<?> dmoIface, java.io.Serializable id)
dmoIface
- DMO interface for temporary table records.id
- Primary key to be recycled.private void dropUnusedTables(boolean sessionClosing) throws PersistenceException
sessionClosing
- true
to mark all open tables as unused, so they are dropped;
false
to only drop tables previously marked as ready to be dropped.PersistenceException
- if a database error occurs dropping any table or creating
the transaction which contains these actions.private void doCreateTable(java.lang.Class<?> dmoIface)
dmoIface
- DMO interface for which a backing temp table is needed.ErrorConditionException
- if an error occurs creating the table and silent error mode
is disabled.doDropTable(java.lang.Class<?>)
private void doDropTable(java.lang.Class<?> dmoIface) throws PersistenceException
dmoIface
- DMO interface for which the backing temp table should be
dropped.PersistenceException
- if an error occurs dropping the table and silent error mode
is disabled.doCreateTable(java.lang.Class<?>)
private java.lang.String getTableName(java.lang.Class<?> dmoIface)
dmoIface
- DMO interface for which a table name is needed.