use of org.vcell.util.Immutable in project vcell by virtualcell.
the class DBCacheTable method putProtected.
public void putProtected(KeyValue key, Cacheable cacheable) throws CacheException {
if (!((cacheable instanceof Cloneable) || (cacheable instanceof Immutable) || (cacheable instanceof Serializable))) {
throw new CacheException("put:Object not Cloneable, Immutable or Serializable");
}
if (key == null) {
throw new CacheException("put: key == null");
}
long dataSize = 1000;
byte[] objData = null;
try {
objData = org.vcell.util.BeanUtils.toSerialized(cacheable);
//
// dataSize is length*3 because three copies are stored in DbObjectWrapper (reference/bytes/working).
//
dataSize = objData.length * 3;
} catch (IOException e) {
e.printStackTrace(System.out);
throw new CacheException(e.getMessage());
}
TimeWrapper oldTimeWrapper = put(key, new TimeWrapper(new DbObjectWrapper(cacheable, objData), dataSize, key));
//
if (oldTimeWrapper != null) {
System.out.println("replacing object ALREADY IN DATABASE_CACHE " + oldTimeWrapper.getObject() + " at key " + key);
}
//
// checking to see if same object (using compareEqual) already in hash
//
// if (cacheable instanceof cbit.vcell.model.Species){
// Enumeration enum1 = hashTable.elements();
// while (enum1.hasMoreElements()){
// TimeWrapper timeWrapper = (TimeWrapper) enum1.nextElement();
// DbObjectWrapper objWrapper = (DbObjectWrapper) timeWrapper.getObject();
// Cacheable cacheObj = objWrapper.getWorkingCopy();
// if (cacheable != cacheObj && cacheable.compareEqual(cacheObj)){
// // throw new RuntimeException("DBCacheTable.put("+cacheable+"), already in cache as ("+cacheObj+")");
// System.out.println("DBCacheTable.put("+cacheable+"), already in cache as ("+cacheObj+")");
// }
// }
// }
// System.out.print("put(cacheable="+cacheable+") ");
show();
}
use of org.vcell.util.Immutable in project vcell by virtualcell.
the class DBCacheTable method putUnprotected.
public void putUnprotected(KeyValue key, Cacheable cacheable) throws CacheException {
if (!((cacheable instanceof Cloneable) || (cacheable instanceof Immutable) || (cacheable instanceof Serializable))) {
throw new CacheException("put:Object not Cloneable, Immutable or Serializable");
}
if (key == null) {
throw new CacheException("put: key == null");
}
long dataSize = 1000;
try {
byte[] objData = org.vcell.util.BeanUtils.toSerialized(cacheable);
dataSize = objData.length;
} catch (IOException e) {
e.printStackTrace(System.out);
throw new CacheException(e.getMessage());
}
TimeWrapper oldTimeWrapper = put(key, new TimeWrapper(new DbObjectWrapper(cacheable), dataSize, key));
//
if (oldTimeWrapper != null) {
System.out.println("replacing object ALREADY IN DATABASE_CACHE " + oldTimeWrapper.getObject() + " at key " + key);
}
//
// checking to see if same object (using compareEqual) already in hash
//
// if (cacheable instanceof cbit.vcell.model.Species){
// Enumeration enum1 = hashTable.elements();
// while (enum1.hasMoreElements()){
// TimeWrapper timeWrapper = (TimeWrapper) enum1.nextElement();
// DbObjectWrapper objWrapper = (DbObjectWrapper) timeWrapper.getObject();
// Cacheable cacheObj = objWrapper.getWorkingCopy();
// if (cacheable != cacheObj && cacheable.compareEqual(cacheObj)){
// // throw new RuntimeException("DBCacheTable.put("+cacheable+"), already in cache as ("+cacheObj+")");
// System.out.println("DBCacheTable.put("+cacheable+"), already in cache as ("+cacheObj+")");
// }
// }
// }
// System.out.print("put(cacheable="+cacheable+") ");
show();
}
Aggregations