Package tigase.db.converter
Class DataRepoPool
java.lang.Object
tigase.db.converter.DataRepoPool
- All Implemented Interfaces:
DataRepository
,DataSource
,DataSourcePool<DataRepository>
,Repository
,RepositoryPool<DataRepository>
-
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
-
Field Summary
Fields inherited from interface tigase.db.DataRepository
UTC_CALENDAR
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addRepo
(DataRepository repo) Method called to add instance of a repository to the repository pool.boolean
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
checkSchemaVersion
(DataSourceAware<? extends DataSource> datasource, boolean shutdownServer) Method checks version of the particular DataSource stored in the defined source.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.createStatement
(BareJID user_id) Creates a SQL statement on which SQL queries can be executed later by the higher repository layer.void
Ends current transaction on the DataRepository connection.Returns type of DataRepository databaseint
getPreparedStatement
(int hashCode, String stIdKey) Returns a prepared statement for a given key.getPreparedStatement
(BareJID user_id, String stIdKey) Returns a prepared statement for a given key.Returns a DB connection string or DB connection URI.getSchemaVersion
(String component) Method obtains version of the schema for particular component stored in the database.void
initialize
(String resource_uri) The method is called to initialize the data repository.void
initPreparedStatement
(String stIdKey, String query) Initializes a prepared statement for a given query and stores it internally under the given id key.void
initPreparedStatement
(String stIdKey, String query, int autoGeneratedKeys) Initializes a prepared statement for a given query and stores it internally under the given id key.void
A helper method to release resources from the statement and result set.void
void
rollback()
Rolls back started transaction on the DataRepository connection.void
Starts transaction on the DataRepository connection.takeRepoHandle
(BareJID user_id) ReturnsDataRepository
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.Repository
initRepository
-
Constructor Details
-
DataRepoPool
public DataRepoPool()
-
-
Method Details
-
addRepo
Description copied from interface:RepositoryPool
Method called to add instance of a repository to the repository pool.- Specified by:
addRepo
in interfaceRepositoryPool<DataRepository>
- Parameters:
repo
- instance of a repository
-
takeRepoHandle
Description copied from interface:DataRepository
ReturnsDataRepository
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 interfaceDataRepository
- Parameters:
user_id
- is user account ID for which we acquire the handle.- Returns:
- DataRepository instance.
-
releaseRepoHandle
- Specified by:
releaseRepoHandle
in interfaceDataRepository
-
automaticSchemaManagement
public boolean automaticSchemaManagement()- Specified by:
automaticSchemaManagement
in interfaceDataSource
-
checkConnectivity
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 interfaceDataSource
- 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 interfaceDataSource
- Parameters:
datasource
- implementation ofDataSourceAware
interfaceshutdownServer
- 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. ifshutdownServer
is set totrue
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
Description copied from interface:DataSource
Method obtains version of the schema for particular component stored in the database.- Specified by:
getSchemaVersion
in interfaceDataSource
- Parameters:
component
- name of the component for which we want to get the schema version- Returns:
- an optional value of the version.
-
checkTable
Description copied from interface:DataRepository
The method checks whether a table for the given name exists in the database.- Specified by:
checkTable
in interfaceDataRepository
- Parameters:
tableName
- is aString
value of the table name to check- Returns:
true
boolean
value if the table exist in the database andfalse
if the table was not found.- Throws:
SQLException
- if there was a problem accessing database.
-
checkTable
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 interfaceDataRepository
- Parameters:
tableName
- is aString
value of the table name to checkcreateTableQuery
- is aString
with the query to create table- Returns:
true
boolean
value if the table exist in the database andfalse
if the table was not found.- Throws:
SQLException
- if there was a problem accessing database.
-
createStatement
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 interfaceDataRepository
- 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
Description copied from interface:DataRepository
Returns a prepared statement for a given key.- Specified by:
getPreparedStatement
in interfaceDataRepository
- 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
Description copied from interface:DataRepository
Returns a prepared statement for a given key.- Specified by:
getPreparedStatement
in interfaceDataRepository
- 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
Description copied from interface:DataRepository
Returns a DB connection string or DB connection URI.- Specified by:
getResourceUri
in interfaceDataRepository
- Specified by:
getResourceUri
in interfaceDataSource
- Returns:
- a
String
value representing database connection string.
-
getDatabaseType
Description copied from interface:DataRepository
Returns type of DataRepository database- Specified by:
getDatabaseType
in interfaceDataRepository
- Returns:
- a value of
dbTypes
-
initPreparedStatement
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 usinggetPreparedStatement(stIdKey)
method.- Specified by:
initPreparedStatement
in interfaceDataRepository
- Parameters:
stIdKey
- is a statement identification key.query
- is a query for the prepared statement.- Throws:
SQLException
-
initPreparedStatement
public void initPreparedStatement(String stIdKey, 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 usinggetPreparedStatement(stIdKey)
method.- Specified by:
initPreparedStatement
in interfaceDataRepository
- 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:
SQLException
-
initialize
Description copied from interface:DataSource
The method is called to initialize the data repository.- Specified by:
initialize
in interfaceDataSource
- Parameters:
resource_uri
- value in most cases representing the database connection string.- Throws:
DBInitException
-
release
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 interfaceDataRepository
- Parameters:
stmt
- aStatement
variable to release resources for. Might be null.rs
- aResultSet
variable to release resources for. Might be null.
-
startTransaction
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 interfaceDataRepository
- Throws:
SQLException
-
commit
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 interfaceDataRepository
- Throws:
SQLException
-
rollback
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 interfaceDataRepository
- Throws:
SQLException
-
endTransaction
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 interfaceDataRepository
- Throws:
SQLException
-
getPoolSize
public int getPoolSize()- Specified by:
getPoolSize
in interfaceDataRepository
-