|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.compomics.util.db.ObjectsDB
public class ObjectsDB
A database which can easily be used to store objects.
Constructor Summary | |
---|---|
ObjectsDB(String folder,
String dbName,
boolean deleteOldDatabase,
ObjectsCache objectsCache)
Constructor. |
Method Summary | |
---|---|
void |
addTable(String tableName,
String blobSize)
Adds the desired table in the database. |
void |
close()
Closes the db connection. |
String |
correctTableName(String tableName)
Removes the characters forbidden in table names and puts a '_' instead. |
void |
deleteObject(String tableName,
String objectKey)
Deletes an object from the desired table. |
void |
establishConnection(String aDbFolder,
boolean deleteOldDatabase,
ObjectsCache objectsCache)
Establishes connection to the database. |
Connection |
getDbConnection()
Returns the database connection. |
String |
getName()
Returns the database name |
ObjectsCache |
getObjectsCache()
Returns the cache used by this database |
boolean |
inDB(String tableName,
String objectKey,
boolean cache)
Indicates whether an object is loaded in the given table. |
void |
insertObject(String tableName,
String objectKey,
Object object,
boolean inCache)
Stores an object in the desired table. |
Object |
retrieveObject(String tableName,
String objectKey)
Retrieves an object from the desired table. |
void |
setObjectCache(ObjectsCache objectCache)
Sets the object cache to be used by this database |
void |
updateObject(String tableName,
String objectKey,
Object object)
Updates an object in the cache or in the tables if not in cache. |
void |
updateObject(String tableName,
String objectKey,
Object object,
boolean cache)
Updates an object in the cache or in the tables if not in cache or if cache is wrong. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ObjectsDB(String folder, String dbName, boolean deleteOldDatabase, ObjectsCache objectsCache) throws SQLException
folder
- absolute path of the folder where to establish the databasedbName
- name of the databasedeleteOldDatabase
- if true, tries to delete the old databaseobjectsCache
-
SQLException
Method Detail |
---|
public Connection getDbConnection()
public String getName()
public ObjectsCache getObjectsCache()
public void setObjectCache(ObjectsCache objectCache)
objectCache
- the object cache to be used by this databasepublic void addTable(String tableName, String blobSize) throws SQLException
tableName
- the name of the tableblobSize
- the size of the blob
SQLException
- exception thrown whenever a problem occurred while
working with the databasepublic void insertObject(String tableName, String objectKey, Object object, boolean inCache) throws SQLException, IOException
tableName
- the name of the tableobjectKey
- the key of the objectobject
- the object to storeinCache
- boolean indicating whether the method shall try to put the
object in cache or not
SQLException
- exception thrown whenever an error occurred while
storing the object
IOException
- exception thrown whenever an error occurred while
writing in the databasepublic Object retrieveObject(String tableName, String objectKey) throws SQLException, IOException, ClassNotFoundException
tableName
- the name of the tableobjectKey
- the object key
SQLException
- exception thrown whenever an error occurred while
interrogating the database
IOException
- exception thrown whenever an error occurred while
reading the database
ClassNotFoundException
- exception thrown whenever the class of the
object is not found when deserializing it.public boolean inDB(String tableName, String objectKey, boolean cache) throws SQLException
tableName
- the table nameobjectKey
- the object keycache
- a boolean indicating whether the cache should be searched as
well
SQLException
- exception thrown whenever an exception occurred
while interrogating the databasepublic void deleteObject(String tableName, String objectKey) throws SQLException, IOException
tableName
- the name of the tableobjectKey
- the object key
SQLException
- exception thrown whenever an error occurred while
interrogating the database
IOException
- exception thrown whenever an error occurred while
interrogating the databasepublic void updateObject(String tableName, String objectKey, Object object) throws SQLException, IOException
tableName
- the name of the tableobjectKey
- the key of the objectobject
- the object to store
SQLException
- exception thrown whenever an error occurred while
storing the object
IOException
- exception thrown whenever an error occurred while
writing in the databasepublic void updateObject(String tableName, String objectKey, Object object, boolean cache) throws SQLException, IOException
tableName
- the name of the tableobjectKey
- the key of the objectobject
- the object to storecache
- a boolean indicating whether the method should look in the
cache
SQLException
- exception thrown whenever an error occurred while
storing the object
IOException
- exception thrown whenever an error occurred while
writing in the databasepublic void close() throws SQLException
SQLException
- exception thrown whenever an error occurred while
closing the database connectionpublic void establishConnection(String aDbFolder, boolean deleteOldDatabase, ObjectsCache objectsCache) throws SQLException
aDbFolder
- the folder where the database is locateddeleteOldDatabase
- if true, tries to delete the old databaseobjectsCache
-
SQLException
- exception thrown whenever an error occurred while
establishing the connectionpublic String correctTableName(String tableName)
tableName
- the table name
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |