Package tigase.db
Interface DataRepository
-
- All Superinterfaces:
DataSource,Repository
- All Known Implementing Classes:
DataRepoPool,DataRepositoryImpl,DataRepositoryPool
public interface DataRepository extends DataSource
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- Author:
- Artur Hefczyc
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classDataRepository.dbTypesHelper enumeration with types of supported databases.-
Nested classes/interfaces inherited from interface tigase.db.Repository
Repository.Meta, Repository.SchemaId
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.CalendarUTC_CALENDAR-
Fields inherited from interface tigase.db.DataSource
log
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description booleancheckTable(java.lang.String tableName)The method checks whether a table for the given name exists in the database.booleancheckTable(java.lang.String tableName, java.lang.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.voidcommit()Commits current transaction on the DataRepository connection.java.sql.StatementcreateStatement(BareJID user_id)Creates a SQL statement on which SQL queries can be executed later by the higher repository layer.voidendTransaction()Ends current transaction on the DataRepository connection.DataRepository.dbTypesgetDatabaseType()Returns type of DataRepository databaseintgetPoolSize()java.sql.PreparedStatementgetPreparedStatement(int hashCode, java.lang.String stIdKey)Returns a prepared statement for a given key.java.sql.PreparedStatementgetPreparedStatement(BareJID user_id, java.lang.String stIdKey)Returns a prepared statement for a given key.java.lang.StringgetResourceUri()Returns a DB connection string or DB connection URI.default java.sql.TimestampgetTimestamp(java.sql.ResultSet rs, int pos)Helper method to get timestamp from result set.default java.sql.TimestampgetTimestamp(java.sql.ResultSet rs, java.lang.String field)Helper method to get timestamp from result set.voidinitPreparedStatement(java.lang.String stIdKey, java.lang.String query)Initializes a prepared statement for a given query and stores it internally under the given id key.voidinitPreparedStatement(java.lang.String stIdKey, java.lang.String query, int autoGeneratedKeys)Initializes a prepared statement for a given query and stores it internally under the given id key.voidrelease(java.sql.Statement stmt, java.sql.ResultSet rs)A helper method to release resources from the statement and result set.voidreleaseRepoHandle(DataRepository repo)voidrollback()Rolls back started transaction on the DataRepository connection.default voidsetTimestamp(java.sql.PreparedStatement stmt, int pos, java.sql.Timestamp timestamp)Helper method to set timestamp into prepared statements.voidstartTransaction()Starts transaction on the DataRepository connection.DataRepositorytakeRepoHandle(BareJID user_id)ReturnsDataRepositoryinstance.-
Methods inherited from interface tigase.db.DataSource
automaticSchemaManagement, checkConnectivity, checkSchemaVersion, getSchemaVersion, initialize
-
Methods inherited from interface tigase.db.Repository
initRepository
-
-
-
-
Method Detail
-
checkTable
boolean checkTable(java.lang.String tableName) throws java.sql.SQLExceptionThe method checks whether a table for the given name exists in the database.- Parameters:
tableName- is aStringvalue of the table name to check- Returns:
truebooleanvalue if the table exist in the database andfalseif the table was not found.- Throws:
java.sql.SQLException- if there was a problem accessing database.
-
checkTable
boolean checkTable(java.lang.String tableName, java.lang.String createTableQuery) throws java.sql.SQLExceptionThe 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 aStringvalue of the table name to checkcreateTableQuery- is aStringwith the query to create table- Returns:
truebooleanvalue if the table exist in the database andfalseif the table was not found.- Throws:
java.sql.SQLException- if there was a problem accessing database.
-
commit
void commit() throws java.sql.SQLExceptionCommits 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:
java.sql.SQLException
-
createStatement
java.sql.Statement createStatement(BareJID user_id) throws java.sql.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:
java.sql.SQLException- if a JDBC error occurs.
-
endTransaction
void endTransaction() throws java.sql.SQLExceptionEnds 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:
java.sql.SQLException
-
initPreparedStatement
void initPreparedStatement(java.lang.String stIdKey, java.lang.String query) throws java.sql.SQLExceptionInitializes a prepared statement for a given query and stores it internally under the given id key. It can be retrieved later usinggetPreparedStatement(stIdKey)method.- Parameters:
stIdKey- is a statement identification key.query- is a query for the prepared statement.- Throws:
java.sql.SQLException
-
initPreparedStatement
void initPreparedStatement(java.lang.String stIdKey, java.lang.String query, int autoGeneratedKeys) throws java.sql.SQLExceptionInitializes a prepared statement for a given query and stores it internally under the given id key. It can be retrieved later usinggetPreparedStatement(stIdKey)method.- 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:
java.sql.SQLException
-
release
void release(java.sql.Statement stmt, java.sql.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- aStatementvariable to release resources for. Might be null.rs- aResultSetvariable to release resources for. Might be null.
-
releaseRepoHandle
void releaseRepoHandle(DataRepository repo)
-
rollback
void rollback() throws java.sql.SQLExceptionRolls 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:
java.sql.SQLException
-
startTransaction
void startTransaction() throws java.sql.SQLExceptionStarts 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:
java.sql.SQLException
-
takeRepoHandle
DataRepository takeRepoHandle(BareJID user_id)
ReturnsDataRepositoryinstance. 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
-
getPoolSize
int getPoolSize()
-
getPreparedStatement
java.sql.PreparedStatement getPreparedStatement(BareJID user_id, java.lang.String stIdKey) throws java.sql.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
PreparedStatementfor the given id key or null if such a statement does not exist. - Throws:
java.sql.SQLException
-
getPreparedStatement
java.sql.PreparedStatement getPreparedStatement(int hashCode, java.lang.String stIdKey) throws java.sql.SQLExceptionReturns a prepared statement for a given key.- 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
PreparedStatementfor the given id key or null if such a statement does not exist. - Throws:
java.sql.SQLException
-
getResourceUri
java.lang.String getResourceUri()
Returns a DB connection string or DB connection URI.- Specified by:
getResourceUriin interfaceDataSource- Returns:
- a
Stringvalue representing database connection string.
-
setTimestamp
default void setTimestamp(java.sql.PreparedStatement stmt, int pos, java.sql.Timestamp timestamp) throws java.sql.SQLExceptionHelper method to set timestamp into prepared statements. Provides proper calendar when needed to adjust timestamps so that they are stored in the database in proper time zone.- Throws:
java.sql.SQLException
-
getTimestamp
default java.sql.Timestamp getTimestamp(java.sql.ResultSet rs, int pos) throws java.sql.SQLExceptionHelper method to get timestamp from result set. Provides proper calendar when needed to adjust timestamps so that they are stored in the database in proper time zone.- Throws:
java.sql.SQLException
-
getTimestamp
default java.sql.Timestamp getTimestamp(java.sql.ResultSet rs, java.lang.String field) throws java.sql.SQLExceptionHelper method to get timestamp from result set. Provides proper calendar when needed to adjust timestamps so that they are stored in the database in proper time zone.- Throws:
java.sql.SQLException
-
-