public class CachingBOLoader extends BOLoaderWrapper implements BOLoaderWithCacheI, SaveBOListenerI, DBManEventListenerI, java.io.Closeable
BOQueryLoaderI.InternalHelper| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
bpQuery
The query used to load the procs when merging changes
|
rootPaneToLockOnConnectionInterrupt| Constructor and Description |
|---|
CachingBOLoader(BOLoaderI _realBOLoader) |
CachingBOLoader(BOLoaderI _realBOLoader,
CachingBOLoaderGCStrategyI _gcStrategy,
CachingBOLoaderUpdateStrategyI _updateStrategy) |
CachingBOLoader(BOLoaderI _realBOLoader,
java.lang.Class[] _keepClasses,
int[] _maxKeeps)
Creates a caching bo loader with a default LRU strategy to limit the number of certain classes inside the cache.
|
CachingBOLoader(BOLoaderI _realBOLoader,
java.lang.Class[] _keepClasses,
int[] _maxKeeps,
int _interval) |
| Modifier and Type | Method and Description |
|---|---|
void |
addBOCacheListener(BOCacheListenerI l)
Registers a BOCacheListenerI on this Object that is notified of any BO changes
|
static BO[] |
assureInstrumentedSchema(BO[] _bos) |
void |
close()
Closes the 'cache', dropping all cached values, stopping any update and gc collection threads.
|
BO |
coerceBOLoader(BO bo) |
void |
drain()
If this BOLoader has a cache, we request it to empty it.
|
static CachingBOLoader |
find(BOLoaderI bol)
Finds and returns the nearest CachingBOLoader instance in the hierarchy
of a given
BOLoaderI. |
BO |
frapBO(BO bo)
Coerces the BO Loader of the provided BO to this BOLoaderI on cache miss or returns the cached instance
|
void |
frapEntries(java.util.Map mapForReplacingFrappedValues,
java.util.Iterator entriesIterator,
boolean cloneOnFrap,
java.util.Map<java.lang.Long,BO> tempCache)
Calls the 'frapBO' method on all map entries in the given iterator and potentially updates the values in the map the iterator is based on.
|
BO |
frapFromCache(BO bo)
Either returns the cached version for this BO or creates a deepcloned copy with this as BOLoader
|
void |
gc(java.util.Iterator rootsIt)
Remove any BOs inside the cache that aren't reachable from any BO returned by the Iterator
|
void |
gc(java.util.Map root)
Remove any BOs inside the cache that aren't reachable from the provided root-BOs.
|
BO |
getBO(java.lang.Long id)
wrapper for getBO(id, null).
|
BO |
getBO(java.lang.Long id,
java.lang.Class<? extends BOI> classtip)
Returns the BO with the given id.
|
BO[] |
getBOs(java.lang.Long[] ids)
wrapper for getBOs(ids, null)
|
BO[] |
getBOs(java.lang.Long[] ids,
java.lang.Class<? extends BOI> classtip)
returns the BOs with the given ids.
|
BOT |
getBOT(java.lang.Class<? extends BOI> clazz) |
int |
getDrainCount() |
static CachingBOLoader |
getInstrumentedInstance(BOLoaderI _bol)
Creates a CachingBOLoader instance with an instrumented schema which allows to dynamically add new virtual attributes.
|
java.util.Collection<BO> |
getKnown(java.lang.Class<? extends BOI> clazz) |
BO |
getKnown(java.lang.Long id) |
java.lang.String |
getMiniDesc(BO bo) |
SchemaI |
getSchema()
gets a reference to the schema which is used by this BOLoader.
|
boolean |
isCaching()
If true, then this BOLoaderI uses an internal cache, holding all BOs hat were loaded or frapped into it.
|
boolean |
isKnown(java.lang.Long id)
returns true, if the passed Class is one of the keepClasses or a subclass of them
|
void |
processDBManEvent(DBManEvent e)
Invoked when a subscribed DBManEvent occurs.
|
void |
removeBOCacheListener(BOCacheListenerI l)
Removes a previously registered BOCacheListenerI again
|
void |
replayProc(BOProc p,
java.util.Map<java.lang.Long,BO> affected)
Replays the provided BOProc on the cached object and adds the updated BO to the affected Map
|
void |
rescheduleGC(int interval)
Starts or stops a daemon, that clears the cache every interval seconds, but keeps a maximum number
of instances of objects of types keepClasses specified in maxKeeps.
|
void |
setGCStrategy(CachingBOLoaderGCStrategyI _gcStrategy)
Stops a possibly running AutoGC on the old gcStrategy and replaces it with this instance.
|
void |
setRealBOLoader(BOLoaderI _realBOLoader)
Sets the BOLoader to handle any cache misses with.
|
void |
setUpdateStrategy(CachingBOLoaderUpdateStrategyI _updateStrategy) |
void |
stopAutoGC()
Stops the daemon thread that automatically runs, if any.
|
void |
subscribeForUpdatesViaEvents()
Register for BOChangeEvents so we can call replayProc for the relevant BPs which affect the keepClasses or their subclasses.
|
void |
transactionSaveSuccess(Transaction stubTx,
java.util.Map<java.lang.Long,java.lang.Long> tempIdToDbIdMap,
java.util.function.Predicate<Transaction> isSavedTransactionInstancePredicate)
Notifies this listener that a transaction has been successfully saved.
|
void |
unsubscribeForUpdatesViaEvents()
Unsubscribes from any update registration, effectively letting objects in the cache go stale.
|
void |
updateCache(BP bp,
java.util.Map<java.lang.Long,BO> affected,
CachingBOLoaderUpdateStrategyI myUpdateStrategy)
Checks the given BP against the current cache state and merges it if it appears to be needed in the cache.
|
void |
updateCache(DBManBOChangeEvent boce)
Does the actual merge and replay of a BO Change event.
|
void |
updateStrategies(CachingBOLoaderGCStrategyI _gcStrategy,
CachingBOLoaderUpdateStrategyI _updateStrategy)
Replaces the current update and gc strategy with the provided ones.
|
coerceBOLoader, coerceBOLoader, coerceBOLoader, coerceBOLoader, execute, exists, exists, getBLOB, getBLOB, getBLOB, getBLOB, getBLOB, getBLOB, getBLOB, getBLOB, getBLOBInfo, getBLOBInfo, getBOs, getBOs, getBOUncached, getBOUncached, getCryptoHandler, getEventProvider, getFeatureManager, getFileVault, getNextId, getParentLoader, getRelationBOs, getRootLoader, getRootPaneToLockOnConnectionInterrupt, hasBLOB, hasBLOB, haveBLOB, isLoggedIn, isLoggedInNN, isRecording, prepareQuery, prepareQuery, query, query, query, queryBO, queryBO, queryBO, queryRelation, setRootPaneToLockOnConnectionInterrupt, testAuth, testAuthequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitisKnownexecute, exists, exists, frapBOArrayFromCache, frapBOIArrayFromCache, frapBOsFromCache, frapFromCache, getBOs, getBOs, getBOUncached, getBOUncached, getCryptoHandler, getEventProvider, getFeatureManager, getFileVault, getNextId, getParentLoader, getRelationBOs, getRootLoader, isAncestorOf, isLoggedIn, isLoggedInNN, isRecording, isRootLoader, isServerSide, isTesting, prepareQuery, prepareQuery, prepareQuery, query, query, query, queryBO, queryBO, queryBO, queryRelation, testAuth, testAuthgetBLOB, getBLOB, getBLOB, getBLOB, getBLOB, getBLOB, getBLOB, getBLOB, getBLOBInfo, getBLOBInfo, hasBLOB, hasBLOB, haveBLOB, haveBLOB, haveBLOBgetBOByAttr, getBOByAttr, getBOByAttr, getBOByAttrs, getBOByAttrs, getBOByAttrs, getBOsByAttrs, getBOsByAttrs, getBOsByAttrs, getBOsByAttrs, getOneBOByAttr, getUniqueBOByAttrpublic static final java.lang.String bpQuery
public CachingBOLoader(BOLoaderI _realBOLoader)
public CachingBOLoader(BOLoaderI _realBOLoader, CachingBOLoaderGCStrategyI _gcStrategy, CachingBOLoaderUpdateStrategyI _updateStrategy)
public CachingBOLoader(BOLoaderI _realBOLoader, java.lang.Class[] _keepClasses, int[] _maxKeeps)
CachingBOLoaderLRUStrategypublic CachingBOLoader(BOLoaderI _realBOLoader, java.lang.Class[] _keepClasses, int[] _maxKeeps, int _interval)
public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablepublic static CachingBOLoader find(BOLoaderI bol)
BOLoaderI.
This static method recursively traverses the parent loaders of the provided
bol until it finds an instance that is a CachingBOLoader.
This is useful for obtaining a caching context from any point in a loader chain.
bol - The BOLoaderI to start the search from. Can be null.null if the input bol is null or no CachingBOLoader
is found in the chain.public static CachingBOLoader getInstrumentedInstance(BOLoaderI _bol)
public void updateStrategies(CachingBOLoaderGCStrategyI _gcStrategy, CachingBOLoaderUpdateStrategyI _updateStrategy)
public void setGCStrategy(CachingBOLoaderGCStrategyI _gcStrategy)
public void setUpdateStrategy(CachingBOLoaderUpdateStrategyI _updateStrategy)
public BOT getBOT(java.lang.Class<? extends BOI> clazz)
getBOT in interface BOLoaderIgetBOT in class BOLoaderWrapperpublic BO getBO(java.lang.Long id)
BOLoaderIgetBO in interface BOLoaderIgetBO in class BOLoaderWrapperBOLoaderI.getBO(Long, Class)public BO getBO(java.lang.Long id, java.lang.Class<? extends BOI> classtip)
BOLoaderIgetBO in interface BOLoaderIgetBO in class BOLoaderWrapperid - the id of the BOclasstip - a guess which class the object has. May be null.public BO[] getBOs(java.lang.Long[] ids)
BOLoaderIgetBOs in interface BOLoaderIgetBOs in class BOLoaderWrapperBOLoaderI.getBOs(Long[],Class)public BO[] getBOs(java.lang.Long[] ids, java.lang.Class<? extends BOI> classtip)
BOLoaderIgetBOs in interface BOLoaderIgetBOs in class BOLoaderWrapperids - array of Longs with ids for the requested BOs.classtip - guess for classes which the BOs belong to, may be null.Transactionpublic void rescheduleGC(int interval)
public void stopAutoGC()
public void subscribeForUpdatesViaEvents()
public void unsubscribeForUpdatesViaEvents()
public void processDBManEvent(DBManEvent e)
DBManEventListenerIDBManBOChangeEvent for events triggered after modification on BOs.processDBManEvent in interface DBManEventListenerIpublic void updateCache(DBManBOChangeEvent boce)
public void updateCache(BP bp, java.util.Map<java.lang.Long,BO> affected, CachingBOLoaderUpdateStrategyI myUpdateStrategy)
bp - the BP to merge into the cache, nonnull.affected - a Map containing BOs affected by the updating of the cache, will be updated if a new BO changed, nonnull.myUpdateStrategy - the updateStrategy to check if this type of classes should be kept updated, nonnullpublic SchemaI getSchema()
BOLoaderIgetSchema in interface BOLoaderIgetSchema in interface SchemaProviderIgetSchema in class BOLoaderWrapperpublic void setRealBOLoader(BOLoaderI _realBOLoader)
public BO coerceBOLoader(BO bo)
coerceBOLoader in class BOLoaderWrapperpublic void drain()
BOLoaderI.isCaching() returns false, this is a nop.
Sets the BOLoader of all cached BOs to the real BOLoader, which shouldn't be caching,
and then clears the internal cache from all of them.
As soon as the previously cached BOs are no longer referenced, they get gc'ed.
Also resets the gcStrategy afterwards, because its roots are no longer valid.drain in interface BOLoaderIdrain in interface BOLoaderWithCacheIdrain in class BOLoaderWrapperpublic int getDrainCount()
public boolean isCaching()
BOLoaderIisCaching in interface BOLoaderIisCaching in class BOLoaderWrapperpublic BO frapFromCache(BO bo)
frapFromCache in interface BOLoaderIfrapFromCache in class BOLoaderWrapperpublic BO frapBO(BO bo)
public void frapEntries(java.util.Map mapForReplacingFrappedValues,
java.util.Iterator entriesIterator,
boolean cloneOnFrap,
java.util.Map<java.lang.Long,BO> tempCache)
mapForReplacingFrappedValues - The map for replacing the value with the frapped instance (optional).entriesIterator - An iterator for iterating through the map entries, on which 'frapBO(BO, boolean, Map)' will be called.cloneOnFrap - The 'cloneOnFrap' mode that will be passed to 'frapBO(BO, boolean, Map)'.tempCache - An internal helper map passed to 'frapBO' and used during recursive calls.public java.lang.String getMiniDesc(BO bo)
public boolean isKnown(java.lang.Long id)
isKnown in interface BOLoaderWithCacheIpublic BO getKnown(java.lang.Long id)
getKnown in interface BOLoaderWithCacheIpublic java.util.Collection<BO> getKnown(java.lang.Class<? extends BOI> clazz)
getKnown in interface BOLoaderWithCacheIpublic void gc(java.util.Map root)
public void gc(java.util.Iterator rootsIt)
public void transactionSaveSuccess(Transaction stubTx, java.util.Map<java.lang.Long,java.lang.Long> tempIdToDbIdMap, java.util.function.Predicate<Transaction> isSavedTransactionInstancePredicate)
SaveBOListenerItransactionSaveSuccess in interface SaveBOListenerIstubTx - A shallow copy (stub) of the saved Transaction object. This object contains
all the business data of the transaction but is detached from any active
persistence context. It is intended for read-only use, such as updating
display logic or triggering post-save business processes.tempIdToDbIdMap - A map containing the original temporary IDs of new entities
within the transaction as keys, and their newly assigned persistent
database IDs as values. This is crucial for updating references to
these entities in local data structures. A key-value pair of
(tempId, dbId) indicates that the entity with tempId was saved
and now has dbId.isSavedTransactionInstancePredicate - A predicate to verify if a given
Transaction instance is the same object that was just saved. This is
particularly useful in scenarios where multiple instances of a transaction
might exist in memory. By using this predicate, callers can efficiently
identify the specific instance that needs to be updated or processed,
avoiding redundant operations. The predicate returns true if the provided
transaction is the same instance, and false otherwise.public void replayProc(BOProc p, java.util.Map<java.lang.Long,BO> affected)
public void addBOCacheListener(BOCacheListenerI l)
public void removeBOCacheListener(BOCacheListenerI l)
Copyright © 2000-2025 OAshi S.à r.l. All Rights Reserved.