Class BeetRootDatabaseManager
java.lang.Object
ch.autumo.beetroot.BeetRootDatabaseManager
Database manager.
Supported databases: H2, MySQL, MariaDB, Oracle, PostgreSQL and
unsupported databases.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConfiguration key of an external JNDI data source.static final StringConfiguration key of the internal data source class name.protected static final org.slf4j.LoggerLogger for this class.static final StringPostfix appended to the connection pool name. -
Method Summary
Modifier and TypeMethodDescriptionintcountRecords(String entity) Count amount of records of an entity / table in database.describeTable(String table) Describe table columns for given table.Get an new DB connection.Get the data source.Returns the data source class name.Returns the JDBC driver class name.Get an new global DB connection.getH2Url()Returns the parsed H2 URL.static BeetRootDatabaseManagerAccess DB manager.getLanguage(int userId) Get language for user.getPass()Returns the database password.getProperty(String name) Get property value from database (table 'properties').getProperty(String name, String defValue) Get property value from database (table 'properties').intgetPropertyInt(String name) Get property value from database (table 'properties').getUrl()Returns the JDBC URL.getUser()Returns the database user.voidInitialize DB manager.voidinitialize(String webAppRootPath) Initialize DB manager.booleanisH2Db()Checks whether the database is H2.booleanHas this database manager been initialized?booleanChecks whether the database is MariaDB.booleanChecks whether the database is MySQL.booleanChecks whether the database is Oracle.booleanChecks whether the database is PostgreSQL.booleanChecks whether PostgreSQL is used with the NG driver.booleanChecks whether the database is unsupported.booleanGet property On/Off value from database (table 'properties').voidrelease()Resource database pool resources.voidresetToken(int dbId) Reset users token.voidRetire a global DB connection.voidupdateLanguage(String lang, int dbId) Update language.
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOGLogger for this class. -
POOL_NAME_POSTFIX
Postfix appended to the connection pool name.- See Also:
-
CFG_KEY_DS_EXT_JNDI
Configuration key of an external JNDI data source.- See Also:
-
CFG_KEY_DS_INT_DSCN
Configuration key of the internal data source class name.- See Also:
-
-
Method Details
-
getInstance
-
isInitialized
public boolean isInitialized()Has this database manager been initialized?- Returns:
- true if so, otherwise false
-
initialize
-
initialize
-
release
public void release()Resource database pool resources. Should be called when a container life-cycle or a server ends! -
getDataSource
-
getConnection
Get an new DB connection.- Returns:
- DB connection
- Throws:
SQLException- SQL exception
-
getGlobalConnection
Get an new global DB connection. You have to roll back or commit the transaction, before you retire it withretireGlobalConnection(Connection). If you useDBroll-backs are done automatically and you'll receive anSQLException. Don't close it by yourself!- Returns:
- global DB connection
- Throws:
SQLException- SQL exception
-
retireGlobalConnection
Retire a global DB connection.- Parameters:
conn- the connection to retire- Throws:
SQLException- SQL exception- See Also:
-
getH2Url
-
isH2Db
public boolean isH2Db()Checks whether the database is H2.- Returns:
- true if the database is H2
-
isMysqlDb
public boolean isMysqlDb()Checks whether the database is MySQL.- Returns:
- true if the database is MySQL
-
isMariaDb
public boolean isMariaDb()Checks whether the database is MariaDB.- Returns:
- true if the database is MariaDB
-
isOracleDb
public boolean isOracleDb()Checks whether the database is Oracle.- Returns:
- true if the database is Oracle
-
isPostgreDb
public boolean isPostgreDb()Checks whether the database is PostgreSQL.- Returns:
- true if the database is PostgreSQL
-
isPostgreDbWithNGDriver
public boolean isPostgreDbWithNGDriver()Checks whether PostgreSQL is used with the NG driver.- Returns:
- true if the NG driver is used
-
isUnsupported
public boolean isUnsupported()Checks whether the database is unsupported.- Returns:
- true if the database is unsupported
-
resetToken
-
countRecords
Count amount of records of an entity / table in database.- Parameters:
entity- entity- Returns:
- amount of records
- Throws:
SQLException- SQL exception
-
onOrOff
Get property On/Off value from database (table 'properties'). If the value isn't found, false is returned.- Parameters:
name- On/Off switch name- Returns:
- true (On) or false (Off, null or any other value not "on" or "On")
- Throws:
SQLException- SQL exception
-
getProperty
-
getPropertyInt
Get property value from database (table 'properties'). If the value isn't found, null is returned. It throws a NullPointerException if value is not found in database.- Parameters:
name- name/key- Returns:
- value for name/key as integer
- Throws:
SQLException- SQL exception
-
getProperty
Get property value from database (table 'properties'). If the value isn't found, null is returned.- Parameters:
name- name/key- Returns:
- value for name/key
- Throws:
SQLException- SQL exception
-
getLanguage
-
updateLanguage
-
describeTable
Describe table columns for given table.- Parameters:
table- database table- Returns:
- list of DB fields with table column descriptions
- Throws:
SQLException- SQL exception
-
getUrl
-
getUser
-
getPass
-
getDriver
-
getDataSourceClassName
Returns the data source class name.- Returns:
- the data source class name
-