|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.compomics.util.db.ObjectsCache
public class ObjectsCache
An object cache can be combined to an ObjectDB to improve its performance. A single cache can be used by different databases. This ough not to be serialized.
Constructor Summary | |
---|---|
ObjectsCache()
Constructor. |
Method Summary | |
---|---|
void |
addDb(ObjectsDB objectsDB)
Adds a database in the list of the databases handled by the cache. |
void |
addObject(String dbName,
String tableName,
String objectKey,
Object object)
Adds an object to the cache. |
boolean |
databaseContainsKey(String dbName,
String tableName,
String objectKey)
Returns true of the given object key is in the database. |
int |
getCacheSize()
Returns the cache size in number of objects. |
double |
getMemoryShare()
Returns the share of heap size which can be used before emptying the cache. 0.99 (default) means that objects will be removed from the cache as long as more than 99% of the heap size is used. |
Object |
getObject(String dbName,
String tableName,
String objectKey)
Returns the objects if present in the cache. |
void |
insertObjectInDatabaseMap(String dbName,
String tableName,
String objectKey)
Inserts the object into the database map. |
boolean |
isAutomatedMemoryManagement()
Returns whether the cache is in automated memory management mode. |
boolean |
memoryCheck()
Indicates whether the memory used by the application is lower than 99% of the heap size. |
void |
reduceMemoryConsumption(double share,
WaitingHandler waitingHandler)
Reduces the memory consumption by saving the given share of hits. |
void |
removeObject(String dbName,
String tableName,
String objectKey)
Removes an object from the cache mappings. |
void |
removeObjectInDatabaseMap(String dbName,
String tableName,
String objectKey)
Removes the object in the database map. |
void |
saveCache(WaitingHandler waitingHandler,
boolean emptyCache)
Saves the cache content in the database. |
void |
saveObject(String entryKey)
Saves an entry in the database if modified and clears it from the cache. |
void |
saveObject(String entryKey,
boolean clearEntry)
Saves an entry in the database if modified. |
void |
setAutomatedMemoryManagement(boolean automatedMemoryManagement)
Sets whether the cache is in automated memory management mode. |
void |
setCacheSize(int cacheSize)
Sets the cache size in number of objects. |
void |
setMemoryShare(double memoryShare)
Sets the share of heap size which can be used before emptying the cache. |
void |
updateCache()
Updates the cache according to the memory settings. |
boolean |
updateObject(String dbName,
String tableName,
String objectKey,
Object object)
Sets that a match has been modified and returns true in case of success. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ObjectsCache()
Method Detail |
---|
public boolean isAutomatedMemoryManagement()
public void setAutomatedMemoryManagement(boolean automatedMemoryManagement)
automatedMemoryManagement
- a boolean indicating whether the cache
is in automated memory management modepublic int getCacheSize()
public void setCacheSize(int cacheSize)
cacheSize
- the cache size in number of objectspublic double getMemoryShare()
public void setMemoryShare(double memoryShare)
memoryShare
- the share of heap size which can be used before
emptying the cachepublic void addDb(ObjectsDB objectsDB)
objectsDB
- the objects databasepublic void removeObject(String dbName, String tableName, String objectKey)
dbName
- the name of the databasetableName
- the name of the tableobjectKey
- the key of the objectpublic Object getObject(String dbName, String tableName, String objectKey)
dbName
- the name of the databasetableName
- the name of the tableobjectKey
- the key of the object
public boolean updateObject(String dbName, String tableName, String objectKey, Object object)
dbName
- the name of the databasetableName
- the name of the tableobjectKey
- the key of the objectobject
-
public void addObject(String dbName, String tableName, String objectKey, Object object) throws IOException, SQLException
dbName
- the name of the databasetableName
- the name of the tableobjectKey
- the key of the objectobject
- the object to store in the cache
IOException
SQLException
public boolean memoryCheck()
public void saveObject(String entryKey) throws IOException, SQLException
entryKey
- the key of the entry
SQLException
- exception thrown whenever an error occurred while
adding the object in the database
IOException
- exception thrown whenever an error occurred while
writing the objectpublic void saveObject(String entryKey, boolean clearEntry) throws IOException, SQLException
entryKey
- the key of the entryclearEntry
- a boolean indicating whether the entry shall be cleared
from the cache
SQLException
- exception thrown whenever an error occurred while
adding the object in the database
IOException
- exception thrown whenever an error occurred while
writing the objectpublic void updateCache() throws IOException, SQLException
SQLException
- exception thrown whenever an error occurred while
adding the object in the database
IOException
- exception thrown whenever an error occurred while
writing the objectpublic void reduceMemoryConsumption(double share, WaitingHandler waitingHandler) throws IOException, SQLException
share
- the share to be saved, 0.25 means that 25% of the hits will
be savedwaitingHandler
- a waiting handler on which the progress will be
displayed as secondary progress. can be null
SQLException
- exception thrown whenever an error occurred while
adding the object in the database
IOException
- exception thrown whenever an error occurred while
writing the objectpublic void saveCache(WaitingHandler waitingHandler, boolean emptyCache) throws IOException, SQLException
waitingHandler
- a waiting handler on which the progress will beemptyCache
- boolean indicating whether the cache content shall be
cleared while saving displayed as secondary progress. can be null
SQLException
- exception thrown whenever an error occurred while
adding the object in the database
IOException
- exception thrown whenever an error occurred while
writing the objectpublic void insertObjectInDatabaseMap(String dbName, String tableName, String objectKey) throws SQLException, IOException
dbName
- the DB nametableName
- the name of the tableobjectKey
- the key of the object
SQLException
- exception thrown whenever an error occurred while
storing the object
IOException
- exception thrown whenever an error occurred while
writing in the databasepublic void removeObjectInDatabaseMap(String dbName, String tableName, String objectKey) throws SQLException, IOException
dbName
- the DB nametableName
- the name of the tableobjectKey
- the key of the object
SQLException
- exception thrown whenever an error occurred while
storing the object
IOException
- exception thrown whenever an error occurred while
writing in the databasepublic boolean databaseContainsKey(String dbName, String tableName, String objectKey)
dbName
- the DB nametableName
- the name of the tableobjectKey
- the key of the object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |