private static class TemporaryBuffer.Context extends java.lang.Object implements SessionListener
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 Cache<FastCopyHelper.FastCopyKey,FastCopyHelper> |
fastCopyCache
Cache responsible with storing instances of FastCopyHelper.
|
private boolean |
hasMappingTables
Flag to indicate that this context database session has the mapping tables for fast-copy created
|
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 org.roaringbitmap.RoaringBitmap |
nonEmptyTableFlags
Map of flags indicating whether each virtual table is empty
|
private java.util.Map<java.lang.Class<?>,RefCount> |
ooObjectCounter
The counter of stored
objects 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 Persistence |
persistence
Persistence service object for temp tables
|
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 in-DB PK mapping tables.
|
(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.
|
private FastCopyHelper |
getFastCopyHelper(FastCopyHelper.FastCopyContext fastCopyContext)
Get an instance of a
FastCopyHelper from the cache if it exists, or create a new one
if there is no suitable instance in the cache. |
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)
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)
Deprecated.
|
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.
|
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.Set<java.lang.String> activeTables
private final org.roaringbitmap.RoaringBitmap nonEmptyTableFlags
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
objects for each DMO interface.
Only the objects that have active destructors are counted.
private int nextMPID
private final Cache<FastCopyHelper.FastCopyKey,FastCopyHelper> fastCopyCache
private boolean hasMappingTables
public boolean sessionEvent(SessionListener.Event event) throws PersistenceException
sessionEvent in interface SessionListenerevent - 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 SessionListenervoid 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.java.lang.Long nextPrimaryKey(java.lang.Class<? extends DataModelObject> dmoIface, java.lang.Integer multiplexID)
dmoIface - Data model object interface.multiplexID - The multiplex ID for the temp-table reclaiming this key.@Deprecated
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 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.private FastCopyHelper getFastCopyHelper(FastCopyHelper.FastCopyContext fastCopyContext)
FastCopyHelper from the cache if it exists, or create a new one
if there is no suitable instance in the cache.fastCopyContext - The context for the FastCopyHelper.FastCopyHelper, either retrieved from cache, or just created.