Class DataRepoPool

    • Constructor Summary

      Constructors 
      Constructor Description
      DataRepoPool()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addRepo​(DataRepository repo)
      Method called to add instance of a repository to the repository pool.
      boolean automaticSchemaManagement()  
      void checkConnectivity​(java.time.Duration watchdogTime)
      This method is called by data source bean watchdog mechanism to ensure that there is proper connectivity to underlying data storage.
      boolean checkSchemaVersion​(DataSourceAware<? extends DataSource> datasource, boolean shutdownServer)
      Method checks version of the particular DataSource stored in the defined source.
      boolean checkTable​(java.lang.String tableName)
      The method checks whether a table for the given name exists in the database.
      boolean checkTable​(java.lang.String tableName, java.lang.String createTableQuery)
      The method checks whether a table for the given name exists in the database and if it does not, it automatically creates it.
      void commit()
      Commits current transaction on the DataRepository connection.
      java.sql.Statement createStatement​(BareJID user_id)
      Creates a SQL statement on which SQL queries can be executed later by the higher repository layer.
      void endTransaction()
      Ends current transaction on the DataRepository connection.
      DataRepository.dbTypes getDatabaseType()
      Returns type of DataRepository database
      int getPoolSize()  
      java.sql.PreparedStatement getPreparedStatement​(int hashCode, java.lang.String stIdKey)
      Returns a prepared statement for a given key.
      java.sql.PreparedStatement getPreparedStatement​(BareJID user_id, java.lang.String stIdKey)
      Returns a prepared statement for a given key.
      java.lang.String getResourceUri()
      Returns a DB connection string or DB connection URI.
      java.util.Optional<Version> getSchemaVersion​(java.lang.String component)
      Method obtains version of the schema for particular component stored in the database.
      void initialize​(java.lang.String resource_uri)
      The method is called to initialize the data repository.
      void initPreparedStatement​(java.lang.String stIdKey, java.lang.String query)
      Initializes a prepared statement for a given query and stores it internally under the given id key.
      void initPreparedStatement​(java.lang.String stIdKey, java.lang.String query, int autoGeneratedKeys)
      Initializes a prepared statement for a given query and stores it internally under the given id key.
      void release​(java.sql.Statement stmt, java.sql.ResultSet rs)
      A helper method to release resources from the statement and result set.
      void releaseRepoHandle​(DataRepository repo)  
      void rollback()
      Rolls back started transaction on the DataRepository connection.
      void startTransaction()
      Starts transaction on the DataRepository connection.
      DataRepository takeRepoHandle​(BareJID user_id)
      Returns DataRepository instance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DataRepoPool

        public DataRepoPool()
    • Method Detail

      • takeRepoHandle

        public DataRepository takeRepoHandle​(BareJID user_id)
        Description copied from interface: DataRepository
        Returns DataRepository instance. If this is a repository pool then it returns particular instance from the pool. It this is a real repository instance it returns itself. This is exclusive take, no other thread may use this handle until it is returned to the pool.
        Specified by:
        takeRepoHandle in interface DataRepository
        Parameters:
        user_id - is user account ID for which we acquire the handle.
        Returns:
        DataRepository instance.
      • checkConnectivity

        public void checkConnectivity​(java.time.Duration watchdogTime)
        Description copied from interface: DataSource
        This method is called by data source bean watchdog mechanism to ensure that there is proper connectivity to underlying data storage.
        Specified by:
        checkConnectivity in interface DataSource
        Parameters:
        watchdogTime - time which should pass between checks
      • checkSchemaVersion

        public boolean checkSchemaVersion​(DataSourceAware<? extends DataSource> datasource,
                                          boolean shutdownServer)
        Description copied from interface: DataSource
        Method checks version of the particular DataSource stored in the defined source.
        Specified by:
        checkSchemaVersion in interface DataSource
        Parameters:
        datasource - implementation of DataSourceAware interface
        shutdownServer - specifies whether server should be shutdown automatically if the version in the database doesn't match required version.
        Returns:
        a false when the version doesn't match or there is no version information in the repository. if shutdownServer is set to true and the component version is final it would force shutting down of the server, otherwise (for non-final version) only a warning would be printed.
      • getSchemaVersion

        public java.util.Optional<Version> getSchemaVersion​(java.lang.String component)
        Description copied from interface: DataSource
        Method obtains version of the schema for particular component stored in the database.
        Specified by:
        getSchemaVersion in interface DataSource
        Parameters:
        component - name of the component for which we want to get the schema version
        Returns:
        an optional value of the version.
      • checkTable

        public boolean checkTable​(java.lang.String tableName)
                           throws java.sql.SQLException
        Description copied from interface: DataRepository
        The method checks whether a table for the given name exists in the database.
        Specified by:
        checkTable in interface DataRepository
        Parameters:
        tableName - is a String value of the table name to check
        Returns:
        true boolean value if the table exist in the database and false if the table was not found.
        Throws:
        java.sql.SQLException - if there was a problem accessing database.
      • checkTable

        public boolean checkTable​(java.lang.String tableName,
                                  java.lang.String createTableQuery)
                           throws java.sql.SQLException
        Description copied from interface: DataRepository
        The method checks whether a table for the given name exists in the database and if it does not, it automatically creates it.
        Specified by:
        checkTable in interface DataRepository
        Parameters:
        tableName - is a String value of the table name to check
        createTableQuery - is a String with the query to create table
        Returns:
        true boolean value if the table exist in the database and false if the table was not found.
        Throws:
        java.sql.SQLException - if there was a problem accessing database.
      • createStatement

        public java.sql.Statement createStatement​(BareJID user_id)
                                           throws java.sql.SQLException
        Description copied from interface: DataRepository
        Creates a SQL statement on which SQL queries can be executed later by the higher repository layer.
        Specified by:
        createStatement in interface DataRepository
        Parameters:
        user_id - user id for which the statement has to be created. This is an optional parameter and null can be provided. It is used mainly to group queries for the same user on the same DB connection.
        Returns:
        a newly created Statement
        Throws:
        java.sql.SQLException - if a JDBC error occurs.
      • getPreparedStatement

        public java.sql.PreparedStatement getPreparedStatement​(BareJID user_id,
                                                               java.lang.String stIdKey)
                                                        throws java.sql.SQLException
        Description copied from interface: DataRepository
        Returns a prepared statement for a given key.
        Specified by:
        getPreparedStatement in interface DataRepository
        Parameters:
        user_id - user id for which the statement has to be created. This is an optional parameter and null can be provided. It is used mainly to group queries for the same user on the same DB connection.
        stIdKey - is a statement identification key.
        Returns:
        a PreparedStatement for the given id key or null if such a statement does not exist.
        Throws:
        java.sql.SQLException
      • getPreparedStatement

        public java.sql.PreparedStatement getPreparedStatement​(int hashCode,
                                                               java.lang.String stIdKey)
                                                        throws java.sql.SQLException
        Description copied from interface: DataRepository
        Returns a prepared statement for a given key.
        Specified by:
        getPreparedStatement in interface DataRepository
        Parameters:
        hashCode - user for selection of connection to use. It is used mainly to group queries for the same user on the same DB connection.
        stIdKey - is a statement identification key.
        Returns:
        a PreparedStatement for the given id key or null if such a statement does not exist.
        Throws:
        java.sql.SQLException
      • getResourceUri

        public java.lang.String getResourceUri()
        Description copied from interface: DataRepository
        Returns a DB connection string or DB connection URI.
        Specified by:
        getResourceUri in interface DataRepository
        Specified by:
        getResourceUri in interface DataSource
        Returns:
        a String value representing database connection string.
      • initPreparedStatement

        public void initPreparedStatement​(java.lang.String stIdKey,
                                          java.lang.String query)
                                   throws java.sql.SQLException
        Description copied from interface: DataRepository
        Initializes a prepared statement for a given query and stores it internally under the given id key. It can be retrieved later using getPreparedStatement(stIdKey) method.
        Specified by:
        initPreparedStatement in interface DataRepository
        Parameters:
        stIdKey - is a statement identification key.
        query - is a query for the prepared statement.
        Throws:
        java.sql.SQLException
      • initPreparedStatement

        public void initPreparedStatement​(java.lang.String stIdKey,
                                          java.lang.String query,
                                          int autoGeneratedKeys)
                                   throws java.sql.SQLException
        Description copied from interface: DataRepository
        Initializes a prepared statement for a given query and stores it internally under the given id key. It can be retrieved later using getPreparedStatement(stIdKey) method.
        Specified by:
        initPreparedStatement in interface DataRepository
        Parameters:
        stIdKey - is a statement identification key.
        query - is a query for the prepared statement.
        autoGeneratedKeys - defines if statement should return auto generated keys
        Throws:
        java.sql.SQLException
      • initialize

        public void initialize​(java.lang.String resource_uri)
                        throws DBInitException
        Description copied from interface: DataSource
        The method is called to initialize the data repository.
        Specified by:
        initialize in interface DataSource
        Parameters:
        resource_uri - value in most cases representing the database connection string.
        Throws:
        DBInitException
      • release

        public void release​(java.sql.Statement stmt,
                            java.sql.ResultSet rs)
        Description copied from interface: DataRepository
        A helper method to release resources from the statement and result set. This is most common operation for all database calls, therefore it does make sense to add such a utility method to the API.
        Specified by:
        release in interface DataRepository
        Parameters:
        stmt - a Statement variable to release resources for. Might be null.
        rs - a ResultSet variable to release resources for. Might be null.
      • startTransaction

        public void startTransaction()
                              throws java.sql.SQLException
        Description copied from interface: DataRepository
        Starts transaction on the DataRepository connection. Please note that calling this method on the repository pool has no effect. You have to obtain particular repository handle first, before you can start transaction.
        Specified by:
        startTransaction in interface DataRepository
        Throws:
        java.sql.SQLException
      • commit

        public void commit()
                    throws java.sql.SQLException
        Description copied from interface: DataRepository
        Commits current transaction on the DataRepository connection. Please note that calling this method on the repository pool has no effect. You have to obtain particular repository handle first, before you can start transaction.
        Specified by:
        commit in interface DataRepository
        Throws:
        java.sql.SQLException
      • rollback

        public void rollback()
                      throws java.sql.SQLException
        Description copied from interface: DataRepository
        Rolls back started transaction on the DataRepository connection. Please note that calling this method on the repository pool has no effect. You have to obtain particular repository handle first, before you can start transaction.
        Specified by:
        rollback in interface DataRepository
        Throws:
        java.sql.SQLException
      • endTransaction

        public void endTransaction()
                            throws java.sql.SQLException
        Description copied from interface: DataRepository
        Ends current transaction on the DataRepository connection. Please note that calling this method on the repository pool has no effect. You have to obtain particular repository handle first, before you can start transaction.
        Specified by:
        endTransaction in interface DataRepository
        Throws:
        java.sql.SQLException