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 ofPCachedContextfrom 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 anFlistand sets thatFlistin the cache.createModelFrom(FList fl, String type) Creates a new model handle of a specified type from anFlist, and sets thatFlistin the cache.createModelFrom(Poid pd) Creates a new model handle from aPoid.Creates a new model handle from aSparseArray.voidRemoves a model from the cache to free resources.com.portal.permission.ScopeEntryPointReturns 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 anFlistmodel.getModelField(PModelHandle data, PFieldSpecification spec) Gets a field from a model.getModelField(FList data, PFieldSpecification spec) Gets a field from anFlistmodel.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.ScopeEntryPointgetScope()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.voidlogCache()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 thePoidfrom 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.voidOpens a connection context with the server.Calls thesearchopcode, but returns an array of model handles.Calls thesearchopcode, but returns an array of model handles.Calls the search opcode and depending on cacheResults flag, it caches the results.voidsetField(PModelHandle modl, PDataFieldSpecification spec, Object val) Sets a field in a model to the specified value.voidsetField(FList list, PDataFieldSpecification spec, Object val) Sets anFlistfield in a model to the specified value.voidsetModel(PModelHandle modl, FList fl) Sets anFlistmodel in the cache associated with a handle.voidsetModel(PModelHandle modl, Poid pd) Sets aPoidmodel in the cache associated with a handle.voidsetModel(PModelHandle modl, SparseArray sa) Sets aSparseArraymodel in the cache associated with a handle.voidsetScope(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, reconnectMethods 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 basePropertiesobject- Throws:
EBufException- thrown if an error occurs
-
PCachedContext
Creates an instance ofPCachedContextfrom anotherPCachedContext. The two contexts share a cache, but have different Portal connections.- Parameters:
ctx- anotherPCachedContextto 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:
openin classcom.portal.appcenter.BRMClientContext- Parameters:
in- anFlistthat 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:
opcodein 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 inputFListmodelopcode- the opcode to call- Returns:
- The output
FListmodel. - 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 parameterFListsetCacheToStale- parameter to indicate whether to stale the cache or not.- Returns:
- The output
FListmodel - 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 parameterPModelHandlesetCacheToStale- parameter to indicate whether to stale the cache or not.- Returns:
- The output
FListmodel - 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 thesearchopcode, but returns an array of model handles.- Parameters:
in- the opcode inputFListopcode- an Portal search opcode (SEARCH, STEP_SEARCH, STEP_NEXT)- Returns:
- An array of model handles.
- Throws:
EBufException- thrown if an error occurs
-
search
Calls thesearchopcode, 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 thatFlistin 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 anFlistand sets thatFlistin 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 thePoidfrom 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), passingfalsefor the second, andPModelHandle.LOOKUP_UPDATE_IF_NEEDEDfor the third parameter.- Parameters:
handle- a non-nullPModelHandle.- 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 ifhandleis "collect-only", applies the collected data in the handle to the model.- Parameters:
handle- a non-nullmodel 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_UPDATEit is not. Otherwise, the model is updated if marked stale, or ifensureWholeistrueand 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 anFlistmodel in the cache associated with a handle.- Parameters:
modl- thePModelHandleto use as a keyfl- the model to store
-
setModel
Sets aSparseArraymodel in the cache associated with a handle.- Parameters:
modl- thePModelHandleto use as a keysa- the model to store
-
setModel
Sets aPoidmodel in the cache associated with a handle.- Parameters:
modl- thePModelHandleto 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 anFlistmodel. 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
Flistobject. - 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- aPModelHandleforce- a flag to force aPCM_OP_READ_OBJ- Throws:
EBufException- thrown if an error occurs
-
getField
Gets a field from anFlistmodel.- 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 anFlistfield 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.
-