public final class RemoteDirtyShareManager extends java.lang.Object implements DirtyShareManager
DirtyShareManager
which delegates
requests for dirty share services to the remote P2J server which is
authoritative for the target database. This is necessary in cases where
business logic dynamically connects to a remote database which is not
managed by the current P2J server instance, since actions of management of
the information about uncommitted modifications to database records must be
serialized through a dirty share manager which is authoritative for the
target database.
An instance of this class works with a local proxy for a remote instance of
DirtyShareMultiplexer
residing at the target server. The
remote object may manage multiple databases, each of which is assigned a
unique database identifier. When the database is set
into a RemoteDirtyShareManager
instance, the associated identifier is requested from the remote
multiplexer. The ID returned by the multiplexer is used on all subsequent
service requests sent by the DirtyShareManager
instance.
RemotePersistence
Modifier and Type | Field and Description |
---|---|
private int |
mpID
Multiplex ID for the remote database associated with this object
|
private DirtyShareMultiplexer |
multiplexer
Dirty share manager multiplexer which will service remote requests
|
Constructor and Description |
---|
RemoteDirtyShareManager(DirtyShareMultiplexer multiplexer)
Constructor which stores a proxy to the remote object which will
service dirty share manager requests for the remote database.
|
Modifier and Type | Method and Description |
---|---|
void |
cleanupChanges(java.util.Map<java.lang.String,java.util.Set<java.lang.Long>> subChanges,
java.util.Set<RecordIdentifier<java.lang.String>> subInserts)
Stop tracking uncommitted changes to the the subset of records
represented by
subChanges , and remove from the master set
of uncommitted, inserted records the subset of records represented by
subInserts . |
void |
cleanupDeletes(java.util.Map<java.lang.String,java.util.Set<java.lang.Long>> subDeletes)
Remove from the master set of uncommitted, deleted records the subset of
records represented by
subDeletes . |
void |
delete(java.lang.String entity,
java.lang.Long id,
boolean rollback,
boolean lock)
Mark a record as having been deleted in an uncommitted transaction, or
unmark a record which previously was so marked.
|
void |
deregisterForGlobalEvents(long registerID)
Deregister with a global event clearinghouse an interest in insert,
delete, and update events which affect a particular DMO type.
|
Record |
getDirtyDMO(java.lang.String entity,
java.lang.Long id)
Retrieve from the dirty database the record specified by the given
entity and primary key, if it exists.
|
DirtyInfo |
getDirtyInfo(java.lang.String entity,
java.lang.Long candidateID,
int index,
java.util.List<java.lang.String> statements,
java.lang.Object[] params,
boolean rowidLookup)
Given certain search criteria and possibly the primary key of a potential DMO match in the
primary database, report any significant information currently being tracked for uncommitted
transactions, which might override data (or the lack thereof) found in the primary database.
|
int |
getEntityDirtyState(java.lang.String entity)
Indicate whether any uncommitted modification is being tracked for the
database table associated with the specified entity.
|
GlobalChangeEvent[] |
getGlobalEvents(long registerID,
long lastID)
Retrieve any new events that have been collected by a global event
clearinghouse, representing inserts, deletes, and updates made to
record types for which the caller previously has registered interest.
|
void |
insert(java.lang.String entity,
Record dmo,
IndexState indexState,
boolean lock)
Begin tracking a newly inserted record in the dirty database.
|
boolean |
isDeleted(java.lang.String entity,
java.lang.Long id)
Indicate whether the record specified by the given entity and primary
key has been deleted within an uncommitted transaction in any
context.
|
boolean |
isTracked(java.lang.String entity,
java.lang.Long id)
Indicate whether the record specified by the given entity and primary
key is being tracked for changes within an uncommitted transaction.
|
<T> java.util.List<T> |
list(java.lang.String fql,
java.lang.Object[] params,
int maxResults,
int startOffset,
boolean readOnly)
Execute an HQL query and return the results as a list.
|
void |
lockAllIndexes(java.lang.String entity,
LockType lockType)
Lock or unlock all indexes associated with the given DMO entity.
|
long |
registerForGlobalEvents(java.lang.String entity)
Register with a global event clearinghouse an interest in insert,
delete, and update events which affect the given DMO entity.
|
void |
rollbackInsert(RecordIdentifier<java.lang.String> ident,
boolean lock)
Rollback the insert of a record previously introduced with the
insert(String, Record, IndexState, boolean) method. |
void |
setDatabase(Database database)
Set the name of the physical database with which this dirty share
manager is associated.
|
void |
update(java.lang.String entity,
java.lang.Long id,
java.lang.String[] properties,
int[] extIndexes,
BaseDataType[] values,
boolean validatedTransientIndex,
boolean lock)
Retrieve a DMO which is being tracked in the dirty database, and apply
the specified updates to it, as provided by the
properties
and values arguments. |
void |
update(java.lang.String entity,
Record copy,
java.lang.String[] properties,
int[] extIndexes,
BaseDataType[] values,
boolean lock)
Begin tracking a DMO for changes, based on the updates indicated by the
properties , extIndexes and values arguments. |
private final DirtyShareMultiplexer multiplexer
private int mpID
public RemoteDirtyShareManager(DirtyShareMultiplexer multiplexer)
multiplexer
- Dirty share manager multiplexer which will service remote
requests.public void setDatabase(Database database)
database
- Database information object.public long registerForGlobalEvents(java.lang.String entity)
registerForGlobalEvents
in interface DirtyShareManager
entity
- DMO entity for which the caller is interested in tracking
change.getGlobalEvents(long, long)
,
deregisterForGlobalEvents(long)
public void deregisterForGlobalEvents(long registerID)
deregisterForGlobalEvents
in interface DirtyShareManager
registerID
- A unique identifier for the registrant being deregistered.getGlobalEvents(long, long)
,
registerForGlobalEvents(String)
public GlobalChangeEvent[] getGlobalEvents(long registerID, long lastID) throws EventRegistrationException
getGlobalEvents
in interface DirtyShareManager
registerID
- A unique identifier for an object which has registered interest
in DMO changing events.lastID
- A unique identifier representing the last event retrieved by
the caller. If less than 0, it is assumed no events have yet
been retrieved since the caller registered interest in these
events.null
if no
such events have been collected.EventRegistrationException
- if registerID
is invalid or has expired.public void lockAllIndexes(java.lang.String entity, LockType lockType) throws PersistenceException
lockAllIndexes
in interface DirtyShareManager
entity
- Name of an entity, which is the name of the DMO implementation
class associated with a table being tracked for uncommitted
changes.lockType
- Type of lock to acquire, or NONE
to release
existing locks. NO_WAIT
variants will be treated
as regular, blocking variants.PersistenceException
- if there is an error querying JDBC metadata while retrieving
index information.public void insert(java.lang.String entity, Record dmo, IndexState indexState, boolean lock) throws PersistenceException
This record is removed when the current transaction is committed or rolled back.
insert
in interface DirtyShareManager
entity
- Name of an entity, which is the name of the DMO implementation class associated
with a table being tracked for uncommitted changes.dmo
- Record to be tracked.indexState
- The index update state of the record at the time of insertion.lock
- true
to acquire write locks to insert the record; false
to assume write locks are acquired by calling code.PersistenceException
- if there is any database error.public void rollbackInsert(RecordIdentifier<java.lang.String> ident, boolean lock) throws PersistenceException
insert(String, Record, IndexState, boolean)
method.rollbackInsert
in interface DirtyShareManager
ident
- Identifier for the target record, which encapsulates its entity
name and primary key.lock
- true
to acquire write locks;
false
to assume write locks are acquired by
calling code.PersistenceException
- if there is any database error.public boolean isTracked(java.lang.String entity, java.lang.Long id)
isTracked
in interface DirtyShareManager
entity
- Name of an entity, which is the name of the DMO implementation
class associated with a table being tracked for uncommitted
changes.id
- Primary key of the record to be checked.true
to indicate the target record is being
tracked for changes, else false
.public void update(java.lang.String entity, Record copy, java.lang.String[] properties, int[] extIndexes, BaseDataType[] values, boolean lock) throws PersistenceException
properties
, extIndexes
and values
arguments.
Make a copy of the given record, apply the specified updates to that copy, and store the copy in the dirty database.
This record is removed when the adding context's current transaction is committed or rolled back.
update
in interface DirtyShareManager
entity
- Name of an entity, which is the name of the DMO implementation
class associated with a table being tracked for uncommitted changes.copy
- Record to be tracked.properties
- Array of names of those DMO properties which were updated.
These should represent columns which participate in one or more indexes.extIndexes
- In case of EXTENT fields this array contains their index. Otherwise -1.values
- Updated DMO property values. Each value in the array
corresponds positionally with its matching property name in the
properties
array.lock
- true
to acquire write locks to update the record;
false
to assume write locks are acquired by calling code.PersistenceException
- if there is any database error.public void update(java.lang.String entity, java.lang.Long id, java.lang.String[] properties, int[] extIndexes, BaseDataType[] values, boolean validatedTransientIndex, boolean lock) throws PersistenceException
properties
and values
arguments. It is assumed the DMO already exists
in the database, from a previous call to update(String, Record, String[], int[], BaseDataType[], boolean)
.update
in interface DirtyShareManager
entity
- Name of an entity, which is the name of the DMO implementation
class associated with a table being tracked for uncommitted changes.id
- Primary key id of the record to be retrieved and updated.properties
- Array of names of those DMO properties which were updated.
These should represent columns which participate in one or more indexes.extIndexes
- In case of EXTENT fields this array contains their index. Otherwise -1.values
- Updated DMO property values. Each value in the array
corresponds positionally with its matching property name in the
properties
array.validatedTransientIndex
- true
if the update was caused by an index validation of a transient record.lock
- true
to acquire write locks to update the record;
false
to assume write locks are acquired by calling code.PersistenceException
- if there is any database error.public int getEntityDirtyState(java.lang.String entity)
getEntityDirtyState
in interface DirtyShareManager
entity
- Name of an entity, which is the name of the DMO implementation
class associated with a table being tracked for uncommitted
changes.DirtyInfo
. Zero return indicates entity is not
dirty. Only CHANGE
and DELETE
are
detected, not INSERT
.public boolean isDeleted(java.lang.String entity, java.lang.Long id)
isDeleted
in interface DirtyShareManager
entity
- Name of an entity, which is the name of the DMO implementation
class associated with a table being tracked for uncommitted
changes.id
- Primary key of the record to be checked.true
if the specified record has been deleted,
else false
.public void delete(java.lang.String entity, java.lang.Long id, boolean rollback, boolean lock) throws PersistenceException
A record is unmarked when the adding context's current transaction is committed or rolled back.
delete
in interface DirtyShareManager
entity
- Name of an entity, which is the name of the DMO implementation
class associated with a table being tracked for uncommitted
changes.id
- Primary key of deleted record.rollback
- If false
, the target record is marked as deleted;
if true
, it is unmarked.lock
- true
to acquire write locks to delete the record;
false
to assume write locks are acquired by
calling code.PersistenceException
- if there was an error deleting the record from the database.public Record getDirtyDMO(java.lang.String entity, java.lang.Long id) throws PersistenceException
getDirtyDMO
in interface DirtyShareManager
entity
- Name of an entity, which is the name of the DMO implementation
class associated with a table being tracked for uncommitted
changes.id
- Primary key of the record to be retrieved.null
.PersistenceException
- if there is any database error.public DirtyInfo getDirtyInfo(java.lang.String entity, java.lang.Long candidateID, int index, java.util.List<java.lang.String> statements, java.lang.Object[] params, boolean rowidLookup) throws PersistenceException
If a DirtyInfo
object is returned by this method, it will contain overriding
information, such as a dirty DMO which matched the search criteria, whether that record was
newly inserted, or the fact that the candidate record found in the primary search has been
deleted or modified in an uncommitted transaction. A null
return indicates no
overriding information was available.
getDirtyInfo
in interface DirtyShareManager
entity
- Name of an entity, which is the name of the DMO implementation class associated
with a table being tracked for uncommitted changes.candidateID
- Primary key ID of DMO, if any, found in the primary database, which matches the
current query criteria.index
- Name of index which governs the ordering of data in the current query.statements
- One or more HQL statements to be executed against the dirty database to find a
record which matches the current query criteria. The list is in order of most
specific to least specific search criteria.params
- Query substitution parameters which match placeholders in the most specific HQL
statement.rowidLookup
- The predicate of the query does a lookup for ROWID/RECID of the table. In case of
transient records they are accessible without the need of having a full matched
index.null
if no uncommitted change
information was available for the given arguments.PersistenceException
- if there was any database error.public <T> java.util.List<T> list(java.lang.String fql, java.lang.Object[] params, int maxResults, int startOffset, boolean readOnly) throws PersistenceException
Object
s.
No locking is attempted.
list
in interface DirtyShareManager
fql
- FQL query statement. This method makes no assumptions as to the types of object(s) returned.params
- Substitution values for the query. If none, this should be an empty array.maxResults
- The maximum number of elements to be returned in the list.
If this value is non-positive, no upper limit is applied.startOffset
- The 0-based offset of the first record to retrieve. If this
value is non-positive, an offset of 0 is used by default.readOnly
- true
to execute the query in read-only mode, else false
.null
if no result was found.PersistenceException
- if there was an error executing the query.public void cleanupChanges(java.util.Map<java.lang.String,java.util.Set<java.lang.Long>> subChanges, java.util.Set<RecordIdentifier<java.lang.String>> subInserts) throws PersistenceException
subChanges
, and remove from the master set
of uncommitted, inserted records the subset of records represented by
subInserts
.cleanupChanges
in interface DirtyShareManager
subChanges
- Sets of primary keys representing those records to be removed
from uncommitted change tracking, mapped by entity name.subInserts
- A set of identifiers of those records to be removed from the
master set of uncommitted inserts.PersistenceException
- if there is any database error.public void cleanupDeletes(java.util.Map<java.lang.String,java.util.Set<java.lang.Long>> subDeletes)
subDeletes
.cleanupDeletes
in interface DirtyShareManager
subDeletes
- Sets of primary keys representing those records to be removed
from uncommitted delete tracking, mapped by entity name.