public class JDBCRepository extends Object implements AuthRepository, UserRepository, DataSourceAware<DataRepository>, RepositoryVersionAware
Thanks to Daniele for better unique IDs handling. Created: Thu Oct 26 11:48:53 2006
Modifier and Type | Class and Description |
---|---|
static interface |
JDBCRepository.IRepoCache<K,V> |
AuthRepository.AccountStatus, AuthRepository.DefaultCredentials, AuthRepository.SingleCredential
UserRepository.UserRemovedEvent
Repository.Meta, Repository.SchemaId
RepositoryVersionAware.SchemaVersion
Modifier and Type | Field and Description |
---|---|
static String |
CURRENT_DB_SCHEMA_VER |
static String |
DEF_MAXIDS_TBL |
static String |
DEF_NODES_TBL |
static String |
DEF_PAIRS_TBL |
static String |
DEF_ROOT_NODE |
static String |
DEF_USERS_TBL |
static String |
DERBY_GETSCHEMAVER_QUERY |
static String |
JDBC_GETSCHEMAVER_QUERY |
static String |
SCHEMA_UPGRADE_LINK |
static String |
SQLSERVER_GETSCHEMAVER_QUERY
Stored procedure used to check version of the schema
neither MS SQL Server JDBC driver supports default schema prefix in connection string for stored functions |
DATA_KEY, DIGEST_ID_KEY, DIGEST_KEY, MACHANISM_KEY, PASSWORD_KEY, PROTOCOL_KEY, PROTOCOL_VAL_NONSASL, PROTOCOL_VAL_SASL, REALM_KEY, RESULT_KEY, SERVER_NAME_KEY, USER_ID_KEY
Constructor and Description |
---|
JDBCRepository() |
Modifier and Type | Method and Description |
---|---|
void |
addDataList(BareJID user_id,
String subnode,
String key,
String[] list)
addDataList method adds mode entries to existing data list associated with given key in repository
under given node path. |
void |
addUser(BareJID user_id)
This
addUser method allows to add new user to repository. |
void |
addUser(BareJID user,
String password) |
AuthRepository.AccountStatus |
getAccountStatus(BareJID user) |
String |
getData(BareJID user_id,
String key)
getData method returns a value associated with given key for user repository in default subnode. |
String |
getData(BareJID user_id,
String subnode,
String key)
getData method returns a value associated with given key for user repository in given subnode. |
String |
getData(BareJID user_id,
String subnode,
String key,
String def)
getData method returns a value associated with given key for user repository in given subnode. |
String[] |
getDataList(BareJID user_id,
String subnode,
String key)
getDataList method returns array of values associated with given key or null if given
key does not exist for given user ID in given node path. |
Map<String,String> |
getDataMap(BareJID user_id,
String subnode)
getDataMap method returns a values associated with each key for user repository in given subnode. |
<T> Map<String,T> |
getDataMap(BareJID user,
String subnode,
Function<String,T> converter)
getDataMap method returns a values associated with each key for user repository in given subnode. |
String[] |
getKeys(BareJID user_id)
getKeys method returns list of all keys stored in default user repository node. |
String[] |
getKeys(BareJID user_id,
String subnode)
getKeys method returns list of all keys stored in given subnode in user repository. |
String |
getPassword(BareJID user) |
protected DataRepository |
getRepository() |
String |
getResourceUri()
getResourceUri method returns database connection string. |
String[] |
getSubnodes(BareJID user_id)
getSubnodes method returns list of all root nodes for given user. |
String[] |
getSubnodes(BareJID user_id,
String subnode)
getSubnodes method returns list of all direct subnodes from given node. |
List<BareJID> |
getUsers()
This method is only used by the data conversion tools.
|
long |
getUsersCount()
This method is only used by the server statistics component to report number of registered users.
|
long |
getUsersCount(String domain)
This method is only used by the server statistics component to report number of registered users for given
domain.
|
long |
getUserUID(BareJID user_id)
Returns a user unique ID number within the given repository.
|
void |
initRepository(String connection_str,
Map<String,String> params)
Deprecated.
|
protected boolean |
isExceptionKeyViolation(SQLException ex) |
boolean |
isMechanismSupported(String domain,
String mechanism) |
boolean |
isUserDisabled(BareJID user) |
void |
loggedIn(BareJID user)
Do some actions on repository, when user logs in.
|
void |
logout(BareJID user) |
boolean |
otherAuth(Map<String,Object> props) |
void |
queryAuth(Map<String,Object> authProps)
queryAuth returns mechanisms available for authentication. |
void |
removeData(BareJID user_id,
String key)
removeData method removes pair (key, value) from user repository in default repository node. |
void |
removeData(BareJID user_id,
String subnode,
String key)
removeData method removes pair (key, value) from user repository in given subnode. |
void |
removeSubnode(BareJID user_id,
String subnode)
removeSubnode method removes given subnode with all subnodes in this node and all data stored in
this node and in all subnodes. |
void |
removeUser(BareJID user_id)
removeUser method is thread safe. |
void |
setAccountStatus(BareJID user,
AuthRepository.AccountStatus status) |
void |
setData(BareJID user_id,
String key,
String value)
This
setData method sets data value for given user ID associated with given key in default
repository node. |
void |
setData(BareJID user_id,
String subnode,
String key,
String value)
setData method sets data value for given user ID in repository under given node path and associates
it with given key. |
void |
setDataList(BareJID user_id,
String subnode,
String key,
String[] list)
setDataList method sets list of values for given user associated given key in repository under given
node path. |
void |
setDataSource(DataRepository dataSource)
Method called to provide class with instance of a data source.
|
void |
setUserDisabled(BareJID user,
Boolean value) |
void |
updatePassword(BareJID user,
String password) |
boolean |
userExists(BareJID user)
Method
userExists checks whether the user (or repository top node) exists in the database. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getCredentialIds, getCredentials, getUsernames, removeCredential, setCredentialsCodecs, updateCredential
getVersion, updateSchema
public static final String CURRENT_DB_SCHEMA_VER
public static final String DEF_MAXIDS_TBL
public static final String DEF_NODES_TBL
public static final String DEF_PAIRS_TBL
public static final String DEF_ROOT_NODE
public static final String DEF_USERS_TBL
public static final String DERBY_GETSCHEMAVER_QUERY
public static final String SQLSERVER_GETSCHEMAVER_QUERY
public static final String JDBC_GETSCHEMAVER_QUERY
public static final String SCHEMA_UPGRADE_LINK
public void addDataList(BareJID user_id, String subnode, String key, String[] list) throws UserNotFoundException, TigaseDBException
UserRepository
addDataList
method adds mode entries to existing data list associated with given key in repository
under given node path. This method is very similar to setDataList(...)
except it doesn't remove
existing data.addDataList
in interface UserRepository
user_id
- a BareJID
value of user ID for which data must be stored. User ID consists of user name
and domain name.subnode
- a String
value is a node path where data is stored. Node path has the same form as
directory path on file system:
/root/subnode1/subnode2.
key
- a String
with which the specified values list is to be associated.list
- a String[]
is an array of values to be associated with the specified key.UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.public void addUser(BareJID user_id) throws UserExistsException, TigaseDBException
UserRepository
addUser
method allows to add new user to repository. It must throw en exception
UserExistsException
if such user already exists because user must be unique within user
repository data base.user
id consists of user name and domain address: username@domain.address.net for
example.addUser
in interface UserRepository
user_id
- a BareJID
value of user id consisting of user name and domain address.UserExistsException
- if user with the same id already exists.TigaseDBException
- if database backend error occurs.public void addUser(BareJID user, String password) throws UserExistsException, TigaseDBException
addUser
in interface AuthRepository
UserExistsException
TigaseDBException
public String getData(BareJID user_id, String subnode, String key, String def) throws UserNotFoundException, TigaseDBException
UserRepository
getData
method returns a value associated with given key for user repository in given subnode. If
key is not found in repository given default value is returned.getData
in interface UserRepository
user_id
- a BareJID
value of user ID for which data must be stored. User ID consists of user name
and domain name.subnode
- a String
value is a node path where data is stored. Node path has the same form as
directory path on file system:
/root/subnode1/subnode2.
key
- a String
with which the needed value is associated.def
- a String
value which is returned in case if data for specified key does not exixist in
repository.String
valueUserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.public String getData(BareJID user_id, String subnode, String key) throws UserNotFoundException, TigaseDBException
UserRepository
getData
method returns a value associated with given key for user repository in given subnode. If
key is not found in repository null
value is returned.getData
in interface UserRepository
user_id
- a BareJID
value of user ID for which data must be stored. User ID consists of user name
and domain name.subnode
- a String
value is a node path where data is stored. Node path has the same form as
directory path on file system:
/root/subnode1/subnode2.
key
- a String
with which the needed value is associated.String
valueUserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.public String getData(BareJID user_id, String key) throws UserNotFoundException, TigaseDBException
UserRepository
getData
method returns a value associated with given key for user repository in default subnode. If
key is not found in repository null
value is returned.getData
in interface UserRepository
user_id
- a BareJID
value of user ID for which data must be stored. User ID consists of user name
and domain name.key
- a String
with which the needed value is associated.String
valueUserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.public Map<String,String> getDataMap(BareJID user_id, String subnode) throws TigaseDBException
UserRepository
getDataMap
method returns a values associated with each key for user repository in given subnode.getDataMap
in interface UserRepository
user_id
- a BareJID
value of user ID for which data must be stored. User ID consists of user name
and domain name.subnode
- a String
value is a node path where data is stored. Node path has the same form as
directory path on file system:
/root/subnode1/subnode2.
Map
with valuesUserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.public <T> Map<String,T> getDataMap(BareJID user, String subnode, Function<String,T> converter) throws TigaseDBException
UserRepository
getDataMap
method returns a values associated with each key for user repository in given subnode.getDataMap
in interface UserRepository
user
- a BareJID
value of user ID for which data must be stored. User ID consists of user name
and domain name.subnode
- a String
value is a node path where data is stored. Node path has the same form as
directory path on file system:
/root/subnode1/subnode2.
converter
- a Function
which takes value for a key and converts to expected value typeMap
with valuesUserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.public String[] getDataList(BareJID user_id, String subnode, String key) throws UserNotFoundException, TigaseDBException
UserRepository
getDataList
method returns array of values associated with given key or null
if given
key does not exist for given user ID in given node path.getDataList
in interface UserRepository
user_id
- a BareJID
value of user ID for which data must be stored. User ID consists of user name
and domain name.subnode
- a String
value is a node path where data is stored. Node path has the same form as
directory path on file system:
/root/subnode1/subnode2.
key
- a String
with which the needed values list is associated.String[]
valueUserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.public String[] getKeys(BareJID user_id, String subnode) throws UserNotFoundException, TigaseDBException
UserRepository
getKeys
method returns list of all keys stored in given subnode in user repository. There is a value
(or list of values) associated with each key. It is up to user (developer) to know what key keeps one value and
what key keeps list of values.getKeys
in interface UserRepository
user_id
- a BareJID
value of user ID for which data must be stored. User ID consists of user name
and domain name.subnode
- a String
value is a node path where data is stored. Node path has the same form as
directory path on file system:
/root/subnode1/subnode2.
String[]
valueUserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.public String[] getKeys(BareJID user_id) throws UserNotFoundException, TigaseDBException
UserRepository
getKeys
method returns list of all keys stored in default user repository node. There is some a
value (or list of values) associated with each key. It is up to user (developer) to know what key keeps one value
and what key keeps list of values.getKeys
in interface UserRepository
user_id
- a BareJID
value of user ID for which data must be stored or retrieved. User ID consists
of user name and domain name.String[]
valueUserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.public String getResourceUri()
AuthRepository
getResourceUri
method returns database connection string.getResourceUri
in interface AuthRepository
getResourceUri
in interface UserRepository
String
value of database connection string.public String[] getSubnodes(BareJID user_id, String subnode) throws UserNotFoundException, TigaseDBException
UserRepository
getSubnodes
method returns list of all direct subnodes from given node.getSubnodes
in interface UserRepository
user_id
- a BareJID
value of user ID for which data must be stored. User ID consists of user name
and domain name.subnode
- a String
value is a node path where data is stored. Node path has the same form as
directory path on file system:
/root/subnode1/subnode2.
String[]
value is an array of all direct subnodes.UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.public String[] getSubnodes(BareJID user_id) throws UserNotFoundException, TigaseDBException
UserRepository
getSubnodes
method returns list of all root nodes for given user.getSubnodes
in interface UserRepository
user_id
- a BareJID
value of user ID for which data must be stored. User ID consists of user name
and domain name.String[]
value is an array of all root nodes for given user.UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.public long getUserUID(BareJID user_id) throws TigaseDBException
UserRepository
getUserUID
in interface UserRepository
user_id
- a BareJID
value of user ID for which data must be stored or retrieved. User ID consists
of user name and domain name.TigaseDBException
- if there is a problem with accessing user repository.public List<BareJID> getUsers() throws TigaseDBException
UserRepository
getUsers
in interface UserRepository
TigaseDBException
public long getUsersCount()
AuthRepository
getUsersCount
in interface AuthRepository
getUsersCount
in interface UserRepository
long
number of registered users in the repository.public long getUsersCount(String domain)
AuthRepository
getUsersCount
in interface AuthRepository
getUsersCount
in interface UserRepository
domain
- for which get the statisticslong
number of registered users in the repository.public void setDataSource(DataRepository dataSource) throws DBInitException
DataSourceAware
setDataSource
in interface DataSourceAware<DataRepository>
DBInitException
public boolean isMechanismSupported(String domain, String mechanism)
isMechanismSupported
in interface AuthRepository
@Deprecated public void initRepository(String connection_str, 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
connection_str
- 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 logout(BareJID user) throws UserNotFoundException, TigaseDBException
logout
in interface AuthRepository
UserNotFoundException
TigaseDBException
public void loggedIn(BareJID user) throws TigaseDBException
AuthRepository
last_login_time
)loggedIn
in interface AuthRepository
user
- JID of logged user.TigaseDBException
- if an error occurspublic boolean otherAuth(Map<String,Object> props) throws UserNotFoundException, TigaseDBException, AuthorizationException
otherAuth
in interface AuthRepository
UserNotFoundException
TigaseDBException
AuthorizationException
public void queryAuth(Map<String,Object> authProps)
AuthRepository
queryAuth
returns mechanisms available for authentication.queryAuth
in interface AuthRepository
authProps
- a Map
value with parameters for authentication.public void removeData(BareJID user_id, String subnode, String key) throws UserNotFoundException, TigaseDBException
UserRepository
removeData
method removes pair (key, value) from user repository in given subnode. If the key exists
in user repository there is always a value associated with this key - even empty String
. If key does
not exist the null
value is returned from repository backend or given default value.removeData
in interface UserRepository
user_id
- a BareJID
value of user ID for which data must be stored. User ID consists of user name
and domain name.subnode
- a String
value is a node path where data is stored. Node path has the same form as
directory path on file system:
/root/subnode1/subnode2.
key
- a String
for which the value is to be removed.UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.public void removeData(BareJID user_id, String key) throws UserNotFoundException, TigaseDBException
UserRepository
removeData
method removes pair (key, value) from user repository in default repository node. If the
key exists in user repository there is always a value associated with this key - even empty String
.
If key does not exist the null
value is returned from repository backend or given default value.removeData
in interface UserRepository
user_id
- a BareJID
value of user ID for which data must be stored. User ID consists of user name
and domain name.key
- a String
for which the value is to be removed.UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.public void removeSubnode(BareJID user_id, String subnode) throws UserNotFoundException, TigaseDBException
UserRepository
removeSubnode
method removes given subnode with all subnodes in this node and all data stored in
this node and in all subnodes. Effectively it removes entire repository tree starting from given node.removeSubnode
in interface UserRepository
user_id
- a BareJID
value of user ID for which data must be stored. User ID consists of user name
and domain name.subnode
- a String
value is a node path to subnode which has to be removed. Node path has the
same form as directory path on file
system: /root/subnode1/subnode2.
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.public void removeUser(BareJID user_id) throws UserNotFoundException, TigaseDBException
removeUser
method is thread safe. It uses local variable for storing Statement
.removeUser
in interface AuthRepository
removeUser
in interface UserRepository
user_id
- a String
value the user Jabber ID.UserNotFoundException
- if an error occursTigaseDBException
- if database backend error occurs.public void setData(BareJID user_id, String subnode, String key, String value) throws UserNotFoundException, TigaseDBException
UserRepository
setData
method sets data value for given user ID in repository under given node path and associates
it with given key. If there already exists value for given key in given node, old value is replaced with new
value. No warning or exception is thrown in case if methods overwrites old value.setData
in interface UserRepository
user_id
- a BareJID
value of user ID for which data must be stored. User ID consists of user name
and domain name.subnode
- a String
value is a node path where data is stored. Node path has the same form as
directory path on file system:
/root/subnode1/subnode2.
key
- a String
with which the specified value is to be associated.value
- a String
value to be associated with the specified key.UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.public void setData(BareJID user_id, String key, String value) throws UserNotFoundException, TigaseDBException
UserRepository
setData
method sets data value for given user ID associated with given key in default
repository node. Default node is dependent on implementation and usually it is root user node. If there already
exists value for given key in given node, old value is replaced with new value. No warning or exception is thrown
in case if methods overwrites old value.setData
in interface UserRepository
user_id
- a BareJID
value of user ID for which data must be stored. User ID consists of user name
and domain name.key
- a String
with which the specified value is to be associated.value
- a String
value to be associated with the specified key.UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.public void setDataList(BareJID user_id, String subnode, String key, String[] list) throws UserNotFoundException, TigaseDBException
UserRepository
setDataList
method sets list of values for given user associated given key in repository under given
node path. If there already exist values for given key in given node, all old values are replaced with new
values. No warning or exception is thrown in case if methods overwrites old value.setDataList
in interface UserRepository
user_id
- a BareJID
value of user ID for which data must be stored. User ID consists of user name
and domain name.subnode
- a String
value is a node path where data is stored. Node path has the same form as
directory path on file system:
/root/subnode1/subnode2.
key
- a String
with which the specified values list is to be associated.list
- a String[]
is an array of values to be associated with the specified key.UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.public void updatePassword(BareJID user, String password) throws TigaseDBException
updatePassword
in interface AuthRepository
TigaseDBException
public boolean userExists(BareJID user)
UserRepository
userExists
checks whether the user (or repository top node) exists in the database. The
method doesn't throw any exception nor it creates the user in case it is missing. It just checks whether the user
is already in the database.
UserNotFoundException
exception in case
the user is missing for which you executed the method. The exception is thrown unless userAutoCreate
property is set to true. In such case the exception is never thrown and the methods are executed for given
parameters prior to creating user entry if it is missing.
userExists
in interface UserRepository
user
- a BareJID
valueboolean
valuepublic String getPassword(BareJID user) throws UserNotFoundException, TigaseDBException
getPassword
in interface AuthRepository
UserNotFoundException
TigaseDBException
public boolean isUserDisabled(BareJID user) throws UserNotFoundException, TigaseDBException
isUserDisabled
in interface AuthRepository
UserNotFoundException
TigaseDBException
public void setAccountStatus(BareJID user, AuthRepository.AccountStatus status) throws TigaseDBException
setAccountStatus
in interface AuthRepository
TigaseDBException
public AuthRepository.AccountStatus getAccountStatus(BareJID user) throws TigaseDBException
getAccountStatus
in interface AuthRepository
TigaseDBException
public void setUserDisabled(BareJID user, Boolean value) throws UserNotFoundException, TigaseDBException
setUserDisabled
in interface AuthRepository
UserNotFoundException
TigaseDBException
protected DataRepository getRepository()
protected boolean isExceptionKeyViolation(SQLException ex)
Copyright © 2004–2020 "Tigase, Inc.". All rights reserved.