p3j.database.hibernate
Class P3MDatabase

java.lang.Object
  extended by p3j.database.hibernate.P3MDatabase
All Implemented Interfaces:
IP3MDatabase

public class P3MDatabase
extends Object
implements IP3MDatabase

Implementation of IP3MDatabase based on Hibernate. Created: August 17, 2008

Author:
Christina Bohk, Roland Ewald

Constructor Summary
P3MDatabase()
          Constructor using the default configuration file.
P3MDatabase(String configurationFile)
          Constructor for custom configuration.
 
Method Summary
 void clear()
          Clears the database.
 void clearCache(Object o)
          Clears the given object from cache.
 void close()
          Closes the database connection.
protected  void dbChanged()
          DB-write hook for switching flushing on or off.
 void delete(Object o)
          Deletes an object with hibernate.
 void deleteAllResults(ProjectionModel projection)
          Delete all results of the projection.
 boolean deleteMatrix(Matrix matrix)
          Deletes given matrix from the database.
 boolean deleteParameter(Parameter parameter)
          Deletes given parameter from database.
 boolean deleteParameterAssignment(ParameterAssignment assignment)
          Deletes given parameter assignment.
 boolean deleteParameterInstance(ParameterInstance instance)
          Deletes given parameter instances from the data base.
 boolean deleteProjection(ProjectionModel projection)
          Delete projection from database.
 void deleteResult(ResultsOfTrial resultOfTrial)
          Deletes a result.
 boolean deleteSet(Set set)
          Deletes given set from database.
 boolean deleteSeType(SetType setType)
          Delete SetType from database.
 List<Matrix> getAllMatrices()
          Retrieves all input matrices from the database.
 List<ParameterAssignment> getAllParameterAssignments(ParameterInstance param)
          Retrieves all ParameterAssignment entities for a certain ParameterInstance.
 List<ParameterInstance> getAllParameterInstances()
          Retrieves list with all parameter instances.
 List<Parameter> getAllParameters()
          Retrieves list with all parameters.
 List<ProjectionModel> getAllProjections()
          Retrieves list of all projections from the database.
 List<ResultsOfTrial> getAllResults(ProjectionModel projection)
          Retrieves all results for the given projection.
 List<Set> getAllSets()
          Retrieves all sets from database.
 List<SetType> getAllSetTypes()
          Retrieve all Settypes from data base.
static String getHibernateConfigFile()
          Gets the hibernate configuration file.
 Matrix getMatrix(Matrix2D value)
          Get matrix with a certain value from database.
 Parameter getParameter(String name)
          Retrieves a parameter with the given name from the database.
 ParameterInstance getParameterInstance(Parameter param, int generation)
          Retrieves a parameter instance from the database.
 ProjectionModel getProjectionByID(int id)
          Retrieves projection by id.
 IProjectionResultsIterator getResultIterator(ProjectionModel projection)
          Gets the result iterator.
 void init(james.core.data.DBConnectionData dbConn)
          Initialize database connection.
 Matrix newMatrix(Matrix2D value)
          Creates a new matrix if a matrix with the same values is not already existing in the system.
 Parameter newParameter(String name, boolean genDep, MatrixDimension height, MatrixDimension width, Population population)
          Creates a new parameter (if not already existent) and returns it.
 ParameterAssignment newParameterAssignment(ParameterInstance paramInstance, String name, String description, double probability, double deviation, Matrix2D value)
          Creates a new parameter assignment.
 ParameterInstance newParameterInstance(int comparisonIndex, Parameter param, int generation)
          Creates new parameter instance.
 void newProjection(ProjectionModel projection)
          Adds new projection to database, automatically adds any Parameter or ParameterInstance entities that have not yet been created.
 Set newSet(List<ParameterInstance> defParams, String name, String desc, double prob)
          Creates a new set.
 SetType newSetType(String name, String description)
          Create new Settype.
 void open()
          Establishes database connection.
 void save(Object o)
          Saves an object with hibernate.
 void saveParameterAssignment(ParameterAssignment assignment)
          Saves given parameter assignment.
 void saveProjection(ProjectionModel projection)
          Saves projection.
 void saveSet(Set set)
          Updates the set.
 void saveSetType(SetType setType)
          Updates the Settype.
 void saveTrialResults(ResultsOfTrial resultOfTrial)
          Saves results of a single trial.
