Package cz.metacentrum.perun.core.bl
Interface DatabaseManagerBl
- All Known Implementing Classes:
DatabaseManagerBlImpl
public interface DatabaseManagerBl
Database manager can work with database version and upgraded state of perun DB.
- Author:
- Michal Stava email:<stavamichal@gmail.com>
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
createProperty
(String property) Create new property in configurations.getChangelogVersions
(String currentDBVersion, String fileName) Parses all new database versions from DB changelog file and creates from them list of DBVersion objects.Return current database version in string (ex.Get DB driver information from datasource (name-version)Get DB information from datasource (name-version)Return JDBC template for performing custom simple SQLs where jdbc is not normally availablelong
Get time in ns "nanoseconds" of calling 1 simple update query to DB.static Array
prepareSQLArrayOfNumbers
(List<? extends PerunBean> perunBeans, PreparedStatement preparedStatement) Take list of perunBeans and generate an array of ids in sql database from it.static Array
prepareSQLArrayOfNumbersFromIntegers
(List<Integer> integers, PreparedStatement preparedStatement) Take list of integers and generate an array of integers in sql database from it.static Array
prepareSQLArrayOfStrings
(List<String> strings, PreparedStatement preparedStatement) Take list of String and generate an array in sql database from it.boolean
propertyExists
(String property) Return true if property already exists, false if not.void
updateDatabaseVersion
(List<DBVersion> dbVersions) Method updates database to the current code version.
-
Field Details
-
NAME_OF_ORACLE_ARRAY_METHOD
- See Also:
-
-
Method Details
-
prepareSQLArrayOfNumbers
static Array prepareSQLArrayOfNumbers(List<? extends PerunBean> perunBeans, PreparedStatement preparedStatement) throws SQLException Take list of perunBeans and generate an array of ids in sql database from it. Implementation can be different for every type of supported DB- Parameters:
perunBeans
- list of PerunBeans to get Ids frompreparedStatement
- database prepared statement to get working connection- Returns:
- java sql array with pre-loaded list of ids
- Throws:
SQLException
- if any sql exception has been thrownInternalErrorException
- if oracle method to work with an array can't be get or invoked
-
prepareSQLArrayOfNumbersFromIntegers
static Array prepareSQLArrayOfNumbersFromIntegers(List<Integer> integers, PreparedStatement preparedStatement) throws SQLException Take list of integers and generate an array of integers in sql database from it. Implementation can be different for every type of supported DB- Parameters:
integers
- list of integerspreparedStatement
- database prepared statement to get working connection- Returns:
- java sql array with pre-loaded list of integers
- Throws:
SQLException
- if any sql exception has been thrownInternalErrorException
- if oracle method to work with an array can't be get or invoked
-
prepareSQLArrayOfStrings
static Array prepareSQLArrayOfStrings(List<String> strings, PreparedStatement preparedStatement) throws SQLException Take list of String and generate an array in sql database from it. Implementation can be different for every type of supported DB- Parameters:
strings
- list of Strings to get an sql array frompreparedStatement
- database prepared statement to get working connection- Returns:
- java sql array with pre-loaded list of strings
- Throws:
SQLException
- if any sql exception has been thrownInternalErrorException
- if oracle method to work with an array can't be get or invoked
-
createProperty
Create new property in configurations. Initial value will be "N/A".- Parameters:
property
- name of property to be created
-
getChangelogVersions
Parses all new database versions from DB changelog file and creates from them list of DBVersion objects. The list contains all versions from currentDBVersion (without currentDBVersion itself) to now (the version at the top of the changelog file)- Parameters:
currentDBVersion
- current DB versionfileName
- DB changelog file name, file should be in resources- Returns:
- list of DBVersion objects ordered by version descending
- Throws:
InternalErrorException
- if 1.there is an error reading file, 2.currentDBVersion was not found 3.DBVersion does not match pattern 4.DB versions are not ordered as they should be
-
getCurrentDatabaseVersion
String getCurrentDatabaseVersion()Return current database version in string (ex. 3.0.1)- Returns:
- return current database version
- Throws:
InternalErrorException
-
getDatabaseDriverInformation
String getDatabaseDriverInformation()Get DB driver information from datasource (name-version)- Returns:
- string information about database driver
- Throws:
InternalErrorException
-
getDatabaseInformation
String getDatabaseInformation()Get DB information from datasource (name-version)- Returns:
- string information about database
- Throws:
InternalErrorException
-
getJdbcPerunTemplate
JdbcPerunTemplate getJdbcPerunTemplate()Return JDBC template for performing custom simple SQLs where jdbc is not normally available- Returns:
- Peruns JDBC template
-
getTimeOfQueryPerformance
long getTimeOfQueryPerformance()Get time in ns "nanoseconds" of calling 1 simple update query to DB. This query will update property for this purpose in configurations table.- Returns:
- time of processing query in nanoseconds
-
propertyExists
Return true if property already exists, false if not.- Parameters:
property
- name of property to check existence- Returns:
- true if property exists, false if not
-
updateDatabaseVersion
Method updates database to the current code version. It takes list of dbVersions and executes all the commands from them. Commands from the oldest (lowest) version are executed first.- Parameters:
dbVersions
- list of dbVersion objects ordered by version descending, should not be empty- Throws:
InternalErrorException
- if any of the commands fails to execute
-