Package tigase.db
Class UserRepositoryPool
java.lang.Object
tigase.db.UserRepositoryPool
- All Implemented Interfaces:
Repository
,RepositoryPool<UserRepository>
,UserRepository
public class UserRepositoryPool
extends Object
implements UserRepository, RepositoryPool<UserRepository>
Pool for user repositories. *
This pool should be used if connection to user storage is blocking or synchronized, ie. implemented using single connection.*
If implementation of
Created: Jan 28, 2009 8:46:53 PM
This pool should be used if connection to user storage is blocking or synchronized, ie. implemented using single connection.*
If implementation of
UserRepository
uses connection pool
or non blocking, concurrent access to user storage (ie. DataSourcePool
), then this pool is not need.
Created: Jan 28, 2009 8:46:53 PM
- Author:
- Artur Hefczyc
-
Nested Class Summary
Nested classes/interfaces inherited from interface tigase.db.Repository
Repository.Meta, Repository.SchemaId
Nested classes/interfaces inherited from interface tigase.db.UserRepository
UserRepository.UserRemovedEvent
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDataList
(BareJID user, 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
addRepo
(UserRepository repo) Method called to add instance of a repository to the repository pool.void
ThisaddUser
method allows to add new user to repository.getData
method returns a value associated with given key for user repository in default subnode.getData
method returns a value associated with given key for user repository in given subnode.getData
method returns a value associated with given key for user repository in given subnode.String[]
getDataList
(BareJID user, String subnode, String key) getDataList
method returns array of values associated with given key ornull
if given key does not exist for given user ID in given node path.getDataMap
(BareJID user, String subnode) getDataMap
method returns a values associated with each key for user repository in given subnode.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
method returns list of all keys stored in default user repository node.String[]
getKeys
method returns list of all keys stored in given subnode in user repository.Returns a DB connection string or DB connection URI.String[]
getSubnodes
(BareJID user) getSubnodes
method returns list of all root nodes for given user.String[]
getSubnodes
(BareJID user, String subnode) Deprecated.getUsers()
This method is only used by the data conversion tools.long
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) Returns a user unique ID number within the given repository.void
initRepository
(String resource_uri, Map<String, String> params) Method is deprecated and should not be user any more.void
removeData
(BareJID user, String key) removeData
method removes pair (key, value) from user repository in default repository node.void
removeData
(BareJID user, String subnode, String key) removeData
method removes pair (key, value) from user repository in given subnode.void
removeSubnode
(BareJID user, 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) ThisremoveUser
method allows to remove user and all his data from user repository.void
ThissetData
method sets data value for given user ID associated with given key in default repository node.void
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, String subnode, String key, String[] list) setDataList
method sets list of values for given user associated given key in repository under given node path.takeRepo()
boolean
userExists
(BareJID user) MethoduserExists
checks whether the user (or repository top node) exists in the database.
-
Constructor Details
-
UserRepositoryPool
public UserRepositoryPool()
-
-
Method Details
-
addDataList
public void addDataList(BareJID user, String subnode, String key, String[] list) throws UserNotFoundException, TigaseDBException Description copied from interface: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 tosetDataList(...)
except it doesn't remove existing data.- Specified by:
addDataList
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored. User ID consists of user name and domain name.subnode
- aString
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
- aString
with which the specified values list is to be associated.list
- aString[]
is an array of values to be associated with the specified key.- Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
addRepo
Description copied from interface:RepositoryPool
Method called to add instance of a repository to the repository pool.- Specified by:
addRepo
in interfaceRepositoryPool<UserRepository>
- Parameters:
repo
- instance of a repository
-
addUser
Description copied from interface:UserRepository
ThisaddUser
method allows to add new user to repository. It must throw en exceptionUserExistsException
if such user already exists because user must be unique within user repository data base.
As one XMPP server can support many virtual internet domains it is required thatuser
id consists of user name and domain address: username@domain.address.net for example.- Specified by:
addUser
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user id consisting of user name and domain address.- Throws:
UserExistsException
- if user with the same id already exists.TigaseDBException
- if database backend error occurs.
-
getData
public String getData(BareJID user, String subnode, String key, String def) throws UserNotFoundException, TigaseDBException Description copied from interface: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.- Specified by:
getData
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored. User ID consists of user name and domain name.subnode
- aString
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
- aString
with which the needed value is associated.def
- aString
value which is returned in case if data for specified key does not exixist in repository.- Returns:
- a
String
value - Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
getData
public String getData(BareJID user, String subnode, String key) throws UserNotFoundException, TigaseDBException Description copied from interface:UserRepository
getData
method returns a value associated with given key for user repository in given subnode. If key is not found in repositorynull
value is returned.- Specified by:
getData
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored. User ID consists of user name and domain name.subnode
- aString
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
- aString
with which the needed value is associated.- Returns:
- a
String
value - Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
getData
Description copied from interface:UserRepository
getData
method returns a value associated with given key for user repository in default subnode. If key is not found in repositorynull
value is returned.- Specified by:
getData
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored. User ID consists of user name and domain name.key
- aString
with which the needed value is associated.- Returns:
- a
String
value - Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
getDataMap
Description copied from interface:UserRepository
getDataMap
method returns a values associated with each key for user repository in given subnode.- Specified by:
getDataMap
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored. User ID consists of user name and domain name.subnode
- aString
value is a node path where data is stored. Node path has the same form as directory path on file system:/root/subnode1/subnode2
.- Returns:
- a
Map
with values - Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
getDataMap
public <T> Map<String,T> getDataMap(BareJID user, String subnode, Function<String, T> converter) throws TigaseDBExceptionDescription copied from interface:UserRepository
getDataMap
method returns a values associated with each key for user repository in given subnode.- Specified by:
getDataMap
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored. User ID consists of user name and domain name.subnode
- aString
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
- aFunction
which takes value for a key and converts to expected value type- Returns:
- a
Map
with values - Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
getDataList
public String[] getDataList(BareJID user, String subnode, String key) throws UserNotFoundException, TigaseDBException Description copied from interface:UserRepository
getDataList
method returns array of values associated with given key ornull
if given key does not exist for given user ID in given node path.- Specified by:
getDataList
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored. User ID consists of user name and domain name.subnode
- aString
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
- aString
with which the needed values list is associated.- Returns:
- a
String[]
value - Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
getKeys
public String[] getKeys(BareJID user, String subnode) throws UserNotFoundException, TigaseDBException Description copied from interface: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.- Specified by:
getKeys
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored. User ID consists of user name and domain name.subnode
- aString
value is a node path where data is stored. Node path has the same form as directory path on file system:/root/subnode1/subnode2
.- Returns:
- a
String[]
value - Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
getKeys
Description copied from interface: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.- Specified by:
getKeys
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored or retrieved. User ID consists of user name and domain name.- Returns:
- a
String[]
value - Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
getResourceUri
Description copied from interface:UserRepository
Returns a DB connection string or DB connection URI.- Specified by:
getResourceUri
in interfaceUserRepository
- Returns:
- a
String
value representing database connection string.
-
getSubnodes
@Deprecated public String[] getSubnodes(BareJID user, String subnode) throws UserNotFoundException, TigaseDBException Deprecated.Description copied from interface:UserRepository
getSubnodes
method returns list of all direct subnodes from given node.- Specified by:
getSubnodes
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored. User ID consists of user name and domain name.subnode
- aString
value is a node path where data is stored. Node path has the same form as directory path on file system:/root/subnode1/subnode2
.- Returns:
- a
String[]
value is an array of all direct subnodes. - Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
getSubnodes
Description copied from interface:UserRepository
getSubnodes
method returns list of all root nodes for given user.- Specified by:
getSubnodes
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored. User ID consists of user name and domain name.- Returns:
- a
String[]
value is an array of all root nodes for given user. - Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
getUserUID
Description copied from interface:UserRepository
Returns a user unique ID number within the given repository. Please note it is also possible that the ID number is unique only for the user domain. The ID is a positive number if the user exists and negative if the user was not found in the repository.- Specified by:
getUserUID
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored or retrieved. User ID consists of user name and domain name.- Returns:
- a user inique ID number within the repository or domain. The ID is a positive number if the user exists and negative if the user was not found in the repository.
- Throws:
TigaseDBException
- if there is a problem with accessing user repository.
-
getUsers
Description copied from interface:UserRepository
This method is only used by the data conversion tools. They attempt to copy whole user repositories from one to another database. Databases might not be compatible but as long as the API is implemented and they support adding user the user database can be copied to a different data source.- Specified by:
getUsers
in interfaceUserRepository
- Returns:
- returns a collection of all user IDs (Jabber IDs) stored in the user repository.
- Throws:
TigaseDBException
-
getUsersCount
public long getUsersCount()Description copied from interface:UserRepository
This method is only used by the server statistics component to report number of registered users.- Specified by:
getUsersCount
in interfaceUserRepository
- Returns:
- a
long
number of registered users in the repository.
-
getUsersCount
Description copied from interface:UserRepository
This method is only used by the server statistics component to report number of registered users for given domain.- Specified by:
getUsersCount
in interfaceUserRepository
- Returns:
- a
long
number of registered users in the repository.
-
initRepository
Description copied from interface:Repository
Method is deprecated and should not be user any more.
The method is called to initialize the data repository. Depending on the implementation all the initialization parameters can be passed either viaresource_uri
parameter as the database connection string or viaparams
map if the required repository parameters are more complex or both.- Specified by:
initRepository
in interfaceRepository
- Parameters:
resource_uri
- value in most cases representing the database connection string.params
- is aMap
with repository properties necessary to initialize and perform all the functions. The initialization parameters are implementation dependent.- Throws:
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.
-
removeData
public void removeData(BareJID user, String subnode, String key) throws UserNotFoundException, TigaseDBException Description copied from interface: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 emptyString
. If key does not exist thenull
value is returned from repository backend or given default value.- Specified by:
removeData
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored. User ID consists of user name and domain name.subnode
- aString
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
- aString
for which the value is to be removed.- Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
removeData
Description copied from interface: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 emptyString
. If key does not exist thenull
value is returned from repository backend or given default value.- Specified by:
removeData
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored. User ID consists of user name and domain name.key
- aString
for which the value is to be removed.- Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
removeSubnode
public void removeSubnode(BareJID user, String subnode) throws UserNotFoundException, TigaseDBException Description copied from interface: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.- Specified by:
removeSubnode
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored. User ID consists of user name and domain name.subnode
- aString
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
.- Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
removeUser
Description copied from interface:UserRepository
ThisremoveUser
method allows to remove user and all his data from user repository. If given user id does not existUserNotFoundException
must be thrown. As one XMPP server can support many virtual internet domains it is required thatuser
id consists of user name and domain address: username@domain.address.net for example.- Specified by:
removeUser
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user id consisting of user name and domain address.- Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
setData
public void setData(BareJID user, String subnode, String key, String value) throws UserNotFoundException, TigaseDBException Description copied from interface: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.- Specified by:
setData
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored. User ID consists of user name and domain name.subnode
- aString
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
- aString
with which the specified value is to be associated.value
- aString
value to be associated with the specified key.- Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
setData
public void setData(BareJID user, String key, String value) throws UserNotFoundException, TigaseDBException Description copied from interface:UserRepository
ThissetData
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.- Specified by:
setData
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored. User ID consists of user name and domain name.key
- aString
with which the specified value is to be associated.value
- aString
value to be associated with the specified key.- Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
setDataList
public void setDataList(BareJID user, String subnode, String key, String[] list) throws UserNotFoundException, TigaseDBException Description copied from interface: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.- Specified by:
setDataList
in interfaceUserRepository
- Parameters:
user
- aBareJID
value of user ID for which data must be stored. User ID consists of user name and domain name.subnode
- aString
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
- aString
with which the specified values list is to be associated.list
- aString[]
is an array of values to be associated with the specified key.- Throws:
UserNotFoundException
- if user id hasn't been found in repository.TigaseDBException
- if database backend error occurs.
-
takeRepo
-
userExists
Description copied from interface:UserRepository
MethoduserExists
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.
Please don't overuse this method. All other methods throwUserNotFoundException
exception in case the user is missing for which you executed the method. The exception is thrown unlessuserAutoCreate
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.
Therefore this method should be used only to check whether the account exists without creating it.- Specified by:
userExists
in interfaceUserRepository
- Parameters:
user
- aBareJID
value- Returns:
- a
boolean
value
-