static void setHibernateConfigFile(String hibernateConfigFile)
          Sets the hibernate configuration file.
static Exception testConnection(james.core.data.DBConnectionData dbConnData)
          Test connection to database.
static Exception testConnection(String dbURL, String dbUserName, String dbPassword)
          Test connection to database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

P3MDatabase

public P3MDatabase()
Constructor using the default configuration file.


P3MDatabase

public P3MDatabase(String configurationFile)
Constructor for custom configuration.

Parameters:
configurationFile - the name of the configuration file
Method Detail

init

public void init(james.core.data.DBConnectionData dbConn)
Description copied from interface: IP3MDatabase
Initialize database connection.

Specified by:
init in interface IP3MDatabase
Parameters:
dbConn - the connection details

open

public void open()
Description copied from interface: IP3MDatabase
Establishes database connection.

Specified by:
open in interface IP3MDatabase

clear

public void clear()
Description copied from interface: IP3MDatabase
Clears the database. I.e., it removes *all* entries and re-initializes the (potentially changed) table structure.

Specified by:
clear in interface IP3MDatabase

close

public void close()
Description copied from interface: IP3MDatabase
Closes the database connection.

Specified by:
close in interface IP3MDatabase

dbChanged

protected void dbChanged()
DB-write hook for switching flushing on or off.


save

public void save(Object o)
Saves an object with hibernate.

Parameters:
o - the object to be saved

delete

public void delete(Object o)
Deletes an object with hibernate.

Parameters:
o - the object to be deleted

newParameter

public Parameter newParameter(String name,
                              boolean genDep,
                              MatrixDimension height,
                              MatrixDimension width,
                              Population population)
Description copied from interface: IP3MDatabase
Creates a new parameter (if not already existent) and returns it.

Specified by:
newParameter in interface IP3MDatabase
Parameters:
name - name of the parameter
genDep - flag to determine generation dependency
height - height of parameter values
width - width of parameter values
population - the population to which this parameter refers
Returns:
newly created parameter (or retrieved from DB)

getParameter

public Parameter getParameter(String name)
Description copied from interface: IP3MDatabase
Retrieves a parameter with the given name from the database.

Specified by:
getParameter in interface IP3MDatabase
Parameters:
name - the name of the parameter to be retrieved
Returns:
the parameter, or null if not exists

getAllParameters

public List<Parameter> getAllParameters()
Description copied from interface: IP3MDatabase
Retrieves list with all parameters.

Specified by:
getAllParameters in interface IP3MDatabase
Returns:
list of all Parameter instances stored in the database

deleteParameter

public boolean deleteParameter(Parameter parameter)
Description copied from interface: IP3MDatabase
Deletes given parameter from database.

Specified by:
deleteParameter in interface IP3MDatabase
Parameters:
parameter - the parameter to be deleted
Returns:
true if deletion was successful, otherwise false

newParameterInstance

public ParameterInstance newParameterInstance(int comparisonIndex,
                                              Parameter param,
                                              int generation)
Description copied from interface: IP3MDatabase
Creates new parameter instance.

Specified by:
newParameterInstance in interface IP3MDatabase
Parameters:
comparisonIndex - comparison index of the instance
param - the associated parameter
generation - the generation of the instance
Returns:
a newly created instance, or instance with the same generation and parameter from the database

getParameterInstance

public ParameterInstance getParameterInstance(Parameter param,
                                              int generation)
Description copied from interface: IP3MDatabase
Retrieves a parameter instance from the database.

Specified by:
getParameterInstance in interface IP3MDatabase
Parameters:
param - the associated parameter
generation - the generation for which the parameter shall be instantiated
Returns:
existing parameter from database, or null

getAllParameterInstances

public List<ParameterInstance> getAllParameterInstances()
Description copied from interface: IP3MDatabase
Retrieves list with all parameter instances.

Specified by:
getAllParameterInstances in interface IP3MDatabase
Returns:
list of all parameter instances that are stored in the database

deleteParameterInstance

public boolean deleteParameterInstance(ParameterInstance instance)
Description copied from interface: IP3MDatabase
Deletes given parameter instances from the data base.

Specified by:
deleteParameterInstance in interface IP3MDatabase
Parameters:
instance - the instance to be deleted
Returns:
true, if deletion was successful

newMatrix

