tigase.db

## Interface DataRepository

- All Known Implementing Classes:
    DataRepositoryImpl, DataRepositoryPool

      public interface DataRepository

  The interface defines a generic data repository for storing arbitrary data in any application specific form. This interface unifies database (repository) access allowing for easier way to create database connections pools or database fail-over mechanisms. Created: Jun 16, 2010 3:34:32 PM
  Version:
    $Rev$
  Author:
    Artur Hefczyc

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Interface and Description
    --- | ---
    `static class` | `DataRepository.dbTypes` Helper enumeration with types of supported databases.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `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(tigase.xmpp.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
    `PreparedStatement` | `getPreparedStatement(tigase.xmpp.BareJID user_id, String stIdKey)` Returns a prepared statement for a given key.
    `String` | `getResourceUri()` Returns a DB connection string or DB connection URI.
    `void` | `initPreparedStatement(String stIdKey, String query)` 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)` The method is called to initialize the data repository.
    `void` | `release(Statement stmt, ResultSet rs)` A helper method to release resources from the statement and result set.
    `void` | `releaseRepoHandle(DataRepository repo)` Method description
    `void` | `rollback()` Rolls back started transaction on the DataRepository connection.
    `void` | `startTransaction()` Starts transaction on the DataRepository connection.
    `DataRepository` | `takeRepoHandle(tigase.xmpp.BareJID user_id)` Returns `DataRepository` instance.

- - ### Method Detail

    - #### checkTable

          boolean checkTable(String tableName)
                             throws SQLException

      The method checks whether a table for the given name exists in the database.
      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

          boolean checkTable(String tableName,
                           String createTableQuery)
                             throws SQLException

      The method checks whether a table for the given name exists in the database and if it does not, it automatically creates it.
      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.

    - #### commit

          void commit()
                      throws SQLException

      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.
      Throws:
        `SQLException`

    - #### createStatement

          Statement createStatement(tigase.xmpp.BareJID user_id)
                                    throws SQLException

      Creates a SQL statement on which SQL queries can be executed later by the higher repository layer.
      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.

    - #### endTransaction

          void endTransaction()
                              throws SQLException

      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.
      Throws:
        `SQLException`

    - #### initPreparedStatement

          void initPreparedStatement(String stIdKey,
                                   String query)
                                     throws SQLException

      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.
      Parameters:
        `stIdKey` - is a statement identification key.
        `query` - is a query for the prepared statement.
      Throws:
        `SQLException`

    - #### initRepository

          void initRepository(String resource_uri,
                            Map<String,String> params)
                              throws SQLException

      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.
      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:
        `SQLException` - 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

          void release(Statement stmt,
                     ResultSet rs)

      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.
      Parameters:
        `stmt` - a `Statement` variable to release resources for. Might be null.
        `rs` - a `ResultSet` variable to release resources for. Might be null.

    - #### releaseRepoHandle

          void releaseRepoHandle(DataRepository repo)

      Method description
      Parameters:
        `repo` - is a `DataRepository`

    - #### rollback

          void rollback()
                        throws SQLException

      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.
      Throws:
        `SQLException`

    - #### startTransaction

          void startTransaction()
                                throws SQLException

      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.
      Throws:
        `SQLException`

    - #### takeRepoHandle

          DataRepository takeRepoHandle(tigase.xmpp.BareJID user_id)

      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.
      Parameters:
        `user_id` - is user account ID for which we acquire the handle.
      Returns:
        DataRepository instance.

    - #### getDatabaseType

          DataRepository.dbTypes getDatabaseType()

      Returns type of DataRepository database
      Returns:
        a value of `dbTypes`

    - #### getPreparedStatement

          PreparedStatement getPreparedStatement(tigase.xmpp.BareJID user_id,
                                               String stIdKey)
                                                 throws SQLException

      Returns a prepared statement for a given key.
      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`

    - #### getResourceUri

          String getResourceUri()

      Returns a DB connection string or DB connection URI.
      Returns:
        a `String` value representing database connection string.

Copyright © 2014 "Tigase, Inc.". All rights reserved.