org.apache.james.user.jdbc
Class AbstractJdbcUsersRepository

java.lang.Object
  extended by org.apache.james.user.lib.AbstractUsersRepository
      extended by org.apache.james.user.lib.AbstractJamesUsersRepository
          extended by org.apache.james.user.jdbc.AbstractJdbcUsersRepository
All Implemented Interfaces:
Configurable, LogEnabled, RecipientRewriteTable, JamesUsersRepository, UsersRepository
Direct Known Subclasses:
DefaultUsersJdbcRepository, JamesUsersJdbcRepository

Deprecated.

@Deprecated
public abstract class AbstractJdbcUsersRepository
extends AbstractJamesUsersRepository

An abstract base class for creating UserRepository implementations which use a database for persistence. To implement a new UserRepository using by extending this class, you need to implement the 3 abstract methods defined below, and define the required SQL statements in an SQLResources file. The SQL statements used by this implementation are:

Required
select Select all users.
insert Insert a user.
update Update a user.
delete Delete a user by name.
createTable Create the users table.
Optional
selectByLowercaseName Select a user by name (case-insensitive lowercase).


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.james.rrt.api.RecipientRewriteTable
RecipientRewriteTable.ErrorMappingException
 
Field Summary
protected  Map<String,String> m_sqlParameters
          Deprecated.  
 
Fields inherited from class org.apache.james.user.lib.AbstractJamesUsersRepository
enableAliases, enableForwarding, ignoreCase
 
Fields inherited from interface org.apache.james.rrt.api.RecipientRewriteTable
ALIASDOMAIN_PREFIX, ERROR_PREFIX, REGEX_PREFIX, WILDCARD
 
Constructor Summary
AbstractJdbcUsersRepository()
          Deprecated.  
 
Method Summary
 boolean contains(String name)
          Deprecated. Returns whether or not this user is in the repository
 boolean containsCaseInsensitive(String name)
          Deprecated. Returns whether or not this user is in the repository.
 int countUsers()
          Deprecated. Returns a count of the users in the repository.
protected  void doAddUser(User user)
          Deprecated. Adds a user to the underlying Repository.
protected  void doConfigure(org.apache.commons.configuration.HierarchicalConfiguration configuration)
          Deprecated.  Configures the UserRepository for JDBC access.
protected  void doRemoveUser(User user)
          Deprecated. Removes a user from the underlying repository.
protected  void doUpdateUser(User user)
          Deprecated. Updates a user record to match the supplied User.
 User getUserByName(String name)
          Deprecated. Get the user object with the specified user name.
protected  User getUserByName(String name, boolean ignoreCase)
          Deprecated. Gets a user by name, ignoring case if specified.
protected  User getUserByNameIterating(String name, boolean ignoreCase)
          Deprecated. Gets a user by name, ignoring case if specified.
 void init()
          Deprecated. Initialises the JDBC repository.
 Iterator<String> list()
          Deprecated. List users in repository.
protected  Iterator<User> listAllUsers()
          Deprecated. Returns a list populated with all of the Users in the repository.
protected  List<String> listUserNames()
          Deprecated. Produces the complete list of User names, with correct case.
protected abstract  User readUserFromResultSet(ResultSet rsUsers)
          Deprecated. Reads properties for a User from an open ResultSet.
 void removeUser(String userName)
          Deprecated. Removes a user from the repository
 void setDatasource(DataSource m_datasource)
          Deprecated. Set the DataSourceSelector
 void setFileSystem(FileSystem system)
          Deprecated. Sets the filesystem service
protected abstract  void setUserForInsertStatement(User user, PreparedStatement userInsert)
          Deprecated. Set parameters of a PreparedStatement object with property values from a User instance.
protected abstract  void setUserForUpdateStatement(User user, PreparedStatement userUpdate)
          Deprecated. Set parameters of a PreparedStatement object with property values from a User instance.
 boolean test(String name, String password)
          Deprecated. Test if user with name 'name' has password 'password'.
 
