tigase.db.jdbc

## Class DataRepositoryImpl

- java.lang.Object
- - tigase.db.jdbc.DataRepositoryImpl

- All Implemented Interfaces:
    DataRepository, DataSource, Repository, RepositoryVersionAware, StatisticsProviderIfc

      public class DataRepositoryImpl
      extends Object
      implements DataRepository, StatisticsProviderIfc, RepositoryVersionAware

  Created: Sep 3, 2010 5:55:41 PM
  Author:
    Artur Hefczyc

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface tigase.db.DataRepository

      `DataRepository.dbTypes`

    - ### Nested classes/interfaces inherited from interface tigase.db.Repository

      `Repository.Meta, Repository.SchemaId`

    - ### Nested classes/interfaces inherited from interface tigase.db.util.RepositoryVersionAware

      `RepositoryVersionAware.SchemaVersion`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DB_CONN_TIMEOUT`
    `static String` | `DB_CONN_TIMEOUT_PROP_KEY`
    `static String` | `DERBY_CHECK_TABLE_QUERY`
    `static String` | `DERBY_CONNVALID_QUERY`
    `static String` | `JDBC_CONNVALID_QUERY`
    `static String` | `JDBC_SCHEMA_VERSION_QUERY`
    `static String` | `MYSQL_CHECK_TABLE_QUERY`
    `static String` | `OTHER_CHECK_TABLE_QUERY`
    `static String` | `PGSQL_CHECK_TABLE_QUERY`
    `static int` | `QUERY_TIMEOUT`
    `static String` | `QUERY_TIMEOUT_PROP_KEY`
    `static String` | `SP_STARTS_WITH`
    `static String` | `SQLSERVER_CHECK_TABLE_QUERY`

    - ### Fields inherited from interface tigase.db.DataRepository

      `UTC_CALENDAR`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DataRepositoryImpl()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `automaticSchemaManagement()`
    `void` | `checkConnectivity(Duration watchdogTime)` This method is called by data source bean watchdog mechanism to ensure that there is proper connectivity to underlying data storage.
    `boolean` | `checkTable(String tableName)` The method checks whether a table for the given name exists in the database.
    `boolean` | `checkTable(String tableName, 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.
    `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
    `protected int` | `getParam(String key, Map<String,String> params, int def)`
    `int` | `getPoolSize()`
    `PreparedStatement` | `getPreparedStatement(BareJID user_id, String stIdKey)` Returns a prepared statement for a given key.
    `PreparedStatement` | `getPreparedStatement(int hashCode, String stIdKey)` Returns a prepared statement for a given key.
    `String` | `getResourceUri()` Returns a DB connection string or DB connection URI.
    `Optional<Version>` | `getSchemaVersion(String component)` Method obtains version of the schema for particular component stored in the database.
    `void` | `getStatistics(String compName, StatisticsList list)`
    `void` | `initialize(String resource_uri)` The method is called to initialize the data repository.
    `void` | `initPreparedStatement(String key, String query)` Initializes a prepared statement for a given query and stores it internally under the given id key.
    `void` | `initPreparedStatement(String key, String query, int autoGeneratedKeys)` Initializes a prepared statement for a given query and stores it internally under the given id key.
    `void` | `initRepository(String resource_uri, Map<String,String> params)` Deprecated.
    `static DataRepository.dbTypes` | `parseDatabaseType(String resource_uri)`
    `void` | `release(Statement stmt, 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`

    - ### Methods inherited from interface tigase.db.DataRepository

      `getTimestamp, getTimestamp, setTimestamp`

    - ### Methods inherited from interface tigase.db.DataSource

      `checkSchemaVersion`

    - ### Methods inherited from interface tigase.db.util.RepositoryVersionAware

      `getVersion, updateSchema`

- - ### Field Detail

    - #### DERBY_CONNVALID_QUERY

          public static final String DERBY_CONNVALID_QUERY

      See Also:
        Constant Field Values

    - #### JDBC_CONNVALID_QUERY

          public static final String JDBC_CONNVALID_QUERY

      See Also:
        Constant Field Values

    - #### JDBC_SCHEMA_VERSION_QUERY

          public static final String JDBC_SCHEMA_VERSION_QUERY

      See Also:
        Constant Field Values

    - #### MYSQL_CHECK_TABLE_QUERY

          public static final String MYSQL_CHECK_TABLE_QUERY

      See Also:
        Constant Field Values

    - #### PGSQL_CHECK_TABLE_QUERY

          public static final String PGSQL_CHECK_TABLE_QUERY

      See Also:
        Constant Field Values

    - #### DERBY_CHECK_TABLE_QUERY

          public static final String DERBY_CHECK_TABLE_QUERY

      See Also:
        Constant Field Values

    - #### SQLSERVER_CHECK_TABLE_QUERY

          public static final String SQLSERVER_CHECK_TABLE_QUERY

      See Also:
        Constant Field Values

    - #### OTHER_CHECK_TABLE_QUERY

          public static final String OTHER_CHECK_TABLE_QUERY

      See Also:
        Constant Field Values

    - #### SP_STARTS_WITH

          public static final String SP_STARTS_WITH

      See Also:
        Constant Field Values

    - #### QUERY_TIMEOUT_PROP_KEY

          public static final String QUERY_TIMEOUT_PROP_KEY

      See Also:
        Constant Field Values

    - #### QUERY_TIMEOUT

          public static final int QUERY_TIMEOUT

      See Also:
        Constant Field Values

    - #### DB_CONN_TIMEOUT_PROP_KEY

          public static final String DB_CONN_TIMEOUT_PROP_KEY

      See Also:
        Constant Field Values

    - #### DB_CONN_TIMEOUT

          public static final int DB_CONN_TIMEOUT

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### DataRepositoryImpl

          public DataRepositoryImpl()

  - ### Method Detail

    - #### automaticSchemaManagement

          public boolean automaticSchemaManagement()

      Specified by:
        `automaticSchemaManagement` in interface `DataSource`

    - #### getSchemaVersion

          public Optional<Version> getSchemaVersion(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(String tableName)
                             throws 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:
        `SQLException` - if there was a problem accessing database.

    - #### checkTable

          public boolean checkTable(String tableName,
                                    String createTableQuery)
                             throws 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:
        `SQLException` - if there was a problem accessing database.

    - #### checkConnectivity

          public void checkConnectivity(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

    - #### createStatement

          public Statement createStatement(BareJID user_id)
                                    throws 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:
        `SQLException` - if a JDBC error occurs.

    - #### getPreparedStatement

          public PreparedStatement getPreparedStatement(BareJID user_id,
                                                        String stIdKey)
                                                 throws 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:
        `SQLException`

    - #### getPreparedStatement

          public PreparedStatement getPreparedStatement(int hashCode,
                                                        String stIdKey)
                                                 throws 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:
        `SQLException`

    - #### getResourceUri

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

    - #### getDatabaseType

          public DataRepository.dbTypes getDatabaseType()

      Description copied from interface: `DataRepository`
      Returns type of DataRepository database
      Specified by:
        `getDatabaseType` in interface `DataRepository`
      Returns:
        a value of `dbTypes`

    - #### initPreparedStatement

          public void initPreparedStatement(String key,
                                            String query)
                                     throws 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:
        `key` - is a statement identification key.
        `query` - is a query for the prepared statement.
      Throws:
        `SQLException`

    - #### initPreparedStatement

          public void initPreparedStatement(String key,
                                            String query,
                                            int autoGeneratedKeys)
                                     throws 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:
        `key` - is a statement identification key.
        `query` - is a query for the prepared statement.
        `autoGeneratedKeys` - defines if statement should return auto generated keys
      Throws:
        `SQLException`

    - #### initialize

          public void initialize(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`

    - #### parseDatabaseType

          public static DataRepository.dbTypes parseDatabaseType(String resource_uri)

    - #### initRepository

          @Deprecated
          public void initRepository(String resource_uri,
                                                 Map<String,String> params)
                                          throws DBInitException

      Deprecated.
      Description copied from interface: `Repository`
      Method is deprecated and should not be user any more.
      The method is called to initialize the data repository. Depending on the implementation all the initialization parameters can be passed either via `resource_uri` parameter as the database connection string or via `params` map if the required repository parameters are more complex or both.
      Specified by:
        `initRepository` in interface `Repository`
      Parameters:
        `resource_uri` - value in most cases representing the database connection string.
        `params` - is a `Map` with repository properties necessary to initialize and perform all the functions. The initialization parameters are implementation dependent.
      Throws:
        `DBInitException` - if there was an error during repository initialization. Some implementations, though, perform so called lazy initialization so even though there is a problem with the underlying repository it may not be signaled through this method call.

    - #### release

          public void release(Statement stmt,
                              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.

    - #### 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.

    - #### startTransaction

          public void startTransaction()
                                throws 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:
        `SQLException`

    - #### commit

          public void commit()
                      throws 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:
        `SQLException`

    - #### rollback

          public void rollback()
                        throws 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:
        `SQLException`

    - #### endTransaction

          public void endTransaction()
                              throws 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:
        `SQLException`

    - #### releaseRepoHandle

          public void releaseRepoHandle(DataRepository repo)

      Specified by:
        `releaseRepoHandle` in interface `DataRepository`

    - #### getStatistics

          public void getStatistics(String compName,
                                    StatisticsList list)

      Specified by:
        `getStatistics` in interface `StatisticsProviderIfc`

    - #### getPoolSize

          public int getPoolSize()

      Specified by:
        `getPoolSize` in interface `DataRepository`

    - #### getParam

          protected int getParam(String key,
                                 Map<String,String> params,
                                 int def)

Copyright © 2004–2021 "Tigase, Inc.". All rights reserved.