|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.salespointframework.core.data.PersistentMap<K,V>
K
- generic key typeV
- generic value typepublic class PersistentMap<K,V>
A PersistentMap
is a Map
that persists its key-value pairs to the data source.
most functions are thread safe.
make sure that key type is a basic one.
make sure that object you put in here are persistable via PersistenceManager.persist(Object)
. It is Possible
to use List
s as value type, but you should avoid this.
The map uses an internal cache for performance reasons.
Each map needs a unique id which is composed of host
and dbid
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Field Summary | |
---|---|
private java.util.Map<K,V> |
cache
cached map items |
private long |
cacheLifetime
cache life time |
private java.util.Map<K,java.lang.Long> |
cacheTS
timestamps of each cache item |
private java.lang.Class |
ck
class of keys |
private java.lang.Class |
cv
class of values |
private java.lang.String |
dbid
id of map |
static long |
DEFAULT_CACHE_LIFETIME
default cache life time |
private java.util.List<ExternalModificationListener> |
externalModificationListeners
list of ExternalModificationListener s |
private boolean |
forceMultiKey
allow multiple keys of same value. if true, the map will return Lists. |
private java.lang.Object |
host
hosting object. mostly the object in which this map us declared |
private long |
largeLoadTS
timestamp of last large load. applies only if PersistenceManager.isPerformanceMode() |
private java.lang.Object |
lock
locking object |
private java.lang.Object |
recoveryContext
recovery context, passed to objects on recovery |
private int |
size
cached size |
private long |
sizeTS
timestamp if cahced size |
Constructor Summary | |
---|---|
PersistentMap(java.lang.Class k,
java.lang.Class v)
default constructor. |
|
PersistentMap(java.lang.Object host,
java.lang.String id,
java.lang.Class k,
java.lang.Class v)
default constructor. |
|
PersistentMap(java.lang.Object host,
java.lang.String id,
java.lang.Class k,
java.lang.Class v,
long cacheLifetime,
java.lang.Object recoveryContext,
boolean forceMultiKey)
constructor. |
|
PersistentMap(java.lang.Object host,
java.lang.String id,
java.lang.Class k,
java.lang.Class v,
java.lang.Object recoveryContext)
constructor. |
|
PersistentMap(java.lang.Object host,
java.lang.String id,
java.lang.Class k,
java.lang.Class v,
java.lang.Object recoveryContext,
boolean forceMultiKey)
constructor. |
Method Summary | |
---|---|
boolean |
addExternalModificationListener(ExternalModificationListener eml)
add ExternalModificationListener |
void |
addList(K key,
java.util.List<java.lang.Object> list)
add list to cache |
void |
checkLargeLoad()
check if cache is out-dated. |
void |
clear()
|
boolean |
containsKey(java.lang.Object key)
|
boolean |
containsValue(java.lang.Object value)
this method is not implemented |
void |
DatasourceChanged(boolean pumpUp)
invalidate caches and pump up the event |
void |
DatasourceOnChange()
pump up datasource on change event |
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
this method is not implemented |
void |
externalModificationOccurred()
invalidate caches and pump up the event |
V |
get(java.lang.Object key)
|
java.util.List<java.lang.Object> |
getList(java.lang.Object key)
get list |
java.lang.String |
getListId()
get encoded list id |
java.lang.String |
getListId(boolean raw)
get list id |
void |
invalidateCaches()
invalidate all caches |
boolean |
isEmpty()
|
java.util.Set<K> |
keySet()
|
V |
put(K key,
V value)
|
void |
putAll(java.util.Map<? extends K,? extends V> m)
|
V |
remove(java.lang.Object key)
|
void |
removeExternalModificationListener(ExternalModificationListener eml)
remove ExternalModificationListener |
void |
setCacheLifetime(long cacheLifetime)
set cacheLifetime |
void |
setRecoveryContext(java.lang.Object recoveryContext)
set recoveryContext |
int |
size()
|
java.lang.String |
toString()
|
void |
unsubscribe()
unsubscribe map from PersistenceManager |
java.util.Collection<V> |
values()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
equals, hashCode |
Field Detail |
---|
public static long DEFAULT_CACHE_LIFETIME
private java.lang.String dbid
private java.lang.Class ck
private java.lang.Class cv
private java.lang.Object recoveryContext
private java.lang.Object host
private boolean forceMultiKey
private java.lang.Object lock
private long cacheLifetime
private int size
private long sizeTS
private java.util.Map<K,V> cache
private java.util.Map<K,java.lang.Long> cacheTS
private long largeLoadTS
PersistenceManager.isPerformanceMode()
private java.util.List<ExternalModificationListener> externalModificationListeners
ExternalModificationListener
s
Constructor Detail |
---|
public PersistentMap(java.lang.Class k, java.lang.Class v)
k
- ck
v
- cv
public PersistentMap(java.lang.Object host, java.lang.String id, java.lang.Class k, java.lang.Class v)
host
- host
id
- dbid
k
- ck
v
- cv
public PersistentMap(java.lang.Object host, java.lang.String id, java.lang.Class k, java.lang.Class v, java.lang.Object recoveryContext)
host
- host
id
- dbid
k
- ck
v
- cv
recoveryContext
- recoveryContext
public PersistentMap(java.lang.Object host, java.lang.String id, java.lang.Class k, java.lang.Class v, java.lang.Object recoveryContext, boolean forceMultiKey)
forceMultiKey
only to true, if you know what you are doing!
.
host
- host
id
- dbid
k
- ck
v
- cv
recoveryContext
- recoveryContext
forceMultiKey
- forceMultiKey
public PersistentMap(java.lang.Object host, java.lang.String id, java.lang.Class k, java.lang.Class v, long cacheLifetime, java.lang.Object recoveryContext, boolean forceMultiKey)
forceMultiKey
only to true, if you know what you are doing!
.
host
- host
id
- dbid
k
- ck
v
- cv
recoveryContext
- recoveryContext
forceMultiKey
- forceMultiKey
cacheLifetime
- cacheLifetime
Method Detail |
---|
public void setCacheLifetime(long cacheLifetime)
cacheLifetime
cacheLifetime
- public void setRecoveryContext(java.lang.Object recoveryContext)
recoveryContext
recoveryContext
- public java.lang.String getListId()
public java.lang.String getListId(boolean raw)
raw
- if true, list id is not encoded
public void clear()
clear
in interface java.util.Map<K,V>
Map.clear()
public void invalidateCaches()
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map<K,V>
Map.containsKey(Object)
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map<K,V>
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
entrySet
in interface java.util.Map<K,V>
public void checkLargeLoad()
public void addList(K key, java.util.List<java.lang.Object> list)
key
- list
- public java.util.List<java.lang.Object> getList(java.lang.Object key)
key
-
public V get(java.lang.Object key)
get
in interface java.util.Map<K,V>
Map.get(Object)
public boolean isEmpty()
isEmpty
in interface java.util.Map<K,V>
Map.isEmpty()
public java.util.Set<K> keySet()
keySet
in interface java.util.Map<K,V>
Map.keySet()
public V put(K key, V value)
put
in interface java.util.Map<K,V>
Map.put(Object, Object)
public void putAll(java.util.Map<? extends K,? extends V> m)
putAll
in interface java.util.Map<K,V>
Map.putAll(Map)
public V remove(java.lang.Object key)
remove
in interface java.util.Map<K,V>
Map.remove(Object)
public int size()
size
in interface java.util.Map<K,V>
Map.size()
public java.util.Collection<V> values()
values
in interface java.util.Map<K,V>
Map.values()
public void DatasourceChanged(boolean pumpUp)
DatasourceChanged
in interface DatasourceChangeListener
pumpUp
- true if the event should be pumped up to hosts, because this event is mostly triggered twice.
first time to invalidate caches. second time for load new datapublic void unsubscribe()
PersistenceManager
public void DatasourceOnChange()
DatasourceOnChange
in interface DatasourceOnChangeListener
public java.lang.String toString()
toString
in class java.lang.Object
public boolean addExternalModificationListener(ExternalModificationListener eml)
ExternalModificationListener
eml
- the listener
public void removeExternalModificationListener(ExternalModificationListener eml)
ExternalModificationListener
eml
- the listenerpublic void externalModificationOccurred()
externalModificationOccurred
in interface ExternalModificationListener
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |