public class ObjectsDB extends Object
Modifier and Type | Field and Description |
---|---|
com.esotericsoftware.kryo.Kryo |
kryo
Configuration for fast serialization.
|
Constructor and Description |
---|
ObjectsDB()
Empty default constructor.
|
ObjectsDB(String folder,
String dbName)
Constructor.
|
ObjectsDB(String path,
String dbName,
boolean overwrite)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close(boolean saveCache)
Closes the db connection.
|
void |
commit()
Committing all changes into the database.
|
void |
dumpToDB()
Triggers a dump of all objects within the cache into the database.
|
void |
establishConnection()
Establishes connection to the database.
|
HashSet<Long> |
getClassObjectIDs(Class className)
Returns an iterator of all objects of a given class.
|
HashSet<Long> |
getClassObjectIDs(Class className,
String filters)
Returns an iterator of all objects of a given class.
|
int |
getCurrentAdded()
Getter for the current number of added objects.
|
Connection |
getDB()
Getter for the persistence manager.
|
File |
getDbFile()
Getter for the database file.
|
File |
getDbFolder()
Getter for the database folder.
|
HashSet<Long> |
getKeysInBackend()
Returns the keys in backend set.
|
String |
getName()
Returns the database name.
|
int |
getNumber(Class className)
Returns the number of instances of a given class stored in the db.
|
ObjectsCache |
getObjectsCache()
Returns the cache used by this database.
|
String |
getPath()
Returns the path to the database.
|
boolean |
inBackend(long objectKey)
Indicates whether an object is loaded in the backend.
|
boolean |
inCache(long objectKey)
Indicates whether an object is loaded in cache.
|
boolean |
inDB(long objectKey)
Indicates whether an object is in the cache or the database.
|
void |
insertObject(long objectKey,
Object object)
Stores an object in the desired table.
|
void |
insertObjects(HashMap<Long,Object> objects,
WaitingHandler waitingHandler,
boolean displayProgress)
Inserts a set of objects in the given table.
|
static boolean |
isConnectionActive()
Indicates whether the connection to the DB is active.
|
void |
loadObjects(Class className,
WaitingHandler waitingHandler,
boolean displayProgress)
Loads all objects from a given class.
|
void |
loadObjects(Collection<Long> keys,
WaitingHandler waitingHandler,
boolean displayProgress)
Loads objects from a table in the cache.
|
void |
lock(WaitingHandler waitingHandler)
Locking the db for storing.
|
void |
removeObject(long key)
Removing an object from the cache and database.
|
void |
removeObjects(Collection<Long> keys,
WaitingHandler waitingHandler,
boolean displayProgress)
Removing an object from the cache and database.
|
Object |
retrieveObject(long objectKey)
Retrieves an object from the database or cache.
|
ArrayList<Object> |
retrieveObjects(Class className,
WaitingHandler waitingHandler,
boolean displayProgress)
Retrieves all objects from a given class.
|
ArrayList<Object> |
retrieveObjects(Collection<Long> keys,
WaitingHandler waitingHandler,
boolean displayProgress)
Retrieves some objects from the database or cache.
|
static void |
setDebugInteractions(boolean debug)
Turn the debugging of interactions on or off.
|
void |
setObjectCache(ObjectsCache objectCache)
Sets the object cache to be used by this database.
|
void |
unlock()
Unlocking the db after storing.
|
void |
updateObject(long objectKey,
Object object)
Update the object with the given key.
|
public ObjectsDB()
public ObjectsDB(String folder, String dbName)
folder
- absolute path of the folder where to establish the databasedbName
- name of the databasepublic void commit()
public int getCurrentAdded()
public File getDbFile()
public File getDbFolder()
public Connection getDB()
public String getName()
public ObjectsCache getObjectsCache()
public void setObjectCache(ObjectsCache objectCache)
objectCache
- the object cache to be used by this databasepublic void insertObject(long objectKey, Object object)
objectKey
- the key of the objectobject
- the object to storepublic HashSet<Long> getClassObjectIDs(Class className)
className
- the class namepublic HashSet<Long> getClassObjectIDs(Class className, String filters)
className
- the class namefilters
- string with filters;public void insertObjects(HashMap<Long,Object> objects, WaitingHandler waitingHandler, boolean displayProgress)
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 handlerpublic void loadObjects(Collection<Long> keys, WaitingHandler waitingHandler, boolean displayProgress)
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 handlerpublic void loadObjects(Class className, WaitingHandler waitingHandler, boolean displayProgress)
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 handlerpublic Object retrieveObject(long objectKey)
objectKey
- the key of the object to loadpublic int getNumber(Class className)
className
- the class name of the objects to be loadpublic void dumpToDB()
public ArrayList<Object> retrieveObjects(Collection<Long> keys, WaitingHandler waitingHandler, boolean displayProgress)
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 handlerpublic void updateObject(long objectKey, Object object)
objectKey
- the object keyobject
- the objectpublic ArrayList<Object> retrieveObjects(Class className, WaitingHandler waitingHandler, boolean displayProgress)
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 handlerpublic void removeObjects(Collection<Long> keys, WaitingHandler waitingHandler, boolean displayProgress)
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 handlerpublic void removeObject(long key)
key
- the object keypublic boolean inCache(long objectKey)
objectKey
- the object keypublic boolean inDB(long objectKey)
objectKey
- the object keypublic boolean inBackend(long objectKey)
objectKey
- the object keypublic HashSet<Long> getKeysInBackend()
public static boolean isConnectionActive()
public void lock(WaitingHandler waitingHandler)
waitingHandler
- the waiting handlerpublic void unlock()
public void close(boolean saveCache)
saveCache
- clearing all database structurespublic void establishConnection()
public String getPath()
public static void setDebugInteractions(boolean debug)
debug
- if true, the debugging is turned onCopyright © 2021. All rights reserved.