Class DatabaseManager
java.lang.Object
ch.autumo.commons.database.DatabaseManager
Commons Database Manager.
Supported databases: H2, MySQL, MariaDB, Oracle, PostgreSQL.
-
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 data-source class name.Get driver class.Get an new global DB connection.getH2Url()Get H2 URL.static DatabaseManagerAccess DB manager.getLanguage(int dbId) Get language for user.getPass()Get password.getProperty(String name) Get property value from database (table 'properties').getUrl()Get database connection URL.getUser()Get user.voidInitialize DB manager.booleanisH2Db()Is a Java H2 database used?booleanHas this database manager been initialized?booleanIs a Maria database used?booleanIs a MySQL database used?booleanIs an Oracle database used?booleanIs a PostgreSQL database used?booleanIs a PostgreSQL database with NG driver used?booleanIs databse unsupported? This doesn't mean that it cannot work, but the SQL used are not verified for the unsupported database's SQL dialect.voidrelease()Resource database pool resources.voidRetire a global DB connection.voidupdateLanguage(String lang, int dbUserId) Update language.
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOGLogger. -
POOL_NAME_POSTFIX
-
CFG_KEY_DS_EXT_JNDI
-
CFG_KEY_DS_INT_DSCN
-
-
Method Details
-
getInstance
-
isInitialized
public boolean isInitialized()Has this database manager been initialized?- Returns:
- true if so, otherwise false
-
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- if a connection cannot be acquired
-
getGlobalConnection
Get an new global DB connection. You have to roll back or commit the transaction, before you retire it withretireGlobalConnection(Connection). If you useDBUtilsroll-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- connection- Throws:
SQLException- SQL exception- See Also:
-
getH2Url
-
isH2Db
public boolean isH2Db()Is a Java H2 database used?- Returns:
- true if so
-
isMysqlDb
public boolean isMysqlDb()Is a MySQL database used?- Returns:
- true if so
-
isMariaDb
public boolean isMariaDb()Is a Maria database used?- Returns:
- true if so
-
isOracleDb
public boolean isOracleDb()Is an Oracle database used?- Returns:
- true if so
-
isPostgreDb
public boolean isPostgreDb()Is a PostgreSQL database used?- Returns:
- true if so
-
isPostgreDbWithNGDriver
public boolean isPostgreDbWithNGDriver()Is a PostgreSQL database with NG driver used?- Returns:
- true if so
-
isUnsupported
public boolean isUnsupported()Is databse unsupported? This doesn't mean that it cannot work, but the SQL used are not verified for the unsupported database's SQL dialect.- Returns:
- true if so
-
countRecords
Count amount of records of an entity / table in database.- Parameters:
entity- entity- Returns:
- amount of records
- Throws:
SQLException- if records cannot be counted
-
getProperty
-
getLanguage
-
updateLanguage
-
describeTable
Describe table columns for given table.- Parameters:
table- database table- Returns:
- list of DB fields with table column descriptions
- Throws:
SQLException- if table description cannot be read from database
-
getUrl
-
getUser
-
getPass
-
getDriver
-
getDataSourceClassName
-