Methods inherited from class org.apache.james.user.lib.AbstractJamesUsersRepository
addAddressMapping, addAliasDomainMapping, addErrorMapping, addMapping, addRegexMapping, configure, doAddUser, getAllMappings, getMappings, getUserDomainMappings, removeAddressMapping, removeAliasDomainMapping, removeErrorMapping, removeMapping, removeRegexMapping, setEnableAliases, setEnableForwarding, setIgnoreCase, updateUser
 
Methods inherited from class org.apache.james.user.lib.AbstractUsersRepository
addUser, getLogger, isValidUsername, setDomainList, setEnableVirtualHosting, setLog, supportVirtualHosting
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.james.user.api.UsersRepository
addUser, supportVirtualHosting
 

Field Detail

m_sqlParameters

protected Map<String,String> m_sqlParameters
Deprecated. 
Constructor Detail

AbstractJdbcUsersRepository

public AbstractJdbcUsersRepository()
Deprecated. 
Method Detail

removeUser

public void removeUser(String userName)
                throws UsersRepositoryException
Deprecated. 
Removes a user from the repository

Parameters:
userName - the user to be removed
Throws:
UsersRepositoryException

getUserByName

public User getUserByName(String name)
                   throws UsersRepositoryException
Deprecated. 
Get the user object with the specified user name. Return null if no such user.

Parameters:
name - the name of the user to retrieve
Returns:
the user if found, null otherwise
Throws:
UsersRepositoryException
Since:
James 1.2.2

contains

public boolean contains(String name)
                 throws UsersRepositoryException
Deprecated. 
Returns whether or not this user is in the repository

Returns:
true or false
Throws:
UsersRepositoryException

containsCaseInsensitive

public boolean containsCaseInsensitive(String name)
                                throws UsersRepositoryException
Deprecated. 
Returns whether or not this user is in the repository. Names are matched on a case insensitive basis.

Returns:
true or false
Throws:
UsersRepositoryException

test

public boolean test(String name,
                    String password)
             throws UsersRepositoryException
Deprecated. 
Test if user with name 'name' has password 'password'.

Parameters:
name - the name of the user to be tested
password - the password to be tested
Returns:
true if the test is successful, false if the password is incorrect or the user doesn't exist
Throws:
UsersRepositoryException
Since:
James 1.2.2

countUsers

public int countUsers()
               throws UsersRepositoryException
Deprecated. 
Returns a count of the users in the repository.

Returns:
the number of users in the repository
Throws:
UsersRepositoryException

list

public Iterator<String> list()
                      throws UsersRepositoryException
Deprecated. 
List users in repository.

Returns:
Iterator over a collection of Strings, each being one user in the repository.
Throws:
UsersRepositoryException

setDatasource

public void setDatasource(DataSource m_datasource)
Deprecated. 
Set the DataSourceSelector

Parameters:
m_datasource - the DataSourceSelector

setFileSystem

public void setFileSystem(FileSystem system)
Deprecated. 
Sets the filesystem service

Parameters:
system - the new service

init

@PostConstruct
public void init()
          throws Exception
Deprecated. 
Initialises the JDBC repository.
  1. Tests the connection to the database.
  2. Loads SQL strings from the SQL definition file, choosing the appropriate SQL for this connection, and performing parameter substitution,
  3. Initialises the database with the required tables, if necessary.

Throws:
Exception - if an error occurs

doConfigure

protected void doConfigure(org.apache.commons.configuration.HierarchicalConfiguration configuration)
                    throws org.apache.commons.configuration.ConfigurationException
Deprecated. 

Configures the UserRepository for JDBC access.

Requires a configuration element in the .conf.xml file of the form:

   <repository name="so even "
       class="org.apache.james.userrepository.JamesUsersJdbcRepository">
       <!-- Name of the datasource to use -->
       <data-source>MailDb</data-source>
       <!-- File to load the SQL definitions from -->
       <sqlFile>dist/conf/sqlResources.xml</sqlFile>
       <!-- replacement parameters for the sql file -->
       <sqlParameters table="JamesUsers"/>
   </repository>
 

Overrides:
doConfigure in class AbstractUsersRepository
Throws:
org.apache.commons.configuration.ConfigurationException
See Also:
AbstractUsersRepository.doConfigure(org.apache.commons.configuration.HierarchicalConfiguration)

