public class DataRepositoryPool extends Object implements DataRepository, DataSourcePool<DataRepository>, StatisticsProviderIfc
DataRepository.dbTypes
Repository.Meta, Repository.SchemaId
UTC_CALENDAR
Constructor and Description |
---|
DataRepositoryPool() |
Modifier and Type | Method and Description |
---|---|
void |
addRepo(DataRepository repo)
Method called to add instance of a repository to the repository pool.
|
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 |
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.
|
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() |
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 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 |
initRepository(String resource_uri,
Map<String,String> params)
Deprecated.
|
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 |
takeRepo(BareJID user_id) |
DataRepository |
takeRepo(int hashCode) |
DataRepository |
takeRepoHandle(BareJID user_id)
Returns
DataRepository instance. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getTimestamp, getTimestamp, setTimestamp
public void addRepo(DataRepository repo)
RepositoryPool
addRepo
in interface RepositoryPool<DataRepository>
repo
- instance of a repositorypublic boolean automaticSchemaManagement()
automaticSchemaManagement
in interface DataSource
public void checkConnectivity(Duration watchdogTime)
DataSource
checkConnectivity
in interface DataSource
watchdogTime
- time which should pass between checkspublic DataRepository takeRepo(BareJID user_id)
public DataRepository takeRepo(int hashCode)
public DataRepository takeRepoHandle(BareJID user_id)
DataRepository
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.takeRepoHandle
in interface DataRepository
user_id
- is user account ID for which we acquire the handle.public void releaseRepoHandle(DataRepository repo)
releaseRepoHandle
in interface DataRepository
public boolean checkSchemaVersion(DataSourceAware<? extends DataSource> datasource, boolean shutdownServer)
DataSource
checkSchemaVersion
in interface DataSource
datasource
- implementation of DataSourceAware
interfaceshutdownServer
- specifies whether server should be shutdown automatically if the version in the database
doesn't match required version.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.public Optional<Version> getSchemaVersion(String component)
DataSource
getSchemaVersion
in interface DataSource
component
- name of the component for which we want to get the schema versionpublic boolean checkTable(String tableName) throws SQLException
DataRepository
checkTable
in interface DataRepository
tableName
- is a String
value of the table name to checktrue
boolean
value if the table exist in the database and false
if
the table was not found.SQLException
- if there was a problem accessing database.public boolean checkTable(String tableName, String createTableQuery) throws SQLException
DataRepository
checkTable
in interface DataRepository
tableName
- is a String
value of the table name to checkcreateTableQuery
- is a String
with the query to create tabletrue
boolean
value if the table exist in the database and false
if
the table was not found.SQLException
- if there was a problem accessing database.public Statement createStatement(BareJID user_id) throws SQLException
DataRepository
createStatement
in interface DataRepository
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.Statement
SQLException
- if a JDBC error occurs.public PreparedStatement getPreparedStatement(BareJID user_id, String stIdKey) throws SQLException
DataRepository
getPreparedStatement
in interface DataRepository
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.PreparedStatement
for the given id key or null if such a statement does not exist.SQLException
public PreparedStatement getPreparedStatement(int hashCode, String stIdKey) throws SQLException
DataRepository
getPreparedStatement
in interface DataRepository
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.PreparedStatement
for the given id key or null if such a statement does not exist.SQLException
public String getResourceUri()
DataRepository
getResourceUri
in interface DataRepository
getResourceUri
in interface DataSource
String
value representing database connection string.public DataRepository.dbTypes getDatabaseType()
DataRepository
getDatabaseType
in interface DataRepository
dbTypes
public void getStatistics(String compName, StatisticsList list)
getStatistics
in interface StatisticsProviderIfc
public void initPreparedStatement(String stIdKey, String query) throws SQLException
DataRepository
getPreparedStatement(stIdKey)
method.initPreparedStatement
in interface DataRepository
stIdKey
- is a statement identification key.query
- is a query for the prepared statement.SQLException
public void initPreparedStatement(String stIdKey, String query, int autoGeneratedKeys) throws SQLException
DataRepository
getPreparedStatement(stIdKey)
method.initPreparedStatement
in interface DataRepository
stIdKey
- is a statement identification key.query
- is a query for the prepared statement.autoGeneratedKeys
- defines if statement should return auto generated keysSQLException
public void initialize(String resource_uri) throws DBInitException
DataSource
initialize
in interface DataSource
resource_uri
- value in most cases representing the database connection string.DBInitException
@Deprecated public void initRepository(String resource_uri, Map<String,String> params) throws DBInitException
Repository
resource_uri
parameter as the database connection string or via
params
map if the required repository parameters are more complex or both.initRepository
in interface Repository
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.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.public void release(Statement stmt, ResultSet rs)
DataRepository
release
in interface DataRepository
stmt
- a Statement
variable to release resources for. Might be null.rs
- a ResultSet
variable to release resources for. Might be null.public void startTransaction() throws SQLException
DataRepository
startTransaction
in interface DataRepository
SQLException
public void commit() throws SQLException
DataRepository
commit
in interface DataRepository
SQLException
public void rollback() throws SQLException
DataRepository
rollback
in interface DataRepository
SQLException
public void endTransaction() throws SQLException
DataRepository
endTransaction
in interface DataRepository
SQLException
public int getPoolSize()
getPoolSize
in interface DataRepository
Copyright © 2004–2021 "Tigase, Inc.". All rights reserved.