com.alachisoft.ncache.jsr107.NCacheEntryEventAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ncache-professional-client Show documentation
Show all versions of ncache-professional-client Show documentation
NCache Professional client for java.
package com.alachisoft.ncache.jsr107;
import javax.cache.configuration.CompleteConfiguration;
import javax.cache.event.CacheEntryEvent;
import javax.cache.event.EventType;
import com.alachisoft.ncache.client.CacheEventArg;
public class NCacheEntryEventAdapter extends CacheEntryEvent {
//private final Class keyType;
//private final Class valueType;
private CacheEventArg cacheEventArg;
private String key = null;
/**
* @param source
* @param eventType
* @param cacheEventArg
* @param key
*/
public NCacheEntryEventAdapter(NCacheCache source, final EventType eventType, CacheEventArg cacheEventArg, String key) {
super(source, eventType);
final CompleteConfiguration cfg = source.getConfiguration(CompleteConfiguration.class);
//this.keyType = cfg.getKeyType();
//this.valueType = cfg.getValueType();
this.cacheEventArg = cacheEventArg;
this.key = key;
}
/**
* Returns the previous value, that existed prior to the modification of the Entry value.
*
* @return
*/
@Override
public V getOldValue() {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
if (isOldValueAvailable()) {
return (V) cacheEventArg.getOldItem().getValue(null);
} else {
throw new UnsupportedOperationException("The old value is not available for key: " + getKey());
}
}
/**
* Whether the old value is available.
*
* @return
*/
@Override
public boolean isOldValueAvailable() {
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
return cacheEventArg.getOldItem().getValue(null) != null;
}
/**
* Returns the key corresponding to this entry.
*
* @return
*/
@Override
public K getKey() {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
return (K) key;
}
/**
* Returns the value stored in the cache when this entry was created.
*
* @return
*/
@Override
public V getValue() {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
return (V) cacheEventArg.getItem().getValue(null);
}
/**
* @param type
* @return
*/
@Override
public T unwrap(Class type) {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
if (type.isAssignableFrom(this.getClass()))
return type.cast(this);
return null;
}
}