listUserNames

protected List<String> listUserNames()
                              throws UsersRepositoryException
Deprecated. 
Produces the complete list of User names, with correct case.

Returns:
a List of Strings representing user names.
Throws:
UsersRepositoryException

listAllUsers

protected Iterator<User> listAllUsers()
                               throws UsersRepositoryException
Deprecated. 
Returns a list populated with all of the Users in the repository.

Returns:
an Iterator of Users.
Throws:
UsersRepositoryException

doAddUser

protected void doAddUser(User user)
                  throws UsersRepositoryException
Deprecated. 
Adds a user to the underlying Repository. The user name must not clash with an existing user.

Specified by:
doAddUser in class AbstractJamesUsersRepository
Parameters:
user - the user to add
Throws:
UsersRepositoryException

doRemoveUser

protected void doRemoveUser(User user)
                     throws UsersRepositoryException
Deprecated. 
Removes a user from the underlying repository. If the user doesn't exist, returns ok.

Parameters:
user - the user to remove
Throws:
UsersRepositoryException

doUpdateUser

protected void doUpdateUser(User user)
                     throws UsersRepositoryException
Deprecated. 
Updates a user record to match the supplied User.

Specified by:
doUpdateUser in class AbstractJamesUsersRepository
Parameters:
user - the user to update
Throws:
UsersRepositoryException

getUserByNameIterating

protected User getUserByNameIterating(String name,
                                      boolean ignoreCase)
                               throws UsersRepositoryException
Deprecated. 
Gets a user by name, ignoring case if specified. This implementation gets the entire set of users, and scrolls through searching for one matching name.

Parameters:
name - the name of the user being retrieved
ignoreCase - whether the name is regarded as case-insensitive
Returns:
the user being retrieved, null if the user doesn't exist
Throws:
UsersRepositoryException

getUserByName

protected User getUserByName(String name,
                             boolean ignoreCase)
                      throws UsersRepositoryException
Deprecated. 
Gets a user by name, ignoring case if specified. If the specified SQL statement has been defined, this method overrides the basic implementation in AbstractJamesUsersRepository to increase performance.

Parameters:
name - the name of the user being retrieved
ignoreCase - whether the name is regarded as case-insensitive
Returns:
the user being retrieved, null if the user doesn't exist
Throws:
UsersRepositoryException

readUserFromResultSet

protected abstract User readUserFromResultSet(ResultSet rsUsers)
                                       throws SQLException
Deprecated. 
Reads properties for a User from an open ResultSet. Subclass implementations of this method must have knowledge of the fields presented by the "select" and "selectByLowercaseName" SQL statements. These implemenations may generate a subclass-specific User instance.

Parameters:
rsUsers - A ResultSet with a User record in the current row.
Returns:
A User instance
Throws:
SQLException - if an exception occurs reading from the ResultSet

setUserForInsertStatement

protected abstract void setUserForInsertStatement(User user,
                                                  PreparedStatement userInsert)
                                           throws SQLException
Deprecated. 
Set parameters of a PreparedStatement object with property values from a User instance. Implementations of this method have knowledge of the parameter ordering of the "insert" SQL statement definition.

Parameters:
user - a User instance, which should be an implementation class which is handled by this Repostory implementation.
userInsert - a PreparedStatement initialised with SQL taken from the "insert" SQL definition.
Throws:
SQLException - if an exception occurs while setting parameter values.

setUserForUpdateStatement

protected abstract void setUserForUpdateStatement(User user,
                                                  PreparedStatement userUpdate)
                                           throws SQLException
Deprecated. 
Set parameters of a PreparedStatement object with property values from a User instance. Implementations of this method have knowledge of the parameter ordering of the "update" SQL statement definition.

Parameters:
user - a User instance, which should be an implementation class which is handled by this Repostory implementation.
userUpdate - a PreparedStatement initialised with SQL taken from the "update" SQL definition.
Throws:
SQLException - if an exception occurs while setting parameter values.


Copyright © 2002-2012 The Apache Software Foundation. All Rights Reserved.