Package com.portal.bas
Class PCachedContext
java.lang.Object
com.portal.pcm.PortalContext
com.portal.appcenter.BRMClientContext
com.portal.bas.PCachedContext
public class PCachedContext
extends com.portal.appcenter.BRMClientContext
PCachedPortalContext
is a subclass of PortalContext
that adds data caching. The usefulness of caching Portal data is limited
and somewhat problematic, however, this class is still useful for the following
reasons:
- It provides a way to abstract the model data.
The client side, is limited to knowledge of model handles and a string description of the field data. It doesn't need to have PCM downloaded, or have a lot of built-in knowledge of Portal. Field descriptions can therefore refer to fields in any database, and type can refer to any kind of table for other types.
- It provides a common entry point to use for descending flists.
A lot of data access is nested, for example, flists in flists. The Description/FieldSpec interfaces provide a common entry point to extract field values from descending flists, an operation that would otherwise have to be repeated frequently throughout the application code.
- Version:
- %version: 13.1.1 % %date_modified: Wed Jan 09 20:01:05 2002 %
- Author:
- larrylf
-
Field Summary
Fields inherited from class com.portal.pcm.PortalContext
Hostname, OPFLG_ADD_ENTRY, OPFLG_CALC_ONLY, OPFLG_CHACHABLE, OPFLG_COUNT_ONLY, OPFLG_META_ONLY, OPFLG_NO_DESCEND, OPFLG_NO_RESULTS, OPFLG_READ_READPAST, OPFLG_READ_RESULT, OPFLG_READ_UNCOMMITTED, OPFLG_REV_CHECK, OPFLG_SEARCH_DB, OPFLG_SEARCH_ONE_PARTITION, OPFLG_SEARCH_PARTITIONS, OPFLG_USE_POID_GIVEN, ProgramName, TRAN_OPEN_GLOBALTRANSACTION, TRAN_OPEN_LOCK_OBJ, TRAN_OPEN_READONLY, TRAN_OPEN_READWRITE
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a default instance of aPCachedContext
.Creates an instance ofPCachedContext
from anotherPCachedContext
.Create a PCachedContext using an existing PortalContext that has already been connected to Portal.PCachedContext
(Properties uprops) Creates an instance ofPCachedContext
, given some base properties. -
Method Summary
Modifier and TypeMethodDescriptioncreateModelFrom
(FList fl) Creates a new model handle from anFlist
and sets thatFlist
in the cache.createModelFrom
(FList fl, String type) Creates a new model handle of a specified type from anFlist
, and sets thatFlist
in the cache.createModelFrom
(Poid pd) Creates a new model handle from aPoid
.Creates a new model handle from aSparseArray
.void
Removes a model from the cache to free resources.com.portal.permission.ScopeEntryPoint
Returns the cached scope entry point which was cached before cm timed out.getField
(PModelHandle mh, PDataFieldSpecification spec) Gets a field from a model.getField
(FList list, PDataFieldSpecification spec) Gets a field from anFlist
model.getModelField
(PModelHandle data, PFieldSpecification spec) Gets a field from a model.getModelField
(FList data, PFieldSpecification spec) Gets a field from anFlist
model.Creates a model for the specifiedFlist
, but doesn't put the flist in the cache unless the created model handle has no match.com.portal.permission.ScopeEntryPoint
getScope()
Retrieves the current scope for this connection through an opcode call to Portal.Force the cache to be loaded with an entire storable class for Forces the cache to be loaded with an entire storable class for a given model handle.getWholeObject
(PModelHandle mh, boolean force) Forces the cache to be loaded with an entire storable class for a given model handle.void
logCache()
A debug function that dumps the cache to the log file.lookupModel
(PModelHandle handle) Gets the cached model that corresponds to the supplied model handle.lookupModel
(PModelHandle handle, boolean ensureWhole, int updateFlag) Returns the model data associated withhandle
.lookupPoid
(PModelHandle modl) Get thePoid
from the cache for a model handle.opcode
(int op, int flags, PModelHandle in) Calls an opcode.opcode
(int op, int flags, PModelHandle in, boolean setCacheToStale) Overloaded method of opcode so that information can be provided whether to stale the cache or not.Sends an opcode to the server.Overloaded method of opcode so that information can be provided whether to stale the cache or not.void
Opens a connection context with the server.Calls thesearch
opcode, but returns an array of model handles.Calls thesearch
opcode, but returns an array of model handles.Calls the search opcode and depending on cacheResults flag, it caches the results.void
setField
(PModelHandle modl, PDataFieldSpecification spec, Object val) Sets a field in a model to the specified value.void
setField
(FList list, PDataFieldSpecification spec, Object val) Sets anFlist
field in a model to the specified value.void
setModel
(PModelHandle modl, FList fl) Sets anFlist
model in the cache associated with a handle.void
setModel
(PModelHandle modl, Poid pd) Sets aPoid
model in the cache associated with a handle.void
setModel
(PModelHandle modl, SparseArray sa) Sets aSparseArray
model in the cache associated with a handle.void
setScope
(com.portal.permission.ScopeEntryPoint scope) This method is used to set the scope of the connection.Methods inherited from class com.portal.appcenter.BRMClientContext
cloneConnection, reconnect
Methods inherited from class com.portal.pcm.PortalContext
addConnectionListner, close, connect, connect, disconnect, enableOpcodeLogging, genCorrelationId, genCorrelationId, genCorrelationId, genCorrelationId, genCorrelationId, getContext, getContextInfoDetails, getCorrelationId, getCreatedTime, getCurrentDB, getDefaultLog, getHost, getInetAddress, getLocalAddress, getLocalPort, getPort, getReasonCode, getSession, getSocketChannelHashCode, getSocketChannelListener, getSocketChannelPort, getTransState, getUserID, getUserName, getUserProperty, initHostnameAndProgramName, isContextValid, isInTransaction, isOpcodeLoggingEnabled, isSocketChannelConnected, isSocketChannelOpen, isSocketChannelRegistered, opcode, opcodeReceive, opcodeReceive, opcodeReceive, opcodeSend, opcodeSend, parseConnectString, readTLSVersionFromConfig, reconnect, reconnectAfterUpdatePwd, recvCorrelation, removeConnectionListener, sendCorrelation, serviceSearch, setAppName, setCorrelationId, setLocalProperties, setSocketChannelListener, setTimeout, setTimeoutOverrideOriginal, transactionAbort, transactionCommit, transactionOpen, transactionOpen
-
Constructor Details
-
PCachedContext
Creates a default instance of aPCachedContext
.- Throws:
EBufException
- thrown if an error occurs
-
PCachedContext
Create a PCachedContext using an existing PortalContext that has already been connected to Portal.- Parameters:
PortalContext
- whose connection to Portal BAS will use internally by PCachedContext. Note that the PortalContext is reset to its default values and is no longer connected to Portal.- Throws:
EBufException
-
PCachedContext
Creates an instance ofPCachedContext
, given some base properties.- Parameters:
uprops
- the baseProperties
object- Throws:
EBufException
- thrown if an error occurs
-
PCachedContext
Creates an instance ofPCachedContext
from anotherPCachedContext
. The two contexts share a cache, but have different Portal connections.- Parameters:
ctx
- anotherPCachedContext
to copy- Throws:
EBufException
- thrown if an error occurs
-
-
Method Details
-
setScope
public void setScope(com.portal.permission.ScopeEntryPoint scope) This method is used to set the scope of the connection.- Parameters:
scope
- , Passed scope will be set in the connection.
-
open
Opens a connection context with the server.- Overrides:
open
in classcom.portal.appcenter.BRMClientContext
- Parameters:
in
- anFlist
that contains login information- Throws:
EBufException
- thrown if an error occurs
-
getCachedScope
public com.portal.permission.ScopeEntryPoint getCachedScope()Returns the cached scope entry point which was cached before cm timed out. -
opcode
Sends an opcode to the server. If this is an object read, the object is cached.- Overrides:
opcode
in classcom.portal.appcenter.BRMClientContext
- Parameters:
op
- the opcode to performflags
- the control flags for opcodein
- the opcode parameterFList
- Returns:
- The opcode output
FList
. - Throws:
EBufException
- thrown if an error occurs- See Also:
-
opcode
Calls an opcode.- Parameters:
flags
- the opcode flagsin
- the inputFList
modelopcode
- the opcode to call- Returns:
- The output
FList
model. - Throws:
EBufException
- thrown for Portal errors
-
opcode
Overloaded method of opcode so that information can be provided whether to stale the cache or not. Mostly useful for custom opcodes, where the custom opcode would like to decide whether to stale the cache or not.- Parameters:
op
- the opcode to performflags
- the control flags for opcodein
- the opcode parameterFList
setCacheToStale
- parameter to indicate whether to stale the cache or not.- Returns:
- The output
FList
model - Throws:
EBufException
- EBufException thrown for Portal errors
-
opcode
public FList opcode(int op, int flags, PModelHandle in, boolean setCacheToStale) throws EBufException Overloaded method of opcode so that information can be provided whether to stale the cache or not. Mostly useful for custom opcodes, where the custom opcode would like to decide whether to stale the cache or not.- Parameters:
op
- the opcode to performflags
- the control flags for opcodein
- the opcode parameterPModelHandle
setCacheToStale
- parameter to indicate whether to stale the cache or not.- Returns:
- The output
FList
model - Throws:
EBufException
- EBufException thrown for Portal errors
-
search
Calls the search opcode and depending on cacheResults flag, it caches the results.- Parameters:
op
- opcodein
- input flistcacheResults
- indicates whether to cache the search results or not- Returns:
- output flist of search
- Throws:
EBufException
-
search
Calls thesearch
opcode, but returns an array of model handles.- Parameters:
in
- the opcode inputFList
opcode
- an Portal search opcode (SEARCH, STEP_SEARCH, STEP_NEXT
)- Returns:
- An array of model handles.
- Throws:
EBufException
- thrown if an error occurs
-
search
Calls thesearch
opcode, but returns an array of model handles.- Parameters:
op
- Portal search opcode (SEARCH, STEP_SEARCH, STEP_NEXT
)flag
- Flag to search opcodein
- InputFList
- Returns:
- An array of model handles.
- Throws:
EBufException
- thrown if an error occurs
-
getOrCreateModelFrom
Creates a model for the specifiedFlist
, but doesn't put the flist in the cache unless the created model handle has no match.- Parameters:
fl
- the model to create a handle for- Returns:
- A new model handle.
- Throws:
EBufException
- thrown if an error occurs
-
createModelFrom
Creates a new model handle of a specified type from anFlist
, and sets thatFlist
in the cache.- Parameters:
fl
- the model to create a handle fortype
- the new model type- Returns:
- A new model handle.
- Throws:
EBufException
- thrown if an error occurs
-
createModelFrom
Creates a new model handle from anFlist
and sets thatFlist
in the cache.- Parameters:
fl
- the model to create a handle for- Returns:
- A new model handle.
- Throws:
EBufException
- thrown if an error occurs
-
createModelFrom
Creates a new model handle from aSparseArray
.- Parameters:
sa
- the model to create a handle for- Returns:
- A new model handle.
- Throws:
EBufException
- thrown if an error occurs
-
createModelFrom
Creates a new model handle from aPoid
.- Parameters:
pd
- the model to create a handle for- Returns:
- A new model handle.
- Throws:
EBufException
- thrown if an error occurs
-
lookupPoid
Get thePoid
from the cache for a model handle.- Parameters:
modl
- the model handle to look up- Returns:
- A
Poid
. - Throws:
EBufException
- thrown if an error occurs
-
lookupModel
Gets the cached model that corresponds to the supplied model handle. Returns the model data associated withhandle
. This method simply callslookupModel(PModelHandle, boolean, int)
, passingfalse
for the second, andPModelHandle.LOOKUP_UPDATE_IF_NEEDED
for the third parameter.- Parameters:
handle
- a non-null
PModelHandle
.- Returns:
- either the model associated with
handle
, ornull
. - Throws:
EBufException
- thrown if an error occurs- See Also:
-
lookupModel
public Object lookupModel(PModelHandle handle, boolean ensureWhole, int updateFlag) throws EBufException Returns the model data associated withhandle
. This method callsPModelCache.lookupModel(PModelHandle, boolean, int)
to get the model, and then ifhandle
is "collect-only", applies the collected data in the handle to the model.- Parameters:
handle
- a non-null
model handleensureWhole
- iftrue
, ensures that the model in the cache is wholeupdateFlag
- ifPModelHandle.LOOKUP_FORCE_UPDATE
, the model is unconditionally updated with data from Portal; ifPModelHandle.LOOKUP_DONT_UPDATE
it is not. Otherwise, the model is updated if marked stale, or ifensureWhole
istrue
and the model is not whole.- Returns:
- Either the model associated with
handle
, ornull
. - Throws:
EBufException
- thrown if an error occurs while reading the object from Portal.
-
setModel
Sets anFlist
model in the cache associated with a handle.- Parameters:
modl
- thePModelHandle
to use as a keyfl
- the model to store
-
setModel
Sets aSparseArray
model in the cache associated with a handle.- Parameters:
modl
- thePModelHandle
to use as a keysa
- the model to store
-
setModel
Sets aPoid
model in the cache associated with a handle.- Parameters:
modl
- thePModelHandle
to use as a keypd
- the model to store
-
discardModel
Removes a model from the cache to free resources.- Parameters:
mh
- aPModelHandle
-
getModelField
Gets a field from anFlist
model. This version only returns a model handle for a field that is itself a model. Use this method when the returned field data will be sent to the client. In the case ofPCompoundFieldSpec
, an object array is returned.- Parameters:
data
- the model to get a field fromspec
- a specification for which field(s) to get- Returns:
- The contents of the field as an Integer, BigDecimal, Date, Double, byte array, String, or ModelHandle.
- Throws:
EBufException
- thrown if an error occurs
-
getModelField
Gets a field from a model. This version only returns a model handle for a field that is itself a model. Use this method when the returned field data will be sent to the client. In the case ofPCompoundFieldSpec
, an object array is returned.- Parameters:
data
- the model to get a field fromspec
- a specification for which field(s) to get- Returns:
- The contents of the field as an Integer, BigDecimal, Date, Double, byte array, String, or ModelHandle.
- Throws:
EBufException
- thrown if an error occurs
-
getWholeObject
Force the cache to be loaded with an entire storable class for Forces the cache to be loaded with an entire storable class for a given model handle. Use this method when you access more than one or two fields.- Parameters:
mh
- aPModelHandle
- Returns:
- An
Flist
object. - Throws:
EBufException
- thrown if an error occursRemoteException
- thrown if an error occurs
-
getWholeObject
Forces the cache to be loaded with an entire storable class for a given model handle. Called when the caller knows they will be accessing more than a field or two.- Parameters:
mh
- aPModelHandle
force
- a flag to force aPCM_OP_READ_OBJ
- Throws:
EBufException
- thrown if an error occurs
-
getField
Gets a field from anFlist
model.- Parameters:
list
- the model to get a field fromspec
- a specification of which field to get- Returns:
- The field value.
- Throws:
EBufException
- thrown if an error occurs
-
getField
Gets a field from a model.- Parameters:
mh
- the model to get a field fromspec
- a specification of which field to get- Returns:
- The field value.
- Throws:
EBufException
- thrown if an error occurs
-
setField
public void setField(PModelHandle modl, PDataFieldSpecification spec, Object val) throws EBufException Sets a field in a model to the specified value.- Parameters:
modl
- the model to set a field inspec
- a specification of which field to setval
- the new value to set- Throws:
EBufException
- thrown if an error occurs
-
setField
Sets anFlist
field in a model to the specified value.- Parameters:
list
- the model to set a field inspec
- a specification of which field to setval
- the new value to set- Throws:
EBufException
- thrown if an error occurs
-
getScope
public com.portal.permission.ScopeEntryPoint getScope() throws com.portal.permission.CredentialExceptionRetrieves the current scope for this connection through an opcode call to Portal. This ensures that you get the true scope.- Returns:
- The current scope for this connection, or null if branding is not enabled.
- Throws:
com.portal.permission.CredentialException
-
logCache
public void logCache()A debug function that dumps the cache to the log file.
-