wt.folder
Class DefaultFolderCache

java.lang.Object
  extended bywt.folder.DefaultFolderCache
All Implemented Interfaces:
FolderCache

final class DefaultFolderCache
extends Object
implements FolderCache

Default implementation of FolderCache

Supported API: false

Extendable: false


Nested Class Summary
(package private) static class DefaultFolderCache.FolderCacheMessage
           
static class DefaultFolderCache.FolderCacheMessenger
           
(package private) static class DefaultFolderCache.Singleton
           
(package private) static class DefaultFolderCache.WindchillPDMCabinets
          Preserve the behavior of the old folder cache, for Windchill PDM.
(package private) static class DefaultFolderCache.WindchillPDMMessage
          Contains the oids of Windchill PDM cabinets to add to the cache, and those that have been removed
static class DefaultFolderCache.WindchillPDMMessenger
          Sends messages about Windchill PDM cabinets
 
Nested classes inherited from class wt.folder.FolderCache
FolderCache.NamesToFoldersKey
 
Field Summary
private static String CLASSNAME
           
private static int CONTAINERS_TO_CABINETS_SIZE
           
(package private)  DirtyMap containersToCabinets
           
private static Object CONTEXT_KEY
           
private static boolean DEBUG
           
private static RefreshSpec INFLATE_READ_ONLY
           
private static DebugWriter LOG
           
private static int MAX_SUBFOLDERS
           
(package private)  DefaultFolderCache.FolderCacheMessenger messenger
           
private static int NAMES_TO_CABINETS_SIZE
           
private static int NAMES_TO_SUBFOLDERS_SIZE
           
(package private)  DirtyMap namesToCabinets
           
(package private)  DirtyMap namesToSubFolders
           
private static String OWNER_ID
           
private static int PARENTS_TO_SUBFOLDERS_SIZE
           
(package private)  DirtyMap parentsToSubFolders
           
private static String RESOURCE
           
private static int SUBFOLDERS_TO_PARENTS_SIZE
           
(package private)  DirtyMap subFoldersToParents
           
private static int USERS_TO_CABINETS_SIZE
           
(package private)  DirtyMap usersToCabinets
           
private static int WINDCHILL_PDM_ALL_CABINETS
           
private static int WINDCHILL_PDM_CABINETS_TO_CACHE
           
private static int WINDCHILL_PDM_NO_CABINETS
           
private static int WINDCHILL_PDM_SHARED_CABINETS
           
(package private)  DefaultFolderCache.WindchillPDMCabinets windchillPDMCabinets
           
 
Constructor Summary
private DefaultFolderCache()
          Wire together the messenger with th4 various local caches, and register event listeners
 
Method Summary
private static void addCabinetToResultBuffer(FolderCache.NamesToFoldersKey key, Map to_query, List result_buffer, Cabinet cabinet, boolean read_only)
          Utility method that adds the Cabinet with the given key to result_buffer, removing it from to_query
(package private)  void addToReferenceCache(WTCollection c)
          Update the reference cache with the given collection of Persistables
private  void cleanupSubFolderLinks(WTKeyedMap objects_to_links)
          React to a local REMOVE event
(package private)  void clear()
          Clear all contents from the cache
(package private) static Folder clone(Folder f)
          Clone the persistent state of the given folder
 WTList getCabinetsByName(WTList ordered_containers, List ordered_cabinet_names, boolean read_only)
          Get the cabinets in the given parent containers with the given names.
(package private)  List getCabinetsByName(WTList ordered_containers, List ordered_cabinet_names, boolean read_only, boolean throw_fnfe)
          Utility version of getCabinetsByName that can either throw FolderNotFoundExceptions or leave those slots null
 WTValuedMap getChildToParentMap(WTCollection children, boolean read_only)
          Get the parents of the given child folders
 WTKeyedMap getContainerToCabinetMap(WTCollection containers, boolean shared_only, boolean read_only)
          Get all of the cabinets that are in the given containers
private  long[] getIdsFromOids(Collection oids)
          Get an array of long ids from the given Collection of ObjectIdentifiers
(package private) static DefaultFolderCache getInstance()
           