public Matrix newMatrix(Matrix2D value)
Description copied from interface: IP3MDatabase
Creates a new matrix if a matrix with the same values is not already existing in the system.

Specified by:
newMatrix in interface IP3MDatabase
Parameters:
value - the value of the matrix
Returns:
the newly created (or retrieved) matrix

getMatrix

public Matrix getMatrix(Matrix2D value)
Description copied from interface: IP3MDatabase
Get matrix with a certain value from database.

Specified by:
getMatrix in interface IP3MDatabase
Parameters:
value - the value of the matrix
Returns:
the matrix, if could be found - otherwise null

getAllMatrices

public List<Matrix> getAllMatrices()
Description copied from interface: IP3MDatabase
Retrieves all input matrices from the database.

Specified by:
getAllMatrices in interface IP3MDatabase
Returns:
list of all matrices

deleteMatrix

public boolean deleteMatrix(Matrix matrix)
Description copied from interface: IP3MDatabase
Deletes given matrix from the database.

Specified by:
deleteMatrix in interface IP3MDatabase
Parameters:
matrix - the matrix to be deleted
Returns:
true if deletion was successful

newParameterAssignment

public ParameterAssignment newParameterAssignment(ParameterInstance paramInstance,
                                                  String name,
                                                  String description,
                                                  double probability,
                                                  double deviation,
                                                  Matrix2D value)
Description copied from interface: IP3MDatabase
Creates a new parameter assignment.

Specified by:
newParameterAssignment in interface IP3MDatabase
Parameters:
paramInstance - the associated parameter instance
name - the name of the assignment
description - the description of the assignment
probability - the probability of the assignment
deviation - the assumption-inherent deviation, i.e. the noise
value - the assigned value
Returns:
the instantiated assignment

getAllParameterAssignments

public List<ParameterAssignment> getAllParameterAssignments(ParameterInstance param)
Description copied from interface: IP3MDatabase
Retrieves all ParameterAssignment entities for a certain ParameterInstance.

Specified by:
getAllParameterAssignments in interface IP3MDatabase
Parameters:
param - the parameter instance
Returns:
list containing all parameter assignments from database

deleteParameterAssignment

public boolean deleteParameterAssignment(ParameterAssignment assignment)
Description copied from interface: IP3MDatabase
Deletes given parameter assignment.

Specified by:
deleteParameterAssignment in interface IP3MDatabase
Parameters:
assignment - the assignment to be deleted
Returns:
true, if deletion was successful

saveParameterAssignment

public void saveParameterAssignment(ParameterAssignment assignment)
Description copied from interface: IP3MDatabase
Saves given parameter assignment.

Specified by:
saveParameterAssignment in interface IP3MDatabase
Parameters:
assignment - the parameter assignment

newSet

public Set newSet(List<ParameterInstance> defParams,
                  String name,
                  String desc,
                  double prob)
Description copied from interface: IP3MDatabase
Creates a new set.

Specified by:
newSet in interface IP3MDatabase
Parameters:
defParams - parameter instance for which assignments can be defined
name - name of the set
desc - description of the set
prob - probability of the set
Returns:
newly created set

saveSet

public void saveSet(Set set)
Description copied from interface: IP3MDatabase
Updates the set. This stores all changed/added/removed ParameterAssignmentSet instances as well.

Specified by:
saveSet in interface IP3MDatabase
Parameters:
set - the set to be updated

getAllSets

public List<Set> getAllSets()
Description copied from interface: IP3MDatabase
Retrieves all sets from database.

Specified by:
getAllSets in interface IP3MDatabase
Returns:
list of all sets

deleteSet

public boolean deleteSet(Set set)
Description copied from interface: IP3MDatabase
Deletes given set from database.

Specified by:
deleteSet in interface IP3MDatabase
Parameters:
set - the set to be deleted
Returns:
true, if deletion was successful

newSetType

public SetType newSetType(String name,
                          String description)
Description copied from interface: IP3MDatabase
Create new Settype.

Specified by:
newSetType in interface IP3MDatabase
Parameters:
name - name of the Settype to be created
description - description of the Settype to be created
Returns:
newly created Settype

getAllSetTypes

public List<SetType> getAllSetTypes()
Description copied from interface: IP3MDatabase
Retrieve all Settypes from data base.

Specified by:
getAllSetTypes in interface IP3MDatabase
Returns:
list with all Settypes in the database

saveSetType

