class Persistence.Context extends java.lang.Object implements TenantChangeListener
Special care is taken to not close a database session while other entities are dependent upon it for services.
| Modifier and Type | Field and Description |
|---|---|
private java.lang.Throwable |
beginTxTrace
Throwable which holds stack trace where last transaction began
|
private BufferManager |
bufferManager
Context-local buffer manager
|
private boolean |
closingSession
Flag to prevent nested session close attempts
|
private Database |
contextDatabase
The database instance assigned to this context.
|
private java.lang.Object |
dialectData
Optional, dialect-specific, context-local data
|
private SessionFactory |
factory
A factory that allows a session to be reclaimed
|
private FastFindCache |
ffCache
Cache for FIND results.
|
private RecordLockContext |
lockContext
Context-local record lock context
|
private RecordNursery |
nursery
Object which manages newly created records
|
private int |
openSessionCount
Count of open database sessions in this context
|
private boolean |
rereadNoLock
rereadnolock command-line parameter, by default deactivated
|
private Session |
session
Active database session, if any
|
private java.util.WeakHashMap<SessionListener,Finalizable> |
sessionListeners
Session listener objects
|
private int |
sessionUseCount
Reference count of resources dependent upon current session
|
private ExpiryCache<Persistence.QueryKey,Query> |
staticQueryCache
Cache of FQL strings, with or without max results and start offsets, to queries.
|
private java.lang.String |
tenantId
The id of the tenant that was assigned to this context, if any.
|
private boolean |
traceTx
Enable tracing transaction starts
|
private boolean |
unsafe
Flag used to indicate if default exception handling is used.
|
| Modifier | Constructor and Description |
|---|---|
private |
Context()
The default constructor reads rereadNoLock from directory.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) boolean |
beginTransaction(SavepointManager savepointManager)
Begin a new database transaction and remember that it is open, for related calls.
|
(package private) boolean |
canCloseSession()
Indicate whether there is an open session and if so, whether it can be closed.
|
(package private) void |
cleanup()
Cleanup hook invoked at the end of the current client context.
|
(package private) boolean |
closeSession(boolean error)
Attempt to close the database session associated with this context, and indicate whether
the attempt was successful.
|
private boolean |
closeSessionImpl(boolean error,
boolean force)
Attempt to close the database session associated with this context, and indicate whether
the attempt was successful.
|
(package private) void |
commit()
Commit the current database transaction.
|
(package private) void |
deregisterSessionListener(SessionListener listener)
Explicitly deregister a global session listener, which represents a dynamic temp-table
resource which has been deleted explicitly.
|
(package private) void |
enableTransactionTrace(boolean enable)
Set enable mode for transaction tracing.
|
(package private) java.lang.Throwable |
getBeginTxTrace()
Retrieve trace information about where the current transaction, if any, was started.
|
(package private) Database |
getDatabase()
Get the database information object associated with this persistence context.
|
(package private) java.lang.Object |
getDialectData()
Get the context-local, dialect-specific data object, if any.
|
(package private) FastFindCache |
getFastFindCache()
Getter for the
ffCache field. |
(package private) RecordNursery |
getNursery()
Get the record nursery.
|
(package private) Persistence |
getPersistence()
Get the
Persistence object associated with this context. |
(package private) Query |
getQuery(java.lang.String fql,
int maxResults,
int startOffset,
DataRelation relation)
Get a cached query for the given combination of FQL query string, maximum result rows,
and starting row offset, creating and caching a new query if no such query already is
cached.
|
(package private) Query |
getQuery(java.lang.String fql,
int maxResults,
int startOffset,
DataRelation relation,
boolean lazyMode)
Get a cached query for the given combination of FQL query string, maximum result rows,
and starting row offset, creating and caching a new query if no such query already is
cached.
|
(package private) RecordLockContext |
getRecordLockContext()
Get the record lock context associated with the current client
session.
|
(package private) Session |
getSession()
Retrieve the ORM
Session object associated with
this context, creating it if necessary. |
(package private) Session |
getSession(java.lang.String tenantId,
java.lang.String ldbName)
Retrieve the ORM
Session object associated with
this context, creating it if necessary. |
(package private) Session |
getSessionNoCreate()
Retrieve the ORM
Session object associated with this context, if any. |
(package private) java.lang.String |
getTenantId()
The id of the tenant that was assigned to this context, if any.
|
(package private) boolean |
isAutoCommit()
Indicate whether auto-commit is needed; this is the case for temp-tables being modified
outside of an explicit transaction.
|
(package private) boolean |
isRereadNoLock()
Checks if the rereadnolock 4GL command-line option is active for this client context.
|
(package private) boolean |
isTransactionOpen()
Indicate whether a database-level transaction currently is open.
|
(package private) boolean |
isUnsafe()
Checks whether this persistence context is unsafe or not.
|
private void |
notifySessionEvent(SessionListener.Event event)
Notify all registered session listeners that the current ORM session is about to
close or the current, implicit transaction is being committed.
|
(package private) void |
postTransaction(boolean rollback)
Perform post-processing and cleanup after a transaction commit or rollback.
|
(package private) void |
registerSessionListener(SessionListener listener,
SessionListener.Scope scope)
Register a
SessionListener to receive session life
cycle event notifications. |
(package private) void |
releaseSession()
Decrement the session use count, indicating the removal of a dependency on the open
session.
|
(package private) void |
rollback(boolean error)
Roll back the current transaction and possibly close the current session.
|
(package private) void |
setTenantDatabase(Database db,
boolean skipRegistering)
Set the database that will be used in this context.
|
(package private) void |
setUnsafe(boolean value)
Decide whether this persistence context is unsafe or not.
|
void |
tenantChanged(java.lang.String tenantId,
java.lang.String ldbName)
When a tenant id is changed, we need to re-open the session, but taking into account
the new tenant's id.
|
(package private) void |
useSession()
Increment the session use count, indicating the addition of a dependency on the open
session.
|
private final ExpiryCache<Persistence.QueryKey,Query> staticQueryCache
private final BufferManager bufferManager
private Database contextDatabase
private FastFindCache ffCache
private RecordNursery nursery
private final RecordLockContext lockContext
private final java.util.WeakHashMap<SessionListener,Finalizable> sessionListeners
private Session session
private int sessionUseCount
private boolean closingSession
private volatile int openSessionCount
private final java.lang.Object dialectData
private boolean rereadNoLock
private boolean traceTx
private java.lang.Throwable beginTxTrace
private SessionFactory factory
private java.lang.String tenantId
private boolean unsafe
private Context()
public void tenantChanged(java.lang.String tenantId,
java.lang.String ldbName)
tenantChanged in interface TenantChangeListenertenantId - The new tenant's id.ldbName - The logical name of the database that the tenant will use in this context.Database getDatabase()
RecordLockContext getRecordLockContext()
Persistence getPersistence()
Persistence object associated with this context.void useSession()
void releaseSession()
boolean canCloseSession()
true if there is an open session which may be closed; otherwise false.Query getQuery(java.lang.String fql, int maxResults, int startOffset, DataRelation relation) throws PersistenceException
fql - FQL query string.maxResults - The maximum number of results to be returned.startOffset - Zero-based offset of first result to be returned (undefined results unless
fql includes an order by phrase).relation - The recursive DATA-RELATION the query is to FILL for.Query object for the requested fql.PersistenceException - if there was an error creating an ORM session.Query getQuery(java.lang.String fql, int maxResults, int startOffset, DataRelation relation, boolean lazyMode) throws PersistenceException
fql - FQL query string.maxResults - The maximum number of results to be returned.startOffset - Zero-based offset of first result to be returned (undefined results unless
fql includes an order by phrase).relation - The recursive DATA-RELATION the query is to FILL for.lazyMode - Flag that indicates whether the query should be executed in a lazy manner.Query object for the requested fql.PersistenceException - if there was an error creating an ORM session.void commit()
throws PersistenceException
java.lang.IllegalStateException - if no transaction is active in the current session; this
represents a programming error.PersistenceException - if there is an error committing the transaction.void rollback(boolean error)
throws PersistenceException
error - Indicates whether the rollback is due to an error.java.lang.IllegalStateException - if no transaction is active in the current session; this
represents a programming error.PersistenceException - if there is an error rolling back the transaction.void enableTransactionTrace(boolean enable)
enable - true to enable; false to disable.boolean beginTransaction(SavepointManager savepointManager) throws PersistenceException
false, and do not begin a new one. A new
database session is created if one does not already exist in the current context.savepointManager - A savepoint manager to install in the session while the transaction is active.
May be null for ad-hoc transactions, but must not be null when
the databbase transaction is being opened in association with a legacy
application transaction.true if a new database transaction was opened successfully;
false if a transaction already exists.PersistenceException - if there is an error beginning the new transaction.void postTransaction(boolean rollback)
throws PersistenceException
rollback - Indicates whether the transaction is being ended after a rollback (as opposed
to a commit).PersistenceException - if an error occurs performing post-transaction processing, if any.java.lang.Throwable getBeginTxTrace()
null.Throwable containing stack trace from last transaction start, or
null.void registerSessionListener(SessionListener listener, SessionListener.Scope scope)
SessionListener to receive session life
cycle event notifications. The listener will be deregistered
according to the following rules at the earlier of:
scope
parameter:
ENCLOSING_EXTERNAL_SCOPE
CURRENT_SCOPE
NEXT_EXTERNAL_SCOPE
listener - Session listener to be registered.scope - SessionListener.Scope enum indicating the scope
to which this listener should be registered. When the
scope ends, the listener is deregistered as described above.void deregisterSessionListener(SessionListener listener)
listener - Listener to deregister.FastFindCache getFastFindCache()
ffCache field.RecordNursery getNursery()
Session getSessionNoCreate()
Session object associated with this context, if any.
If the current session is broken, return null.
null if none has been created.Session getSession() throws PersistenceException
Session object associated with
this context, creating it if necessary. The session can be closed
by closeSession(boolean).PersistenceException - if an error occurs associating a detached record with the
new session.java.lang.IllegalArgumentException - if database has not been registered with the
persistence service.Session getSession(java.lang.String tenantId, java.lang.String ldbName) throws PersistenceException
Session object associated with
this context, creating it if necessary. The session can be closed
by closeSession(boolean).tenantId - The new tenant's id.ldbName - The logical name of the database that the tenant will use in this session.PersistenceException - if an error occurs associating a detached record with the
new session.java.lang.IllegalArgumentException - if database has not been registered with the
persistence service.java.lang.String getTenantId()
void setTenantDatabase(Database db, boolean skipRegistering)
db - The new database that will be used in this context.skipRegistering - true if the registering part should be skipped, false otherwise.boolean isTransactionOpen()
true if open, else false.java.lang.Object getDialectData()
null if no
such data exists.boolean isAutoCommit()
true if auto-commit is needed, else false.boolean closeSession(boolean error)
throws PersistenceException
This implementation is tolerant of multiple closes on the same session. If the session
already was closed or could not be found, the method simply returns false.
error - true to indicate the session is closing due to an error; false
to indicate the session is closing in the course of normal processing.true is the session was closed successfully; false if it was
not closed because either: (a) this method was invoked in the course of an
existing attempt to close the session; or (b) the session is with the legacy
temp-table database while temporary tables are still in use.PersistenceException - if an open session was found but the attempt to close it failed with a database
error.private boolean closeSessionImpl(boolean error,
boolean force)
throws PersistenceException
This implementation is tolerant of multiple closes on the same session. If the session
already was closed or could not be found, the method simply returns false.
error - true to indicate the session is closing due to an error; false
to indicate the session is closing in the course of normal processing.force - true to force the session to be closed and all database resources
associated with it to be cleaned up.true is the session was closed successfully; false if it was
not closed because either: (a) this method was invoked in the course of an
existing attempt to close the session; or (b) the session is with the legacy
temp-table database while temporary tables are still in use.PersistenceException - if an open session was found but the attempt to close it failed with a database
error.private void notifySessionEvent(SessionListener.Event event)
All registered listeners are given a chance to process this event, even if one or more
raise a PersistenceException (there is no such guarantee for unchecked
exceptions). Each exception caught is logged.
event - Session event type.void cleanup()
boolean isRereadNoLock()
true if rereadnolock is specified for this client contextvoid setUnsafe(boolean value)
value - If true the persistence will run in unsafe mode and in safe mode if false.boolean isUnsafe()