private  ObjectIdentifier getOid(Object[] row)
          Create an ObjectIdentifier from the raw query data
 WTKeyedMap getParentToSubFoldersMap(WTCollection parents, boolean read_only)
          Get all the subfolders of the given parent folders
private  Cabinet getSpecialCabinet(ObjectIdentifier container_oid, String cabinet_name)
          Utility method that determines if the cabinet with the given name is either the system or default cabinet for the given container.
 WTList getSubFoldersByName(WTList ordered_parents, List ordered_child_names, boolean read_only)
          Get the children of the given parents with the given names.
 WTValuedMap getUserToCabinetMap(WTCollection users, boolean read_only)
          Get the personal cabinets for the given
(package private)  void inflateFromReferenceCache(WTCollection c, boolean read_only)
          Inflate the given collection
private  void postChangeFolder(WTKeyedMap sources_to_targets, WTKeyedMap destinations_to_targets)
          React to a local POST_CHANGE_FOLDER event
private  void postChangeIdentities(WTKeyedMap identifieds_to_old_identities)
          React to a local POST_CHANGE_IDENTITY event
private  void postChangeOwnership(WTCollection objects, Ownership new_ownership)
          React to a local POST_CHANGE_OWNERSHIP event
private  void postStoreCabinets(WTCollection cabinets)
          React to a local POST_STORE event
private  void postStoreSubFolderLinks(WTCollection subfolder_links)
          React to a local POST_STORE event
private  void removeCabinets(WTCollection cabinets)
          React to a local REMOVE event
(package private)  void sendMessage(DefaultFolderCache.FolderCacheMessage message)
          Notify remote caches of the given message
private  boolean tooManyFolders(int num_folders)
          Decides whether or not to cache inflated SubFolders based on whether their number is fewer than half of MAX_SUBFOLDERS.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

CLASSNAME

private static final String CLASSNAME

DEBUG

private static final boolean DEBUG

LOG

private static final DebugWriter LOG

CONTEXT_KEY

private static final Object CONTEXT_KEY

OWNER_ID

private static final String OWNER_ID
See Also:
Constant Field Values

MAX_SUBFOLDERS

private static final int MAX_SUBFOLDERS

CONTAINERS_TO_CABINETS_SIZE

private static final int CONTAINERS_TO_CABINETS_SIZE

NAMES_TO_CABINETS_SIZE

private static final int NAMES_TO_CABINETS_SIZE

NAMES_TO_SUBFOLDERS_SIZE

private static final int NAMES_TO_SUBFOLDERS_SIZE

PARENTS_TO_SUBFOLDERS_SIZE

private static final int PARENTS_TO_SUBFOLDERS_SIZE

SUBFOLDERS_TO_PARENTS_SIZE

private static final int SUBFOLDERS_TO_PARENTS_SIZE

USERS_TO_CABINETS_SIZE

private static final int USERS_TO_CABINETS_SIZE

INFLATE_READ_ONLY

private static final RefreshSpec INFLATE_READ_ONLY

WINDCHILL_PDM_CABINETS_TO_CACHE

private static final int WINDCHILL_PDM_CABINETS_TO_CACHE

WINDCHILL_PDM_ALL_CABINETS

private static final int WINDCHILL_PDM_ALL_CABINETS
See Also:
Constant Field Values

WINDCHILL_PDM_SHARED_CABINETS

private static final int WINDCHILL_PDM_SHARED_CABINETS
See Also:
Constant Field Values

WINDCHILL_PDM_NO_CABINETS

private static final int WINDCHILL_PDM_NO_CABINETS
See Also:
Constant Field Values

messenger

final DefaultFolderCache.FolderCacheMessenger messenger

containersToCabinets

final DirtyMap containersToCabinets

namesToCabinets

final DirtyMap namesToCabinets

namesToSubFolders

final DirtyMap namesToSubFolders

parentsToSubFolders

final DirtyMap parentsToSubFolders

subFoldersToParents

final DirtyMap subFoldersToParents

usersToCabinets

final DirtyMap usersToCabinets

windchillPDMCabinets

final DefaultFolderCache.WindchillPDMCabinets windchillPDMCabinets
Constructor Detail

DefaultFolderCache

private DefaultFolderCache()
                    throws WTException
Wire together the messenger with th4 various local caches, and register event listeners

