Package com.compomics.util.db.object
Class ObjectsDB
java.lang.Object
com.compomics.util.db.object.ObjectsDB
A database which can easily be used to store objects.
- Author:
- Marc Vaudel, Dominik Kopczynski, Harald Barsnes
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose(boolean saveCache) Closes the db connection.voidcommit()Committing all changes into the database.voiddumpToDB()Triggers a dump of all objects within the cache into the database.voidEstablishes connection to the database.getClassObjectIDs(Class className) Returns an iterator of all objects of a given class.getClassObjectIDs(Class className, String filters) Returns an iterator of all objects of a given class.intGetter for the current number of added objects.getDB()Getter for the persistence manager.Getter for the database file.Getter for the database folder.Returns the keys in backend set.getName()Returns the database name.intReturns the number of instances of a given class stored in the db.Returns the cache used by this database.getPath()Returns the path to the database.booleaninBackend(long objectKey) Indicates whether an object is loaded in the backend.booleaninCache(long objectKey) Indicates whether an object is loaded in cache.booleaninDB(long objectKey) Indicates whether an object is in the cache or the database.voidinsertObject(long objectKey, Object object) Stores an object in the desired table.voidinsertObjects(HashMap<Long, Object> objects, WaitingHandler waitingHandler, boolean displayProgress) Inserts a set of objects in the given table.static booleanIndicates whether the connection to the DB is active.voidloadObjects(Class className, WaitingHandler waitingHandler, boolean displayProgress) Loads all objects from a given class.voidloadObjects(Collection<Long> keys, WaitingHandler waitingHandler, boolean displayProgress) Loads objects from a table in the cache.voidlock(WaitingHandler waitingHandler) Locking the db for storing.voidremoveObject(long key) Removing an object from the cache and database.voidremoveObjects(Collection<Long> keys, WaitingHandler waitingHandler, boolean displayProgress) Removing an object from the cache and database.retrieveObject(long objectKey) Retrieves an object from the database or cache.retrieveObjects(Class className, WaitingHandler waitingHandler, boolean displayProgress) Retrieves all objects from a given class.retrieveObjects(Collection<Long> keys, WaitingHandler waitingHandler, boolean displayProgress) Retrieves some objects from the database or cache.static voidsetDebugInteractions(boolean debug) Turn the debugging of interactions on or off.voidsetObjectCache(ObjectsCache objectCache) Sets the object cache to be used by this database.voidunlock()Unlocking the db after storing.voidupdateObject(long objectKey, Object object) Update the object with the given key.
-
Constructor Details
-
ObjectsDB
public ObjectsDB()Empty default constructor. -
ObjectsDB
Constructor.- Parameters:
folder- absolute path of the folder where to establish the databasedbName- name of the database
-
ObjectsDB
Constructor.- Parameters:
path- absolute path of the folder where to establish the databasedbName- name of the databaseoverwrite- overwriting old database
-
-
Method Details
-
commit
public void commit()Committing all changes into the database. -
getCurrentAdded
public int getCurrentAdded()Getter for the current number of added objects.- Returns:
- the current number of added objects
-
getDbFile
Getter for the database file.- Returns:
- the database file
-
getDbFolder
Getter for the database folder.- Returns:
- the database folder
-
getDB
Getter for the persistence manager.- Returns:
- the persistence manager
-
getName
Returns the database name.- Returns:
- the database name
-
getObjectsCache
Returns the cache used by this database.- Returns:
- the cache used by this database
-
setObjectCache
Sets the object cache to be used by this database.- Parameters:
objectCache- the object cache to be used by this database
-
insertObject
Stores an object in the desired table. When multiple objects are to be inserted, use insertObjects instead.- Parameters:
objectKey- the key of the objectobject- the object to store
-
getClassObjectIDs
Returns an iterator of all objects of a given class.- Parameters:
className- the class name- Returns:
- the iterator
-
getClassObjectIDs
Returns an iterator of all objects of a given class.- Parameters:
className- the class namefilters- string with filters;- Returns:
- the iterator
-
insertObjects
public void insertObjects(HashMap<Long, Object> objects, WaitingHandler waitingHandler, boolean displayProgress) Inserts a set of objects in the given table.- Parameters:
objects- map of the objects (object key > object)waitingHandler- a waiting handler displaying the progress (can be null). The progress will be displayed on the secondary progress bar.displayProgress- boolean indicating whether the progress of this method should be displayed on the waiting handler
-
loadObjects
public void loadObjects(Collection<Long> keys, WaitingHandler waitingHandler, boolean displayProgress) Loads objects from a table in the cache.- Parameters:
keys- the keys of the objects to loadwaitingHandler- the waiting handler allowing displaying progress and canceling the processdisplayProgress- boolean indicating whether the progress of this method should be displayed on the waiting handler
-
loadObjects
Loads all objects from a given class.- Parameters:
className- the class name of the objects to be retrievedwaitingHandler- the waiting handler allowing displaying progress and canceling the processdisplayProgress- boolean indicating whether the progress of this method should be displayed on the waiting handler
-
retrieveObject
Retrieves an object from the database or cache.- Parameters:
objectKey- the key of the object to load- Returns:
- the retrieved object
-
getNumber
Returns the number of instances of a given class stored in the db.- Parameters:
className- the class name of the objects to be load- Returns:
- the number of objects
-
dumpToDB
public void dumpToDB()Triggers a dump of all objects within the cache into the database. -
retrieveObjects
public ArrayList<Object> retrieveObjects(Collection<Long> keys, WaitingHandler waitingHandler, boolean displayProgress) Retrieves some objects from the database or cache.- Parameters:
keys- the keys of the objects to loadwaitingHandler- the waiting handler allowing displaying progress and canceling the processdisplayProgress- boolean indicating whether the progress of this method should be displayed on the waiting handler- Returns:
- a list of objects
-
updateObject
Update the object with the given key.- Parameters:
objectKey- the object keyobject- the object
-
retrieveObjects
public ArrayList<Object> retrieveObjects(Class className, WaitingHandler waitingHandler, boolean displayProgress) Retrieves all objects from a given class.- Parameters:
className- the class name of the objects to be retrievedwaitingHandler- the waiting handler allowing displaying progress and canceling the processdisplayProgress- boolean indicating whether the progress of this method should be displayed on the waiting handler- Returns:
- the list of objects
-
removeObjects
public void removeObjects(Collection<Long> keys, WaitingHandler waitingHandler, boolean displayProgress) Removing an object from the cache and database.- Parameters:
keys- the object keywaitingHandler- the waiting handler allowing displaying progress and canceling the processdisplayProgress- boolean indicating whether the progress of this method should be displayed on the waiting handler
-
removeObject
public void removeObject(long key) Removing an object from the cache and database.- Parameters:
key- the object key
-
inCache
public boolean inCache(long objectKey) Indicates whether an object is loaded in cache.- Parameters:
objectKey- the object key- Returns:
- a boolean indicating whether an object is loaded
-
inDB
public boolean inDB(long objectKey) Indicates whether an object is in the cache or the database.- Parameters:
objectKey- the object key- Returns:
- a boolean indicating whether an object is loaded
-
inBackend
public boolean inBackend(long objectKey) Indicates whether an object is loaded in the backend.- Parameters:
objectKey- the object key- Returns:
- a boolean indicating whether an object is loaded
-
getKeysInBackend
Returns the keys in backend set.- Returns:
- the keys in backend set
-
isConnectionActive
public static boolean isConnectionActive()Indicates whether the connection to the DB is active.- Returns:
- true if the connection to the DB is active
-
lock
Locking the db for storing.- Parameters:
waitingHandler- the waiting handler
-
unlock
public void unlock()Unlocking the db after storing. -
close
public void close(boolean saveCache) Closes the db connection.- Parameters:
saveCache- clearing all database structures
-
establishConnection
public void establishConnection()Establishes connection to the database. -
getPath
Returns the path to the database.- Returns:
- the path to the database
-
setDebugInteractions
public static void setDebugInteractions(boolean debug) Turn the debugging of interactions on or off.- Parameters:
debug- if true, the debugging is turned on
-