public void saveSetType(SetType setType)
Description copied from interface: IP3MDatabase
Updates the Settype. This stores all changed/added/removed Set instances as well.

Specified by:
saveSetType in interface IP3MDatabase
Parameters:
setType - the Settype to be updated

deleteSeType

public boolean deleteSeType(SetType setType)
Description copied from interface: IP3MDatabase
Delete SetType from database.

Specified by:
deleteSeType in interface IP3MDatabase
Parameters:
setType - the Settype to be deleted
Returns:
true, if deletion was successful

newProjection

public void newProjection(ProjectionModel projection)
Description copied from interface: IP3MDatabase
Adds new projection to database, automatically adds any Parameter or ParameterInstance entities that have not yet been created.

Specified by:
newProjection in interface IP3MDatabase
Parameters:
projection - the new projection

deleteProjection

public boolean deleteProjection(ProjectionModel projection)
Description copied from interface: IP3MDatabase
Delete projection from database.

Specified by:
deleteProjection in interface IP3MDatabase
Parameters:
projection - the projection to be deleted
Returns:
true, if deletion was successful

getAllProjections

public List<ProjectionModel> getAllProjections()
Description copied from interface: IP3MDatabase
Retrieves list of all projections from the database.

Specified by:
getAllProjections in interface IP3MDatabase
Returns:
list of all projections from the database

getProjectionByID

public ProjectionModel getProjectionByID(int id)
Description copied from interface: IP3MDatabase
Retrieves projection by id.

Specified by:
getProjectionByID in interface IP3MDatabase
Parameters:
id - the id of the projection
Returns:
the projection, null if none was found

saveProjection

public void saveProjection(ProjectionModel projection)
Description copied from interface: IP3MDatabase
Saves projection.

Specified by:
saveProjection in interface IP3MDatabase
Parameters:
projection - the projection to be saved/updated

testConnection

public static Exception testConnection(james.core.data.DBConnectionData dbConnData)
Test connection to database.

Parameters:
dbConnData - the database connection data
Returns:
the exception (null in case of success)

testConnection

public static Exception testConnection(String dbURL,
                                       String dbUserName,
                                       String dbPassword)
Test connection to database.

Parameters:
dbURL - the URL of the database
dbUserName - the DB user name
dbPassword - the DB password
Returns:
the exception

saveTrialResults

public void saveTrialResults(ResultsOfTrial resultOfTrial)
Description copied from interface: IP3MDatabase
Saves results of a single trial. They are reproducible, as they include the specific parameter assignments that were used.

Specified by:
saveTrialResults in interface IP3MDatabase
Parameters:
resultOfTrial - the result of the trial

getAllResults

public List<ResultsOfTrial> getAllResults(ProjectionModel projection)
Description copied from interface: IP3MDatabase
Retrieves all results for the given projection. Take care:

Specified by:
getAllResults in interface IP3MDatabase
Parameters:
projection - the projection
Returns:
the all results

deleteResult

public void deleteResult(ResultsOfTrial resultOfTrial)
Description copied from interface: IP3MDatabase
Deletes a result.

Specified by:
deleteResult in interface IP3MDatabase
Parameters:
resultOfTrial - the result of trial

deleteAllResults

public void deleteAllResults(ProjectionModel projection)
Description copied from interface: IP3MDatabase
Delete all results of the projection.

Specified by:
deleteAllResults in interface IP3MDatabase
Parameters:
projection - the projection

getResultIterator

public IProjectionResultsIterator getResultIterator(ProjectionModel projection)
Description copied from interface: IP3MDatabase
Gets the result iterator.

Specified by:
getResultIterator in interface IP3MDatabase
Parameters:
projection - the projection for which the results shall be gathered
Returns:
the result iterator

clearCache

public void clearCache(Object o)
Description copied from interface: IP3MDatabase
Clears the given object from cache. Use only if you know this object is not going to be needed again (e.g., during a result export).

Specified by:
clearCache in interface IP3MDatabase
Parameters:
o - the object to be cleared from cache

getHibernateConfigFile

public static String getHibernateConfigFile()
Gets the hibernate configuration file.

Returns:
the hibernate configuration file

setHibernateConfigFile

public static void setHibernateConfigFile(String hibernateConfigFile)
Sets the hibernate configuration file.

Parameters:
hibernateConfigFile - the new hibernate configuration file


Copyright © 2012. All Rights Reserved.