Method Detail

getInstance

static DefaultFolderCache getInstance()

sendMessage

void sendMessage(DefaultFolderCache.FolderCacheMessage message)
           throws WTException
Notify remote caches of the given message

Parameters:
message -
Throws:
WTException

clear

void clear()
Clear all contents from the cache


addToReferenceCache

void addToReferenceCache(WTCollection c)
                   throws WTException
Update the reference cache with the given collection of Persistables

Throws:
WTException

inflateFromReferenceCache

void inflateFromReferenceCache(WTCollection c,
                               boolean read_only)
                         throws WTException
Inflate the given collection

Parameters:
c -
read_only -
Throws:
WTException

getChildToParentMap

public WTValuedMap getChildToParentMap(WTCollection children,
                                       boolean read_only)
                                throws WTException
Get the parents of the given child folders

Specified by:
getChildToParentMap in interface FolderCache
Parameters:
children - A collection of child folders. The implementation will not inflate the children
read_only - Whether or not to return the cached instances of the parent folders
Returns:
The mapping of child folders to parent folders
Throws:
WTException

getSubFoldersByName

public WTList getSubFoldersByName(WTList ordered_parents,
                                  List ordered_child_names,
                                  boolean read_only)
                           throws WTException
Get the children of the given parents with the given names. This API needs to be list-based as neither the parent oids nor the child names need to be unique, and therefore neither can be used as a map key.

Specified by:
getSubFoldersByName in interface FolderCache
Parameters:
ordered_parents - A list of the parent folders to query in. This list may either have the same number of elemnts as ordered_child_names, or it may have 1 element that is used with every name
ordered_child_names - A list of child names to find subfolders for within the corresponding parent folder
read_only - Whether or not to return the cached instances of the subfolders
Returns:
A WTList of the matching subfolders, in the same order as the input parameters.
Throws:
FolderNotFoundException - If any of the subfolders couldn't be found
WTException

getCabinetsByName

public WTList getCabinetsByName(WTList ordered_containers,
                                List ordered_cabinet_names,
                                boolean read_only)
                         throws WTException
Get the cabinets in the given parent containers with the given names. This API needs to be list-based as neither the container oids nor the cabinet names need to be unique, and therefore neither can be used as a map key.

Specified by:
getCabinetsByName in interface FolderCache
Parameters:
ordered_containers - A list of the containers to query in. This list may either have as many elements as ordered_cabinet_names or 1 element that is used with each name.
ordered_cabinet_names - A list of cabinet names to find cabinets for within the corresponding container
read_only - Whether or not to return the cached instances of the cabinets
Returns:
A WTList of the matching cabinets, in the same order as the input parameters.
Throws:
FolderNotFoundException - If any of the cabinets couldn't be found
WTException

getCabinetsByName

List getCabinetsByName(WTList ordered_containers,
                       List ordered_cabinet_names,
                       boolean read_only,
                       boolean throw_fnfe)
                 throws WTException
Utility version of getCabinetsByName that can either throw FolderNotFoundExceptions or leave those slots null

Parameters:
ordered_containers -
ordered_cabinet_names -
read_only -
Returns:
A List of Cabinets. May contain null values if throw_fnfe is false and there are cabinets that can't be found
Throws:
WTException

addCabinetToResultBuffer

private static void addCabinetToResultBuffer(FolderCache.NamesToFoldersKey key,
                                             Map to_query,
                                             List result_buffer,
                                             Cabinet cabinet,
                                             boolean read_only)
                                      throws WTException
Utility method that adds the Cabinet with the given key to result_buffer, removing it from to_query

Parameters:
key - The key for the cabinet
to_query - Mapping of NamesToFoldersKey objects to either a single Integer result index or a List of result indices
result_buffer - The list to add the cabinet to
cabinet - The cabinet
read_only - Whether or not to clone the cabinet into result_buffer
Throws:
WTException

getSpecialCabinet

private Cabinet getSpecialCabinet(ObjectIdentifier container_oid,
                                  String cabinet_name)
                           throws WTException
Utility method that determines if the cabinet with the given name is either the system or default cabinet for the given container. If it is, then the cabinet is returend.

