Package ch.autumo.beetroot
Class BeetRootDatabaseManager
java.lang.Object
ch.autumo.beetroot.BeetRootDatabaseManager
Database manager.
Supported databases: H2, MySQL, MariaDB, Oracle, PostgreSQL and
unsupported databases.
-
Field Summary
Fields -
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.Get an new global DB connection.getH2Url()static BeetRootDatabaseManagerAccess DB manager.getLanguage(int userId) Get language for user.getPass()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()getUser()voidInitialize DB manager.voidinitialize(String webAppRootPath) Initialize DB manager.booleanisH2Db()booleanHas this database manager been initialized?booleanbooleanbooleanbooleanbooleanbooleanbooleanGet 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 LOG -
POOL_NAME_POSTFIX
- See Also:
-
CFG_KEY_DS_EXT_JNDI
- See Also:
-
CFG_KEY_DS_INT_DSCN
- See Also:
-
-
Method Details
-
getInstance
Access DB manager.- Returns:
- DB manager
-
isInitialized
public boolean isInitialized()Has this database manager been initialized?- Returns:
- true if so, otherwise false
-
initialize
Initialize DB manager.- Parameters:
webAppRootPath- Web app root path- Throws:
Exception- exception
-
initialize
Initialize DB manager.- Throws:
Exception- exception
-
release
public void release()Resource database pool resources. Should be called when a container life-cycle or a server ends! -
getDataSource
Get the data source.- Returns:
- data source
-
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.- Throws:
SQLException- SQL exception- See Also:
-
getH2Url
-
isH2Db
public boolean isH2Db() -
isMysqlDb
public boolean isMysqlDb() -
isMariaDb
public boolean isMariaDb() -
isOracleDb
public boolean isOracleDb() -
isPostgreDb
public boolean isPostgreDb() -
isPostgreDbWithNGDriver
public boolean isPostgreDbWithNGDriver() -
isUnsupported
public boolean isUnsupported() -
resetToken
Reset users token.- Parameters:
dbId- user id- Throws:
Exception- exception
-
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
Get property value from database (table 'properties'). If the value isn't found or an exception occurs, the default value is returned.- Parameters:
name- name/keydefValue- default value- Returns:
- value for name/key
-
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
Get language for user.- Parameters:
userId- user id- Returns:
- language
- Throws:
Exception- exception
-
updateLanguage
Update language.- Parameters:
lang- language codedbId- user id- Throws:
Exception- exception
-
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
-