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
  • Constructor Details

    • PCachedContext

      public PCachedContext() throws EBufException
      Creates a default instance of a PCachedContext.
      Throws:
      EBufException - thrown if an error occurs
    • PCachedContext

      public PCachedContext(PortalContext ctx) throws EBufException
      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

      public PCachedContext(Properties uprops) throws EBufException
      Creates an instance of PCachedContext, given some base properties.
      Parameters:
      uprops - the base Properties object
      Throws:
      EBufException - thrown if an error occurs
    • PCachedContext

      public PCachedContext(PCachedContext ctx) throws EBufException
      Creates an instance of PCachedContext from another PCachedContext. The two contexts share a cache, but have different Portal connections.
      Parameters:
      ctx - another PCachedContext 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

      public void open(FList in) throws EBufException
      Opens a connection context with the server.
      Overrides:
      open in class com.portal.appcenter.BRMClientContext
      Parameters:
      in - an Flist 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

      public FList opcode(int op, int flags, FList in) throws EBufException
      Sends an opcode to the server. If this is an object read, the object is cached.
      Overrides:
      opcode in class com.portal.appcenter.BRMClientContext
      Parameters:
      op - the opcode to perform
      flags - the control flags for opcode
      in - the opcode parameter FList
      Returns:
      The opcode output FList.
      Throws:
      EBufException - thrown if an error occurs
      See Also:
    • opcode

      public FList opcode(int op, int flags, PModelHandle in) throws EBufException
      Calls an opcode.
      Parameters:
      flags - the opcode flags
      in - the input FList model
      opcode - the opcode to call
      Returns:
      The output FList model.
      Throws:
      EBufException - thrown for Portal errors
    • opcode

      public FList opcode(int op, int flags, FList 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 perform
      flags - the control flags for opcode
      in - the opcode parameter FList
      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 perform
      flags - the control flags for opcode
      in - the opcode parameter PModelHandle
      setCacheToStale - parameter to indicate whether to stale the cache or not.
      Returns:
      The output FList model
      Throws:
      EBufException - EBufException thrown for Portal errors
    • search

      public FList search(int op, FList in, boolean cacheResults) throws EBufException
      Calls the search opcode and depending on cacheResults flag, it caches the results.
      Parameters:
      op - opcode
      in - input flist
      cacheResults - indicates whether to cache the search results or not
      Returns:
      output flist of search
      Throws:
      EBufException
    • search

      public PModelHandle[] search(int op, FList in) throws EBufException
      Calls the search opcode, but returns an array of model handles.
      Parameters:
      in - the opcode input FList
      opcode - an Portal search opcode (SEARCH, STEP_SEARCH, STEP_NEXT)
      Returns:
      An array of model handles.
      Throws:
      EBufException - thrown if an error occurs
    • search

      public PModelHandle[] search(int op, int flag, FList in) throws EBufException
      Calls the search opcode, but returns an array of model handles.
      Parameters:
      op - Portal search opcode (SEARCH, STEP_SEARCH, STEP_NEXT)
      flag - Flag to search opcode
      in - Input FList
      Returns:
      An array of model handles.
      Throws:
      EBufException - thrown if an error occurs
    • getOrCreateModelFrom

      public PModelHandle getOrCreateModelFrom(FList fl) throws EBufException
      Creates a model for the specified Flist, 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

      public PModelHandle createModelFrom(FList fl, String type) throws EBufException
      Creates a new model handle of a specified type from an Flist, and sets that Flist in the cache.
      Parameters:
      fl - the model to create a handle for
      type - the new model type
      Returns:
      A new model handle.
      Throws:
      EBufException - thrown if an error occurs
    • createModelFrom

      public PModelHandle createModelFrom(FList fl) throws EBufException
      Creates a new model handle from an Flist and sets that Flist 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

      public PModelHandle createModelFrom(SparseArray sa) throws EBufException
      Creates a new model handle from a SparseArray.
      Parameters:
      sa - the model to create a handle for
      Returns:
      A new model handle.
      Throws:
      EBufException - thrown if an error occurs
    • createModelFrom

      public PModelHandle createModelFrom(Poid pd) throws EBufException
      Creates a new model handle from a Poid.
      Parameters:
      pd - the model to create a handle for
      Returns:
      A new model handle.
      Throws:
      EBufException - thrown if an error occurs
    • lookupPoid

      public Poid lookupPoid(PModelHandle modl) throws EBufException
      Get the Poid 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

      public Object lookupModel(PModelHandle handle) throws EBufException
      Gets the cached model that corresponds to the supplied model handle. Returns the model data associated with handle. This method simply calls lookupModel(PModelHandle, boolean, int), passing false for the second, and PModelHandle.LOOKUP_UPDATE_IF_NEEDED for the third parameter.
      Parameters:
      handle - a non-null PModelHandle.
      Returns:
      either the model associated with handle, or null.
      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 with handle. This method calls PModelCache.lookupModel(PModelHandle, boolean, int) to get the model, and then if handle is "collect-only", applies the collected data in the handle to the model.
      Parameters:
      handle - a non-null model handle
      ensureWhole - if true, ensures that the model in the cache is whole
      updateFlag - if PModelHandle.LOOKUP_FORCE_UPDATE, the model is unconditionally updated with data from Portal; if PModelHandle.LOOKUP_DONT_UPDATE it is not. Otherwise, the model is updated if marked stale, or if ensureWhole is true and the model is not whole.
      Returns:
      Either the model associated with handle, or null.
      Throws:
      EBufException - thrown if an error occurs while reading the object from Portal.
    • setModel

      public void setModel(PModelHandle modl, FList fl)
      Sets an Flist model in the cache associated with a handle.
      Parameters:
      modl - the PModelHandle to use as a key
      fl - the model to store
    • setModel

      public void setModel(PModelHandle modl, SparseArray sa)
      Sets a SparseArray model in the cache associated with a handle.
      Parameters:
      modl - the PModelHandle to use as a key
      sa - the model to store
    • setModel

      public void setModel(PModelHandle modl, Poid pd)
      Sets a Poid model in the cache associated with a handle.
      Parameters:
      modl - the PModelHandle to use as a key
      pd - the model to store
    • discardModel

      public void discardModel(PModelHandle mh)
      Removes a model from the cache to free resources.
      Parameters:
      mh - a PModelHandle
    • getModelField

      public Object getModelField(FList data, PFieldSpecification spec) throws EBufException
      Gets a field from an Flist 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 of PCompoundFieldSpec, an object array is returned.
      Parameters:
      data - the model to get a field from
      spec - 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

      public Object getModelField(PModelHandle data, PFieldSpecification spec) throws EBufException
      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 of PCompoundFieldSpec, an object array is returned.
      Parameters:
      data - the model to get a field from
      spec - 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

      public FList getWholeObject(PModelHandle mh) throws EBufException
      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 - a PModelHandle
      Returns:
      An Flist object.
      Throws:
      EBufException - thrown if an error occurs
      RemoteException - thrown if an error occurs
    • getWholeObject

      public FList getWholeObject(PModelHandle mh, boolean force) throws EBufException
      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 - a PModelHandle
      force - a flag to force a PCM_OP_READ_OBJ
      Throws:
      EBufException - thrown if an error occurs
    • getField

      public Object getField(FList list, PDataFieldSpecification spec) throws EBufException
      Gets a field from an Flist model.
      Parameters:
      list - the model to get a field from
      spec - a specification of which field to get
      Returns:
      The field value.
      Throws:
      EBufException - thrown if an error occurs
    • getField

      public Object getField(PModelHandle mh, PDataFieldSpecification spec) throws EBufException
      Gets a field from a model.
      Parameters:
      mh - the model to get a field from
      spec - 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 in
      spec - a specification of which field to set
      val - the new value to set
      Throws:
      EBufException - thrown if an error occurs
    • setField

      public void setField(FList list, PDataFieldSpecification spec, Object val) throws EBufException
      Sets an Flist field in a model to the specified value.
      Parameters:
      list - the model to set a field in
      spec - a specification of which field to set
      val - the new value to set
      Throws:
      EBufException - thrown if an error occurs
    • getScope

      public com.portal.permission.ScopeEntryPoint getScope() throws com.portal.permission.CredentialException
      Retrieves 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.