LEONARDI Application Composer - 8.9.0.40 by W4 S.A.

leon.data
Class LyCache

java.lang.Object
  extended by leon.data.LyCache
Direct Known Subclasses:
LyObjectCache, LySimpleCache

public abstract class LyCache
extends java.lang.Object

This class s an abstract class that implements the generic behavior of a memory cache for instances of objects managed by a LyDataSource. Basically, it only keeps in memory used objects (using strong references).

This class is both used for storing logical or physical objects.

The cache has an associated class that gives information about stored objects. This associated class implements LyClass interface (for logical objects, this is an instance of LyClassInfo).

Caches keeps several tables :

See Also:
LyDataSource, LyClass, LyClassInfo, LyInfoCache, LyObjectId

Nested Class Summary
static class LyCache.Result
          Result types.
 
Field Summary
static java.lang.String __VERSION
          File version.
static int NB_UNKNOWN_OBJECTS
          Number of unknown objects references kept.
 
Constructor Summary
LyCache(LyClass cacheClass, LyInfoCache policy)
          Constructor of a cache of objects related to a given class description.
 
Method Summary
abstract  void allowLoaded(boolean allowLoaded)
          Setter for the allow loaded attribute.
 void clearUnknownIdsCache()
          Clear the cache from all its unknown ids.
 boolean contains(LyObjectId objectId)
          Check if an object is in the cache.
 boolean contains(java.lang.Object object)
          Check if an object is in the cache.
 LyClass getCacheClass()
          Retrieves the class associated to this cache.
 int getCount(LyFilter filter)
          Return the number of objects within this cache that match the given filter If needed, depending on the cache policy, objects that are not in the cache when the method is called may be loaded in it.
 LyEnvironment getEnvironment()
          Gets environment of the cache.
 java.lang.Object getObject(LyObjectId id)
          Gets an object in this cache by its identifier.
abstract  LyObject getObjectFromPeer(java.lang.Object peer)
          Gets an object from its physical representation (peer).
 LyObjectList getObjectList(boolean sorted)
          Get list of objects found in this cache.
 java.util.Vector<java.lang.Object> getObjects()
          Get list of objects found in this cache.
 LyCache.Result getObjects(LyFilter filter, LySimpleObjectList list)
          Adds objects to the given object list that match the specified filter.
 LyInfoCache getPolicy()
          Gets cache policy of this cache.
abstract  int getSize(LyFilter filter)
          Return the number of objects within this cache that match the given filter (all objects of the cache if filter is null).
abstract  boolean isEmpty()
          Tests if this cache is empty or not (contains no object).
 boolean isLoaded()
          Tests whether this cache is completely loaded or not.
 boolean rehash(java.lang.Object object, LyObjectId oldObjectId)
          This method recomputes the association between an object and its objectId.
 void setLoaded(boolean loaded)
          Marks this cache as loaded or not.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

__VERSION

public static final java.lang.String __VERSION
File version.

See Also:
Constant Field Values

NB_UNKNOWN_OBJECTS

public static int NB_UNKNOWN_OBJECTS
Number of unknown objects references kept.

Constructor Detail

LyCache

public LyCache(LyClass cacheClass,
               LyInfoCache policy)
Constructor of a cache of objects related to a given class description.

Parameters:
cacheClass - Class description of objects stored in the cache.
policy - Description of th epolicy of thsi cache.
Method Detail

getObjectFromPeer

public abstract LyObject getObjectFromPeer(java.lang.Object peer)
Gets an object from its physical representation (peer). This method is only valid if stored objects are logical objects (instances of LyObject).

Parameters:
peer - Physical representation of the searched object.
Returns:
Object with the specified physical representation if it exists, otherwise null.
Throws:
java.lang.IllegalStateException - If this cache is not a cache that keep logical objects.

getSize

