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<?>,RefCount> |
ooObjectCounter
The counter of stored
object s for each DMO interface. |
private java.util.Map<java.lang.Class<? extends DataModelObject>,java.util.concurrent.atomic.AtomicLong> |
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<? extends DataModelObject>> |
pendingDrop
Set of DMO interfaces whose corresponding tables will be dropped at the next commit
|
private java.util.Map<TemporaryBuffer.ReclaimTable,java.util.List<java.lang.Long>> |
pendingReclaimedKeys
Primary keys which will be recycled after the next commit
|
private Persistence |
persistence
Persistence service object for temp tables
|
private java.util.Map<TemporaryBuffer.ReclaimTable,java.util.SortedSet<java.lang.Long>> |
reclaimedKeys
Recycled primary keys available for re-use (lowest first)
|
private java.lang.String |
sequenceName
This user's sequence name in the temporary database.
|
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 |
---|---|
(package private) void |
cleanup()
Destroy the user's sequence.
|
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<? extends DataModelObject> 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<? extends DataModelObject> 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<? extends DataModelObject> 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<? extends DataModelObject> dmoIface)
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) long |
getCurrentPrimaryKey(java.lang.Class<? extends DataModelObject> dmoIface)
Get the current primary key for the specified temp-table.
|
private java.lang.String |
getImplicitIndexName(java.lang.Class<? extends DataModelObject> dmoIface)
Get the implicit index name.
|
private java.lang.String |
getImplicitSqlIndexName(java.lang.Class<? extends DataModelObject> dmoIface)
Get the implicit SQL index name.
|
(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.lang.Long |
nextPrimaryKey(java.lang.Class<? extends DataModelObject> dmoIface,
java.lang.Integer multiplexID,
boolean usePendingReclaimed)
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.lang.Integer multiplexID,
java.lang.Long id)
Prepare a single, primary key for reclamation.
|
private void |
removePendingReclaimedKeys(java.util.Map<TemporaryBuffer.ReclaimTable,java.util.List<java.lang.Long>> map,
java.lang.Class<?> dmoIface)
Remove all reclaimed primary keys for the specified DMO.
|
private void |
removeReclaimedKeys(java.util.Map<TemporaryBuffer.ReclaimTable,java.util.SortedSet<java.lang.Long>> map,
java.lang.Class<?> dmoIface)
Remove all reclaimed primary keys for the specified DMO.
|
void |
rollback(boolean transaction)
On a full transaction rollback,clear the set of pending, reclaimable
keys.
|
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.
|
(package private) void |
setCurrentPrimaryKey(java.lang.Class<? extends DataModelObject> dmoIface,
long value)
Set the primary key sequence for the specified temp-table to the new value.
|
void |
validate(boolean transaction,
boolean aggressiveFlush)
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<? extends DataModelObject>,java.util.concurrent.atomic.AtomicLong> openTables
private final java.util.Set<java.lang.Class<? extends DataModelObject>> pendingDrop
private final java.util.Map<TemporaryBuffer.ReclaimTable,java.util.List<java.lang.Long>> pendingReclaimedKeys
private final java.util.Map<TemporaryBuffer.ReclaimTable,java.util.SortedSet<java.lang.Long>> 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 final java.util.Map<java.lang.Class<?>,RefCount> ooObjectCounter
object
s for each DMO interface.
Only the object
s that have active destructors are counted.
private int nextMPID
private final java.lang.String sequenceName
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 validate(boolean transaction, boolean aggressiveFlush)
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).aggressiveFlush
- true
if transaction manager is in aggressive subtransaction
flush mode, indicating that any transient buffers should be validated and
flushed, regardless of other state.Commitable.validate(boolean,boolean)
void init()
Context
instance.void cleanup()
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<? extends DataModelObject> 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<? extends DataModelObject> dmoIface)
tt
- The temp-table resource.table
- Name of temp table to be dropped.dmoIface
- DMO interface.void setCurrentPrimaryKey(java.lang.Class<? extends DataModelObject> dmoIface, long value)
dmoIface
- Data model object interface.value
- The new value for the primary key sequence.long getCurrentPrimaryKey(java.lang.Class<? extends DataModelObject> dmoIface)
dmoIface
- Data model object interface.java.lang.Long nextPrimaryKey(java.lang.Class<? extends DataModelObject> dmoIface, java.lang.Integer multiplexID, boolean usePendingReclaimed) throws PersistenceException
dmoIface
- Data model object interface.multiplexID
- The multiplex ID for the temp-table reclaiming this key.usePendingReclaimed
- Use the pending reclaimed PKs, as we are in the same tx where these were gathered.PersistenceException
- if dmoIface
is unknown.void reclaimKey(java.lang.Class<?> dmoIface, java.lang.Integer multiplexID, java.lang.Long id)
dmoIface
- DMO interface for temporary table records.multiplexID
- The multiplex ID for the temp-table reclaiming this key.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 removeReclaimedKeys(java.util.Map<TemporaryBuffer.ReclaimTable,java.util.SortedSet<java.lang.Long>> map, java.lang.Class<?> dmoIface)
map
- The map to be cleaned.dmoIface
- DMO interface for temporary table records.private void removePendingReclaimedKeys(java.util.Map<TemporaryBuffer.ReclaimTable,java.util.List<java.lang.Long>> map, java.lang.Class<?> dmoIface)
map
- The map to be cleaned.dmoIface
- DMO interface for temporary table records.private java.lang.String getImplicitSqlIndexName(java.lang.Class<? extends DataModelObject> dmoIface)
dmoIface
- DMO interface which represents the temp table.private java.lang.String getImplicitIndexName(java.lang.Class<? extends DataModelObject> dmoIface)
dmoIface
- DMO interface which represents the temp table.private void doCreateTable(java.lang.Class<? extends DataModelObject> 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<? extends com.goldencode.p2j.persist.DataModelObject>)
private void doDropTable(java.lang.Class<? extends DataModelObject> 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<? extends com.goldencode.p2j.persist.DataModelObject>)
private java.lang.String getTableName(java.lang.Class<?> dmoIface)
dmoIface
- DMO interface for which a table name is needed.