Class ObjectsDB

java.lang.Object
com.compomics.util.db.object.ObjectsDB

public class ObjectsDB
extends Object
A database which can easily be used to store objects.
Author:
Marc Vaudel, Dominik Kopczynski, Harald Barsnes
  • Field Details

    • kryo

      public com.esotericsoftware.kryo.Kryo kryo
      Configuration for fast serialization.
  • Constructor Details

    • ObjectsDB

      public ObjectsDB()
      Empty default constructor.
    • ObjectsDB

      public ObjectsDB​(String folder, String dbName)
      Constructor.
      Parameters:
      folder - absolute path of the folder where to establish the database
      dbName - name of the database
    • ObjectsDB

      public ObjectsDB​(String path, String dbName, boolean overwrite)
      Constructor.
      Parameters:
      path - absolute path of the folder where to establish the database
      dbName - name of the database
      overwrite - 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

      public File getDbFile()
      Getter for the database file.
      Returns:
      the database file
    • getDbFolder

      public File getDbFolder()
      Getter for the database folder.
      Returns:
      the database folder
    • getDB

      public Connection getDB()
      Getter for the persistence manager.
      Returns:
      the persistence manager
    • getName

      public String getName()
      Returns the database name.
      Returns:
      the database name
    • getObjectsCache

      public ObjectsCache getObjectsCache()
      Returns the cache used by this database.
      Returns:
      the cache used by this database
    • setObjectCache

      public void setObjectCache​(ObjectsCache objectCache)
      Sets the object cache to be used by this database.
      Parameters:
      objectCache - the object cache to be used by this database
    • insertObject

      public void insertObject​(long objectKey, Object object)
      Stores an object in the desired table. When multiple objects are to be inserted, use insertObjects instead.
      Parameters:
      objectKey - the key of the object
      object - the object to store
    • getClassObjectIDs

      public HashSet<Long> getClassObjectIDs​(Class className)
      Returns an iterator of all objects of a given class.
      Parameters:
      className - the class name
      Returns:
      the iterator
    • getClassObjectIDs

      public HashSet<Long> getClassObjectIDs​(Class className, String filters)
      Returns an iterator of all objects of a given class.
      Parameters:
      className - the class name
      filters - 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 load
      waitingHandler - the waiting handler allowing displaying progress and canceling the process
      displayProgress - boolean indicating whether the progress of this method should be displayed on the waiting handler
    • loadObjects

      public void loadObjects​(Class className, WaitingHandler waitingHandler, boolean displayProgress)
      Loads all objects from a given class.
      Parameters:
      className - the class name of the objects to be retrieved
      waitingHandler - the waiting handler allowing displaying progress and canceling the process
      displayProgress - boolean indicating whether the progress of this method should be displayed on the waiting handler
    • retrieveObject

      public Object retrieveObject​(long objectKey)
      Retrieves an object from the database or cache.
      Parameters:
      objectKey - the key of the object to load
      Returns:
      the retrieved object
    • getNumber

      public int getNumber​(Class className)
      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 load
      waitingHandler - the waiting handler allowing displaying progress and canceling the process
      displayProgress - boolean indicating whether the progress of this method should be displayed on the waiting handler
      Returns:
      a list of objects
    • updateObject

      public void updateObject​(long objectKey, Object 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 retrieved
      waitingHandler - the waiting handler allowing displaying progress and canceling the process
      displayProgress - 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 key
      waitingHandler - the waiting handler allowing displaying progress and canceling the process
      displayProgress - 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

      public HashSet<Long> 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

      public void lock​(WaitingHandler waitingHandler)
      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

      public String 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