public abstract int getSize(LyFilter filter)
Return the number of objects within this cache that match the given filter (all objects of the cache if filter is null). This method gives objects that are in the cache, no other objects are loaded.

Parameters:
filter - Filter used for selecting objects. If filter is null, the total is returned.
Returns:
Number of objects in the cache that match the filter.

isEmpty

public abstract boolean isEmpty()
Tests if this cache is empty or not (contains no object).

Returns:
True if the cache is empty, false otherwise.

allowLoaded

public abstract void allowLoaded(boolean allowLoaded)
Setter for the allow loaded attribute.

Parameters:
allowLoaded - the value of the allowLoaded attribute

getPolicy

public LyInfoCache getPolicy()
Gets cache policy of this cache.

Returns:
the policy of this cache.

getObject

public java.lang.Object getObject(LyObjectId id)
                           throws LyNoSuchObjectException
Gets an object in this cache by its identifier.

Parameters:
id - Object identifier.
Returns:
Object found in cache with the given identifier, or null if no object is found and if the id was registered in unknown ids list.
Throws:
LyNoSuchObjectException - If no object of this cache has this identifier and if the given id has not been registered in unknown ids list.

contains

public boolean contains(java.lang.Object object)
Check if an object is in the cache.

Parameters:
object - Object to check.
Returns:
True if the object is found, false otherwise.

contains

public boolean contains(LyObjectId objectId)
Check if an object is in the cache.

Parameters:
objectId - Object to check.
Returns:
True if the object is found, false otherwise.

getCount

public int getCount(LyFilter filter)
Return the number of objects within this cache that match the given filter If needed, depending on the cache policy, objects that are not in the cache when the method is called may be loaded in it.

Parameters:
filter - Filter used for selecting objects. If filter is null, the total is returned.
Returns:
Number of objects in the cache that match the filter after this call.

getObjects

public LyCache.Result getObjects(LyFilter filter,
                                 LySimpleObjectList list)
Adds objects to the given object list that match the specified filter.

Parameters:
filter - Filter to select objects.
list - List where results are added.
Returns:
One of the result type Result.TOTAL : the list contains all the results, Result.NULL : the lists contains no result, Result.PARTIAL : the list contains partial results.

Result.TOTAL can only be returned when the cache is loaded.


getCacheClass

public final LyClass getCacheClass()
Retrieves the class associated to this cache. If the cache is used for storing logical objects (LyObject), the returned class is an instance of LyClassInfo.

Returns:
Class associated to this cache.

getObjects

public java.util.Vector<java.lang.Object> getObjects()
Get list of objects found in this cache.

Returns:
Vector of all objects of this cache. An empty Vector if the cache is empty (never returns null).

getObjectList

public LyObjectList getObjectList(boolean sorted)
Get list of objects found in this cache.

Parameters:
sorted - True if the requiered list must be sorted.
Returns:
An objects list of all objects of this cache. An empty list if the cache is empty (never returns null).

isLoaded

public boolean isLoaded()
Tests whether this cache is completely loaded or not.

Returns:
True if the cache is loaded, false otherwise.

setLoaded

public void setLoaded(boolean loaded)
Marks this cache as loaded or not. This is for internal use only : changing the loaded status of the cache on wrong purpose may generate an inconsistent cache

Parameters:
loaded - True to mark the cache loaded, false otherwise.

getEnvironment

public LyEnvironment getEnvironment()
Gets environment of the cache.

Returns:
the enviroment of this cache

rehash

public boolean rehash(java.lang.Object object,
                      LyObjectId oldObjectId)
This method recomputes the association between an object and its objectId.

Parameters:
object - The object
oldObjectId - The old value of the objectId of the specified object
Returns:
true if rehash was performed

clearUnknownIdsCache

public void clearUnknownIdsCache()
Clear the cache from all its unknown ids. Calling this method can affect performance of the application (in a wrong way).


(c) January 2013 - W4 S.A.

Website: W4 S.A., contact us: support@w4global.com