public class DataRepositoryImpl extends Object implements DataRepository, StatisticsProviderIfc
DataRepository.dbTypesRepository.Meta| Modifier and Type | Field and Description |
|---|---|
static int |
DB_CONN_TIMEOUT
Field description
|
static String |
DB_CONN_TIMEOUT_PROP_KEY |
static String |
DERBY_CHECK_TABLE_QUERY
Field description
|
static String |
DERBY_CONNVALID_QUERY
Field description
|
static String |
JDBC_CONNVALID_QUERY
Field description
|
static String |
MYSQL_CHECK_TABLE_QUERY
Field description
|
static String |
OTHER_CHECK_TABLE_QUERY
Field description
|
static String |
PGSQL_CHECK_TABLE_QUERY
Field description
|
static int |
QUERY_TIMEOUT
Field description
|
static String |
QUERY_TIMEOUT_PROP_KEY |
static String |
SP_STARTS_WITH
Field description
|
static String |
SQLSERVER_CHECK_TABLE_QUERY
Field description
|
| Constructor and Description |
|---|
DataRepositoryImpl() |
| 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(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) |
PreparedStatement |
getPreparedStatement(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 |
getStatistics(String compName,
StatisticsList list) |
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)
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(BareJID user_id)
Returns
DataRepository instance. |
public static final String DERBY_CONNVALID_QUERY
public static final String JDBC_CONNVALID_QUERY
public static final String MYSQL_CHECK_TABLE_QUERY
public static final String PGSQL_CHECK_TABLE_QUERY
public static final String DERBY_CHECK_TABLE_QUERY
public static final String SQLSERVER_CHECK_TABLE_QUERY
public static final String OTHER_CHECK_TABLE_QUERY
public static final String SP_STARTS_WITH
public static final String QUERY_TIMEOUT_PROP_KEY
public static final int QUERY_TIMEOUT
public static final String DB_CONN_TIMEOUT_PROP_KEY
public static final int DB_CONN_TIMEOUT
public boolean checkTable(String tableName) throws SQLException
DataRepositorycheckTable in interface DataRepositorytableName - 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
DataRepositorycheckTable in interface DataRepositorytableName - 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
DataRepositorycreateStatement in interface DataRepositoryuser_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.StatementSQLException - if a JDBC error occurs.public PreparedStatement getPreparedStatement(BareJID user_id, String stIdKey) throws SQLException
DataRepositorygetPreparedStatement in interface DataRepositoryuser_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.SQLExceptionpublic String getResourceUri()
DataRepositorygetResourceUri in interface DataRepositoryString value representing database connection
string.public DataRepository.dbTypes getDatabaseType()
DataRepositorygetDatabaseType in interface DataRepositorydbTypespublic void initPreparedStatement(String key, String query) throws SQLException
DataRepositorygetPreparedStatement(stIdKey) method.initPreparedStatement in interface DataRepositorykey - is a statement identification key.query - is a query for the prepared statement.SQLExceptionpublic void initPreparedStatement(String key, String query, int autoGeneratedKeys) throws SQLException
DataRepositorygetPreparedStatement(stIdKey) method.initPreparedStatement in interface DataRepositorykey - is a statement identification key.query - is a query for the prepared statement.autoGeneratedKeys - defines if statement should return auto generated keysSQLExceptionpublic void initRepository(String resource_uri, Map<String,String> params) throws DBInitException
Repositoryresource_uri
parameter as the database connection string or via params map if
the required repository parameters are more complex or both.initRepository in interface Repositoryresource_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)
DataRepositoryrelease in interface DataRepositorystmt - a Statement variable to release resources for. Might
be null.rs - a ResultSet variable to release resources for. Might
be null.public DataRepository takeRepoHandle(BareJID user_id)
DataRepositoryDataRepository 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 DataRepositoryuser_id - is user account ID for which we acquire the handle.public void startTransaction()
throws SQLException
DataRepositorystartTransaction in interface DataRepositorySQLExceptionpublic void commit()
throws SQLException
DataRepositorycommit in interface DataRepositorySQLExceptionpublic void rollback()
throws SQLException
DataRepositoryrollback in interface DataRepositorySQLExceptionpublic void endTransaction()
throws SQLException
DataRepositoryendTransaction in interface DataRepositorySQLExceptionpublic void releaseRepoHandle(DataRepository repo)
DataRepositoryreleaseRepoHandle in interface DataRepositoryrepo - is a DataRepositorypublic void getStatistics(String compName, StatisticsList list)
getStatistics in interface StatisticsProviderIfcCopyright © 2018 "Tigase, Inc.". All rights reserved.