Package tigase.db
Class UserRepositoryPool
- java.lang.Object
-
- tigase.db.UserRepositoryPool
-
- All Implemented Interfaces:
Repository,RepositoryPool<UserRepository>,UserRepository
public class UserRepositoryPool extends java.lang.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 ofUserRepositoryuses 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 Modifier and Type Class Description static interfaceUserRepositoryPool.IRepoCache<K,V>-
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
Constructors Constructor Description UserRepositoryPool()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddDataList(BareJID user, java.lang.String subnode, java.lang.String key, java.lang.String[] list)addDataListmethod adds mode entries to existing data list associated with given key in repository under given node path.voidaddRepo(UserRepository repo)Method called to add instance of a repository to the repository pool.voidaddUser(BareJID user)ThisaddUsermethod allows to add new user to repository.java.lang.StringgetData(BareJID user, java.lang.String key)getDatamethod returns a value associated with given key for user repository in default subnode.java.lang.StringgetData(BareJID user, java.lang.String subnode, java.lang.String key)getDatamethod returns a value associated with given key for user repository in given subnode.java.lang.StringgetData(BareJID user, java.lang.String subnode, java.lang.String key, java.lang.String def)getDatamethod returns a value associated with given key for user repository in given subnode.java.lang.String[]getDataList(BareJID user, java.lang.String subnode, java.lang.String key)getDataListmethod returns array of values associated with given key ornullif given key does not exist for given user ID in given node path.java.util.Map<java.lang.String,java.lang.String>getDataMap(BareJID user, java.lang.String subnode)getDataMapmethod returns a values associated with each key for user repository in given subnode.<T> java.util.Map<java.lang.String,T>getDataMap(BareJID user, java.lang.String subnode, java.util.function.Function<java.lang.String,T> converter)getDataMapmethod returns a values associated with each key for user repository in given subnode.java.lang.String[]getKeys(BareJID user)getKeysmethod returns list of all keys stored in default user repository node.java.lang.String[]getKeys(BareJID user, java.lang.String subnode)getKeysmethod returns list of all keys stored in given subnode in user repository.java.lang.StringgetResourceUri()Returns a DB connection string or DB connection URI.java.lang.String[]getSubnodes(BareJID user)getSubnodesmethod returns list of all root nodes for given user.java.lang.String[]getSubnodes(BareJID user, java.lang.String subnode)Deprecated.java.util.List<BareJID>getUsers()This method is only used by the data conversion tools.longgetUsersCount()This method is only used by the server statistics component to report number of registered users.longgetUsersCount(java.lang.String domain)This method is only used by the server statistics component to report number of registered users for given domain.longgetUserUID(BareJID user)Returns a user unique ID number within the given repository.voidinitRepository(java.lang.String resource_uri, java.util.Map<java.lang.String,java.lang.String> params)Method is deprecated and should not be user any more.voidremoveData(BareJID user, java.lang.String key)removeDatamethod removes pair (key, value) from user repository in default repository node.voidremoveData(BareJID user, java.lang.String subnode, java.lang.String key)removeDatamethod removes pair (key, value) from user repository in given subnode.voidremoveSubnode(BareJID user, java.lang.String subnode)removeSubnodemethod removes given subnode with all subnodes in this node and all data stored in this node and in all subnodes.voidremoveUser(BareJID user)ThisremoveUsermethod allows to remove user and all his data from user repository.voidsetData(BareJID user, java.lang.String key, java.lang.String value)ThissetDatamethod sets data value for given user ID associated with given key in default repository node.voidsetData(BareJID user, java.lang.String subnode, java.lang.String key, java.lang.String value)setDatamethod sets data value for given user ID in repository under given node path and associates it with given key.voidsetDataList(BareJID user, java.lang.String subnode, java.lang.String key, java.lang.String[] list)setDataListmethod sets list of values for given user associated given key in repository under given node path.UserRepositorytakeRepo()booleanuserExists(BareJID user)MethoduserExistschecks whether the user (or repository top node) exists in the database.
-
-
-
Method Detail
-
addDataList
public void addDataList(BareJID user, java.lang.String subnode, java.lang.String key, java.lang.String[] list) throws UserNotFoundException, TigaseDBException
Description copied from interface:UserRepositoryaddDataListmethod 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:
addDataListin interfaceUserRepository- Parameters:
user- aBareJIDvalue of user ID for which data must be stored. User ID consists of user name and domain name.subnode- aStringvalue is a node path where data is stored. Node path has the same form as directory path on file system:/root/subnode1/subnode2
.key- aStringwith 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
public void addRepo(UserRepository repo)
Description copied from interface:RepositoryPoolMethod called to add instance of a repository to the repository pool.- Specified by:
addRepoin interfaceRepositoryPool<UserRepository>- Parameters:
repo- instance of a repository
-
addUser
public void addUser(BareJID user) throws UserExistsException, TigaseDBException
Description copied from interface:UserRepositoryThisaddUsermethod allows to add new user to repository. It must throw en exceptionUserExistsExceptionif 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 thatuserid consists of user name and domain address: username@domain.address.net for example.- Specified by:
addUserin interfaceUserRepository- Parameters:
user- aBareJIDvalue 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 java.lang.String getData(BareJID user, java.lang.String subnode, java.lang.String key, java.lang.String def) throws UserNotFoundException, TigaseDBException
Description copied from interface:UserRepositorygetDatamethod 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:
getDatain interfaceUserRepository- Parameters:
user- aBareJIDvalue of user ID for which data must be stored. User ID consists of user name and domain name.subnode- aStringvalue is a node path where data is stored. Node path has the same form as directory path on file system:/root/subnode1/subnode2
.key- aStringwith which the needed value is associated.def- aStringvalue which is returned in case if data for specified key does not exixist in repository.- Returns:
- a
Stringvalue - Throws:
UserNotFoundException- if user id hasn't been found in repository.TigaseDBException- if database backend error occurs.
-
getData
public java.lang.String getData(BareJID user, java.lang.String subnode, java.lang.String key) throws UserNotFoundException, TigaseDBException
Description copied from interface:UserRepositorygetDatamethod returns a value associated with given key for user repository in given subnode. If key is not found in repositorynullvalue is returned.- Specified by:
getDatain interfaceUserRepository- Parameters:
user- aBareJIDvalue of user ID for which data must be stored. User ID consists of user name and domain name.subnode- aStringvalue is a node path where data is stored. Node path has the same form as directory path on file system:/root/subnode1/subnode2
.key- aStringwith which the needed value is associated.- Returns:
- a
Stringvalue - Throws:
UserNotFoundException- if user id hasn't been found in repository.TigaseDBException- if database backend error occurs.
-
getData
public java.lang.String getData(BareJID user, java.lang.String key) throws UserNotFoundException, TigaseDBException
Description copied from interface:UserRepositorygetDatamethod returns a value associated with given key for user repository in default subnode. If key is not found in repositorynullvalue is returned.- Specified by:
getDatain interfaceUserRepository- Parameters:
user- aBareJIDvalue of user ID for which data must be stored. User ID consists of user name and domain name.key- aStringwith which the needed value is associated.- Returns:
- a
Stringvalue - Throws:
UserNotFoundException- if user id hasn't been found in repository.TigaseDBException- if database backend error occurs.
-
getDataMap
public java.util.Map<java.lang.String,java.lang.String> getDataMap(BareJID user, java.lang.String subnode) throws TigaseDBException
Description copied from interface:UserRepositorygetDataMapmethod returns a values associated with each key for user repository in given subnode.- Specified by:
getDataMapin interfaceUserRepository- Parameters:
user- aBareJIDvalue of user ID for which data must be stored. User ID consists of user name and domain name.subnode- aStringvalue 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
Mapwith values - Throws:
UserNotFoundException- if user id hasn't been found in repository.TigaseDBException- if database backend error occurs.
-
getDataMap
public <T> java.util.Map<java.lang.String,T> getDataMap(BareJID user, java.lang.String subnode, java.util.function.Function<java.lang.String,T> converter) throws TigaseDBException
Description copied from interface:UserRepositorygetDataMapmethod returns a values associated with each key for user repository in given subnode.- Specified by:
getDataMapin interfaceUserRepository- Parameters:
user- aBareJIDvalue of user ID for which data must be stored. User ID consists of user name and domain name.subnode- aStringvalue is a node path where data is stored. Node path has the same form as directory path on file system:/root/subnode1/subnode2
.converter- aFunctionwhich takes value for a key and converts to expected value type- Returns:
- a
Mapwith values - Throws:
UserNotFoundException- if user id hasn't been found in repository.TigaseDBException- if database backend error occurs.
-
getDataList
public java.lang.String[] getDataList(BareJID user, java.lang.String subnode, java.lang.String key) throws UserNotFoundException, TigaseDBException
Description copied from interface:UserRepositorygetDataListmethod returns array of values associated with given key ornullif given key does not exist for given user ID in given node path.- Specified by:
getDataListin interfaceUserRepository- Parameters:
user- aBareJIDvalue of user ID for which data must be stored. User ID consists of user name and domain name.subnode- aStringvalue is a node path where data is stored. Node path has the same form as directory path on file system:/root/subnode1/subnode2
.key- aStringwith 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 java.lang.String[] getKeys(BareJID user, java.lang.String subnode) throws UserNotFoundException, TigaseDBException
Description copied from interface:UserRepositorygetKeysmethod 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:
getKeysin interfaceUserRepository- Parameters:
user- aBareJIDvalue of user ID for which data must be stored. User ID consists of user name and domain name.subnode- aStringvalue 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
public java.lang.String[] getKeys(BareJID user) throws UserNotFoundException, TigaseDBException
Description copied from interface:UserRepositorygetKeysmethod 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:
getKeysin interfaceUserRepository- Parameters:
user- aBareJIDvalue 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
public java.lang.String getResourceUri()
Description copied from interface:UserRepositoryReturns a DB connection string or DB connection URI.- Specified by:
getResourceUriin interfaceUserRepository- Returns:
- a
Stringvalue representing database connection string.
-
getSubnodes
@Deprecated public java.lang.String[] getSubnodes(BareJID user, java.lang.String subnode) throws UserNotFoundException, TigaseDBException
Deprecated.Description copied from interface:UserRepositorygetSubnodesmethod returns list of all direct subnodes from given node.- Specified by:
getSubnodesin interfaceUserRepository- Parameters:
user- aBareJIDvalue of user ID for which data must be stored. User ID consists of user name and domain name.subnode- aStringvalue 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
public java.lang.String[] getSubnodes(BareJID user) throws UserNotFoundException, TigaseDBException
Description copied from interface:UserRepositorygetSubnodesmethod returns list of all root nodes for given user.- Specified by:
getSubnodesin interfaceUserRepository- Parameters:
user- aBareJIDvalue 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
public long getUserUID(BareJID user) throws TigaseDBException
Description copied from interface:UserRepositoryReturns 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:
getUserUIDin interfaceUserRepository- Parameters:
user- aBareJIDvalue 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
public java.util.List<BareJID> getUsers() throws TigaseDBException
Description copied from interface:UserRepositoryThis 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:
getUsersin 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:UserRepositoryThis method is only used by the server statistics component to report number of registered users.- Specified by:
getUsersCountin interfaceUserRepository- Returns:
- a
longnumber of registered users in the repository.
-
getUsersCount
public long getUsersCount(java.lang.String domain)
Description copied from interface:UserRepositoryThis method is only used by the server statistics component to report number of registered users for given domain.- Specified by:
getUsersCountin interfaceUserRepository- Returns:
- a
longnumber of registered users in the repository.
-
initRepository
public void initRepository(java.lang.String resource_uri, java.util.Map<java.lang.String,java.lang.String> params) throws DBInitExceptionDescription copied from interface:RepositoryMethod 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_uriparameter as the database connection string or viaparamsmap if the required repository parameters are more complex or both.- Specified by:
initRepositoryin interfaceRepository- Parameters:
resource_uri- value in most cases representing the database connection string.params- is aMapwith 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, java.lang.String subnode, java.lang.String key) throws UserNotFoundException, TigaseDBException
Description copied from interface:UserRepositoryremoveDatamethod 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 thenullvalue is returned from repository backend or given default value.- Specified by:
removeDatain interfaceUserRepository- Parameters:
user- aBareJIDvalue of user ID for which data must be stored. User ID consists of user name and domain name.subnode- aStringvalue is a node path where data is stored. Node path has the same form as directory path on file system:/root/subnode1/subnode2
.key- aStringfor 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
public void removeData(BareJID user, java.lang.String key) throws UserNotFoundException, TigaseDBException
Description copied from interface:UserRepositoryremoveDatamethod 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 thenullvalue is returned from repository backend or given default value.- Specified by:
removeDatain interfaceUserRepository- Parameters:
user- aBareJIDvalue of user ID for which data must be stored. User ID consists of user name and domain name.key- aStringfor 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, java.lang.String subnode) throws UserNotFoundException, TigaseDBException
Description copied from interface:UserRepositoryremoveSubnodemethod 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:
removeSubnodein interfaceUserRepository- Parameters:
user- aBareJIDvalue of user ID for which data must be stored. User ID consists of user name and domain name.subnode- aStringvalue 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
public void removeUser(BareJID user) throws UserNotFoundException, TigaseDBException
Description copied from interface:UserRepositoryThisremoveUsermethod allows to remove user and all his data from user repository. If given user id does not existUserNotFoundExceptionmust be thrown. As one XMPP server can support many virtual internet domains it is required thatuserid consists of user name and domain address: username@domain.address.net for example.- Specified by:
removeUserin interfaceUserRepository- Parameters:
user- aBareJIDvalue 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, java.lang.String subnode, java.lang.String key, java.lang.String value) throws UserNotFoundException, TigaseDBException
Description copied from interface:UserRepositorysetDatamethod 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:
setDatain interfaceUserRepository- Parameters:
user- aBareJIDvalue of user ID for which data must be stored. User ID consists of user name and domain name.subnode- aStringvalue is a node path where data is stored. Node path has the same form as directory path on file system:/root/subnode1/subnode2
.key- aStringwith which the specified value is to be associated.value- aStringvalue 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, java.lang.String key, java.lang.String value) throws UserNotFoundException, TigaseDBException
Description copied from interface:UserRepositoryThissetDatamethod 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:
setDatain interfaceUserRepository- Parameters:
user- aBareJIDvalue of user ID for which data must be stored. User ID consists of user name and domain name.key- aStringwith which the specified value is to be associated.value- aStringvalue 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, java.lang.String subnode, java.lang.String key, java.lang.String[] list) throws UserNotFoundException, TigaseDBException
Description copied from interface:UserRepositorysetDataListmethod 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:
setDataListin interfaceUserRepository- Parameters:
user- aBareJIDvalue of user ID for which data must be stored. User ID consists of user name and domain name.subnode- aStringvalue is a node path where data is stored. Node path has the same form as directory path on file system:/root/subnode1/subnode2
.key- aStringwith 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
public UserRepository takeRepo()
-
userExists
public boolean userExists(BareJID user)
Description copied from interface:UserRepositoryMethoduserExistschecks 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 throwUserNotFoundExceptionexception in case the user is missing for which you executed the method. The exception is thrown unlessuserAutoCreateproperty 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:
userExistsin interfaceUserRepository- Parameters:
user- aBareJIDvalue- Returns:
- a
booleanvalue
-
-