public class DAOCache<K,T extends net.java.ao.RawEntity<K>> extends Object
Modifier and Type | Class and Description |
---|---|
static class |
DAOCache.DBDAOCache<K,T extends net.java.ao.RawEntity<K>>
This cache looks up in the database, but also keeps all data that was ever retrieved, in cache
|
static class |
DAOCache.InMemoryDAOCache<K,T extends net.java.ao.RawEntity<K>>
This cache looks up data in its internal list.
|
static class |
DAOCache.InMemoryDAOCacheWithTrackKeeping<K,T extends net.java.ao.RawEntity<K>>
This cache looks up data in its internal list.
|
Modifier and Type | Field and Description |
---|---|
private AOContext |
aoContext |
private static long |
countUpdates |
private Function<String,Method> |
getterMethodsCache |
private com.google.common.collect.Multimap<List<Object>,T> |
index
An index of the values in localList, by primary key
|
protected List<T> |
localList |
private static org.apache.log4j.Logger |
log |
private static int |
MAX_RECORDS_IN_MEMORY |
private boolean |
popValues |
private RecordTemplateImpl<K,T> |
recordTemplate |
private boolean |
searchInDB |
private boolean |
searchLocally |
private Class<T> |
type |
Modifier | Constructor and Description |
---|---|
private |
DAOCache(AOContext aoContext,
Class<T> type,
boolean searchLocally,
boolean searchInDB,
boolean popValues,
List<T> localList,
RecordTemplateImpl<K,T> recordTemplate)
Builds a cache
|
Modifier and Type | Method and Description |
---|---|
private void |
addEventually(T recordFoundInDB)
Adds a new record to the local cache, whether it was created or found in DB.
|
private StringBuilderForAOWhereClause |
buildWhereClauseForExpectedRecord(RecordTemplate<T> expectedRecord) |
T |
create(RecordTemplate<T> recordTemplate) |
private boolean |
createIndex() |
T |
createOrUpdate(RecordTemplate<T> recordTemplate) |
RecordTemplate<T> |
newTemplate()
Create a template of the AO record,
so we can use it to lookup values / create a record
NOT thread-safe, and only one template can be used at a time in a thread.
|
List<T> |
searchAll(RecordTemplate<T> expectedRecord)
Finds the first, if any, record in the list and/or in the database.
|
T |
searchFirst(RecordTemplate<T> expectedRecord)
Finds the first, if any, record in the list and/or in the database.
|
private static final org.apache.log4j.Logger log
private static final int MAX_RECORDS_IN_MEMORY
private final AOContext aoContext
private final boolean searchLocally
private final boolean searchInDB
private final boolean popValues
private static long countUpdates
private RecordTemplateImpl<K,T extends net.java.ao.RawEntity<K>> recordTemplate
private DAOCache(AOContext aoContext, Class<T> type, boolean searchLocally, boolean searchInDB, boolean popValues, List<T> localList, RecordTemplateImpl<K,T> recordTemplate)
type
- the type of recordssearchLocally
- true if we can search locally, in which case 'localList' must be presentsearchInDB
- true if we can search in DB. Both searchLocally and searchInDB can be true.popValues
- true if we must remove the items from 'localList' after found, so we collect the rest.
If true, then the DB can't be used, and creating a record won't add the item.localList
- the list of records, passed by reference so the parent can also add/remove items.
Beware, if mutating the list from outside, you must not use the 'recordTemplate'.recordTemplate
- optional, can be null; If provided it will be used when returning newTemplate(),
and if provided it can be the SuperfastRecordTemplate which activates the indexing.private boolean createIndex()
public RecordTemplate<T> newTemplate()
public T createOrUpdate(RecordTemplate<T> recordTemplate)
public T create(RecordTemplate<T> recordTemplate)
public T searchFirst(RecordTemplate<T> expectedRecord)
expectedRecord
- the RecordTemplatepublic List<T> searchAll(RecordTemplate<T> expectedRecord)
expectedRecord
- the RecordTemplateprivate StringBuilderForAOWhereClause buildWhereClauseForExpectedRecord(RecordTemplate<T> expectedRecord)
private void addEventually(T recordFoundInDB)
Copyright © 2022 Requirement Yogi. All rights reserved.