Parameters:
cabinet_name -
Returns:
The special cabinet, or null if the name didn't match.
Throws:
WTException

getUserToCabinetMap

public WTValuedMap getUserToCabinetMap(WTCollection users,
                                       boolean read_only)
                                throws WTException
Get the personal cabinets for the given

Specified by:
getUserToCabinetMap in interface FolderCache
Parameters:
users - The users to find personal cabinets for
read_only - Whether or not to return the cached instances of the cabinets
Returns:
A mapping of users to personal cabinets
Throws:
FolderNotFoundException - If the personal cabinet can't be found for any of the users
WTException

getContainerToCabinetMap

public WTKeyedMap getContainerToCabinetMap(WTCollection containers,
                                           boolean shared_only,
                                           boolean read_only)
                                    throws WTException
Get all of the cabinets that are in the given containers

Specified by:
getContainerToCabinetMap in interface FolderCache
Parameters:
containers - The containers to search in
shared_only - Whether or not to only return shared cabinets
read_only - Whether or not to return the cached instances of the cabinets
Returns:
A mapping of the input containers to WTSets of all their cabinets
Throws:
WTException

getParentToSubFoldersMap

public WTKeyedMap getParentToSubFoldersMap(WTCollection parents,
                                           boolean read_only)
                                    throws WTException
Get all the subfolders of the given parent folders

Specified by:
getParentToSubFoldersMap in interface FolderCache
Parameters:
parents - The parent folders to find children for
read_only - Whether or not to return the cached instances of the subfolders
Returns:
A mapping of parent folders to WTSets of their child folders
Throws:
WTException

getIdsFromOids

private long[] getIdsFromOids(Collection oids)
Get an array of long ids from the given Collection of ObjectIdentifiers

Parameters:
oids - A Collection of ObjectIdentifiers
Returns:
An array of the ids from the corresponding object identifiers

getOid

private ObjectIdentifier getOid(Object[] row)
Create an ObjectIdentifier from the raw query data

Parameters:
row - The first element is class name, the second a Number
Returns:
ObjectIdentiifer

tooManyFolders

private boolean tooManyFolders(int num_folders)
Decides whether or not to cache inflated SubFolders based on whether their number is fewer than half of MAX_SUBFOLDERS. This will prevent the reference cache from overflowing because it was filled up by a single large set of SubFolders.

Parameters:
num_folders - the number of SubFolders to be cached
Returns:
true if num_folders is less than half of MAX_SUBFOLDERS

postStoreCabinets

private void postStoreCabinets(WTCollection cabinets)
                        throws WTException
React to a local POST_STORE event

Parameters:
cabinets - Newly stored cabinets
Throws:
WTException

postStoreSubFolderLinks

private void postStoreSubFolderLinks(WTCollection subfolder_links)
                              throws WTException
React to a local POST_STORE event

Parameters:
subfolder_links - Newly stored SubFolderLinks
Throws:
WTException

removeCabinets

private void removeCabinets(WTCollection cabinets)
                     throws WTException
React to a local REMOVE event

Parameters:
cabinets - Newly removed cabinets
Throws:
WTException

cleanupSubFolderLinks

private void cleanupSubFolderLinks(WTKeyedMap objects_to_links)
                            throws WTException
React to a local REMOVE event

Throws:
WTException

postChangeIdentities

private void postChangeIdentities(WTKeyedMap identifieds_to_old_identities)
                           throws WTException
React to a local POST_CHANGE_IDENTITY event

Parameters:
identifieds_to_old_identities - Mapping of identitieds to their old IdentificationObjects
Throws:
WTException

postChangeFolder

private void postChangeFolder(WTKeyedMap sources_to_targets,
                              WTKeyedMap destinations_to_targets)
                       throws WTException
React to a local POST_CHANGE_FOLDER event

Parameters:
sources_to_targets -
destinations_to_targets -
Throws:
WTException

postChangeOwnership

private void postChangeOwnership(WTCollection objects,
                                 Ownership new_ownership)
                          throws WTException
React to a local POST_CHANGE_OWNERSHIP event

Parameters:
objects -
new_ownership -
Throws:
WTException

clone

static Folder clone(Folder f)
Clone the persistent state of the given folder

Parameters:
f -
Returns:
A clone of the folder