Class BeetRootDatabaseManager

java.lang.Object
ch.autumo.beetroot.BeetRootDatabaseManager

public class BeetRootDatabaseManager extends Object
Database manager. Supported databases: H2, MySQL, MariaDB, Oracle, PostgreSQL and unsupported databases.
  • Field Details

  • Method Details

    • getInstance

      public static BeetRootDatabaseManager getInstance()
      Access DB manager.
      Returns:
      DB manager
    • isInitialized

      public boolean isInitialized()
      Has this database manager been initialized?
      Returns:
      true if so, otherwise false
    • initialize

      public void initialize(String webAppRootPath) throws Exception
      Initialize DB manager.
      Parameters:
      webAppRootPath - Web app root path
      Throws:
      Exception - exception
    • initialize

      public void initialize() throws Exception
      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

      public DataSource getDataSource()
      Get the data source.
      Returns:
      data source
    • getConnection

      public Connection getConnection() throws SQLException
      Get an new DB connection.
      Returns:
      DB connection
      Throws:
      SQLException - SQL exception
    • getGlobalConnection

      public Connection getGlobalConnection() throws SQLException
      Get an new global DB connection. You have to roll back or commit the transaction, before you retire it with retireGlobalConnection(Connection). If you use DB roll-backs are done automatically and you'll receive an SQLException. Don't close it by yourself!
      Returns:
      global DB connection
      Throws:
      SQLException - SQL exception
    • retireGlobalConnection

      public void retireGlobalConnection(Connection conn) throws SQLException
      Retire a global DB connection.
      Throws:
      SQLException - SQL exception
      See Also:
    • getH2Url

      public H2Url 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

      public void resetToken(int dbId) throws Exception
      Reset users token.
      Parameters:
      dbId - user id
      Throws:
      Exception - exception
    • countRecords

      public int countRecords(String entity) throws SQLException
      Count amount of records of an entity / table in database.
      Parameters:
      entity - entity
      Returns:
      amount of records
      Throws:
      SQLException - SQL exception
    • onOrOff

      public boolean onOrOff(String name) throws SQLException
      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

      public String getProperty(String name, String defValue)
      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/key
      defValue - default value
      Returns:
      value for name/key
    • getPropertyInt

      public int getPropertyInt(String name) throws SQLException
      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

      public String getProperty(String name) throws SQLException
      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

      public String getLanguage(int userId) throws Exception
      Get language for user.
      Parameters:
      userId - user id
      Returns:
      language
      Throws:
      Exception - exception
    • updateLanguage

      public void updateLanguage(String lang, int dbId) throws Exception
      Update language.
      Parameters:
      lang - language code
      dbId - user id
      Throws:
      Exception - exception
    • describeTable

      public List<DBField> describeTable(String table) throws SQLException
      Describe table columns for given table.
      Parameters:
      table - database table
      Returns:
      list of DB fields with table column descriptions
      Throws:
      SQLException - SQL exception
    • getUrl

      public String getUrl()
    • getUser

      public String getUser()
    • getPass

      public String getPass()
    • getDriver

      public String getDriver()
    • getDataSourceClassName

      public String getDataSourceClassName()