public class ObjectsDB extends Object
Modifier and Type | Field and Description |
---|---|
static AtomicInteger |
ACCESSCOUNTER
The access counter.
|
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()
Closes the db connection.
|
void |
close(boolean clearing)
Closes the db connection.
|
void |
commit()
Committing all changes into the database.
|
static void |
decreaseRWCounter()
Function for decreasing the counter of processes accessing objects from
the db.
|
void |
dumpToDB()
Triggers a dump of all objects within the cache into the database.
|
void |
establishConnection(boolean loading)
Establishes connection to the database.
|
HashSet<Long> |
getClassObjects(Class className)
Returns an iterator of all objects of a given class.
|
int |
getCurrentAdded()
Getter for the current number of added objects.
|
javax.jdo.PersistenceManager |
getDB()
Getter for the persistence manager.
|
File |
getDbFile()
Getter for the database file.
|
File |
getDbFolder()
Getter for the database folder.
|
HashMap<Long,Long> |
getIdMap()
Getter for the id map mapping the hashed keys into zoo db ids.
|
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.
|
Iterator<?> |
getObjectsIterator(Class className,
String filters)
Returns an iterator of all objects of a given class.
|
String |
getPath()
Returns the path to the database.
|
boolean |
inCache(long objectKey)
Indicates whether an object is loaded in cache.
|
static void |
increaseRWCounter()
Function for increasing the counter of processes accessing objects from
the db.
|
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 longKey)
Retrieves some objects 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.
|
public static volatile AtomicInteger ACCESSCOUNTER
public ObjectsDB()
public ObjectsDB(String folder, String dbName)
folder
- absolute path of the folder where to establish the databasedbName
- name of the databasepublic static void increaseRWCounter()
public static void decreaseRWCounter()
public void commit()
public int getCurrentAdded()
public HashMap<Long,Long> getIdMap()
public File getDbFile()
public File getDbFolder()
public javax.jdo.PersistenceManager 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> getClassObjects(Class className)
className
- the class namepublic Iterator<?> getObjectsIterator(Class className, String filters)
className
- the class namefilters
- filters for the classpublic 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 longKey)
longKey
- the keys 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 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 static boolean isConnectionActive()
public void lock(WaitingHandler waitingHandler)
waitingHandler
- the waiting handlerpublic void unlock()
public void close()
public void close(boolean clearing)
clearing
- clearing all database structurespublic void establishConnection(boolean loading)
loading
- load all objects from databasepublic String getPath()
public static void setDebugInteractions(boolean debug)
debug
- if true, the debugging is turned onCopyright © 2019